/*
     Initialize and render the MenuBar when its elements are ready
     to be scripted.
*/
YAHOO.util.Event.onContentReady("productsandservices", function () {
    /*
         Instantiate a MenuBar:  The first argument passed to the
         constructor is the id of the element in the page
         representing the MenuBar; the second is an object literal
         of configuration properties.
    */
    var oMenuBar = new YAHOO.widget.MenuBar("productsandservices", {
                                                autosubmenudisplay: true,
                                                hidedelay: 750,
                                                lazyload: false });
    /*
         Call the "render" method with no arguments since the
         markup for this MenuBar instance is already exists in
         the page.
    */
    oMenuBar.render();
});


YAHOO.util.Event.onContentReady("movingsuppliesmenu", function () {
    /*
         Instantiate a MenuBar:  The first argument passed to the
         constructor is the id of the element in the page
         representing the MenuBar; the second is an object literal
         of configuration properties.
    */
    var oMenuBar = new YAHOO.widget.MenuBar("movingsuppliesmenu", {
                                                autosubmenudisplay: true,
                                                hidedelay: 750,
                                                lazyload: false });
    /*
         Call the "render" method with no arguments since the
         markup for this MenuBar instance is already exists in
         the page.
    */
    oMenuBar.render();
});

YAHOO.namespace("publicStorage.container");

function initOverlayContainerNav() {
	// Build overlay1 based on markup, initially hidden, fixed to the center of the viewport, and 300px wide
	YAHOO.publicStorage.container.overlay1 = new YAHOO.widget.Overlay("overlay1", { xy:[720,35],
																			  visible:false} );

	YAHOO.publicStorage.container.overlay1.render();
	YAHOO.log("Overlay1 rendered.", "info", "example");

	YAHOO.util.Event.addListener("show1", "mouseover", YAHOO.publicStorage.container.overlay1.show, YAHOO.publicStorage.container.overlay1, true);
	YAHOO.util.Event.addListener("hide1", "click", YAHOO.publicStorage.container.overlay1.hide, YAHOO.publicStorage.container.overlay1, true);

	// shopping cart panel
	var panelConfig = {context:["primary_nav","tr","br"],zIndex:90, width:'370px', visible:false, draggable:false}
	YAHOO.publicStorage.container.overlay3 = new YAHOO.widget.Panel("overlay3", panelConfig );
	YAHOO.publicStorage.container.overlay3.render();
	YAHOO.log("Overlay3 rendered.", "info", "example");
	//YAHOO.util.Event.on("show3", "mouseover", YAHOO.publicStorage.container.redrawOrderView);
	YAHOO.util.Event.addListener("hide3", "click", YAHOO.publicStorage.container.overlay3.hide, YAHOO.publicStorage.container.overlay3, true);
	//YAHOO.util.Event.addListener("overlay3", "mouseout", YAHOO.publicStorage.container.overlay3.hide, YAHOO.publicStorage.container.overlay3, true);
	//YAHOO.util.Event.addListener("overlay3", "mouseover", YAHOO.publicStorage.container.overlay3.show, YAHOO.publicStorage.container.overlay3, true);
}

YAHOO.util.Event.onDOMReady(initOverlayContainerNav);

//populate cart functions

YAHOO.publicStorage.container.orderRequestSuccess = function(o){
	var div = document.getElementById('orderOverlayContent');
	YAHOO.log("The success handler was called.  tId: " + o.tId + ".", "info", "example");
	if(o.responseText !== undefined){
		var responseLog = "<li>Transaction id: " + o.tId + "</li>";
		responseLog += "<li>HTTP status: " + o.status + "</li>";
		responseLog += "<li>Status code message: " + o.statusText + "</li>";
		responseLog += "<li>HTTP headers: <ul>" + o.getAllResponseHeaders + "</ul></li>";
		YAHOO.log(responseLog);
		div.innerHTML = "<!--Server response: -->" + o.responseText + "<!--End Server Response-->";
		psui.order.displayCount('itemCounter','all');
		psui.order.displayCount('navOrderCount','all');
		YAHOO.util.Event.addListener("btnContinueShopping", "click",YAHOO.publicStorage.container.overlay3.hide,YAHOO.publicStorage.container.overlay3, true);
	}
}

