// Window opener functions  v1.0.6
var winReference = null;

// Open a window at the center of the screen
function openCenteredWindow(url, name, width, height, status, scrollbars, moreProperties, openerName) {
	var x, y = 0;
	if (screen) {
      x = (screen.availWidth - width) / 2;
	   y = (screen.availHeight - height) / 2;
   }
	if (!status) status = '';
	if (!openerName) openerName = '';
	var reference = openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName);
	return reference;
}	

// Open a window at the center of the parent window
function openCenteredOnOpenerWindow(url, name, width, height, status, scrollbars, moreProperties, openerName) {
	var centerX = 0;
   var centerY = 0;
   if (window.screenX != null && window.outerWidth) {
      centerX = window.screenX + (window.outerWidth / 2);
      centerY = window.screenY + (window.outerHeight / 2);
   }
   else if (window.screenLeft) {
      if (document.documentElement) {
         centerX = window.screenLeft + (document.documentElement.offsetWidth / 2);
         centerY = window.screenTop + (document.documentElement.offsetHeight / 2);
      }
      else if (document.body && document.body.offsetWidth) {
         centerX = window.screenLeft + (document.body.offsetWidth / 2);
         centerY = window.screenTop + (document.body.offsetHeight / 2);
      }
   }
   if (centerX == 0) {
      openCenteredWindow(url, name, width, height, status, scrollbars, moreProperties, openerName);
   }
   var x = parseInt(centerX - (width / 2));
   var y = parseInt(centerY - (height / 2));
	if (!status) status = '';
	if (!openerName) openerName = '';
	var reference = openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName);
	return reference;
}	

// Core utility function that actually creates the window and gives focus to it
function openWindow(url, name, properties, openerName) {
	var agent = navigator.userAgent.toLowerCase();
	if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) == 4 && agent.indexOf("msie 5") == -1 && agent.indexOf("msie5") == -1 && agent.indexOf("win") != -1 && url.indexOf('http://') == 0) {
		winReference = window.open('about:blank', name, properties);
		setTimeout('if (winReference && !winReference.closed) winReference.location.replace("' + url + '")', 300);
	}
	else {
		winReference = window.open(url, name, properties);
	}
	setTimeout('if (winReference && !winReference.closed) winReference.focus()', 200);
	if (openerName) self.name = openerName;
	return winReference;
}


// Close a dialog
// Call from onunload event handler of any page that can create a dialog
function closeDialog(dialog) {
	if (dialog && dialog.closed != true) dialog.close();
}

// Close parent popup
// Call from onload event handler of any page that could be created from a dialog
function closeParentDialog() {
	if (top.opener && isWindowPopup(top.opener)) {
		root = top.opener.top.opener;
		top.opener.close();
		top.opener = root;
	}
}

// Check if a window is a popup
function isWindowPopup(win) {
	return ((win.opener) ? true : false);
}
























// dropnav.js
// Converts nested lists to dropdown menus
// Apply a class of 'drop-nav' to all top-level <ul>s that contain dropdown menus
// Put all possible conflicting flash movies in divs with class of 'flashContainer'
var flashElements = new Array();

