/******************************************************************************
 SI_clearFooter() v1.0
 Use this function when absolutely positioning section navigation, 
 primarary and secondary content and the footer falls below any one
 of them. Absolute positioning avoids the unwanted wrapping that
 sometimes occurs in IE PC when floats are used for layout.
 ******************************************************************************/
function SI_clearFooter() {
	var d = document,w=window,dE=d.documentElement,dB=d.body,h;
	if (!d.getElementById || !dB.offsetHeight) return;
	
	/* Configuration */
	var container	  = 'content';	// The inner container div
	var minHeight	  = 410;	// Minimum page height in pixels
	var extendShallow = false;	// Extends shallow children so that repeating backgrounds 
								// will repeat all the way to the footer
	var bottomOut	  = false;	// Whether the footer should just clear the contents of the 
								// inner-container div or snap to the bottom of the window 
								// when content is too short
								
								
	var ic = d.getElementById(container); // The inner container div
	ic.style.height = '0';		// Resets the height
	var oh = [];		// Holds the offset heights of each child div
	var icTop = ic.offsetTop;
	var winHeight	= (typeof(w.innerHeight)=='number')?w.innerHeight:(dE&&dE.clientHeight)?dE.clientHeight:(dB&&dB.clientHeight)?dB.clientHeight:0;
	var footHeight	= d.getElementById('footer').offsetHeight;
	oh[0] = minHeight-icTop-footHeight;	// Minimum height of the inner-container div

	
	// Make an array of the rendered heights of the contained elements
	for (i=0;i<ic.childNodes.length;i++) { c = ic.childNodes[i]; if (c.nodeName=='DIV') { c.style.height = 'auto'; oh[oh.length] = parseInt(c.offsetHeight)+parseInt(c.offsetTop); }}
	// Determine the max height
	h = 0; for (k=0;k<oh.length;k++) { h = (oh[k]>h)?oh[k]:h;}
	// Force footer to the bottom of the window 
	if (bottomOut) { h = ((icTop+h+footHeight) < winHeight)?winHeight-footHeight-icTop:h; }
	// Extend shorter elements
	if (extendShallow) { for (i=0;i<ic.childNodes.length;i++) { c = ic.childNodes[i]; if (c.nodeName=='DIV') { c.style.height = h+'px'; }}}
	ic.style.height = h+'px';
	SI_forceScreenRedraw();
	}


/******************************************************************************
 SI_forceScreenRedraw() v1.0
 Forces a screen redraw. Often required by Mozilla
 in order to reflow content after modifiying innerHTML
 ******************************************************************************/
function SI_forceScreenRedraw() {
	var d = document;
	if (d.body && d.body.style) {
		d.body.style.height = "100px";
		d.body.style.height = "auto";
		}
	}

/******************************************************************************
 SI_stripe() v1.1 (had to change it for that Stan-defined class)
 
 This function seeks out unordered lists with the class of _'striped'_ 'altList' and marks
 alternate list items with a class of 'alt'. If more than one marked list is 
 found then it begins with an alternate list item.
 
 Call onload or after unordered lists are modified by scripting.
 ******************************************************************************/
function SI_stripe() {
	var d = document;
	if (!d.getElementsByTagName) return;
	
	var u = l = false;
	var uls = d.getElementsByTagName('ul');
	for (i=0; i<uls.length; i++) {
		var ul = uls[i];
		if (ul.className.indexOf('altList')!=-1) {
			var lis = ul.getElementsByTagName('li');
			for (j=0; j<lis.length; j++) {
				var li = lis[j];
				if (l) li.className+=((li.className=='')?'':' ')+'alt';
				l=(!l);
				}
			l = u = (!u);
			}
		}
	}

/******************************************************************************
 SI_swapFeaturedWork() v1.0
 
 Swaps the Featured Work image, title, caption and description on the homepage.
 Expects an index in the SI_works array and a reference to the link clicked.
 ******************************************************************************/
function SI_swapFeaturedWork(w,e) {
	var d = document;
	if (!d.getElementsByTagName) return;
	
	// Set the active button
	var btns = d.getElementById('SI_workOpts').getElementsByTagName('a');
	for (i=0;i<btns.length; i++) { btns[i].className=''; }
	e.className = 'active';
	e.blur();
	
	// Set the work image
	d.getElementById('SI_workImg').src = SI_works[w][0];
	
	// Set the work title
	d.getElementById('SI_workTitle').innerHTML = SI_works[w][1];
	
	// Set the work caption
	d.getElementById('SI_workCapt').innerHTML = SI_works[w][2];
	
	// Set the work description
	d.getElementById('SI_workDesc').innerHTML = SI_works[w][3];
	
	// Clear that footer
	SI_clearFooter();
	}

