//<![CDATA[

try {
document.domain = "kaybo.com";
} catch(e) {}

var appNum = null;
function setBrowser()
{
	var wna = window.navigator.userAgent;
	if(wna.indexOf('MSIE')!=-1){
		this.browser=0;
		appNum = eval(navigator.appVersion.substr(navigator.userAgent.indexOf("MSIE") - 3,3));
	}else if(wna.indexOf('Firefox')!=-1){
		this.browser=1;
	}else  if(wna.indexOf('Opera')!=-1){
		this.browser=2;
	}else  if(wna.indexOf('Safari')!=-1 && wna.indexOf('Chrome')!=-1){
		this.browser=3;
	}else if(wna.indexOf('Safari')!=-1){
		this.browser=4;
	}else if(document.all){//etc = 0;
		this.browser=0;
	}else{
		this.browser=null;
	}
	return this.browser;
}
var app = setBrowser();

function setPng24(pobj)
{
	pobj.width=pobj.height=1;
	pobj.className=pobj.className.replace(/\bpng24\b/i,''); 
	pobj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ pobj.src +"',sizingMethod='image');"
	pobj.src='about:blank;';
	return '';
}

//-- s: submenu
var subDelaytimes = 200;
var subDelayTimerId = null;
var subSelectedMenu = null;
var subSelParent = null;

function showhidemenu(obj)
{
	try{
		if(arguments[1])subSelParent = arguments[1];
		if(obj != undefined){
			var mnObj = document.getElementById(obj);
			subSelectedMenu = mnObj;
			mnObj.style.display = "block";
			if(subSelParent) subSelParent.className = "tabBtn1 tabBtn1Sel";
			if(subDelayTimerId) {
				clearTimeout(subDelayTimerId);
				subDelayTimerId = null;
			}
			if(mnObj.onmouseover == null){
				mnObj.onmouseover = function(){
					showhidemenu(obj);
				}
				mnObj.onmouseout = function(){
					showhidemenu();
				}
			}
		}
		else{
			subDelayTimerId = setTimeout(hidemenu, subDelaytimes);
		}
	}catch(e){
//		alert(e.description);
	}
}
function hidemenu()
{
	if(subSelectedMenu){
		subSelectedMenu.style.display = "none";
		if(subSelParent) subSelParent.className = "tabBtn1";
	}
	
}
function makeSubMenu()
{
	try {
		var obj = document.getElementById('contents');
		var dvObj = document.createElement('div');
		dvObj.setAttribute("id","gameBox");
		if(app == 0) {
			if(appNum < 8){
				dvObj.setAttribute("className","areahide");
			}
			else{
				dvObj.setAttribute("class","areahide");
			}
		}
		else {
			dvObj.setAttribute("class","areahide");
		}
		obj.appendChild(dvObj);
		var isObj = document.getElementById('gameBox');
		isObj.innerHTML = '<div class="depth2">'
						+ '<h2>Juegos submenu</h2>'
						+ '<ul class="depth3">'
						+ '<li class="smn4" id="smenu4"><a href="http://pb.kaybo.com" target="_self">PointBlank</a></li>'
						+ '<li class="smn5" id="smenu5"><a href="http://gunz.kaybo.com" target="_self">GUNZ ULTRA</a> <img src="http://file.kaybo.com/kaybo/_common/iconew1.gif" class="iconew1" alt="Nuevo" title="Nuevo" /></li>'
						+ '<li class="smn1" id="smenu1"><a href="http://crazycombiturbo.kaybo.com" target="_self">CrazyCombiTurbo</a></li>'						
						+ '<li class="smn6" id="smenu2"><a href="http://www.kaybo.com/mobilegames/gamedesc_zombie.html" target="_self">Móvil Juegos</a> <img src="http://file.kaybo.com/kaybo/_common/iconew1.gif" class="iconew1" alt="Nuevo" title="Nuevo" /></li>'
						+ '<li class="smn3" id="smenu3"><a href="http://www.kaybo.com/flashgames/gamelist.html?mode=all" target="_self">Flash Juegos</a></li>'
						+ '</ul>'
						+ '</div>';
	} catch ( e ) {
	}
}


