/*--------------------------------------------------
AddEvent()
- NOTE: this is the only way to add onLoad events
- Degrades on older browsers such as NS4 and IE5 mac
- The this keyword remains in-tact
- Avoids memory leaks in Microsoft Internet Explorer
--------------------------------------------------*/
function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}

var EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();
addEvent(window,'unload',EventCache.flush);

/*--------------------------------------------------
send 2 friend pop-up
--------------------------------------------------*/

function sendPageToFriend(URL){
    var browser = navigator.appName;
    var width = 400;
   	var height = 450;
    swidth = ((screen.width/2)-(width/2));
    sheight = ((screen.height/2)-(height/2));
	newWin = window.open('/send_to_friend.php?url='+escape(URL),'refer_friend','width='+ width +',height='+ height +',screenY='+ sheight +',screenX='+ swidth +',top=' + sheight + ',left=' + swidth + ',resizeable=no,scrollbars=no');
    newWin.focus();
	}
	
/*--------------------------------------------------
news pop-up
--------------------------------------------------*/

function openWindowNews() {
    var browser = navigator.appName;
    var width = 400;
   	var height = 300;
    swidth = ((screen.width/2)-(width/2));
    sheight = ((screen.height/2)-(height/2));
	newWin = window.open('/news.php','news','width='+ width +',height='+ height +',screenY='+ sheight +',screenX='+ swidth +',top=' + sheight + ',left=' + swidth + ',resizeable=no,scrollbars=no');
    newWin.focus();
	}

/*--------------------------------------------------
 large pop-up for careers page
--------------------------------------------------*/

function popup(URL) {
    var browser = navigator.appName;
    var width = 670;
   	var height = 450;
    swidth = ((screen.width/2)-(width/2));
    sheight = ((screen.height/2)-(height/2));
	newWin = window.open(URL,'popup_large','width='+ width +',height='+ height +',screenY='+ sheight +',screenX='+ swidth +',top=' + sheight + ',left=' + swidth + ',resizeable=no,scrollbars=yes');
    newWin.focus();
	}

/*--------------------------------------------------
 large pop-up for size charts page
--------------------------------------------------*/

function popupSizecharts(URL) {
    var browser = navigator.appName;
    var width = 740;
   	var height = 630;
    swidth = ((screen.width/2)-(width/2));
    sheight = ((screen.height/2)-(height/2));
	newWin = window.open(URL,'size_charts','width='+ width +',height='+ height +',screenY='+ sheight +',screenX='+ swidth +',top=' + sheight + ',left=' + swidth + ',resizeable=no,scrollbars=yes');
    newWin.focus();
	}
	
/*--------------------------------------------------
 pop-up for feedback page
--------------------------------------------------*/

function popupFeedback(URL) {
    var browser = navigator.appName;
    var width = 500;
   	var height = 500;
    swidth = ((screen.width/2)-(width/2));
    sheight = ((screen.height/2)-(height/2));
	newWin = window.open('http://vovici.com/wsb.dll/s/15dbdg30c47?url='+escape(URL),'feedback','width='+ width +',height='+ height +',screenY='+ sheight +',screenX='+ swidth +',top=' + sheight + ',center=' + swidth + ',resizeable=yes,scrollbars=no');
    newWin.focus();
	}
	
/*--------------------------------------------------
 pop-up for proud canadian page
--------------------------------------------------*/

function popupCanadian(URL) {
    var browser = navigator.appName;
    var width = 500;
   	var height = 500;
    swidth = ((screen.width/2)-(width/2));
    sheight = ((screen.height/2)-(height/2));
	newWin = window.open('http://vovici.com/wsb.dll/s/15dbdg344e5?url='+escape(URL),'feedback','width='+ width +',height='+ height +',screenY='+ sheight +',screenX='+ swidth +',top=' + sheight + ',center=' + swidth + ',resizeable=yes,scrollbars=no');
    newWin.focus();
	}

/*--------------------------------------------------
card verification number
--------------------------------------------------*/

function openWindowCcvHelp() {
    var browser = navigator.appName;
    var width = 410;
   	var height = 700;
    swidth = ((screen.width/2)-(width/2));
    sheight = ((screen.height/2)-(height/2));
	newWin = window.open('/help_card_auth.php','help_card_auth','width='+ width +',height='+ height +',screenY='+ sheight +',screenX='+ swidth +',top=' + sheight + ',left=' + swidth + ',resizeable=no,scrollbars=no');
    newWin.focus();
	}

	
/*--------------------------------------------------
sidebar rollover
--------------------------------------------------*/
function promoOptions(cat, state) {
  var promoNav = ''; // links to replace current promo text
  var startBlock = '';
  var endBlock = '';

  startBlock += '<div class="rollSub">';
    startBlock += '<div class="tab">';
      startBlock += '<div class="tabLeft"></div>';
      startBlock += '<div class="tabCentre"';

      endBlock += '</div>';
      endBlock += '<div class="tabRight"></div>';
    endBlock += '</div>';
  endBlock += '</div>';


  if (state == 'on') {

    switch (cat) {
      case "baby" :
        promoNav += startBlock;
        promoNav += '>';
        promoNav += '<a href="category.php?category_id=34"><img class="titleSub" src="images/boy.gif" width="30" height="10"></a>';
        promoNav += '<a href="category.php?category_id=33"><img class="titleSub" src="images/girl.gif" width="35" height="10"></a>';
        promoNav += endBlock;

        document.getElementById("rollBaby").innerHTML = promoNav;
        promoOptions('kids', 'off');
        promoOptions('school', 'off');
        break;

      case "kids" :
        promoNav += startBlock;
        promoNav += '>';
        promoNav += '<a href="category.php?category_id=36"><img class="titleSub" src="images/boy.gif" width="30" height="10"></a>';
        promoNav += '<a href="category.php?category_id=35"><img class="titleSub" src="images/girl.gif" width="35" height="10"></a>';
        promoNav += endBlock;

        document.getElementById("rollKids").innerHTML = promoNav;
        promoOptions('baby', 'off');
        promoOptions('school', 'off');
        break;

    }

  }
  else if (state == 'off') {

    switch (cat) {
      case "baby" :
        promoNav += startBlock;
        promoNav += ' onmouseover="javascript:promoOptions(\'baby\', \'on\');">';
        promoNav += '<img class="titleSub" src="images/baby.gif" alt="Baby" width="73" height="10" />';
        promoNav += endBlock;
        document.getElementById("rollBaby").innerHTML = promoNav;
        break;

      case "kids" :
        promoNav += startBlock;
        promoNav += ' onmouseover="javascript:promoOptions(\'kids\', \'on\');">';
        promoNav += '<img class="titleSub" src="images/kids.gif" alt="Kids" width="70" height="10" />';
        promoNav += endBlock;
        document.getElementById("rollKids").innerHTML = promoNav;
        break;

    }
  }
}

/*--------------------------------------------------
IE Hover
--------------------------------------------------*/
ie_navigation_hover = function() {
	if (document.all && document.getElementById && document.getElementById("nav")) {

        var navRoot = document.getElementById("nav");

        for (i=0; i< navRoot.childNodes.length; i++) {

            var node = navRoot.childNodes[i];


            if (node.nodeName == "LI") {
                node.onmouseover = function() { this.className+=" over"; }
                node.onmouseout  = function() { this.className=this.className.replace(" over", ""); }
            }
        }
    }
}
addEvent(window,'load',ie_navigation_hover); // proper way to specify onload events