var menu_timerID = null;
var box_timerID = null;
var lCurrBrand = null;
var lCurrID = null;
var lCurrLink = null;
var lCurrBox = null;
var aBrands = new Array()
//var sBase = '';

function genderPopShowMenu(lBrand,o,oXOffset,oYOffset,oLink) {
	if (typeof(o)=='string') o=document.getElementById(o);
	if (o) {
		if (lBrand != lCurrBrand) {
			if (lCurrBrand != null) closemenu();
			if (lCurrID != null) closemenu();
			//MM_swapImage(sDiv,'','Images/DivFrame-' + sDiv + 'Over.gif',1);
	//		document.images[sDiv].src = imagePath + sDiv + 'Over.gif'
			lCurrLink = oLink;
			lCurrLink.className = "over";
			//alert(lCurrLink.class);
			showGenderPop(lBrand,o,oXOffset,oYOffset);	
			lCurrBrand = lBrand;
		}
		genderPopClearTimer();
	}
}

function genderPopShowMenuTab(sLink,oXOffset,oYOffset,o) {
	var oID = o;
	if (typeof(o)=='string') o=document.getElementById(o);
	if (o) {
		if (oID != lCurrID) {
			if (lCurrBrand != null) closemenu();
			if (lCurrID != null) closemenu();
			lCurrLink = o;
			//alert(lCurrLink.className);
			lCurrLink.className = oID + ' over';
			showGenderPopTab(sLink,o,oXOffset,oYOffset);
			lCurrID = oID;
		}
		genderPopClearTimer();
	}
}

function genderPopShowMenuSale(sLink,oXOffset,oYOffset,o) {
	var oID = o;
	if (typeof(o)=='string') o=document.getElementById(o);
	if (o) {
		if (oID != lCurrID) {
			if (lCurrBrand != null) closemenu();
			if (lCurrID != null) closemenu();
			lCurrLink = o;
			//alert(lCurrLink.className);
			lCurrLink.className = oID + ' over';
			showGenderPopSale(sLink,o,oXOffset,oYOffset);
			lCurrID = oID;
		}
		genderPopClearTimer();
	}
}

//case shapes 

function caseShapePop(sLink,oXOffset,oYOffset,o) {
	var oShape = 'm_ws_' + o;
	var sShape = o;
	if (typeof(o)=='string') o=document.getElementById('m_ws_' + o);
	if (o) {
		if (oShape != lCurrID) {
			//if (lCurrBrand != null) closemenu();
			if (lCurrID != null) closeshapes();
			lCurrLink = o;
			//alert(lCurrLink.className);
			lCurrLink.className = 'm_ws_holder selected';
			showShapePop(sLink,o,oXOffset,oYOffset, sShape);
			lCurrID = oShape;
		}
		shapePopClearTimer();
	}
}

function shapePopSetTimer() {
	if (menu_timerID) return;
	menu_timerID = setTimeout("closeshapes()",1500);
}

function shapePopClearTimer() {
	clearTimeout(menu_timerID)
	menu_timerID = null
}

function closeshapes() {
	if (lCurrLink) { lCurrLink.className = lCurrLink.className.replace('selected',''); lCurrLink = null; }
	//lCurrLink.className = '';
	hideShapePop();
	shapePopClearTimer();
	//lCurrBrand = null;
	lCurrID = null;
}

function showShapePop(sLink,oLink,oXOffset,oYOffset,sShape) {
	var o = document.getElementById('menu_shape_pop')
	//alert('got here');
	var s='';

	if (o) {
		s += '<a href="' + sLink + '" onmouseover="shapePopClearTimer" ><img src="' + sBase + '/images/spacer.gif"><br><span>' + sShape + '</span></a>';
		o.innerHTML = s
		o.style.display='block';
		o.style.background='url(' + sBase + '/images/shapes/ws_' + sShape + '.gif) no-repeat #ffffff';
		var oLinkPos = getPosition(oLink);
		o.style.left = oLinkPos.x + oXOffset + 'px';
		o.style.top = oLinkPos.y + oYOffset + 'px';
	}
}

function hideShapePop() {
	var o = document.getElementById('menu_shape_pop');
	if (o) o.style.display='none';
}

//end case shapes functions