//-- s: addEvent controller
function addEvtFnc(f,types)
{
	var evtFnc = window[types];
	if(typeof evtFnc != 'function'){
		window[types] = function(){
			try{eval(f);}
			catch(err){alert(err.description);}
		}
	}
	else{
		var setFnc = function(){eval(f);}
		window[types] = function(){
			if(evtFnc) evtFnc();
			try{setFnc();}
			catch(err){alert(err.description);}
		}
	}
}

function inputSelect()
{
	if(arguments[0].value.length > 0){
		try{
			arguments[0].select();
		}catch(e){}
	}
}

function addBookmark() {
	var title = "Kaybo";
	var uri = "http://www.kaybo.com";
	
	if (window.sidebar) { // Firefox Bookmark
		window.sidebar.addPanel(title, uri,"");
	}
	else if( window.external ) { // IE Favorite
		window.external.AddFavorite( uri, title);
	}
	else{
		return;
	}
}


//function open_win(_url,_name,_width,_height,_features) {
//	try{
//		if (_features == undefined ) {
//			_features = '';
//		}
//		var wobj = window.open(_url, _name, "width="+ _width + ",height=" + _height + _features);
//	}catch(e){
//		//alert(e.description);
//	}
//}


function open_win(_url,_name,_width,_height,_features) {
	try{
		var qStr = '';
		if(_width != undefined && _width != '') _width = 'width='+_width;
		else _width = '';
		if(_height != undefined && _height != '') {
			_height = ',height='+_height;
			qStr = ',';
		}
		else _height = '';
		if(_features != undefined && _features != '') _features = qStr + _features;
			else _features = '';
		var wobj = window.open(_url, _name, _width + _height + _features);
	}catch(e){
		//alert(e.description);
	}
}

//-- s:swf pickup
function writeSwf (obj, objId, width, height, winmode, mozid, divName, isTitle)
{
	var ewinmode, objName, pageSbj;
	
	if(isTitle != undefined) obj += "?";
	if(isTitle == 1){//auto title
		try{
			var t1 = document.getElementById('dep1txt');
			var t2 = document.getElementById('dep2txt');
			var t3 = document.getElementById('subjtxt');
			pageSbj = t3.firstChild.nodeValue;
			obj += "dep1txt="+encodeURIComponent(t1.firstChild.nodeValue)+"&dep2txt="+encodeURIComponent(t2.firstChild.nodeValue)+"&subjtxt="+encodeURIComponent(pageSbj)+"&";
			//set title
			document.getElementById(divName).attributes['title'].value = pageSbj;
		}catch(err){
			//alert(err.description);
		}		
	}

	var swfObj = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+ width + '" height="'+ height + '" id="'+ objId  + '" align="top">'
		+ '<param name="allowScriptAccess" value="always" />'
		+ '<param name="movie" value="' + obj + '" />'
		+ '<param name="menu" value="false" />'
		+ '<param name="quality" value="high" />'
		+ '<param name="allowFullScreen" value="true" />'
		+ '<param name="scale" value="noscale" />';
	if(winmode == 1){//transparent
		swfObj += '<param name="wmode" value="transparent" />';
		ewinmode = ' wmode="transparent"';
	}else if(winmode==2){//opaque
		swfObj += '<param name="wmode" value="opaque" />';
		ewinmode = ' wmode="opaque"';
	}else{ewinmode = '';}
	if(mozid){//swfObject control name for mozilla
		objName = ' name="'+objId+'"';
	}else{objName = '';}
	swfObj += '<embed src="' + obj + '" menu="false"' + ewinmode + objName + ' quality="high" scale="auto" allowfullscreen="true" bgcolor="#ffffff" width="' + width + '" height="'+ height  +'" id="' + objId + '" align="top" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" allowScriptAccess="always" swLiveConnect="true" /></object>';
	if(divName){
		//alert(swfObj);
		document.getElementById(divName).innerHTML = swfObj;
	}else{document.write (swfObj);}
}
//-- e: swf pickup

