// JavaScript Document
//<!-------------------------------------------
function Point(x,y) {  this.x = x; this.y = y; }
mouseLocation = new Point(-500,-500);

function getMouseLoc(e)
{
  if(!document.all)  //NS
  {
    mouseLocation.x = e.pageX;
    mouseLocation.y = e.pageY;
  }
  else               //IE
  {
    mouseLocation.x = event.x + document.body.scrollLeft;
    mouseLocation.y = event.y + document.body.scrollTop;
  }
  return true;
}

/*-------------------------------------------------------*/

function getterm(term)
{
	if(document.all)    //IE4 and IE5
		{
		term = document.all[term].style;
		}
	else if(document.layers)  //Netscape 4
		{
		term = document.layers[term];
		}
	else if (document.documentElement) //Netscape 6 (and IE5)
   		{
	    term = document.getElementById(term).style;
	    }
	return term;
}

/*---------------------------------------------*/

function show_hide_term(term) 
{
	term = getterm(term);
 	// Toggle visibility. Use "show" and "hidden" for Netscape 4. 
	if (term.visibility == "visible"  ||  term.visibility == "show")
		{
			term.visibility = "hidden";
			//term.display = "none"
		}
 	else
		{
			term.visibility = "visible";
			//term.display = true;
		}
}

/*---------------------------------------------*/

function show_term(term) 
{
	term = getterm(term);
	term.visibility = "visible";
	//term.display = "show";
}

/*---------------------------------------------*/

function hide_term(term) 
{
	strTerm = term;
	if (term == "submenu3")
		maxy = 120;
	else
		maxy = 80; 
	term = getterm(term);
	if (document.layers) getMouseLoc;     //NS
 		else if (document.all) getMouseLoc(); //IE
 	//alert(mouseLocation.x+","+mouseLocation.y);
	if ((mouseLocation.x > 0) && (mouseLocation.x < 98)  && (mouseLocation.y >= -5)  && (mouseLocation.y <= maxy))
	{
		term.visibility = "visible";
		switch (strTerm)
		{   
		case "submenu1" : navButHilite('nav2', 'on');      
			break;  
		case "submenu2" : navButHilite('nav4', 'on');     
			break; 
		case "submenu3" : navButHilite('nav5', 'on');      
			break;   
		}
	} else
	{
		term.visibility = "hidden";
		//term.display = "show";
		navButHilite('nav2', 'off');
		navButHilite('nav4', 'off');
		navButHilite('nav5', 'off');
	}
}

/*---------------------------------------------*/

function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) 
  	foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) 
  	foundObj = document.getElementById(theObj);
  
  return foundObj;
}

/*---------------------------------------------*/

function setColor(objName, fg, bg, bdt)
{
  obj = findObj(objName);
  if (obj.style)
  {
    obj.style.color = fg;
    obj.style.backgroundColor = bg;
	obj.style.borderTopColor = bdt;
  }
}

/*---------------------------------------------*/

// Accepts a variable number of arguments, in triplets as follows:
// arg 1: simple name of a layer object, such as "Layer1"
// arg 2: ignored (for backward compatibility)
// arg 3: 'hide' or 'show'
// repeat...
//
// Example: showHideLayers(Layer1,'','show',Layer2,'','hide');
function showHideLayers()
{ 
  var i, visStr, obj, args = showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
  {
    if ((obj = findObj(args[i])) != null)
    {
      visStr = args[i+2];
      if (obj.style)
      {
        obj = obj.style;
        if(visStr == 'show') 
				{
					obj.visibility  = 'visible';
					obj.display = 'block';
				}
        else if(visStr == 'hide') 
				{
					obj.visibility  = 'hidden';
					obj.display = 'none';
				}
      }
    }
  }
}

/*---------------------------------------------*/

function navButHilite(objName, hilo)
{
	if (hilo == 'on')
	{
		setColor(objName, 'FFFFFF', '555555', '888888');
		document.getElementById(objName).style.color = "#FFFFFF";
		document.getElementById(objName).style.backgroundColor = "#555555";
		document.getElementById(objName).style.borderTopColor = "#888888";
		switch (objName)
		{
			case "nav1" : switchImage("star1", "images/star.gif");
								break;
			case "nav2" : switchImage("star2", "images/star.gif");
								break;
			case "nav3" : switchImage("star3", "images/star.gif");
								break;
			case "nav4" : switchImage("star4", "images/star.gif");
								break;
			case "nav5" : switchImage("star5", "images/star.gif");
								break;
			case "nav6" : switchImage("star6", "images/star.gif");
								break;
		}
		if (objName == 'nav1')
		{
			term = getterm('submenu1');
			term.visibility = "hidden";
			setColor('nav2', 'FFFFFF', '000000', '666666');
			//hide_term("submenu1");
		}
	} 
	if (hilo == 'off') 
	{
		setColor(objName, 'FFFFFF', '000000', '666666');
		document.getElementById(objName).style.color = "#FFFFFF";
		document.getElementById(objName).style.backgroundColor = "#000000";
		document.getElementById(objName).style.borderTopColor = "#666666";
		switch (objName)
		{
			case "nav1" : switchImage("star1", "images/nostar.gif");
								break;
			case "nav2" : switchImage("star2", "images/nostar.gif");
								break;
			case "nav3" : switchImage("star3", "images/nostar.gif");
								break;
			case "nav4" : switchImage("star4", "images/nostar.gif");
								break;
			case "nav5" : switchImage("star5", "images/nostar.gif");
								break;
			case "nav6" : switchImage("star6", "images/nostar.gif");
								break;
		}
	}
}

