/**
 * Global JavaScript for Project SKIP.
 * 
 * 
 */

// Prevents image flicker on hover in IE 6.
try {
    document.execCommand('BackgroundImageCache', false, true);
} catch(e) {};

/**
 * Runs on document load.
 * 
 * 
 */
$(document).ready(function() {
    applyNavHandlers();
    applyLeftNavHandlers();
    // Apply pngfix() to specified elements.
    $('.trans, #left_nav li').pngfix();
});


/**
 * Applies mouseover and mouseout handlers to main nav elements.
 * 
 * 
 */
function applyNavHandlers() {
    if ($.browser.msie && $.browser.version.substr(0, 1) == '6') {
        var nav_children = $('#nav').children('li');
        for (var i = 0; i < nav_children.length; i++) {
            $(nav_children[i]).bind('mouseover', navOver);
            $(nav_children[i]).bind('mouseout', navOut);
        }
    }
}


/**
 * Applies mouseover and mouseout handlers to left sidebar nav elements.
 * 
 * 
 */
function applyLeftNavHandlers() {
    if ($.browser.msie && $.browser.version.substr(0, 1) == '6') {
        var nav_children = $('#left_nav').children('li');
        for (var i = 0; i < nav_children.length; i++) {
            $(nav_children[i]).bind('mouseover', leftNavOver);
            $(nav_children[i]).bind('mouseout', leftNavOut);
        }
    }
}


/**
 * Mouseover for main nav list element.
 * 
 * 
 */
function navOver() {
    $(this).children('a').addClass('on');
    $(this).children('ul').addClass('on');
}


/**
 * Mouseout for main nav list element
 * 
 * 
 */
function navOut() {
    $(this).children('a').removeClass('on');
    $(this).children('ul').removeClass('on');
}


/**
 * Mouseover for main nav list element.
 * 
 * 
 */
function leftNavOver() {
    $(this).addClass('on');
    applyAlphaFilter($(this), '../images/left_nav_button', 'on');
}


/**
 * Mouseout for main nav list element
 * 
 * 
 */
function leftNavOut() {
    $(this).removeClass('on');
    if (!$(this).hasClass('active')) {
        applyAlphaFilter($(this), '../images/left_nav_button');
    }
}


/**
 * Manually change the filter src for IE.
 * 
 * 
 */
function applyAlphaFilter(obj, img, state) {
    var i = (state == 'on') ? (img + '_on.png') : (img + '.png');
    var f = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(' +
            'enabled="true", sizingMethod="crop", ' +
            'src="' + img_path + i + '")'
    $(obj).css('filter', f);
}
