var ct;
var ct2;
var ct3;

jQuery(document).ready(function() {
    if (jQuery('#prod-carousel li').length > 1) {
        jQuery('#prod-carousel li').each(function(i) {
            jQuery('.jcarousel-control-prod').append(jQuery('<a class="image" href="#">'+(i+1)+'</a>'));
        });
        jQuery('.jcarousel-control-prod a:first').addClass('selected');
        jQuery('#prod-carousel').jcarousel({
            scroll: 1,
            animation: "slow",
            initCallback: prod_initCallback,
            buttonNextHTML: null,
            buttonPrevHTML: null
        });
        //ct = setInterval("scrollProdCarousel()", 5000);
    }
	if (jQuery('#promo-carousel li').length > 1) {
        jQuery('#promo-carousel li').each(function(i) {
            jQuery('.jcarousel-control-promo').append(jQuery('<a class="image" href="#">'+(i+1)+'</a>'));
        });
        jQuery('.jcarousel-control-promo a:first').addClass('selected');
        jQuery('#promo-carousel').jcarousel({
            scroll: 1,
            animation: "slow",
            initCallback: promo_initCallback,
            buttonNextHTML: null,
            buttonPrevHTML: null
        });
        //ct2 = setInterval("scrollPromoCarousel()", 5000);
    }
	if (jQuery('#com-carousel li').length > 1) {
        jQuery('#com-carousel li').each(function(i) {
            jQuery('.jcarousel-control-com').append(jQuery('<a class="image" href="#">'+(i+1)+'</a>'));
        });
        jQuery('.jcarousel-control-com a:first').addClass('selected');
        jQuery('#com-carousel').jcarousel({
            scroll: 1,
            animation: "slow",
            initCallback: com_initCallback,
            buttonNextHTML: null,
            buttonPrevHTML: null
        });
        //ct3 = setInterval("scrollComCarousel()", 5000);
    }
});



function prod_initCallback(carousel) {
    jQuery('.jcarousel-control-prod a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        jQuery('.jcarousel-control-prod a.selected').removeClass('selected');
        jQuery(this).addClass('selected');
        return false;
    });
    jQuery('.jcarousel-control-prod a').bind('focus', function() { clearTimeout(ct); this.blur() });
}
function promo_initCallback(carousel) {
    jQuery('.jcarousel-control-promo a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        jQuery('.jcarousel-control-promo a.selected').removeClass('selected');
        jQuery(this).addClass('selected');
        return false;
    });
    jQuery('.jcarousel-control-promo a').bind('focus', function() { clearTimeout(ct2); this.blur() });
}
function com_initCallback(carousel) {
    jQuery('.jcarousel-control-com a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        jQuery('.jcarousel-control-com a.selected').removeClass('selected');
        jQuery(this).addClass('selected');
        return false;
    });
    jQuery('.jcarousel-control-com a').bind('focus', function() { clearTimeout(ct); this.blur() });
}


function scrollProdCarousel() {
    var cur = jQuery('.jcarousel-control-prod a.selected').removeClass('seleted');
    var next = (cur.next().length > 0) ? cur.next() : cur.parent().children('a:first');
    next.click().addClass('selected');
}
function scrollPromoCarousel() {
    var cur = jQuery('.jcarousel-control-promo a.selected').removeClass('seleted');
    var next = (cur.next().length > 0) ? cur.next() : cur.parent().children('a:first');
    next.click().addClass('selected');
}
function scrollComCarousel() {
    var cur = jQuery('.jcarousel-control-com a.selected').removeClass('seleted');
    var next = (cur.next().length > 0) ? cur.next() : cur.parent().children('a:first');
    next.click().addClass('selected');
}
