// Value holders.
var popupGuid = ""; // store guid from flash
var votePageID = ""; // vote id w.r.t language
var tipPageID = ""; // tip id w.r.t language
var uploadPageID = ""; // upload id w.r.t language

// Values
var popupGridWidth;
var popupGridHeight;

// close window
function closeElement(name)
{
	document.getElementById(name).style.display = 'none';
}

// open window
function openElement(name, top)
{
	//closeElement('gridPopup');
	closeElement('imagePopup');
	closeElement('framePopup');
	
	var el = document.getElementById(name);
	el.style.display = '';
	
	if (top == null)
	{
		setDisplay(el, '80px');
		window.onresize = function() { setGridDisplay(el); setDisplay(el, '80px'); };
	}
	else
	{
		setGridDisplay(el);
		window.onresize = function() { setGridDisplay(el); };
	}
}

/* ---- Open Grid ------------------------------------------------------------ */
function popupGrid()
{
	openElement('gridPopup', '20px');
}

function closeGrid()
{
	closeElement('gridPopup');
	closeImage();
	window.onresize = "";
}

/* ---- Open Image ----------------------------------------------------------- */
function popupImage(imageID, name, country, city, guid)
{	
	popupGuid = guid;

	var el2 = document.getElementById('bigImage');
	el2.src = '/Files/Filer/nomore/' + imageID + "_med.jpg"
	
	var el3 = document.getElementById('popupImageText');
	el3.innerHTML = "<b>" + name + "</b><br />" + city + ", " + country ;
	
	openElement('imagePopup');
}

function closeImage()
{
	closeElement('imagePopup');
	document.getElementById('bigImage').src = '/Files/Templates/NomoreView/Flash/blank.gif';
}

/* ---- Open frame ----------------------------------------------------------- */
function popupFrame(id, guid)
{	
	document.getElementById('framePopup_frame').src = 'Default.aspx?ID=' + id + '&guid=' + guid;
	openElement('framePopup');
}

function closeFrame()
{
	closeElement('framePopup');
	document.getElementById('framePopup_frame').src = '';
}

/* ---- Open upload ------------------------------------------------- */
function popupUpload()
{
	document.getElementById('framePopup_frame').src = 'Default.aspx?ID=' + uploadPageID;
	openElement('framePopup');
}


/* ---- Popup display resize ------------------------------------------------- */
function setDisplay(el, top)
{
	el.style.top = top;
	el.style.left = (document.body.scrollWidth - parseInt(el.style.width)) / 2 + 'px';
}

/* ---- Popup grid display resize ------------------------------------------------- */
function setGridDisplay(el)
{
	var myInnerWidth;
	var myInnerHeight;
	if(typeof(window.innerWidth) == 'number')
	{
		//Non-IE
		myInnerWidth = window.innerWidth;
		myInnerHeight = window.innerHeight;
	}
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
		//IE 6+ in 'standards compliant mode'
		myInnerWidth = document.documentElement.clientWidth;
		myInnerHeight = document.documentElement.clientHeight;
	}
	else if(document.body && (document.body.clientWidth || document.body.clientHeight))
	{
		//IE 4 compatible
		myInnerWidth = document.body.clientWidth;
		myInnerHeight = document.body.clientHeight;
	}
	
	popupGridHeight = (document.documentElement.clientHeight >= 320) ? document.documentElement.clientHeight - 60 : 260;
	popupGridWidth = (document.body.clientWidth >= 660) ? document.body.clientWidth - 60 : 600;
	createGridFlash();
}
