diamond_hint=({
	cursor_pos:{},
	grid_pos:{},
	grid_body_scroll:0,
	img_cache : new Image(),
	back_color: "",

	getCurPos:function(event){
		if (!event)event=window.event;
	    var x = y = sw = sh = scl = sct = 0;
 		sw = (window.innerWidth ? window.innerWidth : (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.offsetWidth));
 		sw -= getScrollBarWidth();
 	   	sh = (window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.offsetHeight));
	    if (document.attachEvent != null) { 
	        x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
	        y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
	        scl = document.documentElement.scrollLeft;
	        sct = document.documentElement.scrollTop;	        
	    }
	    if (!document.attachEvent && document.addEventListener) {
	        x = event.clientX + window.scrollX;
	        y = event.clientY + window.scrollY;
	        scl = window.scrollX;
	        sct = window.scrollY;	        
	    }
	    this.cursor_pos = {x:x, y:y, sw:sw, sh:sh, scl:scl, sct:sct};
		    function getScrollBarWidth() {
				var inner = document.createElement('p');
				inner.style.width = '100%';
				inner.style.height = '200px';
 
				var outer = document.createElement('div');
				outer.style.position = 'absolute';
				outer.style.top = '0px';
				outer.style.left = '0px';
				outer.style.visibility = 'hidden';
				outer.style.width = '200px';
				outer.style.height = '150px';
				outer.style.overflow = 'hidden';
				outer.appendChild (inner);
			 
				document.body.appendChild (outer);
				var w1 = inner.offsetWidth;
				outer.style.overflow = 'scroll';
				var w2 = inner.offsetWidth;
				if (w1 == w2)
					w2 = outer.clientWidth;
				document.body.removeChild (outer);
 
				return (w1 - w2);
			};

	},
	getElementPos:function(obj){
	    var w = obj.offsetWidth;
	    var h = obj.offsetHeight;
	    var l = 0;
	    var t = 0;
	    while (obj){
	        l += obj.offsetLeft;
	        t += obj.offsetTop;
	        obj = obj.offsetParent;
	    }
	    return {"l":l, "t":t, "w": w, "h":h};
	},

	
	correctPos:function(hint_obj, from){
		if(hint_obj){
			hint_obj.style.visibility = "visible";
			var status = document.getElementById("status");
			var h_arrow = document.getElementById("hint_arrow");
			if(hint_obj.offsetTop + hint_obj.offsetHeight > this.grid_pos.h + this.grid_pos.t + status.offsetHeight){
				hint_obj.style.top = (this.grid_pos.h + this.grid_pos.t + status.offsetHeight) - hint_obj.offsetHeight + "px";
			}
			if(h_arrow){
				if(this.cursor_pos.y > hint_obj.offsetTop){
					h_arrow.style.top = Math.round((this.getElementPos(from).t - this.grid_body_scroll) - (from.offsetHeight/2) + 4) - hint_obj.offsetTop + "px";
				}
				if(h_arrow.offsetTop < 11){
					var correct = ((11 - h_arrow.offsetTop));
					hint_obj.style.top = hint_obj.offsetTop - correct + "px";
					h_arrow.style.top = h_arrow.offsetTop + correct + "px";
				}
			}
			hint_obj.style.visibility = "visible";
		}
	},
	moveHint:function(event, from){
		hint_obj = document.getElementById("aPopupHintDiv");
		this.getCurPos(event);
		if(hint_obj){
			hint_obj.style.top = (this.cursor_pos.y+6)+"px";
			hint_obj.style.left = (this.cursor_pos.x+6)+"px";
			this.correctPos(hint_obj);			
		}		
	},
	showHint:function(event, from){
		if(from.className){
			this.back_color = "#FFFFFF";
		}else{this.back_color = "#EEEEEE";}
		from.style.background = "url(/diamonds/images/tr-bg.png) repeat-x top";		
//		from.style.backgroundColor = "#CECECE";
		from.onmouseout = function(){
			if(diamond_hint.back_color){
				from.style.background = "";
				this.style.backgroundColor = diamond_hint.back_color;
			}
		}
		this.grid_pos = this.getElementPos(from.parentNode.parentNode.parentNode.parentNode);
		this.grid_body_scroll = from.parentNode.parentNode.parentNode.parentNode.scrollTop;
		from.parentNode.parentNode.parentNode.parentNode.parentNode.onmouseout = function(){
			diamond_hint.destroyHintBody();
		}
		this.getCurPos(event);
		if(!document.getElementById("aPopupHintDiv")){
			this.createHintBody(event, from);
		}
	},
	createHintBody:function(event, par_obj){
		var mainHintDiv = document.createElement("DIV");
		this.img_cache.src = "/assets/img/hints/corners.gif";
		if(mainHintDiv){
			mainHintDiv.style.position = "absolute";
			mainHintDiv.style.top = (this.cursor_pos.y - 27)+"px";
			mainHintDiv.style.left = (this.grid_pos.l + this.grid_pos.w + 23) + "px";			
			mainHintDiv.style.zIndex = "1000000";
			mainHintDiv.style.visibility = "hidden";
			mainHintDiv.id = "aPopupHintDiv";
			mainHintDiv.innerHTML = this.newPopupWindow(par_obj);
			document.body.appendChild(mainHintDiv);
			this.correctPos(mainHintDiv, par_obj);
		}
	},
	destroyHintBody:function(){
		hint_obj = document.getElementById("aPopupHintDiv");
		if(hint_obj){
			document.body.removeChild(hint_obj);						
		}
	},	
		
	newPopupWindow:function(obj){
		id = obj.id.replace("tr_","row_");
		obj = Grid._items[id];
		var hint_text = "";
		var main_shapes = "";
		if(obj && id){
/*			if(obj.shape){
				main_shapes_arr = {'br':'Round','pr':'Princess','ec':'Emerald','as':'Asscher','mq':'Marquise','ov':'Oval','rad':'Radiant','ps':'Pear','hs':'Heart','cu':'Cushion'};
				main_shapes = main_shapes_arr[obj.shape.toLowerCase()];
			} */
			main_shapes = obj.shape;			
			var diam_descr = "This is a "+main_shapes+"-shaped, "+obj.carat_weight+" carats, "+obj.color+"-Color, &amp "+obj.clarity+"-Clarity Diamond";
			if(obj.report_name){
				diam_descr += " Certified by "+obj.report_name;
			}
			
			
			hint_text ="<div id=\"hint_arrow\" style=\"position: absolute; top: 11px; left: -21px; width: 22px; height: 34px; font-size: 0px; background: url(/assets/img/hints/corners.gif) 0 -22px no-repeat; \"></div><div style=\"width: 126px; height: 11px; font-size: 0px; background: url(/assets/img/hints/corners.gif) left top no-repeat;\"></div><div style=\"margin:0 0px 0 0px;width:108px; overflow: hidden; border-left: 1px solid #99aabb;border-right: 1px solid #99aabb; padding: 0 8px 0 8px; background-color: #FFFFFF;\"><strong style=\"color:#5E7482;font-size:9px; font-family: Verdana;\">"+diam_descr+"</strong><br /><table border=\"0\" cellpadding=\"3\" cellspacing=\"2\" width=\"100%\" style=\"font-size:9px;font-family: Verdana;\"><tr><td style=\"background-color:#EFEFEF;color:#000;padding:2px\" width=\"100%\" ><strong style=\"color: #5d5d5d;\">Stock Number:</strong> "+obj.vendor_stocknumber.substr(1,obj.vendor_stocknumber.length)+"</td></tr>";
			
			if(main_shapes){
				hint_text += "<tr><td style=\"background-color:#EFEFEF;color:#000;padding:2px\" width=\"100%\"><strong style=\"color: #5d5d5d;\">Shape:</strong> "+main_shapes+"</td></tr>";
			}
			
			if(obj.carat_weight){
				hint_text += "<tr><td style=\"background-color:#EFEFEF;color:#000;padding:2px\" width=\"100%\"><strong style=\"color: #5d5d5d;\">Total Carat Weight:</strong> "+obj.carat_weight+"</td></tr>";
			}

			if(obj.carat_weight){
				hint_text += "<tr><td style=\"background-color:#EFEFEF;color:#000;padding:2px\" width=\"100%\"><strong style=\"color: #5d5d5d;\">Average Color:</strong> "+obj.color+"</td></tr>";
			}

			if(obj.clarity){
				hint_text += "<tr><td style=\"background-color:#EFEFEF;color:#000;padding:2px\" width=\"100%\"><strong style=\"color: #5d5d5d;\">Average Clarity:</strong> "+obj.clarity+"</td></tr>";
			}
			
			if(obj.symmetry){
				symmetry = "";
				if(obj.symmetry == "EX"){symmetry = "Excellent";}
				if(obj.symmetry == "VG"){symmetry = "Very Good";}
				if(obj.symmetry == "G"){symmetry = "Good";}
				if(obj.symmetry == "F"){symmetry = "Fair";}												
				hint_text += "<tr><td style=\"background-color:#EFEFEF;color:#000;padding:2px\" width=\"100%\"><strong style=\"color: #5d5d5d;\">Symmetry:</strong> "+symmetry+"</td></tr>";
			}

			if(obj.measurements){
				hint_text += "<tr><td style=\"background-color:#EFEFEF;color:#000;padding:2px\" width=\"100%\"><strong style=\"color: #5d5d5d;\">Measurements:</strong> "+obj.measurements+"</td></tr>";
			}

			if(obj.report_name){
				hint_text += "<tr><td style=\"background-color:#EFEFEF;color:#000;padding:2px\" width=\"100%\"><strong style=\"color: #5d5d5d;\">Report Name:</strong> "+obj.report_name+"</td></tr>";
			}

			if(obj.report_number){
				hint_text += "<tr><td style=\"background-color:#EFEFEF;color:#000;padding:2px\" width=\"100%\"><strong style=\"color: #5d5d5d;\">Report Number:</strong> "+obj.report_number+"</td></tr>";
			}

			if(obj.cut){
				cut = "";
				if(obj.cut == "EX"){cut = "Excellent";}
				if(obj.cut == "ID"){cut = "Ideal";}				
				if(obj.cut == "VG"){cut = "Very Good";}
				if(obj.cut == "G"){cut = "Good";}
				if(obj.cut == "F"){cut = "Fair";}												
				hint_text += "<tr><td style=\"background-color:#EFEFEF;color:#000;padding:2px\" width=\"100%\"><strong style=\"color: #5d5d5d;\">Cut:</strong> "+cut+"</td></tr>";
			}
			
			if(obj.depth){
				hint_text += "<tr><td style=\"background-color:#EFEFEF;color:#000;padding:2px\" width=\"100%\"><strong style=\"color: #5d5d5d;\">Depth:</strong> "+obj.depth+"</td></tr>";
			}

			if(obj.table){
				hint_text += "<tr><td style=\"background-color:#EFEFEF;color:#000;padding:2px\" width=\"100%\"><strong style=\"color: #5d5d5d;\">Table:</strong> "+obj.table+"</td></tr>";
			}

			if(obj.polish){
				polish = "";
				if(obj.polish == "EX"){polish = "Excellent";}
				if(obj.polish == "VG"){polish = "Very Good";}
				if(obj.polish == "G"){polish = "Good";}
				if(obj.polish == "F"){polish = "Fair";}												
				hint_text += "<tr><td style=\"background-color:#EFEFEF;color:#000;padding:2px\" width=\"100%\"><strong style=\"color: #5d5d5d;\">Polish:</strong> "+polish+"</td></tr>";
			}

			if(obj.girdle){
				hint_text += "<tr><td style=\"background-color:#EFEFEF;color:#000;padding:2px\" width=\"100%\"><strong style=\"color: #5d5d5d;\">Girdle:</strong> "+obj.girdle+"</td></tr>";
			}

			if(obj.culet){
				culet = "";
				if(obj.culet == "N"){culet = "None";}				
				if(obj.culet == "VS"){culet = "Very Small";}
				if(obj.culet == "S"){culet = "Small";}
				if(obj.culet == "M"){culet = "Medium";}
				if(obj.culet == "SL"){culet = "Slightly Large";}												
				if(obj.culet == "L"){culet = "Large";}				
				hint_text += "<tr><td style=\"background-color:#EFEFEF;color:#000;padding:2px\" width=\"100%\"><strong style=\"color: #5d5d5d;\">Culet:</strong> "+culet+"</td></tr>";
			}
			
			if(obj.fluorescence){
				fluorescence = "";
				if(obj.fluorescence == "N"){fluorescence = "None";}				
				if(obj.fluorescence == "F"){fluorescence = "Faint";}
				if(obj.fluorescence == "M"){fluorescence = "Medium";}
				if(obj.fluorescence == "S"){fluorescence = "Strong";}
				if(obj.fluorescence == "VS"){fluorescence = "Very Strong";}					
				hint_text += "<tr><td style=\"background-color:#EFEFEF;color:#000;padding:2px\" width=\"100%\"><strong style=\"color: #5d5d5d;\">Fluorescence:</strong> "+fluorescence+"</td></tr>";
			}
						
			hint_text += "</table></div><div style=\"width: 126px; height: 11px; background: url(/assets/img/hints/corners.gif) 0 -11px no-repeat; font-size: 0px;\"></div>"
			return hint_text;
		}else{
			return "";	
		}			

	 }		
});
