// JavaScript Document


var quickLook={
	
	el: null,
	set: false,
	curId: 0,
	curModel: false,
		
	
	//set up the product div's with events
	
	
	getElementAttribute: function(node, atName){
		if(node==undefined)
			return false;
		else{
			for(var i=0; i<node.attributes.length; i++){
				//alert(node.attributes[i].name+": "+node.attributes[i].value+" Search Value:  "+atName);
				//alert();
				if(node.attributes[i].name==atName)
					return node.attributes[i].value;
			}
			return false;
		}
	},
	
	
	changeIcon: function(type){
		
		
		var img=document.getElementById("quickLookImage")
		
		//img=img[0];
		
		if(type=="out"){
			img.src="images/quicklook2.gif"
			img.style.height="25px";
			img.style.width="85px";
			
		}
		else if(type=="in"){
			img.src="images/quicklook.gif"
			img.style.height="25px";
			img.style.width="85px";
		}
	},
	
	findPos: function (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];
	},
	
	
	init: function(){
		
		var element=document.createElement('div');
		element.id="quicklook";
		
		//quickLook.el=$(quickLook.el);
		//element.style.border="1px solid black";
		element.style.position="absolute";
		//element.style.top="100px";
		//element.style.backgroundColor="#000000";
		//element.style.left="200px";
		element.style.zindex="100";
		element.style.display="none";
		
		document.body.appendChild(element);
		element.innerHTML="<a id='quickLookLink' href='javascript: void(0);'><img id='quickLookImage' src='images/quicklook2.gif' onMouseOver='javascript: quickLook.changeIcon(\"in\");' onMouseOut='javascript: quickLook.changeIcon(\"out\");' width='85px' height='25px' border='0'></a>";
		
		$('quickLookLink').addEvent('click', function(){
			tip.openTip();
		}) 
		
		
		quickLook.el=element;
		
		//var array=$$('.pdiv');
		
		$$('.pdiv').each(function(pdiv){
			
			pdiv.addEvent('mouseenter', function(pdiv){
				 quickLook.showQuickLook(pdiv);
			})
			pdiv.addEvent('mouseleave', function(pdiv){
				 quickLook.hideQuickLook(pdiv);
			}) 
								 
		})
		
	},
	
	
	showQuickLook: function(e){
		
		
		
		var el=quickLook.el
		el=e.target;
		
		
		while(el.nodeName!="DIV")
			el=el.parentNode;
			
		var pos=quickLook.findPos(el);
		
		var com_model=quickLook.getElementAttribute(el, 'model')
		
		
		quickLook.el.style.position="absolute";
		quickLook.el.style.top=pos[1]+112+"px";
		quickLook.el.style.left=pos[0]+15+"px";
		quickLook.el.style.display="inline";	
		quickLook.curModel=com_model;
		//quickLook.el.style.border="1px solid black";
		
		
			
		
		
		quickLook.set=true;
		var test=$('quicklook')
		//test=quickLook.el;
		//quickLook.el
	},
	
	hideQuickLook: function(e){
		
		/*
		
		try{
			e.cancelBubble=true;
		}
		catch(e){
			e.stopPropagation();
		}
		
		*/
		
		
		
		if(e.target.nodeName!="IMG" && e.target.nodeName!="A" && e.target.nodeName!="TD" && e.target.id!="quicklook"){
			//alert(e.target.nodeName);
			quickLook.el.style.display="none";
		}
		
			
		
		
		//quickLook.el.style.top=-1000+"px";
		//quickLook.el.style.left=-1000+"px";
				
		
	}
	
	
	
	
	
	
	
}


/*

var curScroll=window.pageYOffset

window.onscroll=function(){
	
	var $tip=$('tool_tip')
	if($tip){
		
		var sc=curScroll-window.pageYOffset
		
		$tip.style.top=$tip.style.top+sc;
		
		
	}
}
*/

function openFile(file,name,picw,pich) {
  popupWin = window.open(file, name, 'status=yes, resizable=yes, scrollbars=yes, address=no, menubar=no, location=no, width=' + picw + ',height=' + pich)
}



