﻿
$(document).ready(function() {	
 
  //Set variables
  var HideShowButton = $("a.collapse");
  var MainImageDescription = $(".main_image .block");
  var MainImage = $(".main_image");
	var imgWidth = MainImage.width(); 	
  var imgHeight = MainImage.height(); 	
	var imgDescHeight = MainImage.find('.block').height();	//Calculate height of block	


	//Show Banner
	$(".main_image .desc").show(); //Show Banner
	MainImageDescription.animate({ opacity: 0.85 }, 1 ); //Set Opacity
 
	//Click and Hover events for thumbnail list
	$(".image_thumb ul li:first").addClass('active'); 
	$(".image_thumb ul li").click(function(){ 
		//Set Variables
		var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
		var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
		var imgDesc = $(this).find('.block').html(); 	//Get HTML of block

		if ($(this).is(".active")) {  //If it's already active, then...
			return false; // Don't click through
		}
    else {
      //Animate image 
      $(".main_image img").attr({ src: imgTitle , alt: imgAlt}); //change image
      $(".main_image img").css({"margin-left": imgWidth}); //move image to the right, offscreen
      MainImageDescription.hide(); //hide the desc block
      $(".desc a").hide();

      $(".main_image img").stop().animate({marginLeft : 0}, 1000, function(){
          
          //Set button to (-) Hide
          HideShowButton.removeClass("show");
          HideShowButton.removeClass("collapse");
          HideShowButton.addClass("collapse");

          //Animate the block desc after the image slides to the left
          MainImageDescription.animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() {
          $(".desc a").show();      
          MainImageDescription.show();			
			    MainImageDescription.html(imgDesc).animate({ opacity: 0.85,	marginBottom: "0" }, 250);
   		  });
      });
		}
		
		$(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all lists
		$(this).addClass('active');  //add class of 'active' on this list only
		return false;
		
	}) .hover(function(){
		$(this).addClass('hover');
		}, function() {
		$(this).removeClass('hover');
	});
			
	//Toggle Teaser
  HideShowButton.click(function(){
		MainImageDescription.slideToggle();
    HideShowButton.toggleClass("show");
	});
	
});//Close Function

