$(document).ready(function() {
	$('.home_carousel').each(function(){
		var carousel_id = $(this).attr("id");
		
		$('#'+carousel_id).jcarousel({
			id: carousel_id,
			auto:10,
			scroll:1,
			wrap: 'last',
			initCallback: homecarousel_initCallback,
			itemVisibleInCallback:homecarousel_itemVisibleInCallback
		});
		
	});							   
});
/* ----------------------------------------------------------------- */
function homecarousel_initCallback(carousel, state) {			
	$("#"+carousel.options.id+' .jcarousel-control a').bind('click', function() {
		carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr( "item" )));
		//carousel.stopAuto();
		return false;
	});	
	$("#"+carousel.options.id+' .jcarousel-control a').hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
	
	
	$('#'+carousel.options.id+' .jcarousel-small-list a').bind('click', function() {
		$id = $(this).attr("item");
		carousel.scroll(jQuery.jcarousel.intval($id));
		return false;
	});
	$('#'+carousel.options.id+' .jcarousel-small-list a, #'+carousel.options.id+' .jcarousel-clip .jcarousel-items').hover(function() {
        carousel.stopAuto();
		console.log("stop");
    }, function() {
        carousel.startAuto();
		console.log("start");
    });

	$('#'+carousel.options.id+' .jcarousel-prev').bind('click', function() {
		carousel.prev();
		return false;
	});
	$('#'+carousel.options.id+' .jcarousel-next').bind('click', function() {
		carousel.next();
		return false;
	});
	$("#"+carousel.options.id+' .jcarousel-prev, #'+carousel.options.id+' .jcarousel-next').hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
	
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });	
};
function homecarousel_itemVisibleInCallback(carousel,list,idx)
{
	$("#"+carousel.options.id+" .jcarousel-control").children(".selected").removeClass("selected");
	$("#"+carousel.options.id+" .jcarousel-control").children("#control_"+idx).addClass( "selected" );
	
	$("#"+carousel.options.id+" .jcarousel-list").children(".selected").removeClass("selected");
	$("#"+carousel.options.id+" .jcarousel-list").children("#item_"+idx).addClass( "selected" );
	
	$("#"+carousel.options.id+" .jcarousel-small-list").children(".selected").removeClass("selected");
	$("#"+carousel.options.id+" .jcarousel-small-list").children("#small_item_"+idx).addClass( "selected" );
}
/* ----------------------------------------------------------------- */

function FormFocus(obj) {
	if(obj.value==obj.defaultValue) obj.value='';
}

function FormBlur(obj) {
	if(obj.value=='') obj.value=obj.defaultValue;
}

function Promo(data)
{
	$promo_type = $(data["obj"]).attr("rel");
	$url = (data["url"])?data["url"]:window.location.href;
	
	switch($promo_type)
	{
		case 'email':
			OpenBox($url);
		break;
		
		case 'facebook':
			window.open('http://www.facebook.com/share.php?u='+encodeURI($url),'','width=600,height=400,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=1'); 
		break;
		
		case 'twitter':
			var status = ( data["status"]!=undefined && data["status"] )?data["status"]+" ":"";
			window.open('http://twitter.com/home?status='+status+encodeURI($url),'','width=600,height=400,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=1'); 
		break;
		
		case 'yahoo':
			window.location=encodeURI('ymsgr:im?msg='+($url));
		break;
		
		case 'linkedin':
			window.open('https://www.linkedin.com/cws/share?url='+encodeURI($url),'','width=600,height=400,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=1'); 
		break;
		
		case 'rss':
			if( data["url"] ){
				window.location=data["url"];
			}else{
				window.location='/rss.html';
			}			
		break;
	}
	return false;	
}

function Galerie(id)
{
	window.open("/popup_"+id+".html",'','width=800,height=630,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=0');
}
function GalerieVideo(id)
{
	window.open("/video_"+id+".html",'','width=800,height=630,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=0');
}


function CreateBookmarkLink() { 
	title = document.title;   // Blogger - Replace with <$BlogItemTitle$>   // MovableType - Replace with <$MTEntryTitle$> 
	url = window.location.href;  // Blogger - Replace with <$BlogItemPermalinkURL$>   // MovableType - Replace with <$MTEntryPermalink$>  // WordPress - <?php bloginfo('url'); ?>	
	if($.browser.msie){

		window.external.AddFavorite( url, title); 
	} else if( window.sidebar ) { // IE Favorite
		window.sidebar.addPanel(title, url,"");	
	}	else if(window.opera && window.print) { // Opera Hotlist		
		return true; 
	} 
} 



