//	2007-01-12 evitiello

// Resize the left-hand nav column on interior pages.
//
function resizeContentLeft() {
	if ($("contentLeft") && $("contentRight")) {
		rightHeight = Element.getHeight($("contentRight"));
		//contentLeft = ($("contentLeft"));

		($("contentLeft")).style.paddingBottom = "0px";
		leftHeight = Element.getHeight(($("contentLeft")));

		($("contentLeft")).style.paddingBottom = (rightHeight - leftHeight + 10)+"px";
	}
}

var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible'))
{
	browser = "Netscape Navigator"
	version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac"
	else if (checkIt('win')) OS = "Windows"
	else OS = "an unknown operating system";
}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	if ((browser == "Safari") && (features == "width=600,height=340")) {
		features = "width=600,height=355";
	}
  window.open(theURL,winName,features);
}


/* navigation effects
	Just add the class of parent to the LI that should open,
	as well as display:none to the Ul contained in that LI (if it should start out closed.)
*/

var currentlyOpenNav = null;

/* keep the proper nav open */
function keepNavOpen() {
	var p = new Poly9.URLParser(window.location.href);
	currentPagePathName = p.getPathname();
	if (currentPagePathName != "/") {
		// see if this page exists in the nav, if it does and it's in
		// a child nav,open the parent.
		
		var navLinks = ($('nav')).getElementsByTagName('a');
		for (i=0; i<navLinks.length; i++) {
			
			if (navLinks[i].pathname == currentPagePathName || "/"+navLinks[i].pathname == currentPagePathName) {
				
				var parentNav = navLinks[i].parentNode.parentNode.parentNode;

				// if the item is the parent of some stuff, open it.
				// or if it's a child...
				if (navLinks[i].parentNode.className == "parent") {			
					//open it up.
					Effect.ToggleNav(navLinks[i].parentNode.childNodes[2]);
					break;
				} else if (parentNav.className == "parent") {
					Effect.ToggleNav(parentNav.childNodes[2]);
					break;				
				}
									
				//kill the loop.
				break;
			}
		}
		
	} 
}

Effect.ToggleNav = function(source) {
	source = $(source);
	if (source.style.display == "none") {
		Effect.OpenUp(source);
	} else {
		Effect.CloseDown(source);
	}
}
Effect.OpenUp = function(elementstring) {
	// if there is someone open, close them.
	if (currentlyOpenNav != null && currentlyOpenNav != elementstring) {
		Effect.CloseDown(currentlyOpenNav);
	}
	element = $(elementstring);
	element.parentNode.className = "parent open";
	new Effect.BlindDown(element, {duration: .4} || {});
	currentlyOpenNav = element;
}

Effect.CloseDown = function(elementstring) {
	element = $(elementstring);
	element.parentNode.className = "parent";
	new Effect.BlindUp(element, {duration: .4} || {});
	
}

BehaviourRules = {
	// fire the load function for all links in the content.
	'#nav .parent' : function(el) {
		el.onclick = function() {
			Effect.ToggleNav(this.childNodes[2]);
		}
	}
};

Behaviour.register(BehaviourRules);
Behaviour.addLoadEvent(function(){
	resizeContentLeft();
});
Behaviour.addLoadEvent(function(){
	keepNavOpen();
});
/* end navigation effects */

/* pop on homepage tabify */
function showTabs(showElement, source) {
	if (showElement == "Productions") {
		Element.hide('servicesPopMarketing');
		Element.show('servicesPopProductions');
		$('tabProductions').className = "on";
		$('tabMarketing').className = "off";
	} else {
		Element.hide('servicesPopProductions');
		Element.show('servicesPopMarketing');
		$('tabProductions').className = "off";
		$('tabMarketing').className = "on";
	}
}
/* end POP on homepage tabs */