function genderPopSetTimer() {
	if (menu_timerID) return;
	menu_timerID = setTimeout("closemenu()",500);
}

function genderPopClearTimer() {
	clearTimeout(menu_timerID)
	menu_timerID = null
}

function closemenu() {
	if (lCurrLink) { lCurrLink.className = lCurrLink.className.replace('over',''); lCurrLink = null; }
	//lCurrLink.className = '';
	hideGenderPop();
	genderPopClearTimer();
	lCurrBrand = null;
	lCurrID = null;
}

function hideGenderPop() {
	var o = document.getElementById('div_gender_pop');
	var o2 = document.getElementById('div_sale_pop');
	var o3 = document.getElementById('menu_shop_pop');
	if (o) o.style.display='none';
	if (o2) o2.style.display='none';
	if (o3) o3.style.display='none';
}

function showGenderPop(lBrand,oLink,oXOffset,oYOffset) {
	var o = document.getElementById('div_gender_pop')
	var aGenders = ['Men','Women','Both']
	var s='';
	if (o) {
		for (var i=0;i<aGenders.length;i++) {
			s += '<a href="' + sBase + '/' + encodeURI(aBrands[lBrand][1]) + ((aBrands[lBrand][2]=='True') ? '/Watches/':'/Collections/') + ((aGenders[i]=='Both')?'':(aGenders[i]+'s')) + ((aBrands[lBrand][2]=='True') ? '?PerPage=All':'') + '" onmouseover="genderPopClearTimer()" class="' + aGenders[i] + '"><span>' + (aGenders[i]) + '</span></a>';
		}
		o.innerHTML = s
		o.style.display='block';
		var oLinkPos = getPosition(oLink);
		o.style.left = oLinkPos.x + oXOffset + 'px';
		o.style.top = oLinkPos.y + oYOffset + 'px';
	}
}

function showGenderPopTab(sLink,oLink,oXOffset,oYOffset) {
	var o = document.getElementById('div_gender_pop')
	var aGenders = ['Men','Women','Both']
	var s='';

	if (o) {
		for (var i=0;i<aGenders.length;i++) {
			s += '<a href="' + sLink + '&Gender=' + aGenders[i] + '" onmouseover="genderPopClearTimer()" class="' + aGenders[i] + '"><span>' + ((aGenders[i]=='All')?'Both':aGenders[i]) + '</span></a>';
		}
		o.innerHTML = s
		o.style.display='block';
		var oLinkPos = getPosition(oLink);
		o.style.left = oLinkPos.x + oXOffset + 'px';
		o.style.top = oLinkPos.y + oYOffset + 'px';
	}
}

function showGenderPopSale(sLink,oLink,oXOffset,oYOffset) {
	var o = document.getElementById('div_sale_pop')
	var aGenders = ['Men','Women','Both']
	var s='';

	if (o) {
		s += '<a href="' + sLink + '" onmouseover="genderPopClearTimer()" class="view"><span>View All</span></a>';
		s += '<a href="' + sLink + '&priceFrom=0&priceTo=500" onmouseover="genderPopClearTimer()" class="view0"><span>$0 - $500</span></a>';
		s += '<a href="' + sLink + '&priceFrom=500&priceTo=1000" onmouseover="genderPopClearTimer()" class="view500"><span>$500 - $1,000</span></a>';
		s += '<a href="' + sLink + '&priceFrom=1000&priceTo=5000" onmouseover="genderPopClearTimer()" class="view1000"><span>$1,000 - $5,000</span></a>';
		s += '<a href="' + sLink + '&priceFrom=5000&priceTo=1000" onmouseover="genderPopClearTimer()" class="view5000"><span>$5,000 - $10,000</span></a>';
		s += '<a href="' + sLink + '&priceFrom=10000&priceTo=999999" onmouseover="genderPopClearTimer()" class="view10000"><span>$10,000+</span></a>';
		o.innerHTML = s
		o.style.display='block';
		var oLinkPos = getPosition(oLink);
		o.style.left = oLinkPos.x + oXOffset + 'px';
		o.style.top = oLinkPos.y + oYOffset + 'px';
	}
}