function inputSelect()
{
	if(arguments[0].value.length > 0){
		try{
			arguments[0].select();
		}catch(e){}
	}
}
//-- s: login prcs
function logCheck()
{
	var frm = arguments[0];
	var prePath = "";
	if(arguments[1]) prePath = arguments[1];
	if(frm.id.value.length == 0){
		alert('Por favor introduzca un usuario válido.      ');//id required
		frm.id.focus();
		return false;
	}
	if(frm.pw.value.length == 0){
		alert('Por favor introduzca un Contraseña.      ');//pwd required
		frm.pw.focus();
		return false;
	}
	return true;
}
var logFrm = null;
function setLogFrm(){
	logFrm = document.forms.login_form;
	if(logFrm == undefined) {
		return;
	}
	var logid = logFrm.id;
	var logpw = logFrm.pw;
	if(logid){
		if(logid.value.length == 0) logid.focus();
		logid.onfocus = function(){
			if(this.value.length == 0) this.className = "loginid";
			else this.className = "loginput1";
		}
		logid.onblur = function(){
			if(this.value.length == 0) this.className = "loginid";
			else this.className = "loginput1";
		}
		logid.onclick = logid.onkeyup = function(){
			if(this.value.length > 0) this.className = "loginput1";
			else this.className = "loginid";
		}
	}
	if(logpw){
		logpw.onfocus = function(){
			if(this.value.length == 0) this.className = "loginpw";
			inputSelect(this);
		}
		logpw.onblur = function(){
			if(this.value.length == 0) this.className = "loginpw";
			else this.className = "loginput1";
		}
		logpw.onclick = logpw.onkeyup = function(){
			if(this.value.length > 0) this.className = "loginput1";
			else this.className = "loginpw";
		}
	}
	logid.focus();
}

//-- S: tooltip Box
var tooltipObj  = { 'toolBoxArea':null, 'toolBoxText':null, 'targetObj':null, 'targetTxt':null };

function getMousePos(e) {
	try {
		var mouseX = mouseY = 0;
		var e = e || window.event;
		if (tooltipObj['toolBoxArea'] == null) {
			tooltipObj['toolBoxArea'] = document.getElementById("tooltipBox");
			tooltipObj['toolBoxText'] = document.getElementById("tooltipTxt");
		}	
		mouseX = document.all ? event.clientX + (document.body.scrollLeft == 0 ? document.documentElement.scrollLeft : document.body.scrollLeft) : e.pageX;
		mouseY = document.all ? event.clientY + (document.body.scrollTop == 0 ? document.documentElement.scrollTop : document.body.scrollTop) : e.pageY;

		if (tooltipObj['toolBoxArea'].style.display == "block") {
			tooltipObj['toolBoxArea'].style.left = (mouseX+10) + "px";
			tooltipObj['toolBoxArea'].style.top  = (mouseY+8) + "px";
		}
		
	} catch(e) {
		//alert(e.description);	
	}
}

function toolTip(obj,evt,hide) {
	try {
		if (tooltipObj['toolBoxArea'] == null) {
			tooltipObj['toolBoxArea'] = document.getElementById("tooltipBox");
			tooltipObj['toolBoxText'] = document.getElementById("tooltipTxt");
		}		
		if (hide == undefined || hide == null) {
			if (obj.title != "") {
				tooltipObj['toolBoxText'].innerHTML = obj.title;
				tooltipObj['toolBoxArea'].style.display = "block";			
				tooltipObj['targetObj'] = obj;
				tooltipObj['targetTxt'] = obj.title;
				obj.title = "";
			}
			//obj.removeAttribute("title");
		} else {
			tooltipObj['toolBoxArea'].style.display = "none";
			tooltipObj['targetObj'].setAttribute("title", tooltipObj['targetTxt']);
		}		
	} catch(e) {
		alert(e.description);	
	}
}

function setMousePos()
{
	document.onmousemove = getMousePos;
}
//-- E: tooltip Box


