/* Last updated: 31-March-2008 */

$(document).ready(function () {

    // this is to add PNG alpha transparency support to IE6
    // only a few images need transparent backgrounds, so the fix is applied to each of them
    $('#searchSplashTop, #searchSplashBottom, img[@src$=icon_print.png], img[@src$=icon_discuss.png], img[@src$=icon_thumbsUp.png], img[@src$=icon_thumbsDown.png], img[@src$=background_userRatingSlider.png], img[@src$=background_userRatingHandle.png], img[@src$=background_navigationSeparator.png], img[@src$=button_submit.png], img[@src$=button_find.png], img[@src$=button_buyNow.png], img[@src$=button_next.png], img[@src$=button_previous.png], img[@src$=button_sortDown.png], img[@src$=button_sortUp.png]').ifixpng();

    // turn on display of question mark icons in search splash
    // then activates the tool-tip plugin
    $('a.searchSplashHelp').css("display", "block").cluetip({
        fx: {
            open: 'fadeIn' // can be 'show' or 'slideDown' or 'fadeIn'
        },
        width: 200,
        topOffset: 10,       // Number of px to offset clueTip from top of invoking element.
        leftOffset: 10,       // Number of px to offset clueTip from left of invoking element.
        local: true,     // This forces the tooltip to use content from the same page instead of an ajax call
        hideLocal: true,
        attribute: 'rel',    // the attribute to be used for fetching the clueTip's body content
        titleAttribute: 'title',  // the attribute to be used for fetching the clueTip's title
        showTitle: true,     // show title bar of the clueTip, even if title attribute not set
        waitImage: false,    // whether to show a "loading" img
        arrows: false,    // if true, displays arrow on appropriate side of clueTip.
        dropShadow: false,
        sticky: true,     // keep visible until manually closed
        activation: 'click',  // can be 'click' or hover
        closePosition: 'title',  // can be 'top' or 'bottom' or 'title'
        closeText: 'X'       // text (or HTML) to to be clicked to close sticky clueTips	    
    });

    // this activates the navigation dropdown lists
    // also bgiframe plugin is applied to navigation dropdown lists in order to fix select box bug in IE6
    $('#navigation').jdMenu({
        activateDelay: 0,
        showDelay: 0,
        hideDelay: 600
    }).find('>li:has(ul)').mouseover(function () {
        $('ul', this).bgIframe({ opacity: false });
    }).find('a').focus(function () {
        $('ul', $('.nav>li:has(ul)')).bgIframe({ opacity: false });
    });
    $('#navigation ul').bgiframe();

    // turn off hover underlines on navigation links (left in css for browsers with no js)
    $('ul#navigation a').css('text-decoration', 'none');

    // highlight the currently sorted column of a table
    if ($("th.sorted").length) {
        var i = $('thead th').length;
        var j = $("th.sorted").nextAll().length;
        $('td:nth-child(' + (i - j) + ')').addClass('sortedColumnCell');
        // this bumps up the last checkbox so that the 'compare' button doesn't overlap it
        $(':checkbox:last').addClass('lastCheckboxAdjustment');
    }

    // since the target attribute of <a> elements has been eliminated in xhtml,
    // this finds links that have the class 'openInNewWindow' and opens them... in a new window
    $('a.openInNewWindow').click(function () {
        window.open(this.href);
        return false;
    });

    // this activates the tab navigation on the store pages
    $.tabs('storeTabs');

    // this activates the sliders on the user rating splash
    if ($('.rateThisProductSplash form').length) {
        // store 'for values' of radio button group labels in an array
        $("ul.userRatingRadioButtons").each(function (i) {
            // get the 'for' value of the form label preceding the radio button group
            var sliderName = $(this).prev().attr('for');
            // set the default value of the hidden inputs as well as the starting position for the slider handle
            var sliderHandlePosition = 5;
            // replace the radio button groups with slider divs
        alert('dddd');
            $(this).replaceWith('<div class="userRatingSlider' + (i + 1) + ' userRatingSliderBackground"><div class="userRatingSliderHandle"></div></div><input type="hidden" id="' + sliderName + '" name="' + sliderName + '" value="' + sliderHandlePosition + '" />');
            // activate the slider plugin and set slider attributes
            $('.userRatingSlider' + (i + 1)).slider({
                handle: '.userRatingSliderHandle',
                min: 1,
                max: 10,
                startValue: sliderHandlePosition,
                steps: 9,
                change: function (e, ui) {
                    var sliderValue = ui.value;
                    $('#' + sliderName).attr('value', sliderValue);
                }
            });
        });

    }

});