function showGenderBox1(lBrand,sLink,j,sWatch) {

	if (j != lCurrBox) {
		if (lCurrBox) closemenuBox();
		lCurrBox = j;
		var o = document.getElementById('div_gender_box' + j)
		var aGenders = ['Men','Women','Both']
		var s='';
		if (o) {
			for (var i=0;i<aGenders.length;i++) {
				s += '<a href="' + sLink + '?Gender=' + aGenders[i] + '" onmouseover="genderBoxClearTimer()" class="' + aGenders[i] + '"><span onmouseover="genderBoxClearTimer()">' + ((aGenders[i]=='All')?'Both':aGenders[i]) + '</span></a>';
			}
			s += '<a href="' + sWatch + '"onmouseover="genderBoxClearTimer()" class="watch">This Watch</a>'
			o.innerHTML = s
			o.style.display='block';
		}
	}
	genderBoxClearTimer();
}

function showGenderBox(lBrand,sLink,j,sWatch) {

	if (j != lCurrBox) {
		if (lCurrBox) closemenuBox();
		lCurrBox = j;
		var o = document.getElementById('div_gender_box' + j)
		var aGenders = ['Men','Women','Both']
		var s='';
		if (o) {
			for (var i=0;i<aGenders.length;i++) {
				s += '<a href="' + sLink + ((aGenders[i]=='Both')?'':aGenders[i] + 's') + '" onmouseover="genderBoxClearTimer()" class="' + aGenders[i] + '"><span onmouseover="genderBoxClearTimer()">' + (aGenders[i]) + '</span></a>';
			}
			s += '<a href="' + sWatch + '"onmouseover="genderBoxClearTimer()" class="watch">This Watch</a>'
			o.innerHTML = s
			o.style.display='block';
		}
	}
	genderBoxClearTimer();
}

function genderBoxSetTimer() {
	if (box_timerID) return;
	box_timerID = setTimeout("closemenuBox()",500);
}

function genderBoxClearTimer() {
	clearTimeout(box_timerID)
	box_timerID = null
}

function hideGenderBox(j) {
	var o = document.getElementById('div_gender_box' + j);
	if (o) o.style.display='none';
}

function closemenuBox() {
	if (lCurrBox) {
		//lCurrLink.className = '';
		hideGenderBox(lCurrBox);
		genderBoxClearTimer();
		lCurrBox = null;
	}
}

function getPosition(e){
	var left = 0;
	var top  = 0;

	while (e.offsetParent){
		left += e.offsetLeft;
		top  += e.offsetTop;
		e     = e.offsetParent;
	}

	left += e.offsetLeft;
	top  += e.offsetTop;

return {x:left, y:top};
}


