

$(function(){          


var pauseRotation =  0;

$(".image_thumb ul li:first").addClass('active'); //Add the active class (highlights the very first list item by default)

$(".image_thumb ul li").live('mouseleave', function(){ 

	pauseRotation = 0;
});


$(".image_thumb ul li").live('mouseenter', function(){

   pauseRotation = 1;
	
    //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 the "block" container
    var imgDescHeight = $(".main_image").find('.block').height(); //Find the height of the "block"
    var imgHref = $(this).find('.block span[name="url"]').text();




//    if (0 ||  $(this).is(".active")) {  //If the list item is active/selected, then...
//        return false; // Don't click through - Prevents repetitive animations on active/selected list-item
//    } 
//else 

{ //If not active then...
        //Animate the Description
        $(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 150 , function() { //Pull the block down (negative bottom margin of its own height)
            $(".main_image .block").html(imgDesc).animate({ opacity: 0.85,  marginBottom: "0" }, 150 ); //swap the html of the block, then pull the block container back up and set opacity

            $(".main_image img").fadeOut('fast', function() {
		$(this).attr('src', imgTitle);
		$(this).fadeIn('fast');       
		});



//            $(".main_image img").attr({ src: imgTitle , alt: imgAlt}); //Switch the main image (URL + alt tag)
	    $(".main_image a").attr("href", imgHref); //Switch the main image (URL + alt tag)
        });
    }
    //Show active list-item
    $(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all list-items
    $(this).addClass('active');  //Add class of 'active' on the selected list
    return false; 


	

});

$(".image_thumb ul li").live('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 the "block" container
    var imgDescHeight = $(".main_image").find('.block').height(); //Find the height of the "block"
    var imgHref = $(this).find('.block span[name="url"]').text();




//    if (0 ||  $(this).is(".active")) {  //If the list item is active/selected, then...
//        return false; // Don't click through - Prevents repetitive animations on active/selected list-item
//    } 
//else 

{ //If not active then...
        //Animate the Description
        $(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 150 , function() { //Pull the block down (negative bottom margin of its own height)
            $(".main_image .block").html(imgDesc).animate({ opacity: 0.85,  marginBottom: "0" }, 150 ); //swap the html of the block, then pull the block container back up and set opacity

            $(".main_image img").fadeOut('fast', function() {
		$(this).attr('src', imgTitle);
		$(this).fadeIn('fast');       
		});



//            $(".main_image img").attr({ src: imgTitle , alt: imgAlt}); //Switch the main image (URL + alt tag)
	    $(".main_image a").attr("href", imgHref); //Switch the main image (URL + alt tag)
        });
    }
    //Show active list-item
    $(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all list-items
    $(this).addClass('active');  //Add class of 'active' on the selected list
    return true; 


}) .hover(function() { 
	$(this).addClass('hover');
    }, function() { $(this).removeClass('hover'); 
   });

   $(".main_image a").attr("href", $(".image_thumb ul li div.block span[name='url']").eq(0).text()); //Switch the main image (URL + alt tag)
   $(".image_thumb ul li").eq(0).trigger('click');
   setInterval (function() { nextImage(pauseRotation); }, 8000);

/*
$("a.collapse").hover(function(){
    $(".main_banner .block").slideToggle(); //Toggle the description (slide up and down)
    $("a.collapse").toggleClass("show"); //Toggle the class name of "show" (the hide/show tab)
});
*/













});




function nextImage(pauseRotation)
{



if (!pauseRotation)
{

	if (typeof(startValue) == 'undefined') startValue = 1;
	else startValue = 0;
	if (typeof(c1) == 'undefined' || c1== $(".image_thumb ul li").length) c1 = startValue;
        $(".image_thumb ul li").eq(c1).trigger('click');
	c1++;
}


}