//-- S: img rotation
var KYBImgIdx = [];
var KYBImgSrc = [
	[
		{ type:'img', path:'go_bnr_pb.jpg', alink:'http://pb.kaybo.com/', target:'_self', sbj:'PointBlank' },
		{ type:'img', path:'go_bnr_gunz.jpg', alink:'http://gunz.kaybo.com/', target:'_self', sbj:'GUNZ ULTRA' },		
		{ type:'img', path:'go_bnr_cc3t.jpg', alink:'http://crazycombiturbo.kaybo.com/', target:'_self', sbj:'CrazyCombiTurbo' }
		
	]
];

function KYBSwapData(idx, bnridx) {
	try {
		if (KYBImgIdx[idx]['timerId'] == null) {
			KYBImgIdx[idx]['order'] = 0;
			bnridx = 0;
		} else {
			if (idx < 0) {
				KYBImgIdx[idx]['order'] = 0;
			} else {
				if ((KYBImgIdx[idx]['total']-1) > KYBImgIdx[idx]['order']) { //count
					(KYBImgIdx[idx]['order'])++;
				} else {
					KYBImgIdx[idx]['order'] = 0;
				}
			}
		}
		KYBImgIdx[idx]['obj'].src   = KYBImgIdx[idx]['path'] + KYBImgSrc[idx][KYBImgIdx[idx]['order']]['path'];
		KYBImgIdx[idx]['obj'].title = KYBImgSrc[idx][KYBImgIdx[idx]['order']]['sbj'];
		if (!KYBImgIdx[idx]['obj'].style.cursor) KYBImgIdx[idx]['obj'].style.cursor = "pointer";
		if (!KYBImgIdx[idx]['obj'].onclick) {
			KYBImgIdx[idx]['obj'].onclick = function() {
				if (KYBImgSrc[idx][KYBImgIdx[idx]['order']]['target'] == '_self') {
					window.location.href = KYBImgSrc[idx][KYBImgIdx[idx]['order']]['alink'];
				} else if (KYBImgSrc[idx][KYBImgIdx[idx]['order']]['target'] == '_blank'){
					var opw = window.open(KYBImgSrc[idx][KYBImgIdx[idx]['order']]['alink'], 'popwins');
				}
			}
		}
		if (KYBImgIdx[idx]['timerId'] == null) { //loop
			KYBImgIdx[idx]['timerId'] = setInterval("KYBSwapData("+ KYBImgIdx[idx]['idx'] +", "+ (KYBImgIdx[idx]['order'])+")", KYBImgIdx[idx]['time']);
		}
	} catch(e) {
		alert("KYBSwapData fnc : " + e.description);
	}
}

function setKYBImgAry (obj, idx, time) {
	try {
		var timeValue = 4000;
		var iObj = document.getElementById(obj);
		if (iObj != undefined) {
			var srcLen  = iObj.src.length, findIdx = iObj.src.lastIndexOf('/');
			var imgName = iObj.src.substring(findIdx+1,srcLen).length;
			var prePath = iObj.src.substring(0,srcLen-imgName);
			if (time != undefined) timeValue = time; 
			KYBImgIdx[idx] = { obj: iObj, idx: idx, order: 0, total: KYBImgSrc[idx].length, timerId: null, time: timeValue , path: prePath };
			KYBSwapData(idx);
		}
	} catch(e) {
		alert("setKYBImgAry fnc : " + e.description);
	}
}
//-- E: img rotation


function globalInit(){
	//per page
	makeSubMenu();
	setKYBImgAry('top_banner', 0);
	if((typeof pageInit) != 'undefined') pageInit();
}

try {
	addEvtFnc("globalInit()","onload");
}
catch(e){
	alert("event wrapper error : " + e.description);
}

//+20101231
function openWin( wUrl, wName, winW, winH, wFeat ) {
	try {
		var wObj = null;
		wObj = window.open( wUrl, wName, "width=" + winW + ",height=" + winH + "," + wFeat );
		if (wObj) wObj.focus();
	} catch(e) {alert(e.description);}
}

//]]>
