// JavaScript Document

$(document).ready(function() { 
 //Show Banner
 var i = 0;
 $(".main_image").each(function(){
i ++;

var containerID = this;
 if ($(".gallery",containerID).length > 0) {
 $("img",containerID).first().css("display", "none");
 $(".block",containerID).css("display", "none");
 $("a.collapse",containerID).css("display", "none");
 }
 else
 {
	 var firstItem = $(".image_thumb"+i+" ul li:first");
	$("img",containerID).first().fadeIn(1000);
	 
	 if ($("a",containerID).attr("title") == "") {
		$("a.collapse",containerID).fadeIn(1000);
		$(".block",containerID).show();
	 }

  var imgAlt = $(firstItem).find('img').attr("alt"); //Get Alt Tag of Image
  var imgTitle = $(firstItem).find('a.mainImg').attr("href"); //Get Main Image URL
  var imgDesc = $(firstItem).find('.block').html();  //Get HTML of block
  var imgDescHeight = $(firstItem).find('.block').height(); //Calculate height of block 

    $(".block",containerID).animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() {
    $(".block",containerID).html(imgDesc).animate({ opacity: 1.0, marginBottom: "0" }, 250 );
	
    $("img.mainImg",containerID).attr({ src: imgTitle , alt: imgAlt}); 
	});
 }

 
 
 $(".desc",containerID).show(); //Show Banner
 $(".block",containerID).animate({ opacity: 1.0 }, 1 ); //Set Opacity
 //Click and Hover events for thumbnail list
 $(".image_thumb"+i+" ul li:first").addClass('active'); 
 $(".image_thumb"+i+" ul li").click(function(){ 
 $(".gallery",containerID).fadeOut(1000).delay(1500).remove();
 $("script",containerID).remove();
 //$(".main_image img").first().css("display", "block");
 $("img",containerID).first().fadeIn(1000);
 if ($("a",containerID).attr("title") == "") {
 	$("a.collapse",containerID).fadeIn(1000);
	$(".block",containerID).show();
 }
 
     //Set Variables
  var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
  var imgTitle = $(this).find('a.mainImg').attr("href"); //Get Main Image URL
  var imgDesc = $(this).find('.block').html();  //Get HTML of block
  var imgDescHeight = $(this).find('.block').height(); //Calculate height of block 
  
  //if ($(this).is(".active")) {  //If it's already active, then...
  // return false; // Don't click through
  //} else {
   //Animate the Teaser    
    $(".block",containerID).animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() {
    $(".block",containerID).html(imgDesc).animate({ opacity: 1.0, marginBottom: "0" }, 250 );
	
    $("img.mainImg",containerID).attr({ src: imgTitle , alt: imgAlt});
	//$(".image_thumb ul li .block img").attr({ src: imgTitle , alt: imgAlt});  
  });
  //}
   
  $(".image_thumb"+i+" 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
 $("a.collapse",containerID).click(function(){
  $(".block",containerID).slideToggle();
  $("a.collapse",containerID).toggleClass("show");
  if ($("a",containerID).attr("title") == "") {
  	$("a",containerID).attr("title","hidden");
  }
  else
  {
	  $("a",containerID).attr("title","");
  }
 });
 });
});//Close Function

