//$( document ).ready( function() {
//
//	var frontpremiumNS = {};
//
//	if( $("#promo_banner").length != '0' ){
//		frontpremiumNS.visible = 3;
//	} else {
//		frontpremiumNS.visible = 4;
//	}
//
//	$( '#promotedCarousel' ).show().jcarousel({
//		scroll: 1,
//		start: 1,
//		visible: frontpremiumNS.visible,
//		auto: 5,
//		wrap: 'last'
//	});
//
//} );

function rollCarousel(){

    if ( $(".main-page-carousel-list ul li:last").hasClass('active') ) {

        $(".main-page-carousel-list ul li:first").click();
    } else {
        $(".main-page-carousel-list ul").find('li.active').next().click();
    }
    setTimeout(function() {
        rollCarousel();
    }, 10000);
}
function clickCarusel(elem){
    //Set Variables
    var imgAlt = $(elem).find('img').attr("alt"); //Get Alt Tag of Image
    var imgTitle = $(elem).find('img').attr("src"); //Get Main Image URL
    var imgDesc = $(elem).find('.block2').html();  //Get HTML of the "block" container
    var imgDescHeight = $(".main-page-carousel-mainbox").find('.block').height(); //Find the height of the "block"

    if ($(elem).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-page-carousel-mainbox .block").animate({
            opacity: 0,
            marginBottom: -imgDescHeight
        }, 250 , function() { //Pull the block down (negative bottom margin of its own height)
            $(".main-page-carousel-mainbox .block").html(imgDesc).animate({
                opacity: 0.85,
                marginBottom: "0"
            }, 250 ); //swap the html of the block, then pull the block container back up and set opacity
            $(".main-page-carousel-mainbox img").attr({
                src: imgTitle ,
                alt: imgAlt
            }); //Switch the main image (URL + alt tag)
        });


    }
    //Show active list-item
    $(".main-page-carousel-list ul li").removeClass('active'); //Remove class of 'active' on all list-items
    $(elem).addClass('active');  //Add class of 'active' on the selected list
    return false;
}

$( document ).ready( function() {
    //    BEGIN KARUZELA
    $(".main-page-carousel-mainbox .desc").show(); //Show Banner
    $(".main-page-carousel-mainbox .block").animate({
        opacity: 0.85
    }, 1 ); //Set Opacity
    $(".main-page-carousel-list ul li:first").addClass('active'); //Add the active class (highlights the very first list item by default)
    $(".main-page-carousel-list ul li").click(function(){
        clickCarusel(this);
    }) .hover(function(){ //Hover effects on list-item
        $(this).addClass('hover'); //Add class "hover" on hover
    }, function() {
        $(this).removeClass('hover'); //Remove class "hover" on hover out
    });
    setTimeout(function() {
        rollCarousel();
    }, 10000);
    //    END KARUZELA

} );
