var sliderTimer;
var left;
var kid = 1;
var kids = 0;
var stop=1;
var pagina=0;
$(document).ready(function(){

	var w = $(window).width();

	// position fix
	left = (w/2)-495;
	width = 990-left;

	$('#slide_left').css('left','-'+width+'px');
	$('#slide_right').css('width',left+'px');

	// kids ?
	kids = $('#slider ul').children().size();

	// fancybox
	$("a.view").fancybox({
		centerOnScroll: false
	});

});
function goclick_left() {
	clearInterval(slider);
	if(stop==1){
		var test = jQuery('#slide_left ul').children().size();
		if (test % 1 == 0) {var test = test + 1;}
		stop=0;

		//alert(test);
		var left=$('#slide_left ul').css('left');

		  $('#slide_left ul').animate({
		    left: ((left=='0px')?'':'+=990')
		  }, 500, function() {
		  	stop=1;
		    // Animation complete.
		  });
		  
		 //alert(test);
		var left=$('#slider ul').css('left');

		  $('#slider ul').animate({
		    left: ((left=='0px')?'':'+=990')
		  }, 500, function() {
		  	stop=1;
		    // Animation complete.
		  });
		  
		  if(left=='-990px') {
		  	jQuery('.s_left').css({visibility: 'hidden'});
		  }
		  jQuery('.s_right').css({visibility: 'visible'});
		  
		 //alert(test);
		var left=$('#slide_right ul').css('left');

		  $('#slide_right ul').animate({
		    left: ((left=='0px')?'':'+=990')
		  }, 500, function() {
		  	stop=1;
		    // Animation complete.
		  });
		  
		  
		  

	}

}

function goclick_right() {
	clearInterval(slider);
	if(stop==1){
		var test = jQuery('#slide_left ul').children().size();
		test2=((-990)*(test-2))+'px';
		test3=((-990)*(test-2))+990+'px';
		stop=0;

		var left=$('#slide_left ul').css('left');
		  $('#slide_left ul').animate({
		    left: ((left==test2)?'-=0':'-=990')
		  }, 500, function() {
		  		stop=1;
		    // Animation complete.
		  });
		  
		  var left=$('#slider ul').css('left');
		  $('#slider ul').animate({
		    left: ((left==test2)?'-=0':'-=990')
		  }, 500, function() {
		  		stop=1;
		    // Animation complete.
		  });
		  
		  if(left==test3) {
		  	jQuery('.s_right').css({visibility: 'hidden'});
		  }
		  jQuery('.s_left').css({visibility: 'visible'});
		  
		  var left=$('#slide_right ul').css('left');
		  $('#slide_right ul').animate({
		    left: ((left==test2)?'-=0':'-=990')
		  }, 500, function() {
		  		stop=1;
		    // Animation complete.
		  });
		  
		   
	}

}

$(window).load(function () {
	// let`s play
	slider = setInterval("go();",5000);
});




function go() {

	// left slider
	$('#slide_left ul').animate({
		left: '-'+(kid*990)+'px'
	}, function(){
		if(kid==kids) {
			$('#slide_left ul').css('left','0px');
		}
	});

	// main slider
	$('#slider ul').animate({
		left: '-'+(kid*990)+'px'
	}, function(){
		if(kid==kids) {
			$('#slider ul').css('left','0px');
		}
	});

	// right slider
	$('#slide_right ul').animate({
		left: '-'+(kid*990)+'px'
	}, function(){
		if(kid==kids) {
			$('#slide_right ul').css('left','0px');
			kid = 1;
		}
	});

	kid++;

}

function scroll_gallery_left() {
	if(stop==1){
		var test = jQuery('#showcaseInfo ul').children().size();
		if (test % 1 == 0) {var test = test + 1;}
		stop=0;

		//alert(test);
		var left=$('#showcaseInfo ul').css('left');

		  $('#showcaseInfo ul').animate({
		    left: ((left=='0px')?'':'+=130')
		  }, 500, function() {
		  	stop=1;
		    // Animation complete.
		  });
	}
}
function scroll_gallery_right() {
	if(stop==1){
		var test = jQuery('#showcaseInfo ul').children().size();
		test2=((-130)*(test-7))+'px';
		stop=0;

			var left=$('#showcaseInfo ul').css('left');
	  $('#showcaseInfo ul').animate({
	    left: ((left==test2)?'-=0':'-=130')
	  }, 500, function() {
	  		stop=1;
	    // Animation complete.
	  });
	}

}
function scroll_gallery_left2(id) {
	if(stop==1){
		var test = jQuery('#showcaseInfo_'+id+' ul').children().size();
		if (test % 1 == 0) {var test = test + 1;}
		stop=0;
		//alert(test);
		var left=$('#showcaseInfo_'+id+' ul').css('left');

	  $('#showcaseInfo_'+id+' ul').animate({
	    left: ((left=='0px')?'':'+=130')
	  }, 500, function() {
	  		stop=1;
	    // Animation complete.
	  });
	}


}
function scroll_gallery_right2(id) {
	if(stop==1){
		var test = jQuery('#showcaseInfo_'+id+' ul').children().size();
		test2=((-130)*(test-7))+'px';
		stop=0;

		var left=$('#showcaseInfo_'+id+' ul').css('left');
		  $('#showcaseInfo_'+id+' ul').animate({
	    left: ((left==test2)?'-=0':'-=130')
	 	 }, 500, function() {
	 	 	stop=1;
	 	   // Animation complete.
	 	 });
	}

}