/*---------------------------------------------*/

function testMouseLoc()
{
 	if (document.layers) getMouseLoc;     //NS
 	else if (document.all) getMouseLoc(); //IE
 	alert(mouseLocation.x+","+mouseLocation.y);
  	/*
	in the BODY:
	<a href="#" onmouseover="testMouseLoc()">test</a>
	*/
}

//NS init:
if(document.layers){ document.captureEvents(Event.MOUSEDOWN); document.onMouseDown = getMouseLoc; }

/*---------------------------------------------*/

function subMailingList()
{
	strSubject = "";
	strEmail = "";
	strSendTo = "james@ilovesideline.com";
	
	strEmail = document.frm_MailingList.txt_eMail.value;
	if (document.frm_MailingList.radgr_sub_unsub[0].checked == "1")
		strSubject = "Subscribe";
	else
		strSubject = "Unsubscribe";
	document.frm_MailingList.action = "mailto:james@ilovesideline.com?Subject=" + strSubject + "&body=" + strEmail;
	document.frm_MailingList.submit();
}

/*---------------------------------------------*/
function preloadImages()
{
  if(document.images)
  {
    if(!document.imageArray) document.imageArray = new Array();
    var i,j = document.imageArray.length, args = preloadImages.arguments;
    
    for(i=0; i<args.length; i++)
    {
      if (args[i].indexOf("#")!=0)
      {
        document.imageArray[j] = new Image;
        document.imageArray[j++].src = args[i];
      }
    }
  }
}

/*---------------------------------------------*/

function formatContactMail()
{
	str = "mailto:james@ilovesideline.com?";
	str += "Subject=ContactMe&body=" + document.frm_contact.contact_name.value + document.frm_contact.contact_email.value;
	str += document.frm_contact.contact_number.value +  document.frm_contact.contact_message.value;
}

/*---------------------------------------------*/

function payPal(str)
{
	if (str == 'cart')
	{
		document.frm_shopping_basket.cmd.value = "_cart";
	}
	if (str == 'pay')
	{
		document.frm_shopping_basket.cmd.value = "_xclick";
	}
	document.frm_shopping_basket.submit();
}

/*---------------------------------------------*/

function show_props(p_obj)
{
	var prop;
    //var newwin = window.open('newwin');
	var str = "<font style='font-family:tahoma; font-size:8pt'> <b>PROPERTIES</b>";
	str = str + "<br><br>";
    for (prop in p_obj)
   {
     	str = str + prop + " : " + p_obj[prop] + "<br>";
   }
   str = str + "</font>"
    document.write(str);
}

/*---------------------------------------------*/

function show_sub_menu(submenu_id, button_id)
{
	//TODO
	
	//get button pos
	if (document.all)
	{
		show_hide_term(submenu_id);
	}
	else
	{
		but_term = getterm(button_id);
		sub_term= getterm(submenu_id);
		//show_props(sub_term);
		//sub_term.position = "relative";
		//alert ("pos : " + sub_term.position + " left : " + sub_term.left);
		show_hide_term(submenu_id);
	}
	//vx = but_term.toString();
	//alert ("vx = " + vx);
	//alert ( "button_id = " + button_id + " submenu_id = " + submenu_id);
	
	
	//position sub menu 
	
	//show sub menu
	/* term = getterm(submenu_id);
	term.visibility = "visible"; */
}

/*---------------------------------------------*/

function set_subnavs()
{
	var strBrowser = window.navigator.appName;
	var subnavs = getterm("subnavs");
	//alert ("browser : " + strBrowser);
	if (strBrowser == "Microsoft Internet Explorer")
	{
		subnavs.overflow = "hidden";
	}
	else
	{
		document.getElementById("subnavs").style.overflow = "visible";
		document.getElementById("submenu2").style.top = "-81px"; 
		document.getElementById("submenu3").style.top = "-162px";
	}
}

/*---------------------------------------------*/

function hide_subnavs()
{
	document.getElementById("submenu1").style.visibility = "hidden";
	document.getElementById("submenu2").style.visibility = "hidden";
	document.getElementById("submenu3").style.visibility = "hidden";
}

/*---------------------------------------------*/

function switchImage(imgName, imgSrc) 
{
  if (document.images)
  {
    if (imgSrc != "none")
    {
      document.images[imgName].src = imgSrc;
    }
  }
}

/*---------------------------------------------*/

function MM_reloadPage(init) 
{  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

MM_reloadPage(true);
//-------------------------------------------->