//menu (version b) drop down
//function menuPopShow(sLink,oXOffset,oYOffset,o,sImgPath,sBase) {
//	var oID = o;
//	if (typeof(o)=='string') o=document.getElementById(o);
//	if (o) {
//		if (oID != lCurrID) {
//			if (lCurrBrand != null) closemenu();
//			if (lCurrID != null) closemenu();
//			lCurrLink = o;
//			//alert(lCurrLink.className);
//			lCurrLink.className = oID + ' over';
//			showMenuDrop(sLink,o,oXOffset,oYOffset,sImgPath,sBase);
//			lCurrID = oID;
//		}
//		genderPopClearTimer();
//	}
//}
//
//function showMenuDrop(sLink,oLink,oXOffset,oYOffset,sImgPath,sBase) {
//	var o = document.getElementById('menu_shop_pop')
//	var s='';
//
//	if (o) {
//		s += '<div class="basicmenuelement"><a class="minimenu" href="https://www.mcafeesecure.com/RatingVerify?ref=www.thewatchery.com" target="_blank" onmouseover="genderPopClearTimer()" ><img border="0" oncontextmenu="alert(\'Copying Prohibited by Law - McAfee Secure is a Trademark of McAfee, Inc.\'); return false;" alt="McAfee Secure sites help keep you safe from identity theft, credit card fraud, spyware, spam, viruses and online scams" src="//images.scanalert.com/meter/www.thewatchery.com/12.gif" style="margin: 5px 0pt;"/></a></div>';
//		s += '<div class="basicmenuelement"><a target="_blank" href="http://feedback.ebay.com/ws/eBayISAPI.dll?ViewFeedback2&userid=thewatchery&ftab=AllFeedback&myworld=true" onmouseover="genderPopClearTimer()"><img height="36" border="0" width="140" alt="100% Positive Feedback" src="' + sImgPath + '/images/menu_right_11_feedback.gif"/></a></div>';
//		s += '<div class="basicmenuelement"><a target="_blank" href="https://www.bbb.org/online/consumer/cks.aspx?ID=107061110497" onmouseover="genderPopClearTimer()" ><img height="36" border="0" width="140" alt="BBB" src="' + sImgPath + '/images/menu_right_13_bbb.gif"/></a></div>';
//		s += '<div class="basicmenuelement"><a href="' + sBase + '/about.asp" onmouseover="genderPopClearTimer()"><img src="' + sImgPath + '/images/menu_right_10_brandnew.gif" alt="100% Brand New" width="140" height="52" border="0"></a></div></div>';
//		s += '<div class="basicmenuelement"><a href="' + sBase + '/about.asp?topic=7" onmouseover="genderPopClearTimer()"><img src="' + sImgPath + '/images/menu_right_8_30day.gif" alt="30 Day Money Back Guarantee" width="140" height="36" border="0"></a></div>';
//		s += '<div class="basicmenuelement"><a href="' + sBase + '/about.asp?topic=8" onmouseover="genderPopClearTimer()"><img src="' + sImgPath + '/images/menu_right_9_2year.gif" alt="2-Year Warranty" width="140" height="36" border="0"></a></div>';
//		s += '<div class="basicmenuelement"><a href="' + sBase + '/testimonials.asp" onmouseover="genderPopClearTimer()"><img src="' + sImgPath + '/images/menu_right_12_testimonials.gif" alt="Testimonials" width="140" height="36" border="0"></a></div>';
//		s += '<div class="basicmenuelement"><img src="' + sImgPath + '/images/menu_right_14_customer.gif" alt="100% Customer Satisfaction" width="140" height="36" border="0" onmouseover="genderPopClearTimer()"></div>';
//		s += '<div class="basicmenuelement"><img src="' + sImgPath + '/images/menu_right_15_livehelp.gif" alt="Live Help" width="140" height="36" border="0" onmouseover="genderPopClearTimer()"></div>';
//		s += '<div class="basicmenuelement"><img src="' + sImgPath + '/images/menu_right_16_savings.gif" alt="Great Savings" width="140" height="36" border="0" onmouseover="genderPopClearTimer()"></div>';
//		o.innerHTML = s
//		o.style.display='block';
//		var oLinkPos = getPosition(oLink);
//		o.style.left = oLinkPos.x + oXOffset + 'px';
//		o.style.top = oLinkPos.y + oYOffset + 'px';
//	}
//}

//begin brand pop functions //

