//////////////////////  END OF CUSTOMIZATION AREA  ///////////////////

// preload images that are to appear in tooltip
// from arrays above
if (document.images) {
	var theImgs = new Array();
	for (var i=0; i<messages.length; i++) {
  	theImgs[i] = new Image();
		theImgs[i].src = messages[i][0];
  }
}





// to layout image and text, 2-row table, image centered in top cell
// these go in var tip in doTooltip function
// startStr goes before image, midStr goes between image and text
var startStr = '<table width="' + tipWidth + '"><tr><td align="center" width="100%"><img src="';
var midStr = '" border="0" width=167 height=150 ></td></tr><tr><td valign="top">';
var endStr = '</td></tr></table>';
var src1 = "http://blindsdev.blinds.com/views/content/subModal/loadingAnimation.gif";
		
var startStr_cat = '<table width="' + tipWidth_cat + '" ><tr><td align="center" width="100%"><img src="';
var midStr_cat = '" border="0" width=208 height=188 ></td></tr><tr><td valign="top">';
var endStr_cat = '</td></tr></table>';
////////////////////////////////////////////////////////////
//  initTip	- initialization for tooltip.
//		Global variables for tooltip. 
//		Set styles for all but ns4. 
//		Set up mousemove capture if tipFollowMouse set true.
////////////////////////////////////////////////////////////
var tooltip, tipcss;
function initTip() {
	if (nodyn) return;
	tooltip = (ns4)? document.tipDiv.document: (ie4)? document.all['tipDiv']: (ie5||ns5)? document.getElementById('tipDiv'): null;
	tipcss = (ns4)? document.tipDiv: tooltip.style;
	if (ie4||ie5||ns5) {	// ns4 would lose all this on rewrites
		//tipcss.width = tipWidth+"px";
		tipcss.fontFamily = tipFontFamily;
		tipcss.fontSize = tipFontSize;
		tipcss.color = tipFontColor;
		tipcss.backgroundColor = tipBgColor;
		tipcss.borderColor = tipBorderColor;
		tipcss.borderWidth = tipBorderWidth+"px";
		tipcss.padding = tipPadding+"px";
		tipcss.borderStyle = tipBorderStyle;
		
	}
	if (tooltip&&tipFollowMouse) {
		if (ns4) document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = trackMouse;
	}
}

function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, true); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}

//Start Function
	var image_uri   = [];
	var image_count = [];
/* This function will draw the available colors for the product color.  */
	function drawColorSwatches(num)
	{
		var str = "";

		if(typeof image_uri[num] == 'undefined')
		    return str;
		    
		var splitRow = Math.ceil(image_uri[num].length/6);    
		str = "<div style='height:150px'><table width='100%' border='0' cellspacing='2' cellpadding='0' ><tr>";
		for(i=0,j=0;i< image_uri[num].length;i++,j++)
		{
		  if((j == splitRow ))
		  	{
		  		str = str + "</tr><tr>";
		  		j = 0;
		  	}
		  str = str + "<td width='20px' height='20px' valign='top'><table border='0' height='20px' cellspacing='0' cellpadding='0' ><tr><td width='20px' height='20px' valign='top'><img src='"+ image_uri[num][i] +"' width='20px' height='20px' alt=''";
				str = str + " style='border:1px solid gray;' /><td></tr></table></td>";
	       }		
		str = str + '</tr></table></div><div style="text-align: center;float:left;clear:both;margin-top:5px; font-family:' + tipFontFamily + '; font-size:9;" >' + image_count[num] +' Colors Available.</div>';
		return str;
	}
//End Function

addEvent(window, 'load', initTip);

var t1,t2;	// for setTimeouts
var tipOn = false;	// check if over tooltip link
function doTooltip(evt,num) {
	if (!tooltip) return;else tooltip.innerHTML = "***Loading Image....";
	if (t1) clearTimeout(t1);	if (t2) clearTimeout(t2);
	tipOn = true;
	// set colors if included in messages array
	if (messages[num][2])	var curBgColor = messages[num][2];
	else curBgColor = tipBgColor;
	if (messages[num][3])	var curFontColor = messages[num][3];
	else curFontColor = tipFontColor;
	if (ns4) {
		var tip = '<table border=0 bgcolor="' + tipBorderColor + '" width="' + tipWidth + '" cellspacing="0" cellpadding="' + tipBorderWidth + '" border="0"><tr><td><table bgcolor="' + curBgColor + '" width="100%" cellspacing="0" cellpadding="' + tipPadding + '" border="0"><tr><td align=center>'+ startStr + messages[num][0] + midStr + '<span style="font-family:' + tipFontFamily + '; font-size:' + tipFontSize + '; color:' + curFontColor + ';">' + messages[num][1] + '</span>' + endStr + '</td></tr></table></td></tr></table>';
		tooltip.write(tip);
		tooltip.close();
	} else if (ie4||ie5||ns5) {
		var tip = startStr + messages[num][0] + midStr + '<div style="text-align: center; font-family:' + tipFontFamily + '; font-size:' + tipFontSize + '; color:' + curFontColor + ';">' + messages[num][1] + '</div>' + endStr;
		tipcss.backgroundColor = curBgColor;
	 	tooltip.innerHTML = tip;
		//setTimeout("showImg()",2000);
	}
	if (!tipFollowMouse) positionTip(evt);
	else t1=setTimeout("tipcss.visibility='visible'",100);
}


