// DEFAULT JS

// SUCKERFISH NAVIGATION

startList = function()
{
	if (document.all && document.getElementById)
	{
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++)
		{
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI")
			{
				node.onmouseover=function()
				{
					this.className+=" over";
				}
				node.onmouseout=function()
				{
					this.className=this.className.replace (" over", "");
				}
			}
		}
	}
}

startSide = function()
{
	if (document.all && document.getElementById)
	{
		navRoot = document.getElementById("quick-links");
		if (navRoot)
		{
		var nodes = navRoot.getElementsByTagName("li")
			for (i=0; i<nodes.length; i++)
			 {
				nodes[i].onmouseover=function()
				{
				this.className+=" hover";
				}
				 nodes[i].onmouseout=function()
				{
				this.className=this.className.replace ("hover", "");
				}
				}
		}
	}
}

var _menu = null;
function initPage() {
	_menu = document.getElementById("quick-links");
	if (_menu)
	{
		_menu.h = _menu.offsetHeight;
		_menu.t = 0;
		window.onscroll = fixmenu;
		fixmenu();
	}
	initPopup();
}

function initPopup() {
	var _box = document.getElementById("popup");
	if(!_box)
	{
		_box = document.createElement("div");
		_box.id = "popup";
		
		var logo = document.createElement("div");
		logo.className = "popup-logo";
		
		_box.appendChild(logo);
		
		var _close = document.createElement("a");
		_close.className = "popup-close";
		_close.href = "#";
		_close.innerHTML = "Close Popup"
		_box.appendChild(_close);
		
		_close.onclick = function() {
			hide();
			return false;
		}
		
		var _content = document.createElement("div");
		_content.id = "popup-content";
		_box.appendChild(_content);
		
		_content.innerHTML = '<div class="popup-loader">Loading...</div>';
		
		var _copy = document.createElement("p");
		_copy.className = "popup-copy";
		_copy.innerHTML = "&copy; 2008 Haverick Meats Pty Ltd";
		_box.appendChild(_copy);
		
		document.getElementsByTagName("body")[0].appendChild(_box);
	}
	
	var foot = document.getElementById("footer");
	if (foot)
	{
		var _link = foot.getElementsByTagName("a");
		for (i = 0; i < _link.length; i++)
		{
			if (_link[i].innerHTML == "Terms &amp; Conditions")
			{
				_link[i].onclick = function() {
					enlarge("terms.html");
					return false;
				}
			}
			if (_link[i].innerHTML == "Privacy &amp; Security")
			{
				_link[i].onclick = function() {
					enlarge("privacy.html");
					return false;
				}
			}
		}
	}
	
}


function enlarge(url)
{
	var popup = document.getElementById("popup");
	if (popup)
	{
		var ajax   = new Ajax.Updater({success: 'popup-content'},url,{method: 'get',onFailure: hide});
		
		var popup_content = document.getElementById("popup-content");
		popup_content.innerHTML = '<div class="popup-loader">Loading...</div>';
		
		var selects = document.getElementsByTagName('select');
		for (var i=0;i<selects.length;i++)
		{
			selects[i].style.visibility = 'hidden';
		}
		
		popup.style.display = 'block';
		
		var scrollTop = 0;
		var scrollLeft = 0;
		var h = 0;
		var w = 0;
		if (window.innerHeight)
		{
			h = window.innerHeight;
		}
		else
		{
			h = document.documentElement.clientHeight;
		}
		if (window.innerWidth) {w = window.innerWidth;}
		else{w = document.documentElement.clientWidth;}
		
		
		if (window.pageYOffset){  
 			scrollTop = window.pageYOffset;
		} else if(document.documentElement && document.documentElement.scrollTop){ 
 			scrollTop = document.documentElement.scrollTop; 
		} else if(document.body){ 
 			scrollTop = document.body.scrollTop; 
		} 

		if(window.pageXOffset){ 
 			scrollLeft=window.pageXOffset;
		} else if(document.documentElement && document.documentElement.scrollLeft){ 
 			scrollLeft=document.documentElement.scrollLeft; 
		} else if(document.body){ 
 			scrollLeft=document.body.scrollLeft; 
		}
		
		popup.style.top = ((h/2 - popup.offsetHeight/2) + scrollTop) + 'px';
		popup.style.left = ((w/2 - popup.offsetWidth/2)) + 'px';
	}
	return false;
}

function hide()
{
	
	var popup = document.getElementById("popup");
	
	if (popup)
	{
		popup.style.display = 'none';
	}
	return false;
}


function fixmenu() {
	if (window.pageYOffset) {
 		scrollTop = window.pageYOffset;
	} else if(document.documentElement && document.documentElement.scrollTop){ 
 		scrollTop = document.documentElement.scrollTop; 
	} else if(document.body) {
 		scrollTop = document.body.scrollTop;
	}

		var h = document.getElementById("col-r").offsetHeight;
		if (scrollTop > 405)
		{
			if (h > (scrollTop - 405 + _menu.h))
			{
				_menu.t = scrollTop - 405;
				_menu.parentNode.style.marginTop = _menu.t + "px";
			}
		}
		else
		{
			_menu.t = 0;
			_menu.parentNode.style.marginTop = _menu.t;
		}
}

if (window.addEventListener) {
	window.addEventListener("load", initPage, false);
}
else if (window.attachEvent)  {
	window.attachEvent("onload", initPage);
	window.attachEvent("onload", startList);
	window.attachEvent("onload", startSide);
}