var tip={


	curTip:  false,
	curDrag: false,
	curScroll: [0,0],
	
	
	
	closeTip: function(){
		//alert(document.getElementById("tool_tip"));
		if(tip.curTip){
			var temp=document.getElementById("tool_tip");
			temp.parentNode.removeChild(temp);
			clearTimeout();
			tip.curTip=false;
			tip.curDrag=false;
		}
			
	},

	addDrag: function(){
		if(!tip.curDrag){
			tip.curDrag=new Drag.Move(tip.curTip).attach();
		}
		else
			tip.curDrag.attach();
	
	},
	
	removeDrag: function(){
		tip.curTip=$('tool_tip');
		if(tip.curDrag)
			tip.curDrag.detach();
		
	},
	
	
	scrollable: function(){
		
		if(tip.curTip){
			var tScroll=tip.getScrollXY();
			
			if(tScroll[1]!=tip.scrollY){
				
				//var sd=tip.scrollY-tScroll[1];
					//tip.curTip.setStyle("top", tip.curTip.getCoordinates().top-sd);
				//tip.curTip.style["top"]=tip.curTip.offsetTop-sd+"px";
				//tip.scrollY=tScroll[1];
				//tip.scrollX=tScroll[0];
			}
				
			//setTimeout("tip.scrollable()", 40);
		}
		
	
	
	},
	
	

	getScrollXY: function(){


	  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 ];
	  
	},


	getWindowSize: function(){

	  var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	  }
	  
	  return [ myWidth, myHeight ];
	  
	},




	
	openTip: function(){
		//alert(document.getElementById("tool_tip"));
		//closeTip();
		
		
		var newTip=false;	
		var tool_model=quickLook.curModel;
		if(!tip.curTip){
			
			
			newTip=document.createElement('div');
			newTip.setAttribute('id','tool_tip');
			
			//newTip.innerHTML="TEST ME";
			
			document.body.appendChild(newTip);
			
			
			var temp=tip.getWindowSize();
			
			var windowWidth=temp[0];
			var windowHeight=temp[1];
			
			temp=tip.getScrollXY();
			
			var windowScrollY=temp[1];
			var windowScrollX=temp[0];
			
			//alert(windowScrollX);
			
			
			var divHeight=newTip.offsetHeight;
			var divWidth=newTip.offsetWidth;
			
			
			//alert(divWidth+"  "+divHeight);
			var hpos=Math.round(windowScrollX+((windowWidth-500)/2));
			var vpos=Math.round(windowScrollY+15);
			
			//alert(hpos+"  "+vpos);
			
			hpos = (hpos < 0)?0:hpos;
			vpos = (vpos < 0)?0:vpos;
			
			
			newTip.style.position="absolute";
			newTip.style.top=vpos+"px";
			newTip.style.left=hpos+"px";
			//newTip.style.height="100px";
			//newTip.style.width="100px";
			newTip.style.border="1px solid black";
			newTip.style.backgroundColor="white";
			newTip.style.zIndex="100";
			//newTip.makeDraggable();
			
			newTip.position="absolute";
				
			tip.curTip=newTip;
			
			tip.scrollY=windowScrollY;
			tip.scrollX=windowScrollX;
			
			tip.scrollable();
			//tip.tipDrag=new Drag.Move
		
			//
		}
		tool_model=tool_model.replace(/ /,"%20");
		tool_model=tool_model.replace(/#/,"%23");
		
		var page="tool_tip.php?product_model="+tool_model;
		
		display_ajax(tip.curTip, page);
		//alert(newTip.innerHTML);
		
		
		
		
			
	}
}





