﻿
addNamespace("atlas.HoverMenu");

atlas.HoverMenu = Class.create();

Object.extend(atlas.HoverMenu.prototype, {
	objXML: null,
	r: null,
	pid: null,
	width:300,
	height:200,
	timer: -1,
	htmlText: null,
	hide: function() {
		if (this.timer != -1) { clearTimeout(this.timer); }
		this.div.style.display = 'none';
	},
	show: function() {
		this.r = MS.Position.getBounds(this.ele);
		MS.Position.setBounds(this.div, this.r);
		this.div.innerHTML = this.htmlText;
		this.div.style.width = this.width + "px";
		this.div.style.height = this.height + "px";
		this.div.style.display = "inline";
	},
	onmouseout: function(e) {
		this.hide();
	},
	onmouseover: function(e) {
		if (this.timer != -1) { clearTimeout(this.timer); }

		this.r = MS.Position.getBounds(this.ele);
		MS.Position.setBounds(this.div, this.r);
		this.div.style.width = "30px";
		this.div.style.height = "30px";
		this.div.innerHTML = "<table width=\"30px\" height=\"30px\"><tr><td align='left' valign='top'><img alt='' border='0' src='/'></td></tr></table>";
		this.div.style.display = "inline";
		this.timer = setTimeout(this.preparedata.bind(this),1500);
	},
	preparedata: function() {
		if (this.htmlText == null) { this.getData(); return; }
		else { this.show(); }
	},
	getData: function() {
		objXML = null;
		if (window.XMLHttpRequest) {
			objXML = new XMLHttpRequest();
		}
		else if (window.ActiveXObject) {
			objXML = new ActiveXObject("Microsoft.XMLHTTP");
		}
	
		var b = this;
		var url = window.location.protocol + "//" + window.location.hostname + "/" + this.pid;
		if (objXML) {
			objXML.onreadystatechange = function() {
				if(objXML.readyState == 4)
				{
					if(objXML.status != 200) { return; }
				}
				else 
				{
					return;
				}
				b.htmlText = objXML.responseText;
				b.show();
			};
		}

		this.r = MS.Position.getBounds(this.ele);
		MS.Position.setBounds(this.div, this.r);
		this.div.innerHTML = "<table width=\"188px\" height=\"300px\"><tr><td align='center'><img alt='' border='0' src='/'></td></tr><tr><td align='center'></td></tr>"
		this.div.style.display = "inline";
		objXML.open("GET", url, true);
		objXML.setRequestHeader("Accept-Charset", "iso-8859-9");
		objXML.setRequestHeader("Accept-Language", "tr");
		objXML.send(null);
	},
	initialize: function(eleId, pId, divId, width, height) {
		this.pid = pId;
		this.width = width;
		this.height= height;
		this.ele = $(eleId);
		this.r = MS.Position.getBounds(this.ele);
		this.div = document.getElementById(divId);
		addEvent(this.ele, "mouseover", this.onmouseover.bind(this));
		addEvent(this.ele, "mouseout", this.onmouseout.bind(this));

	}
}, false);

addNamespace("atlas.HoverMenuArray");

atlas.HoverMenuArray = Class.create();

Object.extend(atlas.HoverMenuArray.prototype, {
	count: 0,
	w:0,
	h:0,
	arrayEle: null,
	arrayValue: null,
	addItem: function(eleid, pId) {
		this.arrayEle[this.count] = eleid;
		this.arrayValue[this.count] = pId;
		this.count++;
	},
	ondivmouseover: function(e) {
		this.div.style.display='inline';
	},
	ondivmouseout: function(e) {
		this.div.style.display='none';
	},
	initialize: function(width, height) {
		this.arrayEle = new Array();
		this.arrayValue = new Array();
		this.w = width;
		this.h = height;
	},
	create: function() {
		this.div = document.createElement("div");
		this.div.id = "hoverdiv_image";
		this.div.style.display="none";
		document.body.appendChild(this.div);
		addEvent(this.div, "mouseover", this.ondivmouseover.bind(this));
		addEvent(this.div, "mouseout", this.ondivmouseout.bind(this));

		for (i = 0; i < this.count; i++ )
		{
			if (this.arrayEle[i] == null) { continue; }
			new atlas.HoverMenu(this.arrayEle[i], this.arrayValue[i], this.div.id, this.w, this.h);
		}
	}
},false);

function activateHoverMenu(imgid, pid, divid) {
	setTimeout("initHoverMenu('" + imgid+ "', '" + pid + "', '"+ divid+"')", 2);

}
function initHoverMenu(imgid, pid, divid) {
	new atlas.HoverMenu(imgid, pid, divid, 188, 100);
}

objHArray = new atlas.HoverMenuArray(188,100);