//Start Function
/* New function to show tooltip with images and available colors on the category pages */
function doTooltipWithColor(evt,num) {
var startStr = '<table bodrder="0" width="170px" ><tr><td class="TipDivProductImage"><table width="100%" border="0" ><tr><td align="center"  ><img src="';
var midStr = '" border="0" width=167 height=150 ></td>';
var midStr1 = '</tr><tr><td valign="top">';
var endStr = '</td></tr></table></td>';
var src1 = "http://blindsdev.blinds.com/views/content/subModal/loadingAnimation.gif";

	if (!tooltip) return;
	if (t1) clearTimeout(t1);	if (t2) clearTimeout(t2);
	tipOn = true;
	// set colors if included in messages array
	if (messages[num][2])	var curBgColor = messages[num][2];
	else curBgColor = tipBgColor;
	if (messages[num][3])	var curFontColor = messages[num][3];
	else curFontColor = tipFontColor;
	if (ns4) {
		var tip = '<table border="1" bgcolor="' + tipBorderColor + '" width="' + tipWidth + '" cellspacing="0" cellpadding="' + tipBorderWidth + '"><tr><td><table bgcolor="' + curBgColor + '" width="100%" cellspacing="0" cellpadding="' + tipPadding + '" border="0"><tr><td align=center>'+ startStr + messages[num][0] + midStr + '<span style="font-family:' + tipFontFamily + '; font-size:' + tipFontSize + '; color:' + curFontColor + ';">' + messages[num][1] + '</span>' + endStr + '<td valign="top">'+ drawColorSwatches(num) +'</td></tr></table></td></tr></table>';
		tooltip.write(tip);
		tooltip.close();
	} else if (ie4||ie5||ns5) { 
		var tip = startStr + messages[num][0] + midStr + midStr1 + '<div style="text-align: center; font-family:' + tipFontFamily + '; font-size:' + tipFontSize + '; color:' + curFontColor + ';">' + messages[num][1] + '</div>' + endStr + '<td valign="top"><table width="100%" ><tr>'+ '<td valign="top">'+  drawColorSwatches(num) + '</td></tr></table></td></tr></table>';
		tipcss.backgroundColor = curBgColor;
	 	tooltip.innerHTML = tip;
	 	//document.getElementById("test").innerHTML = tip;
		//setTimeout("showImg()",2000);
	}
	if (!tipFollowMouse) positionTip(evt);
	else t1=setTimeout("tipcss.visibility='visible'",100);
}
//End Function

/*function showImg()
{
		document.getElementById('loading').style.display='none';
		document.getElementById('loadImg').style.display='block';
	
	}*/
/**** FUNCITON FOR CATEGORY IMAGE DISPLAY ROLLOVER ****/
function doTooltip_Cat(evt,num) {
	//alert("image - "+messages_Cat[num][0]);
	if (!tooltip) return;
	if(num<6) offY_Cat=-50;
	else if(num<9)	offY_Cat=-110;
	else if(num<13)	offY_Cat=-150;
	else offY_Cat=-220;
	//alert(num+" : "+ offY_Cat)
	if (t1) clearTimeout(t1);	if (t2) clearTimeout(t2);
	tipOn = true;
	// set colors if included in messages array
	if (messages_Cat[num][2])	var curBgColor = messages_Cat[num][2];
	else curBgColor = tipBgColor;
	if (messages_Cat[num][3])	var curFontColor = messages_Cat[num][3];
	else curFontColor = tipFontColor;
	if (ns4) {
		var tip = '<table border=0 bgcolor="' + tipBorderColor + '" width="' + tipWidth_cat + '" cellspacing="0" cellpadding="' + tipBorderWidth + '" border="0"><tr><td><table bgcolor="' + curBgColor + '" width="100%" cellspacing="0" cellpadding="' + tipPadding + '" border="0"><tr><td align=center>'+ startStr_cat + messages_Cat[num][0] + midStr_cat + '<span style="font-family:' + tipFontFamily + '; font-size:' + tipFontSize + '; color:' + curFontColor + ';">' + messages_Cat[num][1] + '</span>' + endStr_cat + '</td></tr></table></td></tr></table>';
		tooltip.write(tip);
		tooltip.close();
	} else if (ie4||ie5||ns5) {
		src2 = messages_Cat[num][0];
		var tip = startStr_cat + src2 + midStr_cat + '<div style="text-align: center; font-family:' + tipFontFamily + '; font-size:' + tipFontSize + '; color:' + curFontColor + ';">' + messages_Cat[num][1] + '</div>' + endStr_cat;
		tipcss.backgroundColor = curBgColor;
	 	tooltip.innerHTML = tip;
		//setTimeout("showImg()",2000);
		   
		
	}
	if (!tipFollowMouse) positionTip_Cat(evt);
	else t1=setTimeout("tipcss.visibility='visible'",100);
}



