anchor = {
	init : function()  {
		$("a.anchorLink").click(function () {	
			elementClick = $(this).attr("href")
			destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100 );
			return false;
		})
	}
}

currentTab = 1;	

function showSidebarTab(showTabID){
		
	$("#"+currentTab).removeClass("current-tab");
	$("#"+showTabID).addClass("current-tab");
	$("#tab-"+currentTab).hide();					   
	$("#tab-"+showTabID).show();
	currentTab = showTabID;

}

$(document).ready(function(){
				/*		   
	$("#googleMapLink_wheretobuy").click(function(event) { $("#googleMap_wheretobuy").load("/wp-content/themes/ecotech/includes/google_map.php"); });
	$("#googleMapLink_wheretobuy_deux").click(function(event) { $("#googleMap_wheretobuy_deux").load("/wp-content/themes/ecotech/includes/google_map.php"); });
	$("#googleMapLink").click(function(event) { $("#googleMap").load("/wp-content/themes/ecotech/includes/google_map.php"); });
				*/
	var activeThumb = false;				

	$(".thumb-image").click(function(){
									 
		if (activeThumb != true) {
			
			activeThumb = true;
		
			theImageID = this.id;
			
			if (theImageID == 1) {
				$("#2").fadeTo(500, .3);
				$("#3").fadeTo(500, .3);
			} else if (theImageID == 2) {
				$("#1").fadeTo(500, .3);
				$("#3").fadeTo(500, .3);
			} else if (theImageID == 3) {
				$("#1").fadeTo(500, .3);
				$("#2").fadeTo(500, .3);
			}
			
			$("#coverup_" + theImageID).fadeIn("normal");
			$("#pump_" + theImageID + "_image").fadeIn(1600).fadeTo(700, 1, function(){ $("#coverup_" + theImageID).fadeOut("slow"); }).fadeOut(1000, function() {
			
			if (theImageID == 1) {
				$("#2").fadeTo(200,1);
				$("#3").fadeTo(200,1);
			} else if (theImageID == 2) {
				$("#1").fadeTo(200,1);
				$("#3").fadeTo(200,1);
			} else if (theImageID == 3) {
				$("#1").fadeTo(200,1);
				$("#2").fadeTo(200,1);
			} activeThumb = false; });
		
		}
		
    });
						   
	anchor.init();
	
	showSidebarTab(1);

	// NEXT SLIDE
	$("div.subpage-tabs .tab").click(function(event){
		
		tabID = this.id;
		
		$("#"+currentTab).removeClass("current-tab");
		$("#"+tabID).addClass("current-tab");
		$("#tab-"+currentTab).fadeOut("fast", function() {
												   
			$("#tab-"+tabID).fadeIn("fast");
			currentTab = tabID;
			
			//Cookies
			var expire = new Date();
			var today = new Date();
			expire.setTime(today.getTime() + 3600000*24);
			document.cookie = "tabID="+currentTab+";expires="+expire.toGMTString();

		});

	});
	
	// Set up the slide
	
	$('.white-bg').hide();
	
	var slideid = 1;
	var animation_active = false;
	var totalSlides = 6;
	
	// This initially hides all of the slides except the first one
	for (tempSlideNum=2;tempSlideNum<=totalSlides;tempSlideNum=tempSlideNum+1) 
	{
		$("#slide-"+tempSlideNum).hide();
	}
	
	// Set up the slide functionality
	$("li.slide-link").click(function(event){
									  
		idName = this.id;
		if (idName == "one") { trueID = 1; } else
		if (idName == "two") { trueID = 2; } else
		if (idName == "three") { trueID = 3; } else 
		//nazka
		if (idName == "four") { trueID = 4; } else
		if (idName == "five") { trueID = 5; } else{ trueID = 6; }
									  					  
		if (trueID != slideid && animation_active == false) {
			
			animation_active = true;
			
			if (slideid == 1) { oldidName = "one"; } else
			if (slideid == 2) { oldidName = "two"; } else
			if (slideid == 3) { oldidName = "three"; } else
			//nazka
			if (slideid == 4) { oldidName = "four"; } else 
			if (slideid == 5) { oldidName = "five"; } else { oldidName = "six"; }
			
			$("ul.slide-links").find('li#'+oldidName).removeClass("active");
			newslideid = trueID;
			$("ul.slide-links").find('li#'+idName).addClass("active");
			
			$("#slide-"+slideid).animate({'top':'-400px'},600, 'easeInQuint', function(){
															
				$("#slide-"+slideid).hide();
				
				// Wait until the above has finished, then do the rest
	
				slideid = newslideid;
				
				if (slideid == 1) {
					$('.white-bg').fadeOut('normal');
				} else {
					$('.white-bg').fadeIn('normal');
				}
				
				$("#slide-"+slideid).css('top',"400px");
				$("#slide-"+slideid).show();
				
				$("#slide-"+slideid).animate({'top':'0'},{duration:600, easing:'easeOutExpo'});
				
				animation_active = false;
				
			});
		
		}
		
	});
	
	
	
	
	// Set up the Slide Gallery slider
	var gallerySlide = 1; // The initial slide (First one)
	var gallery_animation_active = false;
	
	// This initially hides all of the slides except the first one
	for (tempGallerySlideNum=2;tempGallerySlideNum<=total_gallery_slides;tempGallerySlideNum=tempGallerySlideNum+1) 
	{
		$("#gallery-"+tempGallerySlideNum).hide();
	}
	
	// NEXT SLIDE
	$("span.pagination").click(function(event){
														  
		if (this.id != gallerySlide && gallery_animation_active == false) {
			
			gallery_animation_active = true;
			
			if (this.id == "next") {
				if (gallerySlide != total_gallery_slides) {
					whatClicked = "next";
					newgalleryslideID = gallerySlide + 1;
					abort = false;
					if (newgalleryslideID != total_gallery_slides) {
						$('.pagination#next').fadeIn("normal");
						$('.pagination#previous').fadeIn("normal");
					} else {
						$('.pagination#next').fadeOut("normal");
						$('.pagination#previous').fadeIn("normal");
					}
				} else {
					abort = true;
				}
			} else {
				if (gallerySlide != 1) {
					whatClicked = "previous";
					newgalleryslideID = gallerySlide - 1;
					abort = false;
					if (newgalleryslideID != 1) {
						$('.pagination#previous').fadeIn("normal");
						$('.pagination#next').fadeIn("normal");
					} else { 
						$('.pagination#previous').fadeOut("normal");
						$('.pagination#next').fadeIn("normal");
					}
				} else {
					abort = true;
				}
			}
			
			if (abort == true) {
				gallery_animation_active = false;
			} else {
				
				theSpeed = 400;
				
				if (whatClicked == "next") {
					positionOne = "-333px";
					positionTwo = "333px";
					positionThree = "0";
				}
				
				if (whatClicked == "previous") {
					positionOne = "333px";
					positionTwo = "-333px";
					positionThree = "0";
				}
		
				$("#gallery-"+gallerySlide).animate({left:positionOne},theSpeed, "easeInQuint", function(){
																					
					// Wait until the above has finished, then do the rest
					gallerySlide = newgalleryslideID;
					
					$("#gallery-"+gallerySlide).css("left",positionTwo);
					$("#gallery-"+gallerySlide).show();
					$("#gallery-"+gallerySlide).animate({left:positionThree},theSpeed, "easeOutExpo", function(){
					
						gallery_animation_active = false;

					});
					
				});
			
			}
		
		}
		
	});
	
});