/* Promitional Item Slider */
/* Morrisons ReSkin Phase 1 Functionality */

/* ie6fix */
shortWidth = "isUndefined";

/* Init WideSet and Left Right Hovers Set */
function wideSet() {
    // Apply the left or right values for the hover
    // Reset to new layout
    hoverState = "arrowRight";
    $('#panelSlider .smallResizeBoxWrapper').each(function (i) {

        if ($(this).hasClass("defaultWide")) {
            //alert('defaultWide');
            hoverState = "arrowLeft";

        } else {
            $(this).addClass(hoverState);
            //alert(i+" "+hoverState);
        }
    })
    clickInactive = 0;
}

/* When your friend the good old browser loads... */
$(document).ready(function () {

    // For CSS
    $('#panelSlider').addClass('js');

    // Add hooks and calculate wide and short measurements
    $('.smallResizeBoxWrapper:first').addClass('first');
    $('.smallResizeBoxWrapper:last').addClass('last');
    $('.smallResizeBoxWrapper').each(function (i) {
        $(this).append('<span class="hover"></span>')
        $(this).attr('id', 'exmod_' + i).addClass('exmod');
        if ($(this).hasClass("defaultWide")) {
            wideWidth = $(this).width();
        } else {
            shortWidth = $(this).width();
        }
        if ($(this).hasClass("last")) {
            lastId = $(this).attr("id");
            lsSplitId = lastId.split('_');
            LastNum = lsSplitId[1];
        }
    })
    // Stored Vars Info [To work out size of items and css min/max widths]
    //FirstNum = First box
    //LastNum = Last box

    // Apply the hovers
    wideSet();

    // ie6 sort out onLoad
    if ($.browser.msie) {
        if (parseInt(jQuery.browser.version) < 7) {
            ie6InnerContentWidth = shortWidth - 32;
            $('.arrowRight .ct, .arrowLeft .ct').css('width', ie6InnerContentWidth);
        }
    }

    /* Standard Hover On and Off to show/hide */
    $('.exmod').hover(function () {
        $('.hover').hide();
        $(this).find('.hover').fadeIn();
    }, function () {
        $('.hover').hide();
    })

    /* Item click event to animate between one focussed box to the next */
    $('.arrowRight .panelslider_content, .arrowLeft .panelslider_content, .exmod .hover').live("click", function () {

        /* ie6 Inner Width Fix to make right corner correct */
        if ($.browser.msie) {
            if (parseInt(jQuery.browser.version) < 7) {
                ie6InnerContentWidth = shortWidth - 32;
                $('.defaultWide .ct').css('width', ie6InnerContentWidth);
            }
        }
        /* End ie6 */

        if (clickInactive != 1) {
            clickInactive = 1;
            $('.hover').hide();
            locationId = $(this).parent().attr('id');
            if (!($(locationId).hasClass("defaultWide"))) {
                splitId = locationId.split('_');
                CurNum = splitId[1];
                $('.defaultWide').animate({
                    width: shortWidth
                }, 500, function () {
                });

                $('#' + locationId).animate({
                    width: wideWidth
                }, 500, function () {
                    $('.exmod').removeClass('arrowLeft');
                    $('.exmod').removeClass('arrowRight');
                    $('.exmod').removeClass('defaultWide');
                    $('#' + locationId).addClass('defaultWide');
					
					 /* ie6 Inner Width Fix to make right corner correct */
                    if ($.browser.msie) {
                        if (parseInt(jQuery.browser.version) < 7) {
                            $('.defaultWide .ct').css('width', 'auto');
                        }
                    }
                    /* End ie6 */
					
                    /* Repositions Arrows */
                    wideSet();

                    /* ie6 Inner Width Fix to make right corner correct */
                    if ($.browser.msie) {
                        if (parseInt(jQuery.browser.version) < 7) {
                            ie6InnerContentWidth = shortWidth - 32;
                            $('.arrowRight .ct, .arrowLeft .ct').css('width', ie6InnerContentWidth);
                        }
                    }
                    /* End ie6 */
                });
            }
        } else {
            //alert('busy mate chill out.');
        }
    })

    /* Open Click State */
    $('.defaultWide').live("click", function () {
        url = $(this).find(".panelslider_footer a").attr('href');
        window.location = url;
    })
})

/* Done! */