/*function brandPop(sBase,oXOffset,oYOffset,o,aBrands) {
	if (typeof(o)=='string') o=document.getElementById(o);
	if (o) {
		showBrandPop(sBase,o,oXOffset,oYOffset,aBrands);
		brandPopClearTimer();
	}
}

function brandPopSetTimer(ev) {
	ev = ev || window.event;

	//alert(ev.type)
	ev.cancelBubble = true;
	if (ev.stopPropagation) ev.stopPropagation();

	var oEl = ev.srcElement ? ev.srcElement : ev.target;
	while (oEl.parentElement) {
		//alert(oEl.id)
		if (oEl.id == 'menu_brand_m_l' || oEl.id == 'menu_brand_t') { return }
		oEl = oEl.parentElement;
	}
	if (menu_timerID) return;
	menu_timerID = setTimeout("closeBrands()",100);
}

function brandPopClearTimer() {
	clearTimeout(menu_timerID)
	menu_timerID = null
}

function closeBrands() {
	hideBrandPop();
	brandPopClearTimer();
}

function showBrandPop(sBase,oLink,oXOffset,oYOffset,sBrands) {
	var o = document.getElementById('menu_brand_pop')
	var oContent = document.getElementById('menu_brand_m_r');
	var aBrands = sBrands.split(",");
	var s='';
	var sBrandLink='';
	var capLetter='';
	var curLetter='';
	var iCols=0;
	var iPerCol =23;
	var iColCnt =1;
	
	if (o) {
		s += '<div id="clear" style="height:15px;"><a href="#" oonmouseover="brandPopClearTimer()" onclick="closeBrands(); return false" class="close_popup" title="close popup"><span>close popup</span></a></div>';
		for (var i=0;i<aBrands.length;i++) {
			sBrandLink = aBrands[i].replace(/ /g,"_");
			capLetter = aBrands[i].charAt(0);
			if (iColCnt == 1 ) {
				s += '<div class="column" oonmouseover="brandPopClearTimer()">';
				iCols++;
			}
			if (capLetter != curLetter) {
				s += '<span class="letter';
				if (iColCnt == 1) {
					s += ' first';
				}				
				s += '"  oonmouseover="brandPopClearTimer()">' + capLetter + '</span>';
				curLetter = capLetter;
				iColCnt++;
			} 
			s += '<a href="' + sBase + '/' + sBrandLink + '/Collections/" class="brand_pop_link"  oonmouseover="brandPopClearTimer()">' + aBrands[i] + '</a>';
			if (iColCnt>=iPerCol) {
				s += '</div>';
				iColCnt=1;
			} else {
				s += '<br/>';
				iColCnt = iColCnt+1;
			}
		} 
		if (iColCnt > 1 ) {
			for (iColCnt;iColCnt<iPerCol;iColCnt++) {
				s += '<br/>';
			}
			s += '</div>';	
		}
		s += '<div class="clear" oonmouseover="brandPopClearTimer()"></div>';
		oContent.innerHTML = s
		var oLinkPos = getPosition(oLink);
		o.style.left = oLinkPos.x + oXOffset + 'px';
		o.style.top = oLinkPos.y + oYOffset + 'px';
		o.style.width = (iCols * 113) + 30 +  'px';
		o.style.height = 'auto';
		o.style.display='block';
	}
}

function hideBrandPop() {
	var o = document.getElementById('menu_brand_pop');
	if (o) o.style.display='none';
}*/





function populateBrandPop() {
	var o = document.getElementById('menu_brand_pop')
	var oContent = document.getElementById('menu_brand_m_r');
	var s='';
	var sBrandLink='';
	var capLetter='';
	var curLetter='';
	var iCols=0;
	var iPerCol =20;
	var iColCnt =1;
	if (o) {
		s += '<div style="float: left; clear: both; font-size: 11px; font-weight: bold; width: 95%; padding: 0pt 0pt 2px; margin: -6px 0px 4px; text-align: center; border-bottom:1px dotted #380B42;">All Brands</div>';
		//'<div id="clear" style="height:15px;"><a href="#" oonmouseover="brandPopClearTimer()" onclick="closeBrands(); return false" class="close_popup" title="close popup"><span>close popup</span></a></div>';
		for (var i=0;i<aBrands.length;i++) {
//			sBrandLink = aBrands[i].replace(/ /g,"_");
			sBrandLink = aBrands[i][1];
			capLetter = aBrands[i][1].charAt(0);
			if (iColCnt == 1 ) {
				s += '<div class="column">';
				iCols++;
			}
			if (capLetter != curLetter) {
				s += '<span class="letter';
				if (iColCnt == 1) {
					s += ' first';
				}				
				s += '" >' + capLetter + '</span>';
				curLetter = capLetter;
				iColCnt++;
			} 
			s += '<a href="' + sBase + '/' + sBrandLink + '/' + ((aBrands[i][2]=='True') ? 'Watches' : 'Collections') + '/" class="brand_pop_link" >' + aBrands[i][1].replace(/\_/g,' ') + '</a>';
			if (iColCnt>=iPerCol) {
				s += '</div>';
				iColCnt=1;
			} else {
				s += '<br/>';
				iColCnt = iColCnt+1;
			}
		} 
		if (iColCnt > 1 ) {
			for (iColCnt;iColCnt<iPerCol;iColCnt++) {
				s += '<br/>';
			}
			s += '</div>';	
		}
		s += '<div class="clear"></div>';
		oContent.innerHTML += s
	}
	$(function(){
		$("#s_h_att_1_box").hover(function(){
				if (jQuery.support.opacity) {$("#menu_brand_pop").fadeIn();	} else {$("#menu_brand_pop").show();};
		},function(){
				if (jQuery.support.opacity) {$("#menu_brand_pop").stop(true,true).fadeOut("fast");} else {$("#menu_brand_pop").stop(true,true).hide();};
		});
	});
}
//end brand pop functions //

