// JavaScript Document

function imagemGrande(imagem)
{
	imagemObj = document.getElementById("imagem_grande");
	imagemObj.src = imagem;
}


// BROWSER DETECT

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


// LIGHTBOX

function openLightbox(id)
{
	/*if(BrowserDetect.browser == "Safari")
	{
		pageURL = 'conteudos/jogos/' + id + '/info.html';
		title = "teste";
		w = 874;
		h = 384;
		var left = (screen.width/2)-(w/2);
		var top = (screen.height/2)-(h/2);
		var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);	  
	}
	else
	{*/
		var elemento;
		
		if(document.getElementById)
		{
			elemento = document.getElementById(id);
		}
		else if(document.all)
		{
			elemento = document.all[id];
		}
		else if(document.layers)
		{
			elemento = document.layers[id].document;
		}
		
		fireEvent(elemento,'click');
	/*}*/
}

function fireEvent(obj,evt)
{
	var fireOnThis = obj;
	
	if( document.createEvent )
	{
		var evObj = document.createEvent('MouseEvents');
		evObj.initEvent( evt, true, false );
		fireOnThis.dispatchEvent(evObj);
	}
	else if( document.createEventObject )
	{
		fireOnThis.fireEvent('on'+evt);
	}
}

function lightboxLinks()
{
	document.write('<a href="gamedetails.aspx?id=1&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="action_hero"></a>');
	document.write('<a href="gamedetails.aspx?id=2&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="alpine_racer"></a>');
	document.write('<a href="gamedetails.aspx?id=3&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="crash"></a>');
	document.write('<a href="gamedetails.aspx?id=4&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="zeebo_extreme"></a>');
	document.write('<a href="gamedetails.aspx?id=5&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="fifa_soccer"></a>');
	document.write('<a href="gamedetails.aspx?id=6&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="need_for_speed_carbon"></a>');
	document.write('<a href="gamedetails.aspx?id=7&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="pacmania"></a>');
	document.write('<a href="gamedetails.aspx?id=8&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="prey_evil"></a>');
	document.write('<a href="gamedetails.aspx?id=9&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="quake1"></a>');
	document.write('<a href="gamedetails.aspx?id=10&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="quake2"></a>');
	document.write('<a href="gamedetails.aspx?id=11&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="tekken2"></a>');
	document.write('<a href="gamedetails.aspx?id=12&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="treino_cerebral"></a>');
	document.write('<a href="gamedetails.aspx?id=13&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="ultimate_chess"></a>');
	document.write('<a href="gamedetails.aspx?id=14&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="double_dragon"></a>');
	document.write('<a href="gamedetails.aspx?id=15&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="ridge_racer"></a>');
	document.write('<a href="gamedetails.aspx?id=16&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="resident_evil4"></a>');
	document.write('<a href="gamedetails.aspx?id=17&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="zeebo_extreme_rolima"></a>');
	document.write('<a href="gamedetails.aspx?id=1&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="1"></a>');
	document.write('<a href="gamedetails.aspx?id=2&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="2"></a>');
	document.write('<a href="gamedetails.aspx?id=3&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="3"></a>');
	document.write('<a href="gamedetails.aspx?id=5&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="5"></a>');
	document.write('<a href="gamedetails.aspx?id=6&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="6"></a>');
	document.write('<a href="gamedetails.aspx?id=7&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="7"></a>');
	document.write('<a href="gamedetails.aspx?id=8&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="8"></a>');
	document.write('<a href="gamedetails.aspx?id=9&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="9"></a>');
	document.write('<a href="gamedetails.aspx?id=10&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="10"></a>');
	document.write('<a href="gamedetails.aspx?id=11&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="11"></a>');
	document.write('<a href="gamedetails.aspx?id=12&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="12"></a>');
	document.write('<a href="gamedetails.aspx?id=13&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="13"></a>');
	document.write('<a href="gamedetails.aspx?id=14&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="14"></a>');
	document.write('<a href="gamedetails.aspx?id=15&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="15"></a>');
	document.write('<a href="gamedetails.aspx?id=16&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="16"></a>');
	document.write('<a href="gamedetails.aspx?id=17&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="17"></a>');
	document.write('<a href="gamedetails.aspx?id=18&iframe=true&width=874&height=384" rel="prettyPhoto[iframes]" id="18"></a>');
}
lightboxLinks();

function getUrlVars()
{
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	 
	for(var i = 0; i < hashes.length; i++)
	{
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	
	if(vars["id"] != "" && vars["id"] != "undefined")
	{
		openLightbox(vars["id"]);
	}
}

function startLightBox()
{
	$(document).ready(
		function()
		{
		$("a[rel^='prettyPhoto']").prettyPhoto(
		{
			animationSpeed: 'normal', /* fast/slow/normal */
			padding: 0, /* padding for each side of the picture */
			opacity: 0.85, /* Value betwee 0 and 1 */
			showTitle: false, /* true/false */
			allowresize: false, /* true/false */
			counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
			theme: 'dark_square', /* light_rounded / dark_rounded / light_square / dark_square */
			callback: function(){}
		}
		);
	});
	
	
	getUrlVars();
}