$(document).ready(function() {

    //Show Banner
	var toggleIntervalId = 0;
    $(".banner_main_image .desc").show(); //Show Banner
    $(".banner_main_image .banner_block").animate({ opacity: 0.85 }, 1); //Set Opacity

    //Click and Hover events for thumbnail list
    $(".banner_image_thumb ul li:first").addClass('active');
    $(".banner_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('.banner_block').html(); 	//Get HTML of block
        var imgDescHeight = $(".banner_main_image").find('.banner_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				
            $(".banner_main_image .banner_block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250, function() {
                $(".banner_main_image .banner_block").html(imgDesc).animate({ opacity: 0.85, marginBottom: "0" }, 250);
                $(".the_image").fadeOut(250,function(){$(this).attr({ src: imgTitle, alt: imgAlt }).fadeIn(250)});
            });
        }

        $(".banner_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');
	clearInterval(toggleIntervalId);
    }, function() {
        $(this).removeClass('hover');
	toggleIntervalId = setInterval('toggleSlides()',6000);
    });

    //Toggle Teaser
    $("a.collapse").click(function() {
        $(".banner_main_image .banner_block").slideToggle();
        $("a.collapse").toggleClass("show");
    });

	toggleIntervalId = setInterval('toggleSlides()',6000);
}); //Close Function
function toggleSlides(){
	if($('.banner_image_thumb ul li.active').next().length>0){
		$('.banner_image_thumb ul li.active').next().trigger('click');
	}else{
		$('.banner_image_thumb ul li:first').trigger('click');
	} 
}