function dropNavInit() {
   if (isDefined(document.getElementsByTagName)) {
      // search for unordered lists with a class of 'drop-nav'
      unorderedLists = document.getElementsByTagName('ul');
      for (var listIndex = 0; listIndex < unorderedLists.length; listIndex++) {
         var list = unorderedLists[listIndex];
         if (list.className.indexOf('drop-nav') > -1) {
            // in IE, add iframes to each subnav
            // deals with dhtml over form elements
            if (isIE()) {
               var subnavs = list.getElementsByTagName('ul');
               for (var subnavIndex = 0; subnavIndex < subnavs.length; subnavIndex++) {
                  var subnav = subnavs[subnavIndex];
                  subnav.innerHTML = '<iframe src="about:blank" scrolling="no" frameborder="0"></iframe>' + subnav.innerHTML;
                  var iframe= subnav.firstChild;
                  iframe.style.width = subnav.offsetWidth + 'px';
            		iframe.style.height = subnav.offsetHeight + 'px';	
            		subnav.style.zIndex = '99';
               }
            }
            // add hover effect to list items
            var listItems = list.getElementsByTagName('li');
            for (var listItemIndex = 0; listItemIndex < listItems.length; listItemIndex++) {
               var listItem = listItems[listItemIndex];
               if (isIE()) {
                  listItem.onmouseover = function() { this.className += ' hover'; };
                  listItem.onmouseout = function() { this.className = this.className.replace(/ hover/g, ''); };
               }
               else if (isSafari()) {
                  listItem.onmouseover = function() { disableFlashInteraction(); };
                  listItem.onmouseout = function() { enableFlashInteraction(); };
               }
      	   }
         }
      }
      
      // in Safari, store all flash elements
      if (isSafari()) {
         var divElements = document.getElementsByTagName('div');
         
         for (var divIndex = 0; divIndex < divElements.length; divIndex++) {
            var divElement = divElements[divIndex];
            if (divElement.className.indexOf('flashContainer') >= 0) {
               divElement.originalWidth = divElement.offsetWidth;
               flashElements.push(divElement);
            }
         }
      }
   }
}

/* Browser identification */
var ua = navigator.userAgent.toLowerCase();
function isSafari() { return (ua.indexOf('safari') != -1); }
function isIE() { return (ua.indexOf('msie') != -1); }


/**********************************************************************
   Dealing with flash / dhtml interference issues in Safari
   - set the flash container width to 1 - Safari still shows flash but
     doesn't register mouse events on flash
 *********************************************************************/

function disableFlashInteraction() {
   for (var flashIndex = 0; flashIndex < flashElements.length; flashIndex++) {
      flashElements[flashIndex].style.width = 1 + 'px';
   }
}

function enableFlashInteraction() {
   for (var flashIndex = 0; flashIndex < flashElements.length; flashIndex++) {
      flashElements[flashIndex].style.width = flashElements[flashIndex].originalWidth + 'px';
   }
}

function isDefined(property) {
  return (typeof property != 'undefined');
}



/**********************************************************************
  Product Popup functions
 *********************************************************************/
function showImg(index) {
   if( index == null || index == NaN ) return false;
   var oStage = document.getElementById('stage');
   var oCarousel = document.getElementById('carousel');

   if( !oStage || !oCarousel ) return false;
   var colStage = oStage.getElementsByTagName('li');
   var colCarousel = oCarousel.getElementsByTagName('a');

   if( !(colStage && (colStage.length == colCarousel.length)) ) return false;
   for ( i = 0; i < colStage.length; i++ ) {
       colStage[i].className = ( i == index ) ? "on":"";
       colCarousel[i].className = (i == index) ? "on":"";
   }
}

function closeMe() { window.close(); }

/* Get query string arguments */
function getArgs() {
   var args = new Object();
   var query = location.search.substring(1);
   var pairs = query.split(",");
   for ( var i = 0; i < pairs.length; i++ ) {
      var pos = pairs[i].indexOf('=');
      if ( pos == -1 ) continue;
      var argname = pairs[i].substring( 0, pos );
      var value = pairs[i].substring( pos + 1 );
      args[argname] = unescape( value );
   }
   return args;
}

function loadProdZoom(theArg) {
   openCenteredOnOpenerWindow('../ProductPop/ProductPop.html?image=' + theArg, 'prodPop', 545, 700);
   }

function bumpDiv() {
   var oStage = document.getElementById('carousel');

   if( !oStage ) return false;
   var thumbs = oStage.getElementsByTagName('span');

   if( !thumbs ) return false;
   var theWidth = 51 * thumbs.length;

   oStage.style.width = parseInt(theWidth) + "px";
}

function bumpDiv2() {
   var oStage = document.getElementById('carousel');

   if( !oStage ) return false;
   var thumbs = oStage.getElementsByTagName('span');

   if( !thumbs ) return false;
   var theWidth = 103 * thumbs.length;

   oStage.style.width = parseInt(theWidth) + "px";
}