function scroll_pics_up() {
	if(stop==1){
		var test = jQuery('#showcases ul').children().size();
		if (test % 1 == 0) {var test = test + 1;}
		stop=0;

			//alert(test);
			var top=$('#showcases ul').css('top');

		  $('#showcases ul').animate({
		    top: ((top=='0px')?'':'+=110')
		  }, 1000, function() {
		    // Animation complete.
		    stop=1;
		  });
	}
}

function scroll_pics_down() {
	if(stop==1){
		var test = jQuery('#showcases ul').children().size();

		if(test%3==0) { var test= test;}
		if((test+1)%3==0) { var test= test+1;}
		if((test+2)%3==0) { var test= test+2;}


		test2=((-110)*((test/3)-3))+'px';
		stop=0;

			var top=$('#showcases ul').css('top');
		  $('#showcases ul').animate({
		    top: ((top==test2)?'-=0':'-=110')

		  }, 1000, function() {
		    // Animation complete.
		     stop=1;
		  });
	}
}

function scroll_news_left() {
	if(stop==1){
		var test = jQuery('#showcaseInfo ul').children().size();
		if (test % 1 == 0) {var test = test + 1;}
		stop=0;

		//alert(test);
		var left=$('#showcaseInfo ul').css('left');

		  $('#showcaseInfo ul').animate({
		    left: ((left=='0px')?'':'+=569')
		  }, 500, function() {
		  	stop=1;
		    // Animation complete.
		  });

	}

}

function scroll_news_right() {
	if(stop==1){
		var test = jQuery('#showcaseInfo ul').children().size();
		test2=((-569)*(test-1))+'px';
		stop=0;

			var left=$('#showcaseInfo ul').css('left');
	  $('#showcaseInfo ul').animate({
	    left: ((left==test2)?'-=0':'-=569')
	  }, 500, function() {
	  		stop=1;
	    // Animation complete.
	  });
	}

}

function contact() {

	//eror
	var error='';


	// start
	// jQuery('.buton2').addClass('loading');

	// info
	var nume = jQuery('#nume').val();
	var mail = jQuery('#email').val();
	var telefon = jQuery('#telefon').val();
	var subiect = jQuery('#subiect').val();
	var mesaj = jQuery('#mesaj').val();

	// check
	if(nume.length==0 || nume==' ') error += 'Nu ati completat campul Nume si Prenume <br />';
	if(mail.length==0 || mail==' ') error += 'Nu ati completat campul Email <br />';
	else{
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		if(reg.test(mail) == false) error += 'Adresa de e-mail invalida <br />';
	}

	if(mesaj.length==0 || mesaj==' ') error += 'Nu ati completat campul Mesaj <br />';

	if(error.length==0) {

		jQuery('.flerror2').slideUp('slow');

		// post
		jQuery.post('ajax.php?a=contact',
			{

				nume: nume,
				mail: mail,
				telefon: telefon,
				subiect: subiect,
				mesaj: mesaj

			},
				function(data)
					{

						// afisare ok
						jQuery('.flerror').fadeIn('fast');
						jQuery('#nume').val('');
						jQuery('#email').val('');
						jQuery('#telefon').val('');
						jQuery('#subiect').val('');
						jQuery('#mesaj').val('');
						// stop
						// jQuery('.buton2').removeClass('loading');

					}
		);

	} else {
		 // jQuery('.buton2').removeClass('loading');
		jQuery('.flerror2 p').html(error);
		jQuery('.flerror2').slideDown('slow');
	}

}

function showDespre(){
	if(jQuery('#maimultd').text()=='[Citeste mai mult]'){

		var url = "ajax.php?a=showDespre";
		$.post(url, {tip:'open'},function(data) {
			jQuery('#continut').html(data);
		});
	}
	else {
		var url = "ajax.php?a=showDespre";
		$.post(url, {tip:'close'},function(data) {
			jQuery('#continut').html(data);
		});
	}
}