sfHover = function() {
    if(document.getElementById("nav")) {
        var sfEls = document.getElementById("nav").getElementsByTagName("LI");
        for (var i=0; i<sfEls.length; i++) {
            sfEls[i].onmouseover=function() {
                this.className+=" over";
                if(document.getElementById("menu_iframe")) {
                    var iframe = document.getElementById("menu_iframe");

                    var submenu = this.getElementsByTagName("UL");
                    if(submenu.length) {
                        iframe.style.top = submenu[0].offsetTop + this.offsetTop;
                        iframe.style.left = submenu[0].offsetLeft + this.offsetLeft;
                        iframe.style.width = submenu[0].scrollWidth;
                        iframe.style.height = submenu[0].clientHeight;
                        iframe.style.display = "inline";
                    }
                }
            }
            sfEls[i].onmouseout=function() {
                this.className=this.className.replace(new RegExp(" over\\b"), "");
                if(document.getElementById("menu_iframe")) {
                    var iframe = document.getElementById("menu_iframe");
                    iframe.style.display = "none";
                }
            }
        }
    }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function swapSearchToggle(allImage){
	if(allImage == 0) {
		document.getElementById('search-all').style.backgroundImage = "url(images/search-all-background-off.gif)";
		document.getElementById('search-item').style.backgroundImage =  "url(images/search-item-background-on.gif)";
		document.getElementById('search-item-link').style.color = "#fff";
		document.getElementById('search-all-link').style.color = "#ccc";
		document.getElementById('item-number-check').value = 1;
	} else {
		document.getElementById('search-all').style.backgroundImage = "url(images/search-all-background-on.gif)";
		document.getElementById('search-item').style.backgroundImage =  "url(images/search-item-background-off.gif)";
		document.getElementById('search-item-link').style.color = "#ccc";
		document.getElementById('search-all-link').style.color = "#fff";
		document.getElementById('item-number-check').value = 0;
	}
}


function swapProductSet(fromSet, toSet, pageNoId, pageNo){
		document.getElementById(fromSet).style.display = "none";
		document.getElementById(toSet).style.display = "";
		if(pageNoId.length > 0) {
			document.getElementById(pageNoId).innerHTML = pageNo;
		}
}

function swapBackground(toTabId, fromTabId, formFromId, formToId){
		toClassName = document.getElementById(toTabId).className;
		toClassName = toClassName.substring(0,toClassName.lastIndexOf('-'));
		toClassName += "-active";
		
		fromClassName = document.getElementById(fromTabId).className;
		fromClassName = fromClassName.substring(0,fromClassName.lastIndexOf('-'));
		fromClassName += "-inactive";
		
		document.getElementById(toTabId).className = toClassName;
		
		document.getElementById(fromTabId).className = fromClassName;
		
		document.getElementById(formToId).style.display = "";
		document.getElementById(formFromId).style.display = "none";
}

function swapBackgroundInkHome(changeId, backgroundImageChange, fromId, toId){
		document.getElementById(changeId).style.backgroundImage = backgroundImageChange;
		document.getElementById(fromId).style.display = "none";
		document.getElementById(toId).style.display = "";
}

function launchQuickView(menuName) {
	popupNumber = menuName.substring(13);
	
	popupTopMargin = (popupNumber * 166) + 95;
	document.getElementById(menuName).style.marginTop = popupTopMargin + "px";
	if(document.getElementById(menuName + "-iframe")) {
		document.getElementById(menuName + "-iframe").style.marginTop = document.getElementById(menuName).style.marginTop;
		document.getElementById(menuName + "-iframe").style.marginLeft = "300px";
		document.getElementById(menuName + "-iframe").style.width = "420px";
	}
	showMenu(menuName);
}

function launchQuickViewSummary(menuName) {
	popupNumber = menuName.substring(13);
	if((popupNumber%3)!=0) {
		popupNumber = popupNumber - ((popupNumber%3));
	} else {
		popupNumber = popupNumber - 3;	
	}
	
	alert (popupNumber);
}

function findThisPosition(popupId, obj) {
	origObj = obj;
	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	//alert(curtop);
	
	obj = origObj;
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
		
    //alert(curleft);
	
	if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
	popupTopMargin = curtop-205;
	popupLeftMargin = curleft-200;
	} else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
		popupTopMargin = curtop-105;
		popupLeftMargin = curleft-100;
	} else {
		popupTopMargin = curtop-208;
		popupLeftMargin = curleft-110;
	}
	document.getElementById(popupId).style.marginTop = popupTopMargin + "px";
	document.getElementById(popupId).style.marginLeft = popupLeftMargin + "px";
	if(document.getElementById(popupId + "-iframe")) {
		document.getElementById(popupId + "-iframe").style.marginTop = popupTopMargin + "px";
		document.getElementById(popupId + "-iframe").style.marginLeft = popupLeftMargin + "px";
		document.getElementById(popupId + "-iframe").style.width = "420px";
	}
	showPopup(popupId);
}



