// JavaScript Document

var drawerPosition = new Array();

function currentPage(current_drawer, num_pages, section){
	cookie_value = Get_Cookie('ballyhoo_'+section+'_positions');
	if(cookie_value){
		drawerPosition = cookie_value.split(",");
		page=drawerPosition[current_drawer];
	}
	if (!(page)||(page>num_pages)){
		page=1;
	}
	
	var thumbnails=document.getElementsByName("thumbnail_"+current_drawer);
	num_per_page = 4;
	for(var i=0;i<thumbnails.length;i++){
		if( (num_per_page*(page-1) < i+1) && (i+1 <=num_per_page*page)){ //only show those thumbnails
			thumbnails[i].style.display="inline";
		}else{
			thumbnails[i].style.display="none";
		}
	}

	drawerPosition[current_drawer]=page;
	Set_Cookie ("ballyhoo_"+section+"_positions", drawerPosition, 1,  "/");
}

function nextPage(current_drawer, num_pages, section){
	page=parseInt(page)+1;
	drawerPosition[current_drawer]=page;
	Set_Cookie ('ballyhoo_'+section+'_positions', drawerPosition, 1,  "/");
	currentPage(current_drawer, num_pages, section);
  }

function setDrawerPosition(current_drawer, page){
	drawerPosition[current_drawer]=page;
	Set_Cookie ('ballyhoo_'+section+'_positions', drawerPosition, 1,  "/");
}

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
the expires variable is set in hours 
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}


// this function gets the cookie, if it exists
function Get_Cookie( 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 ) );
}
		
// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
			