/*
	Copyright David Trewern Design         :: www.dtdesign.com ::
	Unauthorised modification / use is a criminal offence, and
	will be prosecuted to the fullest extent permitted by law.
	All Rights Reserved
*/

NAVarr = new Array("blah1", "blah2", "blah3");
if (document.images)
{
	for (var NAVitem in NAVarr)
	{ 
		 for (var NAVicount=0; NAVicount < 2; NAVicount++)
		 { 
				eval("b" + NAVarr[NAVitem] + NAVicount + " = new Image()");
				eval("b" + NAVarr[NAVitem] + NAVicount + ".src = 'assets/swap_" + NAVarr[NAVitem] + "_" + NAVicount + ".gif'");
		 } 
	} 
}

function BturnOn(imageName)
{
	if (document.images)
	{
		var imageNumber = "";
		if (arguments.length > 1) imageNumber = arguments[1];
		document [imageName + imageNumber].src = eval("b" + imageName + "1.src");
	}
}

function BturnOff(imageName)
{
	if (document.images)
	{
		var imageNumber = "";
		if (arguments.length > 1) imageNumber = arguments[1];
		document [imageName + imageNumber].src = eval("b" + imageName + "0.src");
	}
}

function BturnOnInput(obj,imageName)
{
	if (obj.src)
	{
		obj.src = eval("b" + imageName + "1.src");
	}
}

function BturnOffInput(obj,imageName)
{
	if (obj.src)
	{
		obj.src = eval("b" + imageName + "0.src");
	}
}

function imgPopup(path)
{
	if (path)
	{
		window.open("utils_imagepopup.aspx?path=" + path, "popup", "width=400, height=300, toolbar=no, status=no, scrollbars=yes, resizable=yes");
	}
}

function ddRedirect(dd)
{
	if (dd.options[dd.selectedIndex].value != "") self.location = dd.options[dd.selectedIndex].value;
}

function resizeWindow(layoutAdjustmentW, layoutAdjustmentH)
{
	if ((document.images) && (document.theimage) && (document.theimage.width))
	{

		var imageW = document.theimage.width;
		var imageH = document.theimage.height;

		var screenW = screen.availWidth;
		var screenH = screen.availHeight;

		var resizeToScreen = false;

		if (imageW <= screenW)
		{
			resizeW = imageW;
		}
		else
		{
			resizeW = screenW;
			resizeToScreen = true;
		}

		if (imageH <= screenH)
		{
			resizeH = imageH;
		}
		else
		{
			resizeH = screenH;
			resizeToScreen = true;
		}

		var userAgent = navigator.userAgent;

		//Windows Adjustments
		if (userAgent.indexOf("Windows") != -1)
		{
			if (userAgent.indexOf("MSIE 5") != -1)
			{
				resizeW += 29;
				resizeH += 38;

				if (resizeToScreen)
				{
					resizeW -= 29;
				}
			}
			if (userAgent.indexOf("MSIE 6") != -1)
			{
				resizeW += 31;
				resizeH += 61;
			}
			if (userAgent.indexOf("Firefox") != -1)
			{
				resizeW += 8;
				resizeH += 56;

				if (resizeToScreen)
				{
					resizeW -= 8;
				}
			}
			if (userAgent.indexOf("Netscape/7") != -1) {
				resizeW += 8;
				resizeH += 36;

				if (resizeToScreen)
				{
					resizeW -= 8;
				}
			}
		}

		//Mac Adjustments
		if (userAgent.indexOf("Mac") != -1)
		{
			if (userAgent.indexOf("Safari") != -1)
			{
				resizeW += 0;
				resizeH += 23;
			}
			if (userAgent.indexOf("MSIE 5") != -1)
			{
				resizeW += 0;
				resizeH += 0;
			}
			if (userAgent.indexOf("Firefox") != -1)
			{
				resizeW += 0;
				resizeH += 18;
			}
			if (userAgent.indexOf("Netscape/7") != -1)
			{
				resizeW += 0;
				resizeH += 2;
			}
		}

		if (!isNaN(layoutAdjustmentW))
		{
			resizeW += layoutAdjustmentW;
		}
		if (!isNaN(layoutAdjustmentH))
		{
			resizeH += layoutAdjustmentH;
		}

		if (resizeToScreen)
		{
			window.moveTo(0,0);
		}
		window.resizeTo(resizeW, resizeH);

	}
}


var Buttons = {
	
	hideChilds: function(element)
	{
		
		if (document.getElementById)
		{
			var menu = document.getElementById("left-menu");
			if(menu)
			{
				for (var i = 0; i < menu.childNodes.length; i++)
				{
					if(menu.childNodes[i].tagName == "li")
					{
						if(menu.childNodes[i].childNodes[0].tagName == "ul")
						{
							menu.childNodes[i].style.display = "none";
						}
						else
						{
							menu.childNodes[i].onclick = function()
							{
								Buttons.toggleDisplay(menu.childNodes.name);
								return false;
							}
						}
					}
				}
			}
		}
	},
	
	toggleDisplay: function(element)
	{
		if (document.getElementById)
		{
			var ob = document.getElementById(element);
			if(ob)
			{
				if(ob.style.display == "none") ob.style.display = "block";
				else ob.style.display = "none";
			}
		}
	}
	
}

var userAgent = navigator.userAgent;

function macie5_showEnlarge(id)
{	
	if (userAgent.indexOf("Mac") != -1 && userAgent.indexOf("MSIE 5") != -1)
	{		
		var img = document.getElementsByName('img_' + id)[0];
		
		window.open(img.src, "", "width=500, height=500, resizable=1");
	}
}
function showEnlarge(obj, id)
{
	if (userAgent.indexOf("Mac") != -1 && userAgent.indexOf("MSIE 5") != -1) {
		var img = document.getElementsByName('img_' + id)[0];
		window.open(img.src, "", "width=500, height=500, resizable=1");
	} else {
		var divCallout = document.getElementById("enlarge");
		var img = document.getElementById("img_" + id);
		//add padding to img
		var imgWidth = img.style.width;
		var imgHeight = img.style.height;
		imgWidth = imgWidth.replace(/px/, "");
		imgHeight = imgHeight.replace(/px/, "");
		
		var imgX = (findPosX(obj) + 90);
		var imgY = (findPosY(obj) - Math.round(imgHeight / 2)) - 15;
		divCallout.style.top = imgY + "px";
		divCallout.style.display = "block";
		img.style.display = "block";
	}
}

function hideEnlarge(id)
{
	var divCallout = document.getElementById("enlarge");
	var img = document.getElementById("img_" + id);
	divCallout.style.display = "none";
	img.style.display = "none";
}

function findPosX(obj) 
{
	var curleft = 0;
	if (obj.offsetParent) 
	{
		curleft = obj.offsetLeft
		while (obj = obj.offsetParent) 
		{
			curleft += obj.offsetLeft
		}
	}
	return curleft;
}

function findPosY(obj) 
{
	var curtop = 0;
	if (obj.offsetParent) 
	{
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) 
		{
			curtop += obj.offsetTop
		}
	}
	return curtop;
}