var HOST = 'theheadsofstate.com';

/* DEFAULT MT CODE */
// Copyright (c) 1996-1997 Athenia Associates. http://www.webreference.com/js/ License is granted if and only if this entire copyright notice is included. By Tomer Shiran.
function setCookie(name, value, expires, path, domain, secure) { var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : ""); document.cookie = curCookie; }
function getCookie(name) { var prefix = name + '='; var c = document.cookie; var nullstring = ''; var cookieStartIndex = c.indexOf(prefix); if (cookieStartIndex == -1) { return nullstring; } var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length); if (cookieEndIndex == -1) { cookieEndIndex = c.length; } return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex)); }
function deleteCookie(name, path, domain) { if (getCookie(name)) { document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT"; } }
function fixDate(date) { var base = new Date(0); var skew = base.getTime(); if (skew > 0) date.setTime(date.getTime() - skew); }

/******************************************************************************
 SI_swapPortfolioImg() v1.0
 
 Swaps the Portfolio image and activates the appropriate subnav button.
 ******************************************************************************/
function SI_swapPortfolioImg(s,e) {
	var d = document;
	if (!d.getElementsByTagName) return;
	
	// Set the active button
	var btns = d.getElementById('SI_portOpts').getElementsByTagName('a');
	for (i=0;i<btns.length; i++) { btns[i].className=''; }
	e.className = 'active';
	e.blur();
	
	// Set the portfolio image
	d.getElementById('SI_PortfolioImg').src = s;
	}

/******************************************************************************
 SI_redrawPortNav() et al v1.0
 
 Keeps the portfolio navigation consistent across all pages of the portfolio
 using cookies.
 ******************************************************************************/
var SI_portNav = new Array();
function SI_initPortNav() {
	var d = document;
	if (!d.getElementsByTagName) return;
	
	for (var id in SI_portNav) { 
		SI_portNav[id].total = d.getElementById(id).getElementsByTagName('a').length;
		var c = getCookie('HoS-'+id);
		// alert(id+': '+c);
		if (c!='') { SI_portNav[id].current = parseInt(c); }
		SI_redrawPortNav(id);
		}
	}

function SI_redrawPortNav(id) {
	var d = document;
	if (!d.getElementsByTagName) return;
	
	var c = SI_portNav[id];
	var t = d.getElementById(id);
	var p = d.getElementById(id+'-prev');
	var n = d.getElementById(id+'-next');
	p.className = p.className.replace(/ disabled/g,'');
	n.className = n.className.replace(/ disabled/g,'');
	
	// Position the nav
	t.style.left = (c.current<=0)?'0px':'-'+(c.current*55)+'px';
	
	if (c.current<=0) { p.className += ' disabled'; }
	if (c.current>=(c.total-4) || c.total<=4) { n.className += ' disabled'; }
	}

function SI_navigatePortfolio(id,dir) {
	SI_portNav[id].current += dir;
	SI_redrawPortNav(id);
	
	// Set a cookie that will last 1 hour
	var now = new Date(); fixDate(now); now.setTime(now.getTime() + 1 * 60 * 60 * 1000);
	setCookie('HoS-'+id, SI_portNav[id].current, now, '/', HOST, '');
	}

/******************************************************************************
 SI_redrawPosterNav() et al v1.0
 
 ******************************************************************************/
var SI_currentPosterRow = 0;
function SI_initPostersNav() {
	var c = getCookie('HoS-posters');
	if (c!='') { SI_currentPosterRow = parseInt(c); }
	SI_redrawPostersNav();
	}

function SI_redrawPostersNav() {
	var d = document;
	if (!d.getElementsByTagName) return;
	
	var c = SI_currentPosterRow;
	var n = d.getElementById('SI_postersNav');
	var pp = d.getElementById('SI_postersPagination');
	var l = n.getElementsByTagName('a').length;
	var p = Math.ceil(l/25);
	var pagelinks = '';
	
	for (i=0; i<p; i++) { pagelinks += ((i*5)==c)?(i+1)+' ':'<a href="" onclick="SI_navigatePosters('+(i*5)+'); return false;">'+(i+1)+'<'+'/a> '; }
	pp.innerHTML = pagelinks;
	
	// Position the nav
	n.style.top = (c<=0)?'0px':'-'+(c*55)+'px';
	
	}

function SI_navigatePosters(row) {
	//alert(row);
	SI_currentPosterRow = row;
	SI_redrawPostersNav();
	
	// Set a cookie that will last 1 hour
	var now = new Date(); fixDate(now); now.setTime(now.getTime() + 1 * 60 * 60 * 1000);
	setCookie('HoS-posters', SI_currentPosterRow, now, '/', HOST, '');
	}