
function addLoadEvent(func) {
    if (window.addEventListener) {
        window.addEventListener("load", func, false);
    }
    else if (window.attachEvent) {
        window.attachEvent("onload", func);
    }
    else {
        var oldonload = window.onload;
        if (typeof window.onload != 'function') {
            window.onload = func;
        }
        else {
            window.onload = function() {
                if (oldonload) {
                    oldonload();
                }
                func();
            };
        }
    }
}

/* Removing rounded corners for IE, due to DHTML issues
//Add rounded corners for IE
DD_roundies.addRule('#buytabswitch.tab1 div.tab1 .subtab, #buytabswitch.tab2 div.tab2 .subtab', '8px 0px 8px 8px');
DD_roundies.addRule('#buytabswitch.tab1 span.tab2, #buytabswitch.tab2 span.tab1', '6px 6px 0px 0px');
DD_roundies.addRule('#buytabswitch.tab1 span.tab1, #buytabswitch.tab2 span.tab2', '6px 6px 0px 0px');
addRules();

//These need to be repeated in roundiesReset() for redraw after AJAX calls
function addRules() {
    DD_roundies.addRule('.ProductDetails .content', '0px 8px 8px 8px');
    DD_roundies.addRule('.Tab, .Tab:link, .Tab:visited', '6px 6px 0px 0px');
    DD_roundies.addRule('.ActiveTab, .ActiveTab:link, .ActiveTab:visited', '6px 6px 0px 0px');
    DD_roundies.addRule('.searchFilterHeader', '8px');
    DD_roundies.addRule('.searchSortHeader', '8px');
    DD_roundies.addRule('input.button, a.button, a.altoddButton', '6px');
    DD_roundies.addRule('#miniBasketMainBox a', '0 0 0 6px');
}
*/

/*
 *  We have to call roundies again after an AJAX call to recreate rounded corners.
 */
/* Removing rounded corners in IE
var original__doPostBack = __doPostBack;

window['__doPostBack'] = function(eventTarget, eventArgument) {
    original__doPostBack(eventTarget, eventArgument);
    setTimeout('roundiesReset()', 1000);
}

var secondTab = 0;
*/
function roundiesReset() {

    if(!DD_roundies.IE7)
    {
        DD_roundies.selectorsToProcess = new Array();
        addRules();

        //We use secondTab to make sure the second pane is only drawn once, when the tab is clicked the first time.
        if (secondTab<2) {
            DD_roundies.addRule('#buytabswitch.tab1 div.tab1 .subtab, #buytabswitch.tab2 div.tab2 .subtab', '8px 0px 8px 8px');
        }

        if (DD_roundies.IE8 && DD_roundies.querySelector) {
	        if (document.readyState == 'complete') {
		        var selectors = DD_roundies.selectorsToProcess;
		        var length = selectors.length;
		        var delayedCall = function(node, radii, index) {
			        setTimeout(function() {
				        DD_roundies.roundify.call(node, radii);
			        }, index*100);
		        };
		        for (var i=0; i<length; i++) {
			        var results = document.querySelectorAll(selectors[i].selector);
			        var rLength = results.length;
			        for (var r=0; r<rLength; r++) {
				        if (results[r].nodeName != 'INPUT') { /* IE8 doesn't like to do this to inputs yet */
					        delayedCall(results[r], selectors[i].radii, r);
			            }
			        }
		        }
	        }
        }
    }
}

jQuery(document).ready(function() {
     //   jQuery("#megamenu").animate({ width: "462px" }, 0, showMegaProducts);
    // Default configuration parameters
    var config = {
        fadeDelay: 350
    };
    var megaConfig = {
        interval: 100, sensitivity:10, over: showMegaProducts, timeout: 200, out: emptyFn
    };
    var megaConfig_2 = {
        interval: 0, sensitivity: 10, over: emptyFn, timeout: 150, out: hideMegaProducts
    };
    function emptyFn() { }

    jQuery("#AdvancedSearchLink").click(showAdvancedSearch);
    jQuery("#lnkButton2").hoverIntent(megaConfig);
    //jQuery("#megamenu").hoverIntent(megaConfig_2);
    jQuery("#megamenu").hover(showMegaProducts_2,hideMegaProducts);

    function showMegaProducts() {
        jQuery("#megamenu").animate({ width: "462px" }, 150, showMegaProducts_2);
    }
    function showMegaProducts_2() {
        jQuery("#megamenu #menu_content").animate({ height: "385px" }, 200);
    }
    function hideMegaProducts() {
        jQuery("#megamenu #menu_content").animate({ height: "0px" }, 150, hideMegaProducts_2);
    }
    function hideMegaProducts_2() {
        jQuery("#megamenu").animate({ width: "0px" }, 150);
    }
    function showAdvancedSearch() {
        jQuery("#advancedsearch").modal();
        return false;
    }
    function hideAdvanceSearch() {
        jQuery("#advancedsearch").animate({ height: "0px", border: "0px" });
    }
    // Rollovers - Preload not needed since setting up the cross-fade loads the second image
    jQuery("#menubuttons img")
 		.each(function() {
 		    // Add the rollover image to the page
 		    jQuery("<img>")
				.attr("id", jQuery(this).attr("id") + "-over")
				.attr("src", jQuery(this).metadata().over)
				.hide()
				.hover(emptyFn, function() { jQuery(this).fadeOut(config.fadeDelay).prev().fadeIn(config.fadeDelay); })
				.insertAfter(this);
 		})
		.hover(function() { jQuery(this).fadeOut(config.fadeDelay).next().fadeIn(config.fadeDelay); }, emptyFn);


	jQuery("#FeatureButtons img")
 		.each(function() {
 		    jQuery("<img>")
				.attr("id", jQuery(this).attr("id") + "-over")
				.attr("src", jQuery(this).metadata().over)
				.hide()
				.hover(emptyFn, function() { jQuery(this).fadeOut(config.fadeDelay).prev().fadeIn(config.fadeDelay); })
				.insertAfter(this);
 		})
		.hover(function() { jQuery(this).fadeOut(config.fadeDelay).next().fadeIn(config.fadeDelay); }, emptyFn);
});

tab2blank = false;
function tabSwitchInit() {
    try {
        if (tab2blank)
            tabSwitch('empty2');
        else {
            tabSwitch('tab1');

            var tabs = Array();
            tabContns = document.getElementById('buytabswitch').getElementsByTagName('div');
            for (var i = 0; i < tabContns.length; i++) {
                if (tabContns[i].className = 'tabswitchbuttons') {
                    tabs = tabContns[i].getElementsByTagName('span');
                    break;
                }
            }

            for (var i = 0; i < tabs.length; i++) {
                tabs[i].onclick = new Function("tabSwitch(this.className)");
            }
        }
    }
    catch (e) { }
}
addLoadEvent(tabSwitchInit);

function tabSwitch(tabClass) {
    document.getElementById('buytabswitch').className = tabClass;

/*removing rounded corners in IE
    if (tabClass == 'tab2') {
    secondTab++;
    }
    roundiesReset();
*/
}