var g;
var gCurrent = 0;
/**
* Method that returns a DOM Element.
* @param idElem (String) The ID of the Element
*/
getDOMElement = function(idElem)
{
	/*
	* Detect Browser settings
	*/
	var OP = window.opera ? true : false;
	var DOM = document.getElementById ? true : false;
	var MS = (document.all && !OP) ? true : false;
	var NS = (document.layers && !OP) ? true : false;
	var SA = navigator.userAgent.indexOf('Safari');
	
	/*
	* Get Elements based on the Element ID
	*/
	if(DOM){
		return document.getElementById(idElem);
	} else if (MS){
		return document.all[idElem];
	} else if (NS){
		return document[idElem];
	} else {
		alert("This browser does not Support the required JavaScript functionality. Please contact the Webmaster");
		return;
	}
}

openGallery = function( index )
{
	var dwin = getDOMElement( "galleryWin" );
	if( dwin ){
		dwin.style.display = "block";
		var imgc = getDOMElement( "galleryImage" );
		
		imgc.style.width = dwin.style.width = g[index][1] + "px";
		imgc.style.height =  g[index][2]  + "px";
		imgc.style.visibility = "hidden";
		img = new Image();
		img.src = g[index][0];
		imgc.src = img.src;
		imgc.style.visibility = "visible";
		
		gCurrent = index;
	}
}

openFilm = function( uri, wi, he )
{
	wi += 10;
	he += 10;
	var win = window.open(uri, 'movieWin', 'width=' + wi + ',height=' + he + ',resizable=no,scrollbars=no,dependent=yes');
	win.focus();
}

closeGallery = function()
{
	dwin = getDOMElement( "galleryWin" );
	if( dwin ){
		dwin.style.display = "none";
	}
}

nextGallery = function()
{
	gCurrent = (gCurrent+1) % g.length;
	openGallery(gCurrent);
}

prevGallery = function()
{
	gCurrent = gCurrent == 0 ? g.length - 1 : gCurrent -1;
	openGallery(gCurrent);
}

initGallery = function(galleryArray)
{
	g = galleryArray;
}