var mouseX, mouseY;
function trackMouse(evt) {
	mouseX = (ns4||ns5)? evt.pageX: window.event.clientX + document.body.scrollLeft;
	mouseY = (ns4||ns5)? evt.pageY: window.event.clientY + document.body.scrollTop;
	if (tipOn) positionTip(evt);
}

/////////////////////////////////////////////////////////////
//  positionTip function
//		If tipFollowMouse set false, so trackMouse function
//		not being used, get position of mouseover event.
//		Calculations use mouseover event position, 
//		offset amounts and tooltip width to position
//		tooltip within window.
/////////////////////////////////////////////////////////////
function positionTip(evt) {
	if (!tipFollowMouse) {
		mouseX = (ns4||ns5)? evt.pageX: window.event.clientX + document.body.scrollLeft;
		mouseY = (ns4||ns5)? evt.pageY: window.event.clientY + document.body.scrollTop;
	}
	// tooltip width and height
	var tpWd = (ns4)? tooltip.width: (ie4||ie5)? tooltip.clientWidth: tooltip.offsetWidth;
	var tpHt = (ns4)? tooltip.height: (ie4||ie5)? tooltip.clientHeight: tooltip.offsetHeight;
	// document area in view (subtract scrollbar width for ns)
	var winWd = (ns4||ns5)? window.innerWidth-20+window.pageXOffset: document.body.clientWidth+document.body.scrollLeft;
	var winHt = (ns4||ns5)? window.innerHeight-20+window.pageYOffset: document.body.clientHeight+document.body.scrollTop;
	// check mouse position against tip and window dimensions
	// and position the tooltip 
	if ((mouseX+offX+tpWd)>winWd) 
		tipcss.left = (ns4)? mouseX-(tpWd+offX)-100: mouseX-(tpWd+offX)-100+"px";
	else tipcss.left = (ns4)? mouseX+offX-100: mouseX+offX-100+"px";
	if ((mouseY+offY+tpHt)>winHt) 
		
		tipcss.top = (ns4)? (winHt-(tpHt+offY))-175: (winHt-(tpHt+offY))-175+"px";	

	else tipcss.top = (ns4)? mouseY+offY-175: mouseY+offY-175+"px";
	if (!tipFollowMouse) t1=setTimeout("tipcss.visibility='visible'",100);
	
}

/*** CATEGORY DISPLAY IMAGE POSITION ***/
function positionTip_Cat(evt) {
	if (!tipFollowMouse) {
		mouseX = (ns4||ns5)? evt.pageX: window.event.clientX + document.body.scrollLeft;
		mouseY = (ns4||ns5)? evt.pageY: window.event.clientY + document.body.scrollTop;
	}
	// tooltip width and height
	var tpWd = (ns4)? tooltip.width: (ie4||ie5)? tooltip.clientWidth: tooltip.offsetWidth;
	var tpHt = (ns4)? tooltip.height: (ie4||ie5)? tooltip.clientHeight: tooltip.offsetHeight;
	// document area in view (subtract scrollbar width for ns)
	var winWd = (ns4||ns5)? window.innerWidth-20+window.pageXOffset: document.body.clientWidth+document.body.scrollLeft;
	var winHt = (ns4||ns5)? window.innerHeight-20+window.pageYOffset: document.body.clientHeight+document.body.scrollTop;
	// check mouse position against tip and window dimensions
	// and position the tooltip 
	if ((mouseX+offX_Cat+tpWd)>winWd) 
		tipcss.left = (ns4)? mouseX-(tpWd+offX_Cat): mouseX-(tpWd+offX_Cat)+"px";
	else tipcss.left = (ns4)? mouseX+offX_Cat: mouseX+offX_Cat+"px";
	if ((mouseY+offY_Cat+tpHt)>winHt) 
		tipcss.top = (ns4)? winHt-(tpHt+offY_Cat): winHt-(tpHt+offY_Cat)+"px";
	else tipcss.top = (ns4)? mouseY+offY_Cat: mouseY+offY_Cat+"px";
	if (!tipFollowMouse) t1=setTimeout("tipcss.visibility='visible'",100);
}



function hideTip() {
	if (!tooltip) return;
	t2=setTimeout("tipcss.visibility='hidden'",100);
	tipOn = false;
}