function OpenPrint(){
	window.open(window.location.href+'?print','print','width=700,height=500,scrollbars=yes');
}
function Show(obiect,day)
{
	var s=new jQuery(obiect);
	var position = s.position();
	
	$("#box_calendar_events").css("display","block");
	$("#box_calendar_events").css("left",position.left+20);
	$("#box_calendar_events").css("top",position.top +20);
	$("#box_calendar_events .body").html(ev[day]);
}


function Yahoo()
{
	window.location=encodeURI('ymsgr:im?msg='+(window.location.href));
}

//---------------------send email		
function SendEmail(url){
	if (CheckFormEmail()){
		  var name = $("input#name").val();
		  var email = $("input#email").val();
		  var name_friend = $("input#name_friend").val();
		  var email_friend = $("input#email_friend").val();
		  var id = $("input#id").val();
		  var dataString = 'send=send&id='+ id + '&name='+ name + '&email=' + email + '&name_friend=' + name_friend + '&email_friend=' + email_friend;
  		
		    $.ajax({
			  type: "POST",
			  url: url,
			  data: dataString,
			  success: function(data,text) {
				$("#box_email").html(data);
			  }
			});
			return false;
	}	 
}

function CheckFormEmail(){
	
	if( $("#name").attr("value") == "" )
	{
		alert( 'Nu ati completat campul Nume' );
		$('#name').focus();
		return false;
	}
	
	if( $('#email').attr("value") == "" )
	{
		alert( 'Nu ati completat campul Email' );
		$('#email').focus();
		return false;
	}
	var temp= new String($('#email').attr("value"));
	var len=temp.length - 3;
	if(temp=="" || temp.indexOf("@")<0 || temp.indexOf(".")<0 || temp.lastIndexOf(".")> len || temp.length-temp.lastIndexOf(".")>4)
	{
		alert("Va rugam introduceti o adresa de email corecta!");
	//	$('#email').attr("value") = "";
		$('#email').focus();
		return false;
	}
	
	
	if( $("#name_friend").attr("value") == "" )
	{
		alert( 'Nu ati completat campul Nume prieten' );
		$('#name_friend').focus();
		return false;
	}
	
	
	if( $('#email_friend').attr("value") == "" )
	{
		alert( 'Nu ati completat campul Email' );
		$('#email_friend').focus();
		return false;
	}
	var temp= new String($('#email_friend').attr("value"));
	var len=temp.length - 3;
	if(temp=="" || temp.indexOf("@")<0 || temp.indexOf(".")<0 || temp.lastIndexOf(".")> len || temp.length-temp.lastIndexOf(".")>4)
	{
		alert("Va rugam introduceti o adresa de email corecta!");
	//	$('#email').attr("value") = "";
		$('#email_friend').focus();
		return false;
	}
	
	return true;
}

function OpenBox(url){
	if( !$("#box_email").size() )
	{
		$("<div/>").attr("id","box_email").appendTo("body");
	}
	
	$("#box_email").load(url);
	 
	ttop=0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		ttop=window.pageYOffset;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
		ttop=document.documentElement.scrollTop;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
		ttop=document.body.scrollTop;
	}

	l = (myWidth-700)/2;
	t = (myHeight-250)/2+ttop ; 
	
	 $('#box_email').css('left',l+'px');
	 $('#box_email').css('top' , t+'px'); 
	 
	 $('#box_email').css('display','block');
}

function Close(name){
	$('#'+name).css('display','none');
} 
function ChangeMonthCalendar(year,month)
{
	$("#box_calendar").load('/calendar_show.php?year='+year+"&month="+month);
}

function countChar(text,div,numar_caractere) {	
	val = text.value;
	if (val.length > numar_caractere) {
		alert('Textul dumneavoastra depaseste limita de '+numar_caractere+' de caractere!');
		text.value = val.substring(0,numar_caractere);
		text.focus();
	}
	document.getElementById(div).innerHTML = parseInt(val.length);
}


function sidebar_discuri_toggle()
{
	$('#sidebar_discuri_closed').toggle();
	$('#sidebar_discuri_contents').toggle();
}

function sidebar_interviuri_toggle()
{
	$('#sidebar_interviuri_closed').toggle();
	$('#sidebar_interviuri_contents').toggle();
}

function sidebar_concerte_toggle()
{
	$('#sidebar_concerte_closed').toggle();
	$('#sidebar_concerte_contents').toggle();
}

function sidebar_nworm_toggle()
{
	$('#sidebar_nworm_closed').toggle();
	$('#sidebar_nworm_contents').toggle();
}

function sidebar_metalfans_toggle()
{
	$('#sidebar_metalfans_closed').toggle();
	$('#sidebar_metalfans_contents').toggle();
}