function display_media(media_type, media_file, model){
		//alert(media_file);
		
		//alert(arguments.length);
		var div=document.all? document.all["product_details_main"] : document.getElementById? document.getElementById("product_details_main") : "";
		
		var hires=document.all? document.all["hires"] : document.getElementById? document.getElementById("hires") : "";
		
		
		var output="";
		
		
		if(media_type=="image"){
		
			output=output+"<a href=\"javascript:openFile('"+media_file+"','tool_image',500,500)\">";
		
			if(arguments.length==4)
				output=output+"<img src=\""+arguments[3]+"\" alt=\""+media_type+": "+model+"\"  border=\"0\">";
			else
				output=output+"<img src=\""+media_file+"\" alt=\""+media_type+": "+model+"\"  border=\"0\">";
		
			
			output=output+"</a>";
			
			div.innerHTML=output;
			
			hires.innerHTML="For Hi-Res Image <br> <a class='font_reg_blue' style='text-decoration:none;' href=\"javascript:openFile('"+media_file+"','tool_image',500,500)\">Click Here</a>"
			//output=output+"<img src=\""+media_file+"\" alt=\""+media_type+": "+model+"\" width=\"230\" height=\"153\" border=\"0\"></a>";
		}
		else if(media_type=="video"){
			//alert()
			//hires.innerHTML="";
			//output=output+"<center><img src=\"images/FlashIcon.gif\" alt=\"Product Video File\" width=\"183\" height=\"151\" border=\"0\"></center>";
			openFile('play_video.php?com_model='+model+'&media_file='+media_file, media_type, 613, 550)
		}
		else if(media_type=="document"){
			//hires.innerHTML="";
			//output=output+"<center><img src=\"images/PdfIcon.jpg\" alt=\"Product PDF File\" width=\"150\" height=\"150\" border=\"0\"></center>";
			openFile('view_pdf.php?com_model='+model+'&media_file='+media_file, media_type, 815, 700)
		}
		
													 
		
}

function tab_menu(type, com_id){
		var div=document.all? document.all["product_details_bottom"] : document.getElementById? document.getElementById("product_details_bottom") : "";
		
		var menu=document.all? document.all["tab_menu"] : document.getElementById? document.getElementById("tab_menu") : "";
		var menu_array=menu.getElementsByTagName('td')
		
		for(key in menu_array){
				//alert(menu_array[key].tagName);
				
				var id=menu_array[key].id;
				if(id){
						
				        var media_type=id.substring(0, id.length-4);
						if(media_type==type){
							menu_array[key].onmouseover="";
							menu_array[key].onmouseout="";
							menu_array[key].setAttribute("class", "tab_menu_over");
							menu_array[key].setAttribute("className", "tab_menu_over");
						}
						else{
							var id_type=id.substring(id.length-4, id.length);
							if(id_type=="_tab"){
									menu_array[key].setAttribute("class", "tab_menu");
									menu_array[key].setAttribute("className", "tab_menu");
							}
							
						}
				}
		}
		
		if(type=="related"){
			openFile('view_related.php?com_id='+com_id, 'related_products', 560, 500);
			div.innerHTML="<table><tr><td class='font_reg'>Related Products</td></tr></table>";
		}
		else if(type=="parts"){
			openFile('view_related.php?com_id='+com_id+'&rlParts='+true, 'related_products', 560, 500);
			div.innerHTML="<table><tr><td class='font_reg'>Product Parts</td></tr></table>";
		}
		else if(type=="kits"){
			openFile('view_related.php?com_id='+com_id+'&rlKits='+true, 'related_products', 560, 500);
			div.innerHTML="<table><tr><td class='font_reg'>Product Kits</td></tr></table>";
		}
		else{
			var page="bottom_details.php?detail_type="+type+"&com_id="+com_id;
			display_ajax(div, page);
		}
}


function display_ajax(div, page){
		//alert(div);
		try{
				// Opera 8.0+, Firefox, Safari
				ajaxRequest = new XMLHttpRequest();
			} catch (e){
				// Internet Explorer Browsers
				try{
					ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
					try{
						ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e){
						// Something went wrong
						alert("Your browser broke!");
						return false;
					}
				}
			}
			// Create a function that will receive data sent from the server
			ajaxRequest.onreadystatechange = function(){
				if(ajaxRequest.readyState == 4){
					//alert("Enter");
					div.innerHTML = ajaxRequest.responseText;
				}
			}
			ajaxRequest.open("GET", page, true);
			ajaxRequest.send(null); 
}