// JavaScript Document



$(function() {
	
	
	NiftyLoad=function(){
				Nifty("#meniu-principal","transparent big tl br");
				Nifty("#zona-pagina-c","transparent big br fixed-height");
				Nifty("div.block-s","transparent big bl tr");
				Nifty("div.block-d","transparent big br");
			}


	jQuery.preloadImages = function(){
	  for(var i = 0; i<arguments.length-2; i++){
		    //jQuery("<img>").attr("src", arguments[i]);
			  }
		}


	$(".video-zep").fancybox({
				'titleShow'		: 'true',
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic',
				'type'			: 'iframe',
				'autoDimensions': 'false',
				'width'   		: 720,
				'height'   		: 570
			});
// ************************************************* SLIDESHOW BANNER UP
	//$('ul#imagini > li').scramble();
	$('ul#imagini > li').not(':first').hide();
	
	_C = 0;
	$('#controler').css('background', 'url(../img/fundal-02.jpg) center no-repeat');
	
	function next(){
		$('#imagini > li').eq(_C).fadeOut('slow',gogo);
		}
	function gogo(){
		_C = (_C < $('#imagini > li').length-1)?_C+1:0;
		L = $('#imagini > li').size(); 
		C = _C+2;
		if (C > L) {C=1;}

		_Cc = (_C<9)?'0'+C:C;
		$('#controler').css('background', 'url(../img/fundal-' + _Cc + '.jpg) center no-repeat');
		$('#imagini > li').eq(_C).show();
		
		}
	
	//clearInterval(TT);
	var TT=setInterval(function(){
		next();
		},4000);
// ************************************************* SLIDESHOW BANNER UP





	
	var $nr_c=0;
	var $nr_t=7;
	var lista_fundal =		 Array(1,1,3,3,5,5,7,7);
	var lista_fundal_next =  Array(1,2,2,4,4,6,6,1);
	
/*	$(document).bind('FUNDAL-SCHIMBARE',
					 function(){
						 if ($nr_c % 2 == 1) $("#pre-zona-banner").fadeOut("slow");
						 else $("#pre-zona-banner").fadeIn("slow");
						 $("#pre-zona-banner").css({background:'url(../img/fundal-0' + lista_fundal[$nr_c] + '.jpg)'});
						 $("#zona-banner").css({background:'url(../img/fundal-0' + lista_fundal_next[$nr_c] + '.jpg)'});

						 $("#pre-zona-banner").animate({opacity:'1'},5000, 
													  function(){
														  $nr_c = ($nr_c < $nr_t)?$nr_c+1:0;
														  $(document).trigger('FUNDAL-SCHIMBARE');
														  });
						 });
	$(document).trigger('FUNDAL-SCHIMBARE');*/
	
	
	
	// Limba si butonul de schimbare al limbii
	$("a","#alege-limba").click(function(e){e.preventDefault();
		var lang = "ro";
		var langOpus = "en";
		var amRO = window.location.pathname.search("/ro/");	
		var amEN = window.location.pathname.search("/en/");
		if (amRO == -1) {lang="en"; langOpus="ro";}
		var adr = window.location.pathname.replace("/" + lang + "/", "/" + langOpus + "/");
		window.location.replace(adr);
	});
	
	
	$("a[href$='.pdf']").not("a:has(img)").addClass("pdf");
	$("a[href$='.pdf']").attr("target","_blank");
	$("a[href$='.pdf']").live("click",function(e){$(this).attr("target","_blank");});
	$("a[href^='http://']").attr("target","_blank");
	$("a[href^='#']").live("click",function(e){e.preventDefault();});
	
	
	
	$("a[href='#inapoi']").click(function(e){ history.go(-1);});
	$("a[href='#sus']").live("click",function(e){ $.scrollTo("#website",{duration:1000});});

	
	$("#lista-membri li:first").show();
	$(document).bind('SLIDE-MEMBRI-CICLU-COMPLET',function(){
		$("#lista-membri li:first").fadeOut('slow', function(){
								 var lista = $(this).parent().get(0);
								 $(this).appendTo(lista);
								 $("li:first", lista).fadeIn("slow");
								 $(lista).animate({opacity:'1'},3500, function(){
									    $(document).trigger("SLIDE-MEMBRI-CICLU-COMPLET");
										});
								 });
	
		   });
	$(document).trigger('SLIDE-MEMBRI-CICLU-COMPLET');
	



	// transferul de informatie de pe pagina de stiatica + pornire sau ne-pornire slideshow
	$("#lista-tips-load").load("stiatica.html #lista-tips", function(){
		//$("#lista-tips-load").replaceWith("");
		if ($("#lista-tips").children().size()>1){
		$(document).trigger('SLIDE-TIPS-CICLU-COMPLET');}
		else{$("#lista-tips li:first").fadeIn("slow");}
														});	
	
	$("li:first","#lista-tips-load").show();
	$(document).bind('SLIDE-TIPS-CICLU-COMPLET',function(event, semn){
		directia = (semn=="-1")?-1:1;
		$("li:first","#lista-tips").animate({marginLeft:directia*180 + 'px'}, function(){
								 var lista = $(this).parent().get(0);
								 $(this).css("margin-left","0");
								 $(this).hide();
								 if (directia > 0) $("li:last","#lista-tips").prependTo(lista);
								 else $(this).appendTo(lista);
								 
								 $("li:first", lista).css("margin-left",-1*directia*200+"px");
								 $("li:first", lista).fadeIn("fast");
								 $("li:first", lista).animate({marginLeft:'0'});
								 $(lista).animate({opacity:'1'},5000, function(){
									   // $(document).trigger("SLIDE-TIPS-CICLU-COMPLET");
										});
								 });
		   });
	//$(document).trigger('SLIDE-TIPS-CICLU-COMPLET');
	
	$("#tip-left").hover(
						 function(){$(this).attr("src","../img/bt-stg-over.jpg")},
						 function(){$(this).attr("src","../img/bt-stg.jpg")}
						 );
	$("#tip-right").hover(function(){$(this).attr("src","../img/bt-dpt-over.jpg")},function(){$(this).attr("src","../img/bt-dpt.jpg")});
	$("#tip-left").click(function(){
						  $(document).trigger("SLIDE-TIPS-CICLU-COMPLET",["1"]);
						  });
	$("#tip-right").click(function(){
						   $(document).trigger("SLIDE-TIPS-CICLU-COMPLET",["-1"]);
						   });
	
	// transferul de informatie de pe pagina de calendar
	$("#lista-calendarpagina-load").load("calendar.html #lista-calendar > li", function(response, status, xhr) {
		  if (status != "error") {
			$("#lista-calendarpagina-load >li:gt(2)").remove();
		  }
		  
		  });
	




	// transferul de informatie de pe pagina de noutati + pornire sau ne-pornire slideshow
	$("#lista-noutatipagina-load").load("noutati.html #lista-noutati > li", function(response, status, xhr) {
		  if (status != "error") {
			$("#lista-noutatipagina-load >li:gt(2)").remove();
		  }
		  
		  });
		  
	$("#lista-noutati-load").parent(".continut").load("noutati.html #lista-noutati",
													  function(){
		$("#lista-noutati-load").replaceWith("");
		if ($("#lista-noutati").children().size()>1){
		$(document).trigger('SLIDE-NOUTATI-CICLU-COMPLET');
		}
		else{$("#lista-noutati li:first").fadeIn("slow");}
														});
	
	$("#lista-noutati li:first").show();
	$(document).bind('SLIDE-NOUTATI-CICLU-COMPLET',function(){
		$("#lista-noutati li:first").fadeOut('slow', function(){
								 var lista = $(this).parent().get(0);
								 $(this).appendTo(lista);
								 $("li:first", lista).fadeIn("fast");
								 var T = setTimeout(function(){$(document).trigger("SLIDE-NOUTATI-CICLU-COMPLET");},7000);
								 //$(lista).animate({opacity:'1'},7000, function(){});
								 });
		   });



	$("#lista-brosura li:first").show();
	$(document).bind('SLIDE-BROSURA-CICLU-COMPLET',function(){
		$("#lista-brosura li:first").fadeOut('slow', function(){
								 var lista = $(this).parent().get(0);
								 $(this).appendTo(lista);
								 $("li:first", lista).fadeIn("slow");
								 var Tm = setTimeout(function(){
									    $(document).trigger("SLIDE-BROSURA-CICLU-COMPLET");
										},7000);
								 });
	
		   });
	$(document).trigger('SLIDE-BROSURA-CICLU-COMPLET');

});
