/************************************************************
UberGames Website Popup Windows JavaScript Functions
By Timothy 'TiM' Oliver
20/3/2008

JavaScript Functions for the UberGames website relating
to the opening of popup windows off from the current page.
************************************************************/

/****************************
OpenNewWindow

Opens a link in a JavaScript
spawned window.
****************************/
function OpenNewWindow( url )
{
	//if possible, make the new window slightly smaller than the screen
	if ( screen.width > 1024 && screen.height > 768 )
	{
		w = 1024;
		h = 768;
	}
	else
	{
		w = screen.width * 0.85;
		h = screen.height * 0.85;
	}
	
	attributes = "width="+w+",height="+h+", \
					left=5,top=5, \
					resizable=yes, \
					scrollbars=yes, \
					toolbar=no, \
					location=no, \
					directories=no, \
					status=no, \
					menubar=no, \
					copyhistory=no";
	
	window.open( url, "UberGames", attributes );
}

/****************************
NewWindowLink

Draws an HTML link that is
set up to open text to a new
window, while at the same
time maintaining a standard
appearence and function
****************************/
function NewWindowLink( url, statusBar, title, linkText, jScript )
{
	//This is a hack to ensure valid HTML validation.
	//The validator hates HTML tags inside JavaScript strings
	linkText = linkText.replace( /&lt;/ig, "<" );
	linkText = linkText.replace( /&gt;/ig, ">" );
	
	if( !jScript )
		jScript = "";
	
	//in case the status bar has quotes in it, it needs to preserver the backslash
	//for one more level of JavaScript. The title and linktext is fine tho.
	statusBar = statusBar.replace( /\'/ig, "\\'" );
	
	document.write( "<a href=\"#\" onclick=\"javascript:OpenNewWindow( '" + url +"' ); "+jScript+"\"  \
					title=\"" + title + "\" \
					onmouseover=\"window.status='"+statusBar+"';return true;\" \
					onmouseout=\"window.status='';return true;\">" + linkText + "</a>" );
}


/****************************
ThumbnailLink

A quick and dirty unification
of the above functions.
An image, gallery id and a caption is provided,
so automatically fill in the rest
****************************/
function ThumbnailLink( thumbnail, img_id, caption, floatSide )
{
	//set up the float style
	if ( floatSide != 'left' && floatSide != 'right' )
		floatStyle = 'float:none';
	else
		floatStyle = 'float:'+floatSide+';margin-'+floatSide+':0;';
		
	//output the rest - opening brace
	document.write( "<div class=\"galleryBox\" style=\""+floatStyle+"\">");
	//print the window link
	NewWindowLink('/gallery_popup/'+img_id+'/', caption, caption, '<img src="'+thumbnail+'" alt="'+caption+'" title="'+caption+'" />' );
	//close the brace
	document.write( "<br/><em><strong>"+caption+"</strong></em></div>" );
}

