
// HOTSPOTS_ON is a boolean denoting the tags button state
var HOTSPOTS_ON = false;

/*
function favourite()
{
//alert( 'STORYBOARD_ID = ' + STORYBOARD_ID );
	new Ajax.Request( REMOTE_URL
					,	{	method: 'post'
						,	parameters: {	f: 'favourite'
										,	sid: STORYBOARD_ID
										}

						,	onSuccess:
								function(oReq)
								{
//	alert('Addded to favourites: ' + oReq.responseText);
									var code = oReq.responseText.substr( 0, 1 );
									var text = oReq.responseText.substr( 2 );

alert( text );
								}
						,	onFailure:
								function(oReq)
								{
alert('Failed to add to favourites');
								}
						} );
}
*/

function storyboard_init()
{
//alert( 'in storyboard_init()' );
		var oUL = $('ul_hotspots');
//alert( 'oUL = ' + oUL );

	if ( oUL )
	{
	var aEls = $('ul_hotspots').getElementsBySelector( 'li.li_hotspot' );
	for ( var i=0; i < aEls.length; i++ )
	{
//alert( 'aEls[i] = ' + aEls[i].id );
		aEls[i].onmouseover = function() { var idint = parseInt(this.id.substr(6));highlight_hs(idint); }
		aEls[i].onmouseout = function() { var idint = parseInt(this.id.substr(6));unhighlight_hs(idint); }
	}
	}
	
	//	$('print_button').onclick = function() { print_image(); }
	
		var aEls = $$('ul#ul_hotspots li.li_hotspot a.external_link', 'div.sb_main_image a.external_link');
//alert( 'aEls = ' + aEls );
	for ( var i=0; i < aEls.length; i++ )
	{
		aEls[i].onclick = onclick_external_website;
	}
	
	// START Attach actions to toolbar buttons
	$('back-btn').observe( 'click', onclick_back_btn );
	$('tags-btn').observe( 'click', onclick_tags_btn );
	$('enlarge-btn').observe( 'click', onclick_enlarge_btn );
	$('basket-btn').observe( 'click', onclick_basket_btn );
	// END Attach actions to toolbar buttons
}

function onclick_back_btn()
{
	history.go(-1);
}

function onclick_tags_btn()
{
	$$('div#img a[id^=hs_]').each(
		function(hs)
		{
			if ( HOTSPOTS_ON )
			{
				hs.removeClassName('hover');
			}
			else
			{
				hs.addClassName('hover');
			}
		});
	HOTSPOTS_ON = !HOTSPOTS_ON;

	if ( HOTSPOTS_ON )
		$('tags-btn').addClassName('on');
	else
		$('tags-btn').removeClassName('on');
}

function onclick_enlarge_btn()
{

	if ( window.name === 'embed_popup' )
	{
		window.close();
		return false;
	}

//var win = window.open( window.location.href, "embed_popup", "deirectories=0,menubar=0,resizable=1,height="+h+",width="+w+",location=no,scrollbars=no,status=no,titlebar=yes,toolbar=no" );

var w = screen.width - 60;
var h = screen.height - 150;

var x = parseInt((screen.width - w)/2);
var y = 20; //parseInt((screen.height - h)/2);

var url = window.location.href + '&fs=1&w=' + w + '&h=' + h;
url = url.replace( /&si=[sml]/, '' );
//var win = window.open( url, "embed_popup", "deirectories=0,menubar=0,resizable=1,height="+image_height+",width="+image_width+",location=yes,scrollbars=no,status=no,titlebar=no,toolbar=no" );
var win = window.open( url, "embed_popup", "deirectories=0,menubar=0,resizable=1,height="+h+",width="+w+",location=yes,scrollbars=yes,status=no,titlebar=no,toolbar=no,top="+y+",left="+x );

}

function onclick_basket_btn()
{
alert('basket');
}

function onclick_external_website()
{
	//var bRet = confirm( "You are about to enter an external website, for which SlipperyOctopus.com has no responsiblity. Click 'OK' to continue" );
	//return bRet;
	return true;
}

function highlight_hs( iId )
{
	if ( TAGS )
		return false;

	var oEl = $('hs_'+iId);
	if ( oEl )
		oEl.addClassName( 'hover' );
}
function unhighlight_hs( iId )
{
	if ( TAGS )
		return false;

	var oEl = $('hs_'+iId);
	if ( oEl )
		oEl.removeClassName( 'hover' );
}

function print_image()
{
	var pw = window.open("", "_image", 
				"width=" + image_width + ", height=" + image_height + ", " +
				"status=no, toolbar=no, scrollbars=no, resizable=no, menubar=no, location=no, directories=no");
	pw.document.open();
	pw.document.write(
		"<html>\n" +
		"<head>\n" +
		"<title>Print Image</title>\n" +
		"<script>\n" +
		"function print_image() {\n" +
		"	setTimeout('print_impl()', 10);\n" +
		"}\n" +
		"function print_impl() {\n" +
		"	window.print();\n" +
		"	window.close();\n" +
		"}\n" +
		"</scri" + "pt>\n" +
		"</head>\n" +
		"<body leftmargin='0' topmargin='0' onLoad='print_image();'>\n" +
		"<img src='" + IMAGE_SRC + "'/>\n" +
		"</body>\n"
	);
	pw.document.close();
}


