
Cufon.replace('h1, h2, h3, h4, #col2 .sub li a, #mainnav li a', {
    hover: true
});

$(document).ready(function() {
    if ($('#cycle').length > 0) {
        slideshow();
    }
    if ($('#specialOffers').length > 0) {
        specialOffers();
    }
    if ($('#specialNews').length > 0) {
        specialNews();
    }
})

function specialOffers() {
    $('#specialOffers').before('<div id="commPager">')
        .cycle({
            fx: 'fade',
            speed: 400,
            timeout: 5000,
            pager: '#commPager'
        });
    $("#commPager").append("&nbsp;")
    $("#commPager a").html("&nbsp;");
    $("#commPager a").click(function() {
        $('#specialOffers').cycle('pause');
    })
}

function specialNews() {
    $('#specialNews').before('<div id="commPagerNews">')
        .cycle({
            fx: 'fade',
            speed: 400,
            timeout: 5000,
            pager: '#commPagerNews'
        });
        $("#commPagerNews").append("&nbsp;")
        $("#commPagerNews a").html("&nbsp;");
        $("#commPagerNews a").click(function() {
        $('#specialNews').cycle('pause');
    })
}


function slideshow() {
    
    keyprs();

    $('#cycle').cycle({
        fx: 'fade',
        speed: 900,
        timeout: 4500,
        next: '#prv',
        prev: '#nxt',
        after: onAfter,
        before: onBefore
    });

    //single image
    if ($('#cycle img.sigleImg').length > 0) {
        $('#cycle img.sigleImg').show()
        $('#nxtCycle, #prvCycle').hide();
        if ($('#img1Cap').length > 0) {
            $('#capCycle').show().css('opacity', '0.80').css('top', 0)
            $('#capCycle p').html($('#img1Cap').html());
        }
    } 
    
}

function keyprs() {

    $("#nxt, #prv").click(function() {
        $('#cycle').cycle('pause');
    })

    $(document).keydown(function(e) {
        if (e.keyCode == 37) { //left
            $("#nxt").trigger('click').parent().addClass('trigged');
            return false;
        }
        if (e.keyCode == 39) { //right
            $("#prv").trigger('click').parent().addClass('trigged');
            return false;
        }

    });

    $(document).keyup(function(e) {
        if (e.keyCode == 37) { //left
            $("#nxt").parent().removeClass('trigged');
            return false;
        }
        if (e.keyCode == 39) { //right
            $("#prv").parent().removeClass('trigged');
            return false;
        }
    })

}

function onAfter(curr, next, opts) {
    if ($.trim($('#' + this.id + 'Cap').html()) != '') {
        $('#capCycle').fadeIn('slow');
        $('#capCycle p').html($('#' + this.id + 'Cap').html());
    }
}

function onBefore(curr, next, opts) {
    $('#capCycle').fadeOut('slow');
}
