var panels = ["navigation","admin","categories","authors","latest_posts","subscribe","search"];
var controlButtons = {
	collapse: preloadImage('/wp-content/themes/beertuesday_v2/images/panel-control-collapse.gif', 16, 16),
	expand: preloadImage('/wp-content/themes/beertuesday_v2/images/panel-control-expand.gif', 16, 16)
}

function preloadImage( imagePath, width, height ) {
	var img = new Image( width, height );
	img.src = imagePath;
	return img;
}

// THE REST DOESN'T NEED TO BE CHANGED

var $=function(layerId){return document.getElementById(layerId)};

function initialisePanelPreferences() {
	for ( var x=0; x<panels.length; x++ ) {
		if ( getCookie( 'panel_'+panels[x] ) && getCookie( 'panel_'+panels[x] ) == "false" ) 
			togglePanel( panels[x] );
	}
}

function togglePanel( panelId ) {
	if ( $('panel_'+panelId).style.display == "none" ) {
		$('button_'+panelId).src = controlButtons.collapse.src;
		$('panel_'+panelId).style.display = "block";
		setCookie('panel_'+panelId, 'true', 999, null, 'www.beertuesday.co.nz');
	} else {
		$('button_'+panelId).src = controlButtons.expand.src;
		$('panel_'+panelId).style.display = "none";
		setCookie('panel_'+panelId, 'false', 999, null, 'www.beertuesday.co.nz');
	}
}

function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
		var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
		return unescape( document.cookie.substring( len, end ) );
}
 
function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}
 
function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + '=' +
		( ( path ) ? ';path=' + path : '') +
		( ( domain ) ? ';domain=' + domain : '' ) +
		';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}
