var stop=1;
$(document).ready(function() {
	

		 // tabs1
	//When page loads...
		$(".tab_content1").hide(); //Hide all content
		$(".toc1 li:first").addClass("active").show(); //Activate first tab
		$(".tab_content1:first").show(); //Show first tab content
	
		//On Click Event
		$(".toc1 li").click(function() {
	
			$(".toc1 li").removeClass("active"); //Remove any "active" class
			$(this).addClass("active"); //Add "active" class to selected tab
			$(".tab_content1").hide(); //Hide all tab content
	
			var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
			$(activeTab).fadeIn(); //Fade in the active ID content
			return false;
		});
	   


		 // tabs2
	//When page loads...
		$(".tab_content2").hide(); //Hide all content
		$(".toc2 li:first").addClass("active").show(); //Activate first tab
		$(".tab_content2:first").show(); //Show first tab content
	
		//On Click Event
		$(".toc2 li").click(function() {
	
			$(".toc2 li").removeClass("active"); //Remove any "active" class
			$(this).addClass("active"); //Add "active" class to selected tab
			$(".tab_content2").hide(); //Hide all tab content
	
			var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
			$(activeTab).fadeIn(); //Fade in the active ID content
			return false;
		});
		
		
		 // tabs3
	//When page loads...
		$(".tab_content3").hide(); //Hide all content
		$(".toc3 li:first").addClass("active").show(); //Activate first tab
		$(".tab_content3:first").show(); //Show first tab content
	
		//On Click Event
		$(".toc3 li").click(function() {
	
			$(".toc3 li").removeClass("active"); //Remove any "active" class
			$(this).addClass("active"); //Add "active" class to selected tab
			$(".tab_content3").hide(); //Hide all tab content
	
			var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
			$(activeTab).fadeIn(); //Fade in the active ID content
			return false;
		});
		
		
	
	 	 //j carousel
	    $('#mycarousel1, #mycarousel2, #mycarousel3, #mycarousel4, #mycarousel5, #mycarousel6, #mycarousel7, #mycarousel8, #mycarousel9, #mycarousel10, #mycarousel11, #mycarousel12, #mycarousel13').jcarousel({
	    	scroll: '1',
	    	wrap: 'both'
	    });
    
    	//fancy
       $("a.fancy").fancybox();

	
	 //open cautare avansata
	 $('#cautareAvansata_open').click(function(){
		if ($('#cautare_avansata').is(':visible'))
			$('#cautare_avansata').hide();
		else
			$('#cautare_avansata').show();
		return false;
	});
	
	$('.thumbsImg ul li a').click(function(){
		var aThumb = '#big_'+$(this).attr('id');
		$('.mainImg div:visible').fadeOut('slow');
		$(aThumb).fadeIn('fast');
		return false;
	});
	
	
	$('#slideshow').cycle({ 
	    fx:     'fade', 
	    prev:   '#prev', 
   	 	next:   '#next', 
    	after:   onAfter, 
    	pager:  '#mycarousel', 
    	timeout: 0, 
	
	
	    // callback fn that creates a thumbnail to use as pager anchor 
	    pagerAnchorBuilder: function(idx, slide) { 
	        return '<li><a href="#"><img src="images/thumb' + idx + '.jpg" /></a></li>'; 
	    }
	  
	});
	
	 //service
	 
	 $('a.openServ').click(function(){
	 	$('.list_container ul li').css('height','71px');
	 	$(this).parent().parent().css('height','auto');
	 	return false;
	 });
	
	//multiselect
	 //$("#zonas").multiselect();
	 
	 
});


function onAfter(curr, next, opts) {
    var index = opts.currSlide;
   	$('#prev')[index == 0 ? 'hide' : 'show']();
   	$('#next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
}
//asta ii pt slideru de pe pag detalii
function changeImg(id){
	$('#picsBig img:visible').fadeOut('slow');
	$('#detail_'+id).fadeIn('slow');
}

function scroll_thumbs_top(id) {
	if(stop==1){
		var test = jQuery('.thumbsImg ul').children().size();
		arrow=((-140)*(test-4))+'px';
		if (test % 1 == 0) {var test = test + 1;}
		stop=0;
		
		var top=$('.thumbsImg ul').css('top');

	  $('.thumbsImg ul').animate({
	    top: ((top=='0px')?'':'+=140')
	  }, 500, function() {
		  	if(top==arrow) $('a.bottomArrow').attr('style','visibility:visible');
	 		if(top=='-140px') $('a.topArrow').attr('style','visibility:hidden');
	  		stop=1;
	  });
	}

}

function scroll_thumbs_down(id) {
	if(stop==1){
		
		var test = jQuery('.thumbsImg ul').children().size();
		
		test2=((-140)*(test-4))+'px';
		
		if (test>4)
			arrow=((-140)*(test-5))+'px';
		else
			arrow=((-140)*(test-1))+'px'; 
		stop=0;

		var top=$('.thumbsImg ul').css('top');
		  $('.thumbsImg ul').animate({
	    top: ((top==test2)?'-=0':'-=140')
	 	 }, 500, function() {
	 		 if(top==arrow) {
	 			$('a.bottomArrow').attr('style','visibility:hidden');
	 		 }
	 		 if(top=='0px' || top=='auto') $('a.topArrow').attr('style','visibility:visible');
	 	 	stop=1;
	 	 });
	}

}