//begin site ranks pop functions //

/*function ranksPop(oXOffset,oYOffset,o) {
	if (typeof(o)=='string') o=document.getElementById(o);
	if (o) {
		showRanksPop(o,oXOffset,oYOffset);
		ranksPopClearTimer();
	}
}

function ranksPopSetTimer() {
	if (box_timerID) return;
	box_timerID = setTimeout("closeRanks()",500);
}

function ranksPopClearTimer() {
	clearTimeout(box_timerID)
	box_timerID = null
}

function closeRanks() {
	hideRanksPop();
	ranksPopClearTimer();
}

function showRanksPop(oLink,oXOffset,oYOffset) {
	var o = document.getElementById('site_rank_pop')
	
	if (o) {
		var oLinkPos = getPosition(oLink);
		//alert(oLinkPos.x + ' + ' + oXOffset + ' = ' +  (oLinkPos.x + oXOffset) + 'px');
		//alert(oLinkPos.y + ' + ' + oYOffset + ' = ' +  (oLinkPos.y + oYOffset) + 'px');
		o.style.left = (oLinkPos.x + oXOffset) + 'px';
		o.style.top = (oLinkPos.y + oYOffset) + 'px';
		//o.style.width = '500px';
		//o.style.height = '500px';
		o.style.display = 'block';
	}
}

function hideRanksPop() {
	var o = document.getElementById('site_rank_pop');
	if (o) o.style.display='none';
}*/


$(document).ready(function() {
	$(function(){
		$("#site_rank_link").hover(function(){
				if (jQuery.support.opacity) {$("#site_rank_pop").fadeIn(); } else {$("#site_rank_pop").show();};
		},function(){
				if (jQuery.support.opacity) {$("#site_rank_pop").stop(true,true).fadeOut();	} else {$("#site_rank_pop").stop(true,true).hide();};
		});
	});
	$(function(){
		$("#secure_shopping_link").hover(function(){
				if (jQuery.support.opacity) {$("#secure_shopping_pop").fadeIn(); } else {$("#secure_shopping_pop").show();};
		},function(){
				if (jQuery.support.opacity) {$("#secure_shopping_pop").stop(true,true).fadeOut();	} else {$("#secure_shopping_pop").stop(true,true).hide();};
		});
	});
	$(function(){
		$("#industry_link").hover(function(){
				if (jQuery.support.opacity) {$("#industry_pop").fadeIn(); } else {$("#industry_pop").show();};
		},function(){
				if (jQuery.support.opacity) {$("#industry_pop").stop(true,true).fadeOut();	} else {$("#industry_pop").stop(true,true).hide();};
		});
	});
	$(function(){
		$("#gleam_link").click(function(){
				if (jQuery.support.opacity) {$("#gleam_pop").fadeIn(); } else {$("#gleam_pop").show();};
		},function(){
				if (jQuery.support.opacity) {$("#gleam_pop").stop(true,true).fadeOut();	} else {$("#gleam_pop").stop(true,true).hide();};
		});
	});
	$(function(){
		$("#sale_pop_div").hover(function(){
				if (jQuery.support.opacity) {$("#sale_pop").fadeIn(); } else {$("#sale_pop").show();};
		},function(){
				if (jQuery.support.opacity) {$("#sale_pop").stop(true,true).fadeOut();	} else {$("#sale_pop").stop(true,true).hide();};
		});
	});
	$(function(){
		$("#ipmg_link").click(function(){
				if (jQuery.support.opacity) {$("#ipmg_pop").fadeIn(); } else {$("#ipmg_pop").show();};
		},function(){
				if (jQuery.support.opacity) {$("#ipmg_pop").stop(true,true).fadeOut();	} else {$("#ipmg_pop").stop(true,true).hide();};
		});
	});
	$(function(){
		$("#header_ipmg_link").click(function(){
				if (jQuery.support.opacity) {$("#ipmg_pop").fadeIn(); } else {$("#ipmg_pop").show();};
		},function(){
				if (jQuery.support.opacity) {$("#ipmg_pop").stop(true,true).fadeOut();	} else {$("#ipmg_pop").stop(true,true).hide();};
		});
	});
});


//end site ranks pop functions //