function findThisPositionSummary(popupId, obj) {
	origObj = obj;
	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	//alert(curtop);
	
	obj = origObj;
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
		
    //alert(curleft);
	
	if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
	popupTopMargin = curtop-140;
	popupLeftMargin = curleft-350;
	} else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
		popupTopMargin = curtop-35;
		popupLeftMargin = curleft-290;
	} else {
		popupTopMargin = curtop-142;
		popupLeftMargin = curleft-350;
	}
	document.getElementById(popupId).style.marginTop = popupTopMargin + "px";
	document.getElementById(popupId).style.marginLeft = popupLeftMargin + "px";
	showPopup(popupId);
}


  
function showPopup(menuName) {
	

  hideAllPopups(menuName);
  //show iframe
  document.getElementById(menuName).style.visibility='visible';
  //adjust corresponding iframe height
  
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
 		if(document.getElementById(menuName + "-iframe")) {
		document.getElementById(menuName + "-iframe").style.marginTop = document.getElementById(menuName).style.marginTop;
		
		popupsMarginLeft = document.getElementById(menuName).style.marginLeft;
		popupsMarginLeft = parseInt(popupsMarginLeft);
		popupsMarginLeft += 20;
		
		
		popupsMarginTop = document.getElementById(menuName).style.marginTop;
		popupsMarginTop = parseInt(popupsMarginTop);
		popupsMarginTop += 20;
		
		document.getElementById(menuName + "-iframe").style.marginLeft = popupsMarginLeft+"px";
		
		document.getElementById(menuName + "-iframe").style.marginRight = "-"+popupsMarginLeft+"px";
		
		document.getElementById(menuName + "-iframe").style.marginTop = popupsMarginTop+"px";
		document.getElementById(menuName + "-iframe").style.width = "420px";
		document.getElementById(menuName + "-iframe").style.height = document.getElementById(menuName).offsetHeight - 33; 
		document.getElementById(menuName + "-iframe").style.visibility='visible';
	}
  }
} 
  
function hideAllPopups(menuName) {
	  document.getElementById(menuName).style.visibility='hidden';
	  
  if(document.getElementById(menuName + "-iframe")) {
	  document.getElementById(menuName + "-iframe").style.visibility='hidden';
	  document.getElementById(menuName + "-iframe").style.marginTop=0;
	  document.getElementById(menuName + "-iframe").style.marginLeft=0;
	  document.getElementById(menuName + "-iframe").style.width=0;
  }
} 
  
function showMenu(menuName) {
  hideAllMenus(menuName);
  //show iframe
  document.getElementById(menuName).style.visibility='visible';
  //adjust corresponding iframe height
  if(document.getElementById(menuName + "-iframe")) {
  	document.getElementById(menuName + "-iframe").style.height = document.getElementById(menuName).offsetHeight - 13; 
  	document.getElementById(menuName + "-iframe").style.visibility='visible';
  }
} 
  
function showOverlay() {
  if (document.getElementById("overLayer")) {
  	document.getElementById('overLayer').style.visibility='visible';
	overlayHeight = document.getElementById("container").scrollHeight + "px";
	document.getElementById('overLayer').style.height = overlayHeight;
	document.getElementById('overLayer').style.width = document.body.offsetWidth;
  }
}
  
function hideAllMenus(menuName) {
document.getElementById(menuName).style.visibility='hidden';
  if (document.getElementById("overLayer")) {
	document.getElementById('overLayer').style.visibility='hidden';
  }	  
  if(document.getElementById(menuName + "-iframe")) {
	  document.getElementById(menuName + "-iframe").style.visibility='hidden';
  }
} 
function clearText(field){

    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;

}

function toggleInstruction (instructionId,imgId) {
	if (document.getElementById(instructionId).style.display == 'none') {
		document.getElementById(instructionId).style.display = '';
		document.getElementById(imgId).src = 'images/collapse-icon.gif';
	} else {
		document.getElementById(instructionId).style.display = 'none';
		document.getElementById(imgId).src = 'images/expand-icon.gif';
	}
}

function switchTab(tabId) {
	switchToId = "tab" + tabId;
	switchToContentId =  switchToId + "_content";
	
	i=1;
	currTabId = "tab" + i;
	while (document.getElementById(currTabId)) {
	currTabContentId = currTabId + "_content";
		if (i==tabId) {
			document.getElementById(currTabId).className = 'tab';
			document.getElementById(currTabContentId).style.display='';
		} else {	
			document.getElementById(currTabId).className = 'inactive-tab';
			document.getElementById(currTabContentId).style.display='none';
		}
		i++;
		currTabId = "tab" + i;
	}
}

function calculateScrollableWidth(productQuantity) {
	productQuantity = 200*productQuantity;
	productQuantity = productQuantity + "px";
	document.getElementById('scrollable-inner').style.width = productQuantity;
	document.getElementById('top-scrollable-inner').style.width = productQuantity;
}

topScrollPosition = 0;
bottomScrollPosition = 0;

function scrollingDetector(){
	//alert("You're at " + document.getElementById('scrollable').scrollLeft + " pixels.");
	newTopScrollPosition = document.getElementById('top-scrollable').scrollLeft;
	newBottomScrollPosition = document.getElementById('scrollable').scrollLeft;
	//alert ("The New Top Position is" + document.getElementById('top-scrollable').scrollLeft + " \n The Old Top Position was" + topScrollPosition + " \n The New Bottom Position is" + document.getElementById('scrollable').scrollLeft + " \n The Old Bottom Position was" + bottomScrollPosition);
	
	if (newTopScrollPosition != topScrollPosition) {
		document.getElementById('scrollable').scrollLeft = document.getElementById('top-scrollable').scrollLeft;
		bottomScrollPosition = newTopScrollPosition;
		topScrollPosition = newTopScrollPosition;
	//} else if (newBottomScrollPosition != bottomScrollPosition) {
	} else {
		document.getElementById('top-scrollable').scrollLeft = document.getElementById('scrollable').scrollLeft;
		topScrollPosition = newBottomScrollPosition;
		bottomScrollPosition = newBottomScrollPosition;
	}
}

function startScrollingDetector(){
	setInterval("scrollingDetector()", 1);
}

function swapImage(imageId, imgSrc, srcObj, imgSetId) {
	document.getElementById(imageId).src = imgSrc;
	i = 1;
	while(document.getElementById(imgSetId+"-"+i)) {
		document.getElementById(imgSetId+"-"+i).className = "";
		i++;
	}
	srcObj.className = "selected";
}
