jQuery(function () {
    $itemOne = $('.psInterButton > ul > li > div:first').clone();
    $('.psInterMainImage > div > div').replaceWith($itemOne);
});
function slideSwitchTimed() {
    $active = $('.psInterButton ul li.active').next();
    if ($active.length == 0) $active = $('.psInterButton ul li:first'); //goes back to start when finishes
    $active.trigger("rotate");
}
jQuery(document).ready(function () {
    var imgOne = $('.psInterButton > ul > li > a').attr("href");
    //$(".psInterMainImage img").animate({ opacity: 0}, 0 , function() {
    //	$(".psInterMainImage img").attr({ src: imgOne}).animate({ opacity: 1}, 500 );
    //});

    var intTransSpeed = 500;
    var intDelay = 7000;

    var butWidth = ($('.psInterMainImage').width() / $('.psInterButton > ul > li').length);
    $('.psInterButton > ul > li').css('width', butWidth);

    //$("#psImg1").one("load", function () {
        $(".psInterMainImage .psInterMainImageDesc").show(); //Show Banner

        
        var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
        var imgDescHeight = $('.psInterMainImage').find('.psBlock').height(); //Calculate height of block	
        var imgDescWidth = $('.psInterMainImage').find('.psBlock').width(); //Calculate width of block		
        var imgDesc = $('.psInterButton ul li:first').find('.psBlock').html(); 	//Get HTML of block
        var intBlockSize = -1;
        if(intBlockSize == -1){
            intBlockSize = imgDescHeight;
        }

        //$(".psInterMainImage .psBlock").animate({ opacity: 0.85 }, 1 ); //Set Opacity

        $(".psInterMainImage img").css('opacity', 0);
        $(".psInterMainImage .psBlock").css('margin-bottom', -(intBlockSize+10));

        //$(".psInterMainImage .psBlock").css('opacity', 0.85);
        //$(".psInterMainImage .psBlock").html(imgDesc).animate({ marginBottom: "30" }, intTransSpeed);
        //$(".psInterMainImage img").attr({ src: imgOne }).animate({ opacity: 1 }, intTransSpeed);

        //Animate the Teaser
        $(".psInterMainImage .psBlock").animate({ opacity: 0, marginBottom: -intBlockSize }, intTransSpeed, function () {
            $(".psInterMainImage .psBlock").html(imgDesc).animate({ opacity: 1, marginBottom: "30" }, intTransSpeed);
            $(".psInterMainImage img").attr({ src: imgOne, alt: imgAlt }).animate({ opacity: 1 }, intTransSpeed);
        });

        //clearInterval(playSlideshow);
        playSlideshow = setInterval("slideSwitchTimed()", intDelay);
    /*})
	.each(function () {
	    if (this.complete || (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6))
	        $(this).trigger("load");
	});*/

    //Click and Hover events for thumbnail list
    $(".psInterButton ul li:first").addClass('active');
    $(".psInterButton ul li").bind("rotate", 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('.psBlock').html(); 	//Get HTML of block
        var imgDescHeight = $('.psInterMainImage').find('.psBlock').height(); //Calculate height of block	
        var imgDescWidth = $('.psInterMainImage').find('.psBlock').width(); //Calculate width of block	
        var intBlockSize = -1;
        if(intBlockSize == -1){
            intBlockSize = imgDescHeight;
        }

        if ($(this).is(".active")) {  //If it's already active, then...
            playSlideshow = setInterval("slideSwitchTimed()", intDelay);
            return false; // Don't click through
        } else {
            //Animate the Teaser		
            $(".psInterMainImage img").animate({ opacity: 0 }, intTransSpeed);
            $(".psInterMainImage .psBlock").animate({ opacity: 0, marginBottom: -intBlockSize }, intTransSpeed, function () {
                $(".psInterMainImage .psBlock").html(imgDesc).animate({ opacity: 1, marginBottom: "30" }, intTransSpeed);
                $(".psInterMainImage img").attr({ src: imgTitle, alt: imgAlt }).animate({ opacity: 1 }, intTransSpeed);
            });
            $(".psInterMainImage").css("background-image", "none");
        }

        $(".psInterButton ul li").removeClass('active'); //Remove class of 'active' on all lists
        $(this).addClass('active');  //add class of 'active' on this list only

        $(".psInterButton ul li").attr('class', function (i, c) { return c.replace(/\bactive-\S+/g, ''); });
        $(this).addClass('active-' + $(this).attr("id"));
        return false;

    }).hover(function () {
        var itemID = $(this).attr("id");
        $(this).addClass(itemID + '_hover');
    }, function () {
        var itemID = $(this).attr("id");
        $(this).removeClass(itemID + '_hover');
    });

    //Click and Hover events for thumbnail list
    $(".psInterButton ul li:first").addClass('active-' + $(".psInterButton ul li:first").attr("id"));
    $(".psInterButton ul li").click(function () {
        clearInterval(playSlideshow);
        $(this).trigger("rotate");
        return false;
    });


});  //Close Function

