$(document).ready(function() {
    /** 
    --------------------------------
    Special Promotions Slideshow  
    --------------------------------
    */
    // Initializing Special Promotions Slideshow 

    var currentPosition = 0;
    var slideWidth = 720;
    var slides = $('.slide');
    var numberOfSlides = slides.length;

    // Wrap all .slides with #slideInner div
    slides
        .wrapAll('<div id="slideInner"></div>')
        .css({
            'float': 'left',
            'width': slideWidth
        });

    // Set #slideInner width equal to total width of all slides
    $('#slideInner').css('width', slideWidth * numberOfSlides);

    // Insert left and right arrow controls in the DOM
    $('#slideshow')
                .prepend('<span class="control" id="leftControl">Move left</span>')
                .append('<span class="control" id="rightControl">Move right</span>');

    // Hide left arrow control on first load
    manageControls(currentPosition);

    // Create event listeners for .controls clicks
    $('.control')
    .bind('click', function() {
        // Determine new position
        currentPosition = ($(this).attr('id') == 'rightControl') ? currentPosition + 1 : currentPosition - 1;

        // Hide / show controls
        manageControls(currentPosition);
        // Move slideInner using margin-left
        $('#slideInner').animate({
            'marginLeft': slideWidth * (-currentPosition)
        });
    });

    // manageControls: Hides and shows controls depending on currentPosition
    function manageControls(position) {
        // Hide left arrow if position is first slide
        if (position == 0) { $('#leftControl').hide() }
        else { $('#leftControl').show() }
        // Hide right arrow if position is last slide
        if (position == numberOfSlides - 1) { $('#rightControl').hide() }
        else { $('#rightControl').show() }
    }
/** 
    --------------------------------
    Packages Slideshow  
    --------------------------------
    */
    // Initializing Special Promotions Slideshow 

    var pcurrentPosition = 0;
    var pslideWidth = 720;
    var pslides = $('.slide2');
    var pnumberOfSlides = pslides.length;

    // Wrap all .slides with #slideInner div
    pslides
        .wrapAll('<div id="slideInner"></div>')
        .css({
            'float': 'left',
            'width': pslideWidth
        });

    // Set #slideInner width equal to total width of all slides
    $('#slideInner2').css('width', pslideWidth * pnumberOfSlides);

    // Insert left and right arrow controls in the DOM
    $('#slideshow2')
                .prepend('<span class="control2" id="leftControl2">Move left</span>')
                .append('<span class="control2" id="rightControl2">Move right</span>');

    // Hide left arrow control on first load
    manageControls2(pcurrentPosition);

    // Create event listeners for .controls clicks
    $('.control2')
    .bind('click', function() {
        // Determine new position
        pcurrentPosition = ($(this).attr('id') == 'rightControl2') ? pcurrentPosition + 1 : pcurrentPosition - 1;

        // Hide / show controls
        manageControls2(pcurrentPosition);
        // Move slideInner using margin-left
        $('#slideInner2').animate({
            'marginLeft': pslideWidth * (-pcurrentPosition)
        });
    });

    // manageControls: Hides and shows controls depending on currentPosition
    function manageControls2(position) {
        // Hide left arrow if position is first slide
        if (position == 0) { $('#leftControl2').hide() }
        else { $('#leftControl2').show() }
        // Hide right arrow if position is last slide
        if (position == pnumberOfSlides - 1) { $('#rightControl2').hide() }
        else { $('#rightControl2').show() }
    }

    /** 
    --------------------------------
    Special and
    --------------------------------
    */   
    $('.specials-tabs li a').bind('click',function() {
        // Show the active link
        $('.specials-tabs li a').removeClass('active');
        $(this).addClass('active');

        // Hide current and show new content    
        $('.special-tabs-content').css('display', 'none');
        tab_content = $(this).attr('rel');
        $(tab_content).show();
    });


});
