// JavaScript Document
/* functions for menus */

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}


/* END for menus */

/* LUKY.COM - All Code Below Is Copyrighted.
   Copyright (c)2005 Todd Roseman. All Rights Reserved.
   Licensed to Crowder Supply, Denver, CO.
   Do not use without prior permission.
*/
function relativeFilePart( s )	{
	var i;
	
	var rsl = /\\/g;
	s = s.replace(rsl,'/');
	var re = /\/dw\/(.*)/;
	var rg = re.exec(s);
	if (rg)	{
		if (rg.length<=1)	{
			rr = /\/.com\/(.*)/;
			rg = rr.exec(s);
			if (rg.length<=1) { return s; }
		}
		return rg[1];
	}
	else { return s; }
}


function setCurrentPage() {
	var navEl = document.getElementById("nav");
	var aEls = navEl.getElementsByTagName("A");
	var i, as, thisFile, liEl, liEj, liElast;
	
	currentFile = relativeFilePart(document.URL);
	// alert(currentFile);

	// find this page and set it's <li> to different class, also set parents li (if exists)
	for (var i=0; i<aEls.length; i++) {
		// className
		as = new String(aEls[i].href);
		thisFile = relativeFilePart(as);
//		alert(thisFile + " " + as);
		// thisFile = as.substring(as.lastIndexOf('/')+1,100);
		// alert( thisFile + currentFile + (thisFile==currentFile));
		if (thisFile == currentFile)	{
			// break; // do all occurances of this file in menu
			
			// set this element
			// set top-level parent (this menu, immediate parent, (not ul though)
			liEl = aEls[i];
			// mark each li above this one with "here"
			for (liEj = liEl.parentNode; liEj && liEj.id != "nav"; liEj = liEj.parentNode )	{
				if (liEj.tagName == "LI")	{
					// liEl.className = liEl.className + " here";
					liEj.className = liEj.className + " here";
				}
				// alert(liEj.tagName);
			}
		}
	}
	// if (i == aEls.length) { return; }
	
	// top level item
	//	liEl.style.background = "url(images/bar-bg-on.gif)";
}


function postLoad()	{
	if (window.attachEvent) {	// ie only
		sfHover();
	}
	setCurrentPage();
	
//	var doc = new String(document.URL);
	// alert(doc.length + ": " + doc.substring(doc.length-1));
//	if ((doc.indexOf("index.htm") != -1) || (doc.substring(doc.length-1)=="/"))	{
//		ShowNotice();
//	}
	
}


if (document.getElementById){
	document.write('<style type="text/css">\n');
	document.write('.pagesection {display: none;}\n');
	document.write('</style>\n');
}

function SwitchMenu(obj){
	if (document.getElementById) {
		var el = document.getElementById(obj);
		var ar = document.getElementById("allpagesections").getElementsByTagName("div"); 
		if(el.style.display != "block"){ //DynamicDrive.com change
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="pagesection") //DynamicDrive.com change
					ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}




var gNoticeInterval=null;

function ShowNotice()	{
	var bAlreadyShown = false;	// NOTYET - get cookie
	var el = document.getElementById("noticebox");
	var dc = document.cookie;
	if (dc.indexOf("noticebox") != -1) { bAlreadyShown = true; }
	if (el && !bAlreadyShown)	{
		el.style.display = "block";
		// NOTYET - set cookie to not display again for this session
		gNoticeInterval = setInterval(noticeTimeout,1*60*1000);
	}	
}

function noticeTimeout()	{
	clearInterval(gNoticeInterval);
	NoticeOff();
}

function NoticeOff()	{
	var el = document.getElementById("noticebox");
	if (el)	{
		el.style.display = "none";
	}
	document.cookie="noticebox=1";
	return false;
}



// check for movie player
// note: don't use document.ready - swfobject does not work if you wait till dom ready, do right away
if ($('#movie')) {
	var flashvars = { videos: "/assets/media/videos.xml" };
	var params = { allowfullscreen: "true", allowscriptaccess: "always" };
	var attributes = {};
	swfobject.embedSWF("/assets/flash/Titanium-800.swf", "movie", "800", "306", "9.0.0","/assets/flash/expressInstall.swf", flashvars, params, attributes);
}


// home page video toggler
$(document).ready(function(){
	$('#video-block-opener a').css("background-position","0 0");
	
	$('#video-block-opener a').click( function() {
		// change opener icon
		//y = $(this).css("background-position");
		if ($('#video-block').is(':visible')) {
			y = "0 0px";
		} else {
			y = "0 -25px";
		}
		$(this).css("background-position",y);
		$('#video-block').toggle();
		return false;
	});
	

});

