// x_core.js
// X v3.15.1, Cross-Browser DHTML Library from Cross-Browser.com
// Copyright (c) 2002,2003,2004 Michael Foster (mike@cross-browser.com)
// This library is distributed under the terms of the LGPL (gnu.org)

// Variables:
var xVersion='3.15.1',xNN4=false,xOp7=false,xOp5or6=false,xIE4Up=false,xIE4=false,xIE5=false,xUA=navigator.userAgent.toLowerCase();
if(window.opera){
  xOp7=(xUA.indexOf('opera 7')!=-1 || xUA.indexOf('opera/7')!=-1);
  if (!xOp7) xOp5or6=(xUA.indexOf('opera 5')!=-1 || xUA.indexOf('opera/5')!=-1 || xUA.indexOf('opera 6')!=-1 || xUA.indexOf('opera/6')!=-1);
}
else if (document.all) {
  xIE4Up=xUA.indexOf('msie')!=-1 && parseInt(navigator.appVersion)>=4;
  xIE4=xUA.indexOf('msie 4')!=-1;
  xIE5=xUA.indexOf('msie 5')!=-1;
}
// Object:
function xGetElementById(e) {
  if(typeof(e)!='string') return e;
  if(document.getElementById) e=document.getElementById(e);
  else if(document.all) e=document.all[e];
  else e=null;
  return e;
}

function xDef() {
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}

function xPageX(e) {
  if (!(e=xGetElementById(e))) return 0;
  var x = 0;
  while (e) {
    if (xDef(e.offsetLeft)) x += e.offsetLeft;
    e = xDef(e.offsetParent) ? e.offsetParent : null;
  }
  return x;
}
function xPageY(e) {
  if (!(e=xGetElementById(e))) return 0;
  var y = 0;
  while (e) {
    if (xDef(e.offsetTop)) y += e.offsetTop;
    e = xDef(e.offsetParent) ? e.offsetParent : null;
  }
//  if (xOp7) return y - document.body.offsetTop; // v3.14, temporary hack for opera bug 130324
  return y;
}
/* ************** End X functions ************** */



/* dock navigation panel functions */
function collapseSidebarPreference() {
	var hidenav = readCookie("hidenav");
		if (hidenav == 1 && xGetElementById('flow'))
	{
		hideMe();
}
}
function toggle() {
	var expiry = new Date();
	expiry.setFullYear(expiry.getFullYear()+1);
	var xmt = xPageX('flow');
	var cookieString;
	if (xmt > 50) {
		hideMe();
		cookieString = "hidenav=1; expires= " + expiry.toGMTString() + "; path=/";
	}
	else {
	 	showMe();
		cookieString = "hidenav=0; expires= " + expiry.toGMTString() + "; path=/";
	}
	
	// If hostname ends with sitepoint.com
	if (location.hostname.lastIndexOf('sitepoint.com') == location.hostname.length - 'sitepoint.com'.length) {
		cookieString += '; domain=.sitepoint.com'; // Allow cookie on SitePoint domain
	}
	document.cookie = cookieString;
}
function hideMe(){
	var col1 = xGetElementById('col1');
	col1.style.display = "none";
	var flow = xGetElementById('flow');
	flow.style.width = "auto";
	flow.style.margin = "0";
	flow.style.backgroundImage = "url(/images/layout/tab2-b.gif)";
	flow.style.styleFloat = flow.style.cssFloat = 'left';
}

function showMe(){
	var col1 = xGetElementById('col1');
	col1.style.display = "block";
	var flow = xGetElementById('flow');
	flow.style.width = "74%";
	flow.style.margin = "0";
	flow.style.backgroundImage = "url(/images/layout/tab2.gif)";
	flow.style.styleFloat = flow.style.cssFloat = 'right';
}

function cancelbubble(evt) {
evt = (evt) ? evt : ((event) ? event : null);
if (evt) {evt.cancelBubble = true;
}
}

addLoadEvent(collapseSidebarPreference);