YAHOO.publicStorage.container.orderRequestFailure = function(o){
	var div = document.getElementById('orderOverlayContent');
		YAHOO.log("The failure handler was called.  tId: " + o.tId + ".", "info", "example");
	if(o.responseText !== undefined){
		div.innerHTML = '<div class="error">'+ o.status + ' ' + o.statusText + '</div>';
	}
}

YAHOO.publicStorage.container.orderRequestCallback =
 {
  success:YAHOO.publicStorage.container.orderRequestSuccess,
  failure:YAHOO.publicStorage.container.orderRequestFailure,
  argument: {}
};

YAHOO.publicStorage.container.orderRequest = function() {
    return;
    //simple random number
    var randomizer = Math.random() + '';
    //randomize the rpc query to avoid caching issues.
    var rpcURL = 'your-order-nav.aspx?nocache=' + randomizer;
    var request = YAHOO.util.Connect.asyncRequest('GET', rpcURL, YAHOO.publicStorage.container.orderRequestCallback);
    YAHOO.log("Initiating request; tId: " + request.tId + ".", "info", "example");

}

//YAHOO.util.Event.on("show3", "mouseover", YAHOO.publicStorage.container.orderRequest);

YAHOO.util.Event.onDOMReady(YAHOO.publicStorage.container.orderRequest);


YAHOO.publicStorage.container.redrawOrderView = function () {
	document.getElementById('orderOverlayContent').innerHTML = '<div class="interstitial_load">Loading, please wait ...<br /><img src="images/interstitial_loading.gif" /></div>';
	YAHOO.publicStorage.container.orderRequest();
	YAHOO.publicStorage.container.overlay3.render();
	YAHOO.publicStorage.container.overlay3.show(YAHOO.publicStorage.container.overlay3);
	psui.order.displayCount('itemCounter','all');
	psui.order.displayCount('navOrderCount','all');
	YAHOO.util.Event.addListener("btnContinueShopping", "click", YAHOO.publicStorage.container.overlay3.hide, YAHOO.publicStorage.container.overlay3, true);
	showHideSelectListIE6();
}

function showHideSelectListIE6(eventIn)	{
		var itemCount= parseInt(psui.globals['itmeCount']);
		YAHOO.util.Event.addListener("btnContinueShopping", "click", YAHOO.util.Dom.setStyle(getSelectElem,'visibility',''));
	 if((YAHOO.util.Dom.get('refine_search')))	{
		var getSelectElem = document.getElementById('refine_search').getElementsByTagName('select');
		if (itemCount>=2){
			YAHOO.util.Dom.setStyle(getSelectElem[0],'visibility','hidden')	}
		if (itemCount>=3){
			YAHOO.util.Dom.setStyle(getSelectElem,'visibility','hidden')}
		if (eventIn=='show'){
			YAHOO.util.Dom.setStyle(getSelectElem,'visibility','')
				}
			if (eventIn =='reserveUnit'){
				YAHOO.util.Dom.setStyle(getSelectElem,'visibility','')
				YAHOO.publicStorage.container.overlay9.hide();
				YAHOO.util.Dom.setStyle('dialogAddUnit_mask','display','none')
					YAHOO.publicStorage.container.redrawOrderView();
			}

	}

}

YAHOO.publicStorage.container.scrollToTop = function(){
	var mode = document.compatMode; // Standards or Quirks mode? (or null)
	var body = document.body; // Safari and IE/OP/Gecko quirks mode
	if (mode && mode.indexOf('CSS') != -1) {
	body = document.documentElement; // IE/OP/Gecko standards mode
	}
	var anim = new YAHOO.util.Scroll(body,{ scroll: { to: [0, 0] } }, 6,YAHOO.util.Easing.easeOut); // scroll to top
	anim.animate();

}

function getCookie(c_name){
    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name + "=");
        if (c_start!=-1)
        { 
            c_start=c_start + c_name.length+1 ;
            c_end=document.cookie.indexOf(";",c_start);
        if (c_end==-1) c_end=document.cookie.length
         return unescape(document.cookie.substring(c_start,c_end));
        } 
    }
    return "";
}
YAHOO.util.Event.onDOMReady(getCookie);

