// JavaScript Document
var PopOut = new function()
{   this.ajax = new Ajax();
	this.linkParent = null;
	this.popContainer = null;
	this.menu = null;
	this.blendedObj =null;
	this.leftBox = null;
	this.testDiv = null;
	this.Init = function()
	{
		var self = PopOut;
		self.testDiv = document.getElementById('TestDiv')
		self.linkParent = document.getElementById('LinksUl');
		self.popContainer = document.getElementById('PopContainer');
		
		self.popContainer.onmouseover = self.MenuOver;
		self.popContainer.onmouseout = self.MenuMouseOut;
		self.blendedObj = new BlendedObject('PopContainer');
		self.blendedObj.SetOpacityToZero();
		self.leftBox = document.getElementById('LeftBox');
		for(i=0; i < self.linkParent.childNodes.length; i++)
		{
		   // alert(self.linkParent.childNodes[i].innerHTML)
			pattern = /Menu/;
		 	if(pattern.test(self.linkParent.childNodes[i].innerHTML))
			{ 
				self.menu = self.linkParent.childNodes[i];
				self.menu.onmouseover = self.MenuOver;
				self.menu.onmouseout = self.MenuMouseOut;
			//	self.linkParent.childNodes[i].onmouseover = self.MenuOver;
			}
			url = 'a_page.php?page=';
			
			if(self.linkParent.childNodes[i].innerHTML != null)
			{
			var menuName = self.linkParent.childNodes[i].innerHTML;
			pattern = /\s*$/gi;
			
			if(pattern.test(menuName))
				menuName=menuName.replace(pattern,'')
			switch(menuName)
			{
				case 'Home':self.linkParent.childNodes[i].onclick = self.ChangeToHome;
				 			break;
				case 'Contact Us':self.linkParent.childNodes[i].onclick = self.ChangeToContactUs;
							break;
				case 'Location':self.linkParent.childNodes[i].onclick = self.ChangeToLocation;
				break;
				default:
				break;
			}
			} // end if
		}
		
		window.onresize = self.GetCoordinate;
	} // end Init
	
	this.ChangeToLocation = function()
	{
	 var self = PopOut;
	 url = 'a_page.php?page=location';
	 self.ajax.doGet(url, function(){self.leftBox.innerHTML = self.ajax.req.responseText;ShowMap.Init();})
	 
	}
	
	this.ChangeToContactUs = function()
	{
	 var self = PopOut;
	 url = 'a_page.php?page=contact';
	 self.ajax.doGet(url, function(){self.leftBox.innerHTML = self.ajax.req.responseText})
	}
	
	this.ChangeToHome = function()
	{
		var self = PopOut;
		url = 'a_page.php?page=home';
		self.ajax.doGet(url, function(){self.leftBox.innerHTML = self.ajax.req.responseText})
		//self.leftBox.innerHTML = self.ajax.req.responseText;
		
	} // end method
	
	this.SubMenuOnClick = function()
	{
		var self = PopOut;
		//alert('hi')
	} // end method
	
	this.MenuOver = function()
	{
		//alert(document.documentElement.scrollTop)
		var self = PopOut;
		self.blendedObj.BlendingIn();
		self.GetCoordinate();
		
	} // end method
	
	this.GetCoordinate = function()
	{
		var self = PopOut;
		
		topMenu = self.menu.offsetTop;
		left = self.menu.offsetLeft;
		bigContainerLeft = document.getElementById('BigContainer').offsetLeft;
		popContainerWidth = self.popContainer.offsetWidth;
		popContainerHeight = self.popContainer.offsetHeight;
		var scrollYPos = self.GetScrollYPos();
		
		pos = (432+topMenu-(popContainerHeight/2)+scrollYPos-100);
		if(pos > 466)
		pos = 466
		self.popContainer.style.top = pos + 'px';
		
		self.popContainer.style.left = (487+left+bigContainerLeft-popContainerWidth+50) + 'px';
	}// end method	
	
	this.GetScrollYPos=function()
	{
		pos = document.documentElement.scrollTop;
		if(pos==0)
		pos = document.body.scrollTop;
		return pos;
	}
	
	
	this.MenuMouseOut = function()
	{
		var self = PopOut;
		self.blendedObj.BlendingOut();
	}// end method
} // end class


LoadEvent(PopOut.Init);
