// display.js
// Ken Ficara 
// Copyright (C) 2008 Harmonica, LLC
// 
// Various functions for page display
//
// $Id: display.js,v 1.4 2009-02-05 09:47:31-05 ficara Exp $
//-------------------------------------------------------------------

function showpage(page)
{
	// Find all the divs inside textblock and turn display off
	
	var pages = document.getElementById('textblock').getElementsByTagName("div");
	
	for (var pageno = 0; pageno<pages.length;pageno++)
	{
		pages[pageno].style.display='none';
	}
	
	// Turn display on for the given page
	
	document.getElementById(page).style.display="block";
}

// The onload function. Displays the first page and installs the player.

function bodyLoad()
{
	createVideoPlayer();

	qs = window.location.search.substring(1);	
	if (qs != '')
	{
		if (qs.search(/[a-zA-Z0-9]/))
		{
			showpage('p1');
		}
		else
		{
			showpage(qs);
		}
	}
	else
	{
		showpage('p1');
	}
}

// Resets page to home state and reloads player.

function loadP1()
{
	// Resets to start state, including loading video into player.
	
	var dihsf = {type:"video",file:baseURL + "media/dayihadsomefunsmall.mp4",title:"The Day I Had Some Fun",image: baseURL+"media/images/KmizedVideoStillLarge.jpg"};

	player.sendEvent('LOAD', dihsf);
	showpage('p1');
}

// This creates the pager controls at the bottom of the text block, 
// taking three arguments:
//
// page -- the page number for which we are displaying controls
// total -- the total number of pages
// prefix -- the prefix to be used for the hyperlink in front of the page number

function showControls(page, total, prefix)
{
	if (page != 1)
	{
		document.write ('<A HREF="javascript:showpage(\'');
		document.write (prefix);
		document.write (page-1);
		document.write ('\')">Previous</A>');
	}
	
	for (i=1 ; i<=total ; i++)
	{
		if (i != page)
		{
			document.write ('&nbsp;<A HREF="javascript:showpage(\'');
			document.write (prefix);
			document.write (i);
			document.write ('\')">'+i+'</A>&nbsp;');
		}
		else
		{
			document.write('&nbsp;'+i+'&nbsp;');
		}
	}

	if (page != total)
	{
		document.write ('<A HREF="javascript:showpage(\'');
		document.write (prefix);
		document.write (page+1);
		document.write ('\')">Next</A>');
	}
	
}

// Displays the buy links for an album -- dims cover and shows text.

function buy(album)
{
	document.getElementById(album).style.opacity=0.4;
	document.getElementById(album).style.filter='alpha(opacity=40)';
	document.getElementById(album+'-text').style.display='inline';
}

// Hides the buy links and undims the cover. 

function cancelBuy(album)
{
	document.getElementById(album).style.opacity=1;
	document.getElementById(album).style.filter='alpha(opacity=100)';
	document.getElementById(album+'-text').style.display='none';
}

