

	var isOpera = (navigator.userAgent.indexOf('Opera') != -1);
	var isIE = (!isOpera && navigator.userAgent.indexOf('MSIE') != -1)



	///////// rollover stuff

	var time_id;

	function registerHover(obj, type, id)	{

		obj.hover_type = type;
		obj.hover_id = id;
		
		obj.onmousemove = handleRollMouseMove;
		obj.onmouseout = handleRollMouseOut;
		obj.onmousedown = handleRollMouseOut;
		
	}

	function handleRollMouseMove(e) {

		clearTime();

		if(findObj("hover")!=null)	{

			time_id = setTimeout("showRollover('" + this.id + "');", 800);
		}
	}

	function handleRollMouseOut(e) {

		hideRollover();
		
		clearTime();
	}
	
	
	function hideRollover() {

		var div = findObj("hover");

		if(div==null)	return;

		div.style.display = "none";
	}
	

	function clearTime()	{
	
		if(time_id!=null)	{
	
			clearTimeout(time_id);
			time_id = null;
		}
	}

	function showRollover(id)	{
	
		var obj = findObj(id);
		
		doHover(obj, obj.hover_type, obj.hover_id)
	}





	//////// tab stuff


	var cur_tab = -1;

	function setTab(tab)	{

		if(cur_tab>=0)	unsetTab(cur_tab);
	
		var link = findObj("link" + tab);
		var span = findObj("span" + tab);
	
		link.style.backgroundPosition = "0% -42px";
		span.style.backgroundPosition = "100% -42px";
		span.style.color = "#000000";
		
		cur_tab = tab;
	}

	function unsetTab(tab)	{
	
		var link = findObj("link" + tab);
		var span = findObj("span" + tab);
	
		link.style.backgroundPosition = "";
		span.style.backgroundPosition = "100% 0px";
		span.style.color = "#666666";
	}
	
	
	
	//// vote stuff
	
	function saveVote(voteID, productID, loves)	{

		sendVote(voteID, productID, loves, "product");
	}


	function sendVote(voteID, itemID, loves, item_type)	{

		if(!loggedin)	{

			showLogin(findObj("vote_" + voteID), "login");
			return;
		}

		var current = eval("vote_status_" + voteID);

		if((current=="love" && loves) ||
		   (current=="hate" && !loves))		{
		   	
		   	blink(current + "_count_" + voteID, 1, voteID);
		   	return;
		}

		// adjust counts

		adjustCount(voteID, loves?"love":"hate", true);

		if(current!="")	{  // decriment existing vote

			adjustCount(voteID, loves?"hate":"love", false);
		}
		
		// update status cache
		
		eval("vote_status_" + voteID + " = '" + (loves?"love":"hate") + "';");
			
		// change images
		
		findObj((loves?"love":"hate") + "_img_" + voteID).src = "/html/global/images/vote/button-" + (loves?"yes":"no") + ".gif";
		findObj((loves?"hate":"love") + "_img_" + voteID).src = "/html/global/images/vote/button-" + (loves?"no":"yes") + "-off.gif";

		if(findObj("love_icon_" + voteID)!=null)	{  // don't always show icons
	
			findObj("love_icon_" + voteID).src = "/html/global/images/vote/heart-yes-" + (loves?"check":"off") + ".gif";
			findObj("hate_icon_" + voteID).src = "/html/global/images/vote/heart-no-" + (loves?"off":"check") + ".gif";
		}
			
		// save on server
	
		new Image().src="/explore/vote/noheaders?itemID=" + itemID + "&loves=" + (loves?1:0) + "&item_type=" + item_type + "&rand=" + Math.random();
		

	}
	
	

	function adjustCount(voteID, type, increase)	{
	
		var divID = type + "_count_" + voteID;
	
		var div = findObj( divID );
		
		if(div==null)	return;  // don't always have vote count
	
		var new_count = eval(div.innerHTML) + (increase?1:-1);

		div.innerHTML = new_count;

		if(increase)	{
		
			blink(divID, 1, voteID);
		}
	}

	
	

	function blink(divID, i, voteID)	{

		var div = findObj(divID);

		if(div==null)	return;  // don't always have count

		div.style.color = (i%2==0)?"#FFFFFF":"#90917b";

		if(i<6)	{
		
			setTimeout( "blink('" + divID + "', " + (i+1) + ", " + voteID + ");", 100);
		}
		else	{  // dont with blink - do we have a vote action?
		
			var img = findObj("slideimg_" + voteID);
			
			if(img.onvote!=null)	 img.onvote();
		}
	}



	///////// div updates

		
	function saveToStyleCircle(username)	{

		if(!loggedin)	{

			showLogin(findObj("circle_link"), "circle");
			return;
		}

		// save on server
	
		var url = "/profiles/circle_add/noheaders?user=" + username + "&rand=" + Math.random();
	
		new Image().src=url;

		//
		
		findObj("circle_link").style.display = "none";
		findObj("in_circle").style.display = "block";
	}
	

	function removeFromStyleCircle(username)	{

		// save on server
	
		var url = "/profiles/circle_remove/noheaders?user=" + username + "&rand=" + Math.random();
	
		new Image().src=url;

		//
		
		findObj("circle_link").style.display = "block";
		findObj("in_circle").style.display = "none";
	}
	
	function showLogin(div, type)	{
	
		var login_div = findObj("login");

		// position	
		
		var why = findObj("login_why");
		
		if(type=="login") 		 	why.innerHTML = "To make your vote count";
		else if(type=="comment") 	why.innerHTML = "To save a comment";
		else if(type=="tag") 	 	why.innerHTML = "To add a tag";
		else if(type=="send_news") 	why.innerHTML = "To alert your Style Circle";
		else if(type=="circle") 	why.innerHTML = "To add to your circle";
		
		//var div_pos = findPos(div);
		//login_div.style.left = div_pos[0] + 8;
		
		login_div.style.top = getScrollXY()[1] + 80;
	
		document.bgColor = "#f3f3f3";
	
		// display

		login_div.style.display = "block";
	}
	
	
	function hideLogin()	{
	
		var login_div = findObj("login");
	
		login_div.style.display = "none";
		
		//var comment = findObj("comment_fields");
		//if(comment!=null)	comment.style.display = "block";
		
		document.bgColor = "#FFFFFF";
		
	}



	function showFlag(div, type, id)	{
	
		findObj("flag_type").value = type;
		findObj("flag_id").value = id;
	
		var flag_div = findObj("flag");

		// position	

		var div_pos = findPos(div);
		flag_div.style.left = div_pos[0] + 8;
		flag_div.style.top = div_pos[1] + 24;
	
		// display

		flag_div.style.display = "block";
	}

	function hideFlag()	{
	
		findObj("flag").style.display = "none";
	}




	function showNews(div, id)	{
	
		if(!loggedin)	{

			showLogin(div, "send_news");
			return;
		}
		
		findObj("news_productID").value = id;
	
		var news_div = findObj("news");

		// position	

		var div_pos = findPos(div);
		news_div.style.left = div_pos[0] - 30;
		news_div.style.top = div_pos[1] + 24;
	
		// display

		news_div.style.display = "block";
	}

	function hideNews()	{
	
		findObj("news").style.display = "none";
	}


	function switchExplain(id)	{
				
		var current = findObj(id).style.display;
				
		findObj(id).style.display = current=="block"?"none":"block";
	}

	function getScrollXY() {
	  var scrOfX = 0, scrOfY = 0;
	  if( typeof( window.pageYOffset ) == 'number' ) {
	    //Netscape compliant
	    scrOfY = window.pageYOffset;
	    scrOfX = window.pageXOffset;
	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	    //DOM compliant
	    scrOfY = document.body.scrollTop;
	    scrOfX = document.body.scrollLeft;
	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
	    //IE6 standards compliant mode
	    scrOfY = document.documentElement.scrollTop;
	    scrOfX = document.documentElement.scrollLeft;
	  }
	  return [ scrOfX, scrOfY ];
	}
	


	///////////////////


	function findPos(obj) {
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
		}
		return [curleft,curtop];
	}




	function startFade(divID)	{
	
		blue = 0;
	
		fadeHighlight(divID, 100);
	}
	
	
	function fadeHighlight(divID, blue)	{
	
		var color = "#FFFF" + intToHex(Math.round(blue/16)) + intToHex(blue%16);
	
		findObj(divID).style.backgroundColor = color;
	
		if(blue<255)	{
		
			blue+= blue>180?2:5;
	
			if(blue>255)	blue = 255;
	
			setTimeout("fadeHighlight('" + divID + "', " + blue + ");", 40);
		}
	}


	////// slide ui

	var increment = 40;
	
	var targets = new Array();
	var movings = new Array();
	
	for(var i=0; i<100; i++)	{
		targets[i] = 0;
		movings[i] = false;
	}
	
	function slide(slide_index, diff)	{
	
		var slider = findObj("slide_me_" + slide_index);
		
		var parentWidth = getPixels(findObj("icon_layer_" + slide_index).style.width);
	
		if(parentWidth > slider.offsetWidth)	return;  // not scrollable
	
		var max_pos = slider.offsetWidth - parentWidth;
	
		// set new target
	
		targets[slide_index] = targets[slide_index] + diff;
		
		if(targets[slide_index] < -max_pos)			targets[slide_index] = -max_pos;
		if(targets[slide_index] > 0)				targets[slide_index] = 0;
	
		if(!movings[slide_index])	{
		
			move(slide_index);
		}			
	}
	
	function move(slide_index)	{
	
		movings[slide_index] = true;
		
		var slider = findObj("slide_me_" + slide_index);
		
		var diff = targets[slide_index] - getPixels(slider.style.left);
		
		if(diff<-increment)	diff = -increment;
		if(diff>increment)	diff = increment;
		
		slider.style.left = getPixels(slider.style.left) + diff;
		
		showSlideButtons(slide_index);
		
		if(slider.style.left == targets[slide_index])	{
		
			movings[slide_index] = false;
		}
		else	{
		
			setTimeout("move(" + slide_index + ");", (isIE?30:10));
		}
	}

	function getPixels(pos)	{
	
		return(eval(pos.substring(0, pos.length-2)));
	}
	
	function updateAllSlideButtons()	{
	
		for(var i=0; i<100; i++)	{
		
			showSlideButtons(i);
		}
	}
	
	
	function showSlideButtons(slide_index)	{
	
		var slider = findObj("slide_me_" + slide_index);
	
		if(slider==null)	return;
	
		var parentWidth = getPixels(findObj("icon_layer_" + slide_index).style.width);
	
		var max_pos = slider.offsetWidth - parentWidth;
	
		if(parentWidth+10 < slider.offsetWidth)	{  // not scrollable
	
			findObj("slide_left_" + slide_index).style.display = (getPixels(slider.style.left)<0?"block":"none");
			findObj("slide_right_" + slide_index).style.display = (getPixels(slider.style.left)>-max_pos?"block":"none");
		}		
	}	
	
	
	
	

	////// general utilities


	function mouseOver(img)	{
	
		if(img.src.indexOf("-over.gif")!=-1)	return;
	
		img.src = replace(img.src, ".gif", "-over.gif"); 
	}

	function mouseOut(img)	{

		if(img.src.indexOf("-over.gif")==-1)	return;
	
		img.src = replace(img.src, "-over.gif", ".gif");
	}
	
	



	function intToHex(c){
	
		if(c < 10) 	return(c);
		
		if(c==10)	return('A');
		if(c==11)	return('B');
		if(c==12)	return('C');
		if(c==13)	return('D');
		if(c==14)	return('E');
					return('F');
	}
	

	var bgcolor = "FFFFFF"
	
	function setOpacity(obj, opacity) {
	
	  opacity = (opacity == 100)?99.999:opacity;
	
	  // IE/Win
	  obj.style.filter = "alpha(opacity:"+opacity+")";
	  //obj.style.background = bgcolor; 
	
	  // Safari<1.2, Konqueror
	  obj.style.KHTMLOpacity = opacity/100;
	  
	  // Older Mozilla and Firefox
	  obj.style.MozOpacity = opacity/100;
	  
	  // Safari 1.2, newer Firefox and Mozilla, CSS3
	  obj.style.opacity = opacity/100;
	}
	
	
	function uniPop(href,winname,width,height,x,y,toolbar,scrollbars,resizable,status)  {
		if (href == "") href = '/support';
		if (winname == 'spellChecker') href+=escape(document.eventForm.notes.value);
		if ((width < 100) || (width == null)) var width = '515';
		if ((height < 100) || (height == null)) var height = '475';
		if (toolbar == null) var toolbar = 'yes';
		if (scrollbars == null) var scrollbars = 'yes';
		if (resizable == null) var resizable = 'yes';
		if (status == null) var status = 'yes';
		var theParam = "width=" +width+ 
						",height=" +height+  
						",toolbar=" +toolbar+ 
						",scrollbars=" +scrollbars+ 
						",resizable=" +resizable+ 
						",status=" +status+
						",screenX=" + x + ",screenY=" + y + ",top=" + y + ",left=" + x;
		var thePopup = window.open(href,winname,theParam);
	}
		
	function confirmURL(text, url) {
		if(confirm(text)) {
			location.href=(url);
		}
	}

	function trim(str)
	{
	   return str.replace(/^\s*|\s*$/g,"");
	}

	function isdefined( variable)
	{
	    return (typeof(variable) == "undefined")?  false: true;
	}


	
	function findObj(n, d) {
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.ls&&i<d.ls.length;i++) x=findObj(n,d.ls[i].document);
	  if(!x && document.getElementById) x=document.getElementById(n); return x;
	}
	
	
	

	function checkAll(params, value)
	{
		
		if(!isArray(params))	{
		
			if(!params.disabled)		params.checked = value;
			return;
		}
		
		
		for (i = 0; i < params.length; i++)	{
		
			var param = params[i];
			
			if(!param.disabled)		param.checked = value;
		}
		
	}
	
			
	function isArray(obj){return(typeof(obj.length)=="undefined")?false:true;}

 
 
 
	
	
	function replace(s, t, u) {
  /*
  **  Replace a token in a string
  **    s  string to be processed
  **    t  token to be found and removed
  **    u  token to be inserted
  **  returns new String
  */
  i = s.indexOf(t);
  r = "";
  if (i == -1) return s;
  r += s.substring(0,i) + u;
  if ( i + t.length < s.length)
    r += replace(s.substring(i + t.length, s.length), t, u);
  return r;
  }





