/* 
*  Javascript for LaTale Teaser website.
*
*	uses the jQuery engine to call/change billing services looks.
*
*/
var LOGGED_IN = false; //PARAMETER FOR LOGGED STATE  - USED FOR GNB ********** GNB *********** GNB *************** JUST CHANGE THIS!!
var is9thLoginTry = false; //attempt to login for 9th time!!
var ogpTime = "Wed Oct 08 13:44:52 PDT 2008";//for debugging
var ogpTime_mil = 1225397003718;

var player = null;

function playerReady(thePlayer) 
{
	player = window.document[thePlayer.id];
	addListeners();
}

function createPlayer(name, num) 
{
	var flv = new Array 
	( 
		'http://static.ogplanet.com/static/Main_v2/swf/gamelayer/latale.flv', 
		'http://static.ogplanet.com/static/Main_v2/swf/gamelayer/latale.jpg',
		'http://static.ogplanet.com/static/Main_v2/swf/gamelayer/rf.flv',
		'http://static.ogplanet.com/static/Main_v2/swf/gamelayer/rf.jpg',
		'http://static.ogplanet.com/static/Main_v2/swf/gamelayer/cabal.flv', 
		'http://static.ogplanet.com/static/Main_v2/swf/gamelayer/cabal.jpg',
		'http://static.ogplanet.com/static/Main_v2/swf/gamelayer/a18.flv', 
		'http://static.ogplanet.com/static/Main_v2/swf/gamelayer/a18.jpg',
		'http://static.ogplanet.com/static/Main_v2/swf/gamelayer/bbt.flv',		
		'http://static.ogplanet.com/static/Main_v2/swf/gamelayer/bbt.jpg'
	)

	var flashvars = { image:flv[(num*2)+1], file:flv[num*2], autostart:"false", controlbar:"none", stretching:"fill" }
	var params = { allowfullscreen:"true", allowscriptaccess:"always", wmode:"transparent"}
	var attributes = { id:name, name:name }

	swfobject.embedSWF("http://static.ogplanet.com/static/Common/swf/player.swf", name, "233", "174", "9.0.115", false, flashvars, params, attributes);
}


$(function(){
/* ALL FUNCTIONS ARE INSIDE HERE FOR jQuery */
	/* COMMON SETTING FOR LAYER FLOAT */

	//process cookies!
	var cookieName = 'ogpid';
	var cookieValue = cookieMan(cookieName);
		//process cookie
		if (cookieValue != null){
			$('input[@name=f_remember]').attr('checked',1);
			$('input[@name=id]').val(cookieValue);		
		}
		
	//end process cookies
	
			var orig = $.fn.nyroModal.settings.showBackground;
	
			$.fn.nyroModal.settings.padding= 0;
			$.fn.nyroModal.settings.closeButton= '';
			$.fn.nyroModal.settings.closeSelector= '.modalClose';
			$.fn.nyroModal.settings.showBackground= function(elts, settings, callback){
				elts.contentWrapper.css('background',"none")
				.css('border',"none");
				orig(elts,settings,callback);
			};
			$.fn.nyroModal.settings.endFillContent = function(elts,settings){
				elts.contentWrapper.css('background',"none")
				.css('border',"none");
			};
			$.fn.nyroModal.settings.showBackground = function(elts,settings,callback){
				elts.bg.css({opacity:0.75});
				callback();
			};
			$.fn.nyroModal.settings.hideBackground = function(elts,settings,callback){
				elts.bg.css({opacity:1});
				callback();
			};
			$.fn.nyroModal.settings.showContent = function(elts, settings, callback) {
				var h = elts.loading.height();
				var w = elts.loading.width();
				elts.loading
					.css({
						height: settings.width+'px',
						width: settings.height+'px',
						marginTop: (settings.marginTop)+'px',
						marginLeft: (settings.marginLeft)+'px'
					})
					.show();
				elts.contentWrapper
					.css({
						width: settings.width+'px',
						height: settings.height+'px',
						marginTop: (settings.marginTop)+'px',
						marginLeft: (settings.marginLeft)+'px'
					})
					.show();
					elts.loading.hide();
					callback();
			};
			$.fn.nyroModal.settings.hideContent = function(elts, settings, callback) {
				elts.contentWrapper.hide(); callback();			
			};
			
	/* END COMMON SETTING */
	
	/* password setting */
	$('input:password').val('');
	
	/* clock stuff */
	$('#gnb').clock();

	/* select and then click */
	$('#sub_news_notice .listTable #gameSubject').selectLinkify();
	$('#sub_news_patches .listTable #gameSubject').selectLinkify();
	$('#sub_community_rankings .ranking_wrap .info .rightside select').selectLinkify();

	/* main decorations */
	$('.main .wrap_content').prepMain();
	
	/* Login - warning for 9th try logging in */
	$('#login9th_wrap').each(function(){
		if (is9thLoginTry){
			//float the layer!
			$(this).css('width',"400px");
			$('.login9th_trigger').nyroModal().click();//hidden <a> tag triggered.
		}
	});
	
	
	/* add to bookmark */
	$('#footer a.add_bm').addBookmark();
	
	/* deal with the quick link dropdown! */
	$('#wrap_top .quick_link').toggleShow('.quick_link_items');
	
	/* deal wtih messege balloon */
	$('p.captcha a.help').balloonToggle('#cap_help');
	
	/* In case errorBox messages need to hide after showing */
	$('div.errorBox[@rel=hideAfter]').fadeOut(3000);
	
	/* select styling */
	//1. lock select tags for profile edit page
	$('select#nameLock').styleLockSelect();
	$('select#ageLock').styleLockSelect();
	//2. orange dropdown for general use
	$('.sub select.styled').styleSelect();
	
	/* form validation/focus */
	$('input[@type=text],textarea,input[@type=password]').not('.selectLock').focus(function(){$(this).css('border-color',"#f99524");})
		.blur(function(){$(this).css('border-color',"");});
/*	$('#sub_signup form.signupForm').validateSignup();
	$('#sub_reverifyAcc form.signupForm').validateVerify();
	$('#sub_login form.login').validateLogin();
	$('#sub_signup_closeAcc #close1 form').validateCloseReason();
*/	
	$('#sub_login .login2 a.what').hoverTip('#login_tip');//show the tip
	/* video viewing button, using nyroModal */
	$('.games_wrapper').prepVideoView();

	/* community invite functionalities */
	$('#sub_myplanet_invite').inviteFunctions();
	/* community flash e-card view */
	//$('#sub_community_invite').viewInviteCard(); disabled... 
	
	/* myplanet profile page form functions */
	$('#sub_myplanet_friendProfile #profileLayout .right form.module_form').inputFormCheck();
	
	/* myplanet gamer icon modal processing */
	$('.gamer_icon').prepGamerIcon();
	$('#sub_myplanet_editmyprofile form a.editIcon').prepGamerIconModal();
	
	/* go to top function*/
	$('.gotoTop').addGoToTop();
	
	/* FAQ UI */
	$('#sub_support_faq').each(function(){
		var allList = $('li',this);
		$('li.close',this).each(function(){
			var li = $(this);
			$('p.a',this).hide();
			$('h3.q',this).click(function(e){
				e.preventDefault();
				if (li.attr('class') == "open"){li.attr('class',"close").find('p.a').slideUp('fast');}
				else{
					allList.not(li).attr('class',"close").find('p.a').slideUp('fast');
					li.attr('class',"open");
					$('p.a',li).slideDown('fast');
				}
			});
		});
	});
	
	/* HELPDESK LIST UI */
	$('#sub_support_helpdesk').each(function(){
		function TimedShow(){
			var o = this;
			this.trigger = false;
			this.callback = null;
			this.timeoutid = -1;
			function timer(){o.callback(); o.trigger = false;};
			this.causeTimeout = function(){o.timeoutid = setTimeout(timer,500);};
			this.cancelTimeout = function(){clearTimeout(o.timeoutid);};
			this.setCallback = function(func){o.callback = func;};
		};
		var timer = new TimedShow();
		$(this).find('td.subject').hover(function(){
			var floater = $(this).find('.float');
			timer.setCallback(function(){floater.show(); });
			timer.causeTimeout();
				//$(this).find('.float').show();
		},function(){
			$(this).find('.float').hide();
			timer.cancelTimeout();
		});
		$(this).find('th.status select').selectLinkify();
	});
	
	/* notice View page printing */
	$('#sub_news_notice a.printPost').click(function(e){e.preventDefault(); $.jPrintArea('#sub_news_notice .printWrap')});
	
	/* scroll for character info page */
//	$('.box_content .charmenu a').pageScroll();
	/* table coloring */
	$('#sub_support_guidelines .wrap_left table.guidelines tr').oddeven();
	
	/* forum enlarger */
//	$('.freeboard_wrap iframe').enlargeForum();
	
	/* AJAX UI for various parts of pages */
	//1. my Profile
	$('#sub_myplanet_myprofile').each(function(){
		var rCheck = $(this).ajaxIDCheck({
			idInput: $('form input[@name=userid]'),
			qURL: userCheckURL,
			msgLabel: $('#addNewBuddy label.status'),
			doButton: $('#addNewBuddy input.submit'),
			mode: "click",
			customMsgCSS:true,
			msgSend:'<label class="status"><span class="center">Checking user id...</span></label>',
			msgSuccess:'<label class="status"><span class="center"><a href="#VIEWPROFILE" rel="callback">View <b>%%ID%%</b>\'s profile</a></span></label>',
			msgFail:'<label class="status"><span class="center">There is no user of that id. Please try again.</span></label>',
			successFadeMsg: false,
			callback:function(){$('#addNewBuddy form').submit();}//run when msg's <a rel="callback" is clicked.
		});
		$('#addNewBuddy form').find('input.submit').click(function(e){
			//e.preventDefault();
		}).end()
		.submit(function(e){
			if(rCheck.isUser == 1){this.submit();}
			else{e.preventDefault();}
		});
	});
	
	$('#sub_myplanet_friendProfile').prepBuddyRequestAJAX();
	
	/* newsItem images stretch prevention */
	$('.newsItem img').each(function(){
		$(this).imgStretchPrevent();
	});
	
	/* games download - toggle system requirement */
	$('.sub_games #game_downloads').each(function(){
		$(document).click(function(e){
			if ($(e.target).parents('.sysreq').length == 0)
			{	
				if (!($(e.target).hasClass("sysreq") && $(e.target).is('div') || $(e.target).hasClass("sysreq") && $(e.target).is('a') ))
				{	$('div.sysreq').hide();	}
			}
		});
	});
	$('.sub_games #game_downloads .game_info').each(function(){
			var o = $(this);
			//o.find('div.sysreq').wrap('<div style="position:absolute; height:262px; width:500px; z-index:4;"></div>');
			var rel = o.find('a.sysreq').attr('rel');
			var on = false;
			var sysreq = o.find('.sysreq_wrap .sysreq');
			/*$(this).find('a.sysreq').toggle(function(){$('.games_wrapper .sysreqs .'+rel).show();},
				function(){$('.games_wrapper .sysreqs .'+rel).hide();});*/
				$(this).find('a.sysreq').click(function(e){
					on = (sysreq.css('display') == "block") ? true : false;
					e.preventDefault();
					if (!on){sysreq.show(); on = true;}
					else{sysreq.hide(); on = false;}
				});
			
		
	});
	
	/* javascript for special contents such as ad/banner/guide links/additional functionalities */
	$('a.showGuide').click(function(e){
		e.preventDefault();
		x = parseInt(window.screen.width) / 2 - 700/2;  // the number 175 is the exact half of the width of the pop-up and so should be changed according to the size of the pop-up
		y = parseInt(window.screen.height) / 2 - 525/2;  // the number 67 is the exact half of the height of the pop-up and so should be changed according to the size of the pop-up
		day = new Date();
		id = day.getTime();
		var cmd = "page" + id + " = window.open('"+$(this).attr('href')+"', '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,status=0,menubar=0,resizable=0,width=700,height=525,left="+x+",top="+y+"');";
		eval(cmd);
	});
	$('#game_list_small').gamelist_s();

});

$.fn.hoverTip = function(id){
	//shows the given id tip balloon.
	$(id).hover(function(){
	},function(){
		$(this).hide();
	});
	
	this.click(function(e){
		e.preventDefault();
		$(id).show();
	});
}

$.fn.clock = function(){
	function clocker(timeStr,element){//seed time, and element to put the string into.
		this.date = new Date(); 
		this.date.setTime(timeStr); 
		this.ogpTimeStr = "";
		this.el = element;
		var o = this;
		function tick(){
			o.date.setTime(o.date.getTime() + 1000);//increment one second.
			var timeOfDay = (o.date.getUTCHours() < 12) ? "AM" : "PM"; 
			var min = o.date.getUTCMinutes(); var hr = o.date.getUTCHours();
			var dayofMonth = (o.date.getUTCDate() < 10 ? "0" : "") + o.date.getUTCDate();
			min = (o.date.getUTCMinutes() < 10 ? "0" : "") + min; hr = (o.date.getUTCHours() < 10 ? "0" : "") + hr;
			var month_name=new Array(12);
				month_name[0]="JAN";
				month_name[1]="FEB";
				month_name[2]="MAR";
				month_name[3]="APR";
				month_name[4]="MAY";
				month_name[5]="JUN";
				month_name[6]="JUL";
				month_name[7]="AUG";
				month_name[8]="SEP";
				month_name[9]="OCT";
				month_name[10]="NOV";
				month_name[11]="DEC";
			var month = month_name[o.date.getUTCMonth()];
			o.ogpTimeStr = "OGP TIME " + dayofMonth + " " + month + " " + timeOfDay + " " + hr + ":" + min;
			o.el.innerHTML = o.ogpTimeStr;
			o.causeTimeout();
		}
		this.causeTimeout = function()
		{ return setTimeout(tick,1000);}
	};
	var clock = new clocker(ogpTime_mil, $('#gnb span.time').get(0));	
	clock.causeTimeout();
};

$.fn.imgStretchPrevent = function(){
	if (this.length > 0){
		if (this.width() != "0")//if background is not what is shown..
		{	
			//record width,height, url,classname
			var url = this.attr('src');	var height = this.css('height');	var width = this.css('width'); var classname = this.attr('class');
			var display = (this.css('display') != "undefined") ? this.css('display') : "block";
			
			//hide it by making with and height 0
			this.css('width','0px').css('height','0px').css('display',display.toString()).attr('class',"");
			//wrap it with div of same class, to give it same CSS look.
			this.wrap('<div class="'+classname+'"></div>')
			.css('background',"url('"+url+"') no-repeat top left")//set background to img.
			.css('padding',height+" 0 0 "+width);//show by adding padding.
		}
	}
};


$.fn.prepMain = function(){
	if (this.length > 0){
		//event actions
		var event = this.find('div.events');
		event.find('li img').each(function(){$(this).imgStretchPrevent();});
		
		var events = event.find('li').length;
		var timeoutid = -1;
		event.find('h2 a').click(function(e){
			e.preventDefault();
			var li = $(this).parent().parent();
			if (li.hasClass("over")){
				document.location.href = $(this).attr('href');
			}
			else
			{
				event.find('li').removeClass("over").find('img').hide();
					li.addClass("over").find('img').show();
					clearTimeout(timeoutid);
					event.find('li').each(function(i){if ($(this).hasClass("over")){slider.setI(i+1);}});
					timeoutid = slider.causeTimeout();
			}
		});

		function slideEvents()
		{
			this.i = -1;
			this.l = 1;
			var o = this;
			function turnon(){
				event.find('li').removeClass("over").find('img').hide();
				event.find('li').eq(this.i % this.l).addClass("over").find('img').show();
				this.i++;
				timeoutid = o.causeTimeout();
			};
			this.setI = function(index){i = index;};
			this.setLen = function(len){l = len;};
			this.causeTimeout = function()
			{	return setTimeout(turnon,5000);};
		};
		var slider = new slideEvents();
		slider.setLen(events);
		slider.setI(0);
		timeoutid = slider.causeTimeout();
		//new in game slider
		var in_game = this.find('div.new_in_game');
			//1. get starting index
		var in_games_len = in_game.find('.in_games a').length; 
		var in_game_i = Math.ceil((in_games_len) * Math.random()) - 1;  //random no. from 0~len-1
		var in_games = in_game.find('.in_games');
		in_games.find('img').eq(in_game_i).addClass('on');
		function slideInGames(f,index,len){
			this.i = index;
			this.l = len;
			this.timeoutid = -1;
			this.onFunc = f;
			this.curI = index;
			var o = this;
			function turnon(){
				o.i = o.i % (o.l);
				o.onFunc(o.i); //because o.i + + everytime.
				o.curI = o.i;
				o.i++;
				o.timeoutid = o.causeTimeout();
			};
			this.setI = function(index){o.i = (index == -1) ? o.l - 1 : index % o.l; return o.i;};
			this.setLen = function(len){l = len;};
			this.causeTimeout = function()
			{	return setTimeout(turnon, 5000);};
			this.resetTimer = function()
			{	if (o.timeoutid != -1){clearTimeout(o.timeoutid); o.timeoutid = o.causeTimeout();}};
		};
		var in_game_slide_func = function(i){in_games.find('img').removeClass('on').eq(i).addClass('on');};
		var in_game_slider = new slideInGames(in_game_slide_func, in_game_i, in_games_len);
		in_game_slider.causeTimeout();
		in_game.find('a.left').click(function(e){e.preventDefault(); 
			in_game_slider.curI = in_game_slider.setI(in_game_slider.curI - 1);
			in_game_slide_func(in_game_slider.i);
			in_game_slider.resetTimer();
		});
		in_game.find('a.right').click(function(e){e.preventDefault(); 
			in_game_slider.curI = in_game_slider.setI(in_game_slider.curI + 1);
			in_game_slide_func(in_game_slider.i);
			in_game_slider.resetTimer();
		});
		
		//end in_game slider
		
		//hot_topics actions
		var hot_topics = this.find('div.hot_topics');
		hot_topics.find('.topics_wrap .'+hot_topics.find('ul.menu li a.on').attr('rel')).show();
		var menus = hot_topics.find('ul.menu a');
		menus.click(function(e){
			e.preventDefault();
			menus.removeClass('on');
			$(this).addClass('on');
			hot_topics.find('.topics_wrap .topics').hide().end()
			.find('.topics_wrap .'+$(this).attr('rel')).show();
		});
		//logged in prettify
		var logged = this.find('div.logged');
		if ($.browser.msie && $.browser.version == "6.0")
		{//for link to game, make icon presentation possible for ie6 
			function ie6fix(logged){
			logged.find('div.selectGeneralOptions #_input_-1').css('background',"none");
			logged.find('div.selectGeneralOptions #_input_latale').css('background-position',"8px -77px");
			logged.find('div.selectGeneralOptions #_input_cabal').css('background-position',"8px -20px");
			logged.find('div.selectGeneralOptions #_input_rf').css('background-position',"8px -39px");
			logged.find('div.selectGeneralOptions #_input_bbt').css('background-position',"8px -58px");
			};
			logged.find('select.styled').styleSelect().selectLinkify({callback:ie6fix(logged)});
		}
		else
		{
			logged.find('select.styled').styleSelect().selectLinkify();	}
	
	
	}
	
};

$.fn.prepBuddyRequestAJAX = function(){
	if (this.length > 0)
	{
		function callResult(){
			this.status = -1;
		};
		var callData = new callResult();
		var query = "";
		var origEndFill = $.fn.nyroModal.settings.endFillContent;
		$.fn.nyroModal.settings.endFillContent = function(elts,settings){
			var buddyReqBu = elts.contentWrapper.find('a.sendreq_bu[@rel=buddyRequest]');
			if (buddyReqBu.length>0){
				//var requestBuddyURL = 'http://test.ogplanet.com:8080/MyPlanet/buddy.og?op=request&';
				query = requestBuddyURL + 'ruserid=' + friendUserID + '&comment='+ escape(elts.contentWrapper.find('textarea.infobox').text());
				//alert(query);
				$('textarea.infobox').val('');
				buddyReqBu.click(function(){
		//				$.getJSON(query,function(data){callData.status = data.Status;});
				});
			}
			origEndFill(elts,settings);
		};
		//prpare the transition for ajax..
				
		var origShowTrans = $.fn.nyroModal.settings.showTransition;
		$.fn.nyroModal.settings.showTransition = function(elts,settings,callback){
			//add event hooks into result modal
			var text = elts.tmp.find('p.requested');
			if (text.attr('title') != 'ajaxSet'){
				text.bind('ajaxError',function(){text.html('There is an error connecting with the server. <br/> Please try again.'); 
					callback();
				});
				text.bind('ajaxSuccess',function(){
					if (callData.status == 1){text.html('Your buddy request has been declined.<br/> You are already a buddy of this user.');}
					else if (callData.status == 2){text.html('You cannot add yourself to the buddy list.');}
					else if (callData.status == 9){text.html('You have already sent a buddy request to this user <br/> and awaiting the user to accept or decline your request.');}
					callback();
				});
				text.attr('title',"ajaxSet");
			}
			elts.loading
				.css({
					marginTop: elts.contentWrapper.css('marginTop'),
					marginLeft: elts.contentWrapper.css('marginLeft'),
					height: elts.contentWrapper.css('height'),
					width: elts.contentWrapper.css('width'),
					opacity: 0,
					background:"none"
				})
				.append('<div class="showBG"><div class="showBGtop"></div></div>')
				.show()
				.fadeTo(400, 1, function() {
						elts.contentWrapper.hide();
						$.getJSON(query,function(data){callData.status = data.Status;});
						//callback();
				});
			
		};
		
		//$.fn.nyroModal.settings.endFillContent = origEndFill;
		//$.fn.nyroModal.settings.showTransition = origShowTrans;//back to the normal operation!
	}
};


$.fn.selectLinkify = function(options){
	//in: select tag, optional variables too.
	var defaults = {
		callback: null, //runs the given function, if given. It will run this BEFORE the jump.
		attrCallback:false, //runs "rel" attribute tag as javascript code. 
		jump: true	//will jump to the site address given by 'rel' attribute.
	};
	var options = $.extend(defaults, options);
	//out: makes options become as links, and clicked.
	if (this.length > 0){
		this.change(function(){
			if (typeof(options.callback) == "function")
			{
				options.callback();//run callback.
			}
			if ($('option:selected',this).attr('rel')  && options.jump && !options.attrCallback)
			{
				window.location.assign($('option:selected',this).attr('rel'));
			}
			else if($('option:selected',this).attr('rel') && options.attrCallback)
			{
				eval($('option:selected',this).attr('rel'));
			}
		});
	}
};

$.fn.inputFormCheck = function(){
	//simple validation to check if all fields are entered.
	if (this.length > 0){
		var inputs = this.find('input, textarea');
		var inputSubmit = this.find('input.submit');
		var inputChk = true;
		var errormsg = this.find('label.error');
		this.submit(function(){
			inputChk = true;
			inputs.not('.submit').each(function(){
				inputChk = inputChk && (this.value != "");			
			});
			if (inputChk){inputSubmit.get(0).submit();}
			else {errormsg.show().text('Please enter both fields. Thank you!');}
			return false;
		});
	}
	return this;
};

$.fn.prepGamerIcon = function(){
	if (this.length > 0){
		var imgs = this.find('.icons img');
		var myimg = $('img.iconimg');
		var close = this.find('a.modalClose');
		imgs.hover(function(){$(this).attr('class',"hover");},
					function(){
						if ($('input[@name=UserIconType]').val() != $(this).attr('rel'))
						{$(this).attr('class',"");}
					})
		.click(function(){
			$('input[@name=UserIconType]').val($(this).attr('rel'));
			$('img.iconimg').attr('rel',$(this).attr('rel'));
			$(this).css('border-color',"");
			imgs.attr('class',"");
			myimg.attr('src',$(this).attr('src'));
			close.click();
			$('div.styleSelectWrap').css('z-index',0);
		})
		.mousedown(function(){$(this).css('border-color',"red");});
		
	}
	return this;
};
$.fn.prepGamerIconModal = function(){
	if (this.length > 0){
		var value = $('img.iconimg').attr('rel');
		$('.gamer_icon img[@rel='+value+']').attr('class',"hover");//initialization
		this.click(function(e){e.preventDefault();
			$('div.styleSelectWrap').css('z-index',-1);
			var value = $('img.iconimg').attr('rel');
			$('.gamer_icon img[@rel='+value+']').attr('class',"hover");//initialization
		})
		.nyroModal();
		
	}
	return this;
};

$.fn.styleSelect = function(options){
	var defaults = {
		callback: null //runs the given function, if given. It will run this BEFORE the jump.
	};
	var options = $.extend(defaults, options);
	if (this.length > 0){
		var z = 99;
		this.each(function(){
			$(this).wrap('<div class="styleSelectWrap"></div>');
			var wrap = $(this).parent();
			$(this).selectbox({
				inputClass:'selectGeneral',
				containerClass:'selectGeneralOptions',
				hoverClass:'optionCur'
			});
			var styled = $(this).prev().prev();
			var options = $(this).prev();
			wrap.css('z-index',z);
			options.css('z-index',z);
			z--;
			//styled.height($(this).height());
			//styled.width($(this).css('width'));
		});
		if (typeof(callback) == "function")
		{
			callback();
		}
	}
	return this;
};

$.fn.styleLockSelect = function(){
	if (this.length > 0){
	//used with the special DIVs to emulate select operation
	this.selectbox({
			inputClass:'selectLock',
			containerClass:'selectLockOptions',
			hoverClass:'optionCurLock'
	});
	var styled = this.prev().prev();
	var option = this.prev().find('li');
	//initial input styling
	if (styled.val() == 'show')
	{ styled.css('background-position',"");}
	else
	{styled.css('background-position',"-31px top");}
	//initial option image changing
	option.each(function(){
			if ($(this).text() == 'show')
				{$(this).css('background-position',"3px -17px");}
	});
	
	//change input image if option clicked
	option.click(function(){
		if ($(this).text() == 'show')
			{ styled.val($(this).text()).css('background-position',"");}
		else
		{styled.val($(this).text()).css('background-position',"-31px top");}
	});
	}
	return this;
};

$.fn.inviteFunctions = function(){
	//functions that make the page work
	if (this.length > 0){
	var o = this;
	var done = false;
	
	/* initialization: if not already declared outside!*/
	var startCard = parseInt($('#startCard').text());//first one in holiday card !!!!! **** SET THIS ONE!!!! CORRECTLY!
	
	/* click a thumbnail skin image, it changes the image, stores the image value */
	if (this.find('.message_skins_wrap').length > 0){
		this.find('.message_skins_wrap').cycle({ 
				fx:     'fade',
				//easing: 'easeOutQuart',
				timeout: 0,
				pager: '.skin_wrap',
				speed:300,
				startingSlide:startCard
			});
	}
	
	//at this point .skin_wrap is populated with links that flip the images. Now we must categorize them into 'holiday' and 'game'.
	//easiest way would be to append divs, put the images in accordingly, and use <a>tags to operate.
	var skinField = o.find('input[@name=skinNo]');//field which stores what card was selected
	var nav = o.find('.skin_wrap a');//all links that flip images

	nav.click(function(){
		skinField.get(0).value = o.find('.message_skins_wrap .card').eq(Number($(this).text())-1).attr('rel').split(',')[0];//store selected card info to field
	});

	this.find('.message_skins_wrap .card').each(function(i){
		//sort out and categorize
		if ($(this).attr('rel').indexOf("holiday") == -1){
			nav.eq(i).attr('class',"skin").attr('rel',"game").css('background-image',"url("+(this.src).replace('.jpg',"_t.gif")+")");//add .skin class and therefore display
		}else if($(this).attr('rel').indexOf("holiday") != -1){
			var url = $(this).attr('rel').split(',')[1];
			nav.eq(i).attr('class',"skin").attr('rel',"holiday").css('background-image',"url("+url.replace('.jpg',"_t.gif")+")");
		}
	});
	
	//skinField.get(0).value = "holiday_a181"; // Added by Jonghyun Han

	//now group 'game' links into a div
	
	o.find('.skin_wrap').append('<div class="game"></div>');
	o.find('.skin_wrap').append('<div class="holiday"></div>');
	nav.filter('[@rel=game]').appendTo(o.find('.skin_wrap .game'))
	   .end()
	   .filter('[@rel=holiday]').appendTo(o.find('.skin_wrap .holiday'));
	
	var icon_game = o.find('.skin_wrap .game');
	var icon_holiday = o.find('.skin_wrap .holiday');
		
	//make 'holiday' menu show only if there are .card with rel=holiday*
	var existsHoliday = this.find('.message_skins_wrap .card[@rel*=holiday]').length > 0; 
	if (existsHoliday){o.find('.skin_cat a[@rel=holiday],.skin_cat span.space').show(); o.find('.skin_cat a[@rel=holiday]').addClass('sel');}
	else {o.find('.skin_cat a[@rel=game]').addClass('sel');}
	o.find('.skin_cat a[@rel=game]').show();
	//make the groups show/hide by the link in .skin_cat
	o.find('.skin_cat a').click(function(e){
		//if this link has class .sel, it's selected, so disable its click event
		e.preventDefault();
		if (!$(this).hasClass('sel')){
		  icon_game.hide();	icon_holiday.hide();
		  o.find('.skin_wrap .'+$(this).attr('rel')).show();
		  $(this).siblings().removeClass('sel').end().addClass('sel');
		}
	});
	
	
	//add clear class for landing floating divs
	o.find('.skin_wrap').append('<div class="clear"></div>');
	
	/* initialization:*/ 
	
	if (skinField.length > 0){ skinField.get(0).value = o.find('.message_skins_wrap .card').eq(startCard).attr('rel').split(',')[0];}//since first one already shows
	nav.eq(startCard).addClass("activeSlide");//show first one as selected
	//then hide game.
	if(existsHoliday){icon_game.hide();}
	else{icon_holiday.hide();}
	
	/* click more friends, load 3 more input fields. stop there! */
	var addFriendsStr = 	'<div class="friend"><input name="friend_name5" id="friend_name5" type="text" value="Name" class="input_left"/><input type="text" name="friend_email5" id="friend_email5" value="E-mail"/></div><div class="friend"><input name="friend_name6" id="friend_name6" type="text" value="Name" class="input_left"/><input type="text" name="friend_email6" id="friend_email6" value="E-mail"/></div><div class="friend"><input name="friend_name7" id="friend_name7" type="text" value="Name" class="input_left"/><input type="text" name="friend_email7" id="friend_email7" value="E-mail"/></div>';
	addFriendsStr = addFriendsStr +	'<div class="friend"><input name="friend_name8" id="friend_name8" type="text" value="Name" class="input_left"/><input type="text" name="friend_email8" id="friend_email8" value="E-mail"/></div><div class="friend"><input name="friend_name9" id="friend_name9" type="text" value="Name" class="input_left"/><input type="text" name="friend_email9" id="friend_email9" value="E-mail"/></div><div class="friend"><input name="friend_name10" id="friend_name10" type="text" value="Name" class="input_left"/><input type="text" name="friend_email10" id="friend_email10" value="E-mail"/></div>';
	addFriendsStr = addFriendsStr + '<div style="clear:both;"></div>';
	this.find('input[@type=text]').css('color','#bbbbbb');
	var noInputColor = this.find('input[@type=text]').css('color');
	
	this.find('input[@type=text]').focus(function(){if ($(this).css('color')== noInputColor){this.value=""; $(this).css('color',"");}})
		.blur(function(){
				if (this.value == ""){
					$(this).css('color',"#bbbbbb");
					if($(this).attr('class') != 'title'){
						this.value=($(this).attr('class') == "input_left") ? 'Name' : 'E-mail';
					}else{	
						this.value='Enter Title';
					}
				}
		});
	this.find('.addFriend').click(function(e){
		e.preventDefault();
		if (!done){
			o.find('.friends').append(addFriendsStr).find('input[@type=text]').not('[@rel=noJS]').css('color','#bbbbbb')
				.focus(function(){$(this).css('border-color',"#f99524");if ($(this).css('color')== noInputColor){this.value=""; $(this).css('color',"");}})
				.blur(function(){$(this).css('border-color',"");
				if (this.value == ""){$(this).css('color',"#bbbbbb");
				this.value=($(this).attr('class') == "input_left") ? 'Name' : 'E-mail'}
				});
			done = true;
			$(this).hide();
		}
		return false;
	});
	this.find('form').submit(function(){
		//check if all fiel.ds filled
		var error = o.find('label.error');
		var fieldChk = false;
		var myFieldChk = true;
		var friendChk = true;
		var errorFriends = new Array();
		//user's name check
		o.find('input[@name=email],input[@name=name]').each(function(){myFieldChk = myFieldChk && $(this).css('color') != noInputColor;});
		o.find('div.friend').each(function(i){
			//each friend, or condition.
			friendChk = true;
			$(this).find('input[@type=text]:not(.title)').each(function(){friendChk = friendChk && $(this).css('color') != noInputColor;});
			if (!friendChk){errorFriends[i] = i;}
			else{errorFriends[i]=-1; }
			fieldChk = fieldChk || ((friendChk) ? true : false);
		});
		
		if (fieldChk && myFieldChk)
		{ 
			error.text(' '); 
			for (i = 0; i < errorFriends.length; i++)
			{
				if (errorFriends[i] != -1) {o.find('div.friend').eq(i).find('input').val("");}
			}
			this.submit();	
		}
		else{error.text('Please enter all values in a name/e-mail pair. Thanks!');}
		return false;
	});
	//function to handle printing
	
	this.find('a.print').click(function(e){e.preventDefault();
		//prepare the div to be printed, by copying info from the input from of the e-card
		var text = $('div.invite div.left textarea').val().replace(/[\n\r]/g,"<br/>");// .replace(/ /g,"&nbsp;") <-add this for preserving whitespace, but won't word-wrap
		var printDiv = $('div.printDiv');
		var image = $('.message_skins_wrap .card:visible').attr('rel').split(',')[1];
		image = (image == undefined) ? $('.message_skins_wrap .card:visible').attr('src') : image;
		
		printDiv.css('z-index',"-1000").css('position',"absolute").css('top',"-1000em").show();
		printDiv.find('p.body').html(text);
		printDiv.find('img.head').attr('src',image.replace(".jpg","_head.jpg"));
		printDiv.find('img.foot').attr('src',image.replace(".jpg","_foot.gif"));
		var height = (423+printDiv.find('p.body').height() > 700) ? 700 : 423+printDiv.find('p.body').height(); 
		printDiv.height(height);//console.debug($(window).height());
		$.jPrintArea('.printDiv');});
	}
};

$.fn.viewInviteCard = function(){//not used 
	if (this.length > 0){
		var flash = this.find('div.flash');
		var text = flash.find('div.animate p');
		function roll(text){
			text.animate({marginTop:(0-(Number(text.height()) + 10)).toString()+"px"}, text.height()*200, function(){
				$(this).css('margin-top',$(this).parent().height().toString()+"px");
				roll(text);
			});
		}
		roll(text);
		
	}
}

$.fn.prepVideoView = function(){
	if (this.size() > 0)
	{
		$.fn.nyroModal.settings.processHandler = function(settings) {
			var from = settings.from;
			if (from && from.href && $(from).text() == "MOVIE") {
				$.nyroModalSettings({
						type: 'swf',
						height: 325,
						width: 425,
						url: from.href
				});
			}
		};
	}
};

/*** validation collections ***/
$.fn.validateCloseReason = function(){
	var error = this.find('label.error');
	var validated = false;
	var get_val = function(dom){return dom.options[dom.selectedIndex].value;};
	var checkfunc = function(o){
		validated = true;
		var val = get_val(o);
		if (val == "select") {error.text('Please select a reason.'); validated = validated && false;}
		else {error.text(' '); validated = validated && true;}
	}
	this.find('select').change(function(){
		checkfunc(this);
	});
	this.submit(function(){
		checkfunc($(this).find('select').get(0));
		if (validated) {this.submit();}
		return false;
	});
	return this;
};
$.fn.validateLogin = function(){
	var id = this.find('#id');
	var pw = this.find('#pw');
	var error = this.find('label.error');
	var validated = false;
	this.find('input').not('.submit').each(function(){
			$(this).blur(function(){
				validated = true;
				if (this.value == "") {error.text('Please enter both input fields.'); validated = validated && false;}
				else {error.text(' '); validated = validated && true;}
			});
	});
	this.submit(function(){
		if (validated) {this.submit();}
		else{error.text('Please enter both input fields.');} 
		return false;
	});
	return this;
};
$.fn.validateVerify = function(){
	var id = this.find('#id');
	var pw = this.find('#pw');
	var email = this.find('#email');
	var emailre = this.find('#emailre');
	if (this.parents('#sub_reverifyAcc').length > 0){
	var v_id = new LiveValidation(id.attr('id'), {validMessage: " ", wait:200});
		v_id.add(Validate.Presence, { failureMessage:" "});
		v_id.add(Validate.Length, { minimum:4, maximum:20, wrongLengthMessage:" ", tooShortMessage:" ", tooLongMessage:" "});
		v_id.add(Validate.Format, { pattern: /^[a-z0-9\_\-]+$/i , failureMessage:" "});
	/*	v_id.add(Validate.Custom, {against: function(value, args)
				{//checking valid userid - via AJAX
					var rCheck = new ruserIDCheck();
					var rinput = args.uid;
					var queryURL = 'http://billing.ogplanet.com/checkuser.og?ruserid=';
					if ($('.ajax_status',o).length != 1){o.find(id).after('<span class="ajax_status"></span>');}//only create one.
					var statusLabel = $('.ajax_status',o);
					rCheck.set(rinput, queryURL, statusLabel);//AJAX function that handles user checking and related visual effects. returns if user or not user.
					rCheck.run();//AJAX check function runs..
					return rCheck.correct;
				},args: {uid: id.get(0).value}});*/
	var v_pw = new LiveValidation(pw.attr('id'), {validMessage: " ", wait:500});
		v_pw.add(Validate.Presence, { failureMessage:" "});
		v_pw.add(Validate.Length, { minimum:6, maximum:15, wrongLengthMessage:" ", tooShortMessage:" ", tooLongMessage:" "});
	var v_email = new LiveValidation(email.attr('id'), {validMessage: " ", wait:500});
		v_email.add(Validate.Presence, { failureMessage:""});	
		v_email.add(Validate.Email, { failureMessage:"Enter valid address, please."});
	var v_emailre = new LiveValidation(emailre.attr('id'), {validMessage: " ", wait:500});
		v_emailre.add(Validate.Presence);
		v_emailre.add(Validate.Confirmation, {match: email.attr('id')});
	}
	
};

$.fn.validateSignup = function(){
	var id = this.find('#id');
	var pw = this.find('#pw');
	var pwre = this.find('#pwre');
	var sa = this.find('#sa');
	var email = this.find('#email');
	var emailre = this.find('#emailre');
	var nameF = this.find('#nameF');
	var nameL = this.find('#nameL');
	var sq = this.find('#sq');
	var dobM = this.find('#dobM');
	var dobD = this.find('#dobD');
	var dobY = this.find('#dobY');
	var sex = this.find('input.sex');
	var country = this.find('#country');
	var agree = this.find('#agree');
	
	var o = this;
	if (this.parents('#sub_signup').length > 0){
	var v_id = new LiveValidation(id.attr('id'), {validMessage: " ", wait:200});
		v_id.add(Validate.Presence, { failureMessage:" "});
		v_id.add(Validate.Length, { minimum:4, maximum:20, wrongLengthMessage:" ", tooShortMessage:" ", tooLongMessage:" "});
		v_id.add(Validate.Format, { pattern: /^[a-z0-9\_\-]+$/i , failureMessage:" "});
	/*	v_id.add(Validate.Custom, {against: function(value, args)
				{//checking valid userid - via AJAX
					var rCheck = new ruserIDCheck();
					var rinput = args.uid;
					var queryURL = 'http://billing.ogplanet.com/checkuser.og?ruserid=';
					if ($('.ajax_status',o).length != 1){o.find(id).after('<span class="ajax_status"></span>');}//only create one.
					var statusLabel = $('.ajax_status',o);
					rCheck.set(rinput, queryURL, statusLabel);//AJAX function that handles user checking and related visual effects. returns if user or not user.
					rCheck.run();//AJAX check function runs..
					return rCheck.correct;
				},args: {uid: id.get(0).value}});*/
	var v_pw = new LiveValidation(pw.attr('id'), {validMessage: " ", wait:500});
		v_pw.add(Validate.Presence, { failureMessage:" "});
		v_pw.add(Validate.Length, { minimum:6, maximum:15, wrongLengthMessage:" ", tooShortMessage:" ", tooLongMessage:" "});
	var v_pwre = new LiveValidation(pwre.attr('id'), {validMessage: " ", wait:500});
		v_pwre.add(Validate.Presence);
		v_pwre.add(Validate.Confirmation, {match: pw.attr('id')});
	var v_sa = new LiveValidation(sa.attr('id'), {validMessage: " ", wait:500});
		v_sa.add(Validate.Presence, { failureMessage:" "});
		v_sa.add(Validate.Length, { minimum:3, maximum:20, wrongLengthMessage:" ", tooShortMessage:" ", tooLongMessage:" "});
	var v_email = new LiveValidation(email.attr('id'), {validMessage: " ", wait:500});
		v_email.add(Validate.Presence, { failureMessage:" "});	
		v_email.add(Validate.Email, { failureMessage:" "});
	var v_nameF = new LiveValidation(nameF.attr('id'), {validMessage: " ", wait:500});
		v_nameF.add(Validate.Presence, {});
	var v_nameL = new LiveValidation(nameL.attr('id'), {validMessage: " ", wait:500});
		v_nameL.add(Validate.Presence, {});
	var v_sq = new LiveValidation(sq.attr('id'), {validMessage: " ", wait:500});
		v_sq.add(Validate.Exclusion,{ within: ["select"], failureMessage:" "});
	
	var v_country = new LiveValidation(country.attr('id'), {validMessage: " ", wait:500});
		v_country.add(Validate.Exclusion,{ within: ["select"], failureMessage:" "});
	var v_agree = new LiveValidation(agree.attr('id'), {validMessage: " ", wait:500});
		v_agree.add(Validate.Acceptance,{failureMessage:" "});
		
	var checkArr = [v_id,v_pw,v_pwre,v_sa,v_email,v_nameF,v_nameL,v_sq,v_country, v_agree];

	//further checking..
	//1.radio buttons
	
	
	var radioChkFn = function(){
		var radioCheck = false;
		radioCheck = (sex.get(1).checked || sex.get(0).checked) ? true : false;
		var msg = (radioCheck) ? '<span class="LV_validation_message LV_valid"> </span>' : '<span class="LV_validation_message LV_invalid"> </span>';
		var inset = (radioCheck) ? 'LV_validation_message LV_valid' : 'LV_validation_message LV_invalid';
		($(sex.get(1), o).next().next().attr('class') == undefined) ? $(sex.get(1), o).next().after(msg) : $(sex.get(1), o).next().next().attr('class', inset);  
		return radioCheck;
	};
	 
	sex.click(function(){radioChkFn();});
	
	//2. birth dates.
	var get_val = function(dom){return dom.options[dom.selectedIndex].value;};
	var birthCheck = function(){
		var chkM = (get_val(dobM.get(0)) == "select") ? false : true;
		var chkD = (get_val(dobD.get(0)) == "select") ? false : true;
		var chkY = (get_val(dobY.get(0)) == "select") ? false : true;
		var check = chkM && chkD && chkY;
		var errmsg = (check) ? '' : "Please enter all parts.";
		var msg = (check) ? '<span class="LV_validation_message LV_valid"></span>' : '<span class="LV_validation_message LV_invalid">'+errmsg+'</span>';
		var inset = (check) ? 'LV_validation_message LV_valid' : 'LV_validation_message LV_invalid';
		(dobY.next().attr('class') == undefined) ? dobY.after(msg) : dobY.next().attr('class', inset).text(errmsg);
		return check;  
	};
	
	this.find('#dobM, #dobD, #dobY').change(function(){birthCheck();});
	
	this.submit(function(){
		a = radioChkFn();
		b = birthCheck(); 
		if (LiveValidation.massValidate(checkArr) && a && b)
		{
			this.submit();
		}
		return false;
	});
	
	}
};

/*** AJAX user id check function
function ruserIDCheck()//***** AJAX TESTING FUNCTION
{//takes rinput, queries it the queryURL, prints status in statusLabel
	this.userID = "";
	this.rinput = "";
	this.queryURL = "";
	this.statusLabel = "";
	this.isUser = 0;
	this.correct = false;
	var o = this;//did this to call and use 'o.isUser'. this will be updated as AJAX request is finished, which happens asynchronously but will be updated as o.isUser is calling by REFERENCE! ^^
	this.set = function(rinput,queryURL, statusLabel)
	{//sets the object variables.
		o.userID = rinput.attr('value');
		o.rinput = rinput;
		o.queryURL = queryURL;
		o.statusLabel = statusLabel;
		//o.isUser = 0;
	};
	this.run = function()//just runs the AJAX request again.
	{
		o.userID = o.rinput.attr('value');
		o.isUser = 0;
		//when input gets blurred,
		//1. show the message "Checking user id ..."
		if (o.userID != undefined)
		{
			var query = o.queryURL+o.userID;
			o.rinput.bind("ajaxSend", function(){
			//2. do an AJAX call the to the server for user check. - if only it's a new user.
				o.statusLabel.css('font-weight',"normal").css('font-size',"1em").text("Checking user id ..").css('color',"red");})
			.bind("ajaxSuccess",function(){
				if (o.isUser == 1)
			//3. if correct user, say correct
				{o.statusLabel.text("Entered a valid user ID.").css('font-weight',"normal").css('font-size',"1em").sleep(700,function(){o.statusLabel.text("");});
					o.rinput.attr('value',o.userID).css('color',"black");
					o.correct = true;}
				else if (o.isUser == 0)
			//4. if incorrect user, say "Incorrect user ID. Try again."
				{	o.statusLabel.css('font-weight',"bold").css('font-size',"2em").text("User ID NOT CORRECT!");
						o.rinput.attr('value',o.userID).css('color',"red").focus();}
				
			});
			$.getJSON(query, function(data){o.isUser = data.IsUser;});
		}
	};
}***/
// END AJAX function
/*** END validations ***/


jQuery.fn.toggleShow = function(showDiv){
	var sd = this.find(showDiv);
	var shown = false;
	var sdover = false;
	this.find('.quick_link_bu').click(function(e){
		e.preventDefault();
		if (shown) {sd.slideUp("fast"); shown=false;}
		else {
			sd.slideDown("fast");
			shown = true;}
	});
	this.hover(function(){},function(){
		if (shown )
		{
			shown = false;
			sd.slideUp("fast");
		}
		return this;
	});
	sd.hover(function(){},function(){
		if (shown )
		{
			shown = false;
			sd.slideUp("fast");
		}
		return this;
	});
	
};

jQuery.fn.balloonToggle = function(showDiv){
	var sd = $(showDiv);
	this.click(function(e){
		e.preventDefault();
		sd.show();
	});
	sd.click(function(e){
		e.preventDefault();
		sd.hide();
	});
};

jQuery.fn.addBookmark = function(){
	this.click(function(e){
		e.preventDefault();
		 var title = "OGPlanet - It's Your World - Online Games Portal"; 
		
		 var url = "http://www.ogplanet.com";
		
			if (window.sidebar) { // Mozilla Firefox Bookmark
				window.sidebar.addPanel(title, url,"");
			} else if( window.external ) { // IE Favorite
				window.external.AddFavorite( url, title); }
			else if(window.opera && window.print) { // Opera Hotlist
				return true; }
		 
	});
};

jQuery.fn.enlargeForum = function(){
	// enlarges the forum window by making it absolute.
	if (this.length != 0){
		//changing css
		var height = this.height();
		this.css('height',"30px");
		var width = this.width();
		this.css('position',"absolute");
		this.css('top',"300px");
		this.css('left',"50%");
		this.css('margin-left',"-220px");
		this.css('z-index',"99");
		//animating to enlarge forum
		this.animate({width:"900px", marginLeft:"-433px", height:height, top:"200px"},"slow");
		//adding close button
		var closePos = 'top: 188px; left:50%; margin-left:468px;'
		var close = '<a id="closeForum" href="#" style="display:block; position:absolute; '+closePos+' background:url(http://static.ogplanet.com/static/Latale/images/forum/close.gif) no-repeat; width:12px; height:12px;"></a>';
		this.parent().prepend(close);
		//when clicking this button, close css and bring to what it was before
		var forumIframe = this
		this.parent().find('#closeForum').click(function(e){
			e.preventDefault();
			//return the forum window to how it was before
			forumIframe.css('height',height);
			forumIframe.css('position',"");
			forumIframe.css('top',"");
			forumIframe.css('left',"");
			forumIframe.css('margin-left',"");
			forumIframe.css('z-index',"");
			forumIframe.css('width',"");
			$(this).remove();//remove close button.
		});
	}
	return this;
};
jQuery.fn.oddeven = function(){
	//adds odd,even class to tr's. for table row coloring/background selection.
	this.each(function(i){
		if (i % 2 == 1) {$(this).attr('class',"even"); }
		else {$(this).attr('class',"odd");}
	});
	return this;
};

jQuery.fn.pageScroll = function(){
	//handles animated scrolling to anchor locations.
	this.click(function(e){
		e.preventDefault();
		$.scrollTo($(this).attr('href'), 700, {easing:"easeOutQuart"});
	});
	return this;
};

jQuery.fn.addGoToTop = function(){
	if (this.css('top') != undefined)
	{
		var menuYloc = parseInt(this.css('top').substring(0,this.css('top').indexOf("px")));
		var el = this;
		this.click(function(e){
			e.preventDefault();
			$('html,body').animate({scrollTop:0},{duration:500, easing: "easeOutCirc"});
			
		});

	}
	return this;
};

var check = cookieMan('close_aday') == null ? false : true;

//open_gl for game_list_layer

var flag_div = false;
var flag_div_mouseover = false;
var timerID1 = null;

function open_gl(game_num) {
	clearTimeout(timerID1);
	if(game_num == 5){
		timerID1 = setTimeout('open_gl_op(' + game_num + ')', 0)
	}else{
		$('.game_list_layer').hide();
		timerID1 = setTimeout('open_gl_op(' + game_num + ')', 500)
	}
};
var id_num = 1;
function open_gl_op(game_num){

	if(check == true) return; 
	$('.close_aday').click(function(e){
		cookieMan('close_aday', 'close_true', { expires: 1, secure: false });//var close_aday_cookie does not get passed outside this function
		$('.game_list_layer').hide();
		check = true;
		
	});

	if (cookieMan('close_aday') != 'close_true')//no you have to get the value from the cookieMan('close_aday')
	{
		
		$(function(){
			id_num = game_num;
			var glayer = $('.game_list_layer');
			var peak = $('.game_list_layer .top_peak');
			var glayer_00 = $('.ogp_glmovie_loader_00');
			var glayer_01 = $('.ogp_glmovie_loader_01');
			var glayer_02 = $('.ogp_glmovie_loader_02');
			var glayer_04 = $('.ogp_glmovie_loader_04');
			var title = glayer.find('.game_layer_title_01');
			var title_00 = ('<img id="game_layer_title_img" src="http://static.ogplanet.com/static/Main_v2/images/main/game_layer/game_layer_title_01.jpg" /><span>(Genre : MMORPG)</span>');
			var title_01 = ('<img id="game_layer_title_img" src="http://static.ogplanet.com/static/Main_v2/images/main/game_layer/game_layer_title_02.jpg" /><span>(Genre : ACTION)</span>');
			var title_02 = ('<img id="game_layer_title_img" src="http://static.ogplanet.com/static/Main_v2/images/main/game_layer/game_layer_title_03.jpg" /><span>(Genre : MMORPG)</span>');
			var title_04 = ('<img id="game_layer_title_img" src="http://static.ogplanet.com/static/Main_v2/images/main/game_layer/game_layer_title_05.jpg" /><span>(Genre : STRATEGY)</span>');
			var contents = glayer.find('.game_layer_contents_01');
			var contents_00 = ('La Tale beautifully illustrates the greatest story of them all: Yours. Journey across strange and beautiful lands that combine swords, sorcery, science, art, music, and much more!');
			var contents_01 = ('Rumble Fighter offers fast-paced beat-em- up action with players from all over. Create your own unique character, equip them with sacred martial arts scrolls and powerful ExoCores, and jump into the fight.');
			var contents_02 = ('Master a wide range of skills and spectacularly animated battle moves while exploring the beautifully-rendered world of Nevareth. Challenge other players with an expanded PvP and Nation War system.');
			var contents_04 = ('Make friends, and then blow them up!Command your cartoony tank and shoot it out with others. in this whimsical turn-based strategy shooter.');
			var scr_01 = glayer.find('.scr_list_01');
			var scr_01_00 = ('<a href="http://latale.ogplanet.com/download.og?op=gallery"><img class="game_layer_title" src="http://static.ogplanet.com/static/Main_v2/images/main/game_layer/scr_01_01.jpg" /></a>');
			var scr_01_01 = ('<a href="http://rf.ogplanet.com/downloads/screenshots.asp"><img class="game_layer_title" src="http://static.ogplanet.com/static/Main_v2/images/main/game_layer/scr_02_01.jpg" /></a>');
			var scr_01_02 = ('<a href="http://cabal.ogplanet.com/community.og?op=screenshot"><img class="game_layer_title" src="http://static.ogplanet.com/static/Main_v2/images/main/game_layer/scr_03_01.jpg" /></a>');
			var scr_01_04 = ('<a href="http://bbt.ogplanet.com/downloads.og?op=screenshot"><img class="game_layer_title" src="http://static.ogplanet.com/static/Main_v2/images/main/game_layer/scr_05_01.jpg" /></a>');
			var scr_02 = glayer.find('.scr_list_02');
			var scr_02_00 = ('<a href="http://latale.ogplanet.com/download.og?op=gallery"><img class="game_layer_title" src="http://static.ogplanet.com/static/Main_v2/images/main/game_layer/scr_01_02.jpg" /></a>');
			var scr_02_01 = ('<a href="http://rf.ogplanet.com/downloads/screenshots.asp"><img class="game_layer_title" src="http://static.ogplanet.com/static/Main_v2/images/main/game_layer/scr_02_02.jpg" /></a>');
			var scr_02_02 = ('<a href="http://cabal.ogplanet.com/community.og?op=screenshot"><img class="game_layer_title" src="http://static.ogplanet.com/static/Main_v2/images/main/game_layer/scr_03_02.jpg" /></a>');
			var scr_02_04 = ('<a href="http://bbt.ogplanet.com/downloads.og?op=screenshot"><img class="game_layer_title" src="http://static.ogplanet.com/static/Main_v2/images/main/game_layer/scr_05_02.jpg" /></a>');
			var global = glayer.find('.global');
			var coming_game = ('Coming soon');
			var canada_game = ('Region : USA and Canada Only');
			var none = ('');
			var game_list_scr = glayer.find('.game_list_scr');
			var game_list_scr_01 = ('<img src="http://static.ogplanet.com/static/Main_v2/images/main/game_layer/scr_01.jpg" />');
			var game_list_scr_02 = ('<img src="http://static.ogplanet.com/static/Main_v2/images/main/game_layer/scr_02.jpg" />');
			var game_list_scr_03 = ('<img src="http://static.ogplanet.com/static/Main_v2/images/main/game_layer/scr_03.jpg" />');
			var game_list_scr_05 = ('<img src="http://static.ogplanet.com/static/Main_v2/images/main/game_layer/scr_05.jpg" />');

			if( game_num != 5)
			{
				$(glayer).show();
			}

			$('.game_list_layer').mouseover(function(){
				flag_div_mouseover = true;
			});
			$('.game_list_layer').mouseout(function(){
				flag_div_mouseover = false;
			});


			switch(id_num) {
				case 0 :
					flag_div = true;
					glayer.css('margin-left', "-396px").css('margin-top', "0");
					peak.css('background-position', "28px 0");
					title.html(title_00);
					contents.html(contents_00);
					scr_01.html(scr_01_00);
					scr_02.html(scr_02_00);
					global.html(none);
					$('.close_aday').css('padding-top', "22px");
					game_list_scr.html(game_list_scr_01);
					createPlayer('ogp_glmovie_loader', 0);
					return;
				case 1 :
					flag_div = true;
					glayer.css('margin-left', "-334px").css('margin-top', "0");
					peak.css('background-position', "117px 0");
					title.html(title_01);
					contents.html(contents_01);
					scr_01.html(scr_01_01);
					scr_02.html(scr_02_01);
					global.html(canada_game);
					$('.close_aday').css('padding-top', "2px");
					game_list_scr.html(game_list_scr_02);
					createPlayer('ogp_glmovie_loader', 1);
					return;
				case 2 :
					flag_div = true;
					glayer.css('margin-left', "-298px").css('margin-top', "0");
					peak.css('background-position', "236px 0");
					title.html(title_02);
					contents.html(contents_02);
					scr_01.html(scr_01_02);
					scr_02.html(scr_02_02);
					global.html(canada_game);
					$('.close_aday').css('padding-top', "2px");
					game_list_scr.html(game_list_scr_03);
					createPlayer('ogp_glmovie_loader', 2);
					return;
				case 4 :
					flag_div = true;
					glayer.css('margin-left', "-290px").css('margin-top', "0");
					peak.css('background-position', "382px 0");
					title.html(title_04);
					contents.html(contents_04);
					scr_01.html(scr_01_04);
					scr_02.html(scr_02_04);
					global.html(coming_game);
					$('.close_aday').css('padding-top', "13px");
					game_list_scr.html(game_list_scr_05);
					createPlayer('ogp_glmovie_loader', 4);
					return;
				case 5 :
					if(flag_div == true)
					{
						if(flag_div_mouseover == false){
							$('.game_list_layer').hide();
							clearTimeout(timerID1);
						}
					}
					break;
			}
		});
	}

};
var checking_play = 0;
$(function(){//#game_list_layer_close
	$('#game_list_layer_close').click(function(e){
		e.preventDefault();
		$('.game_list_layer').hide();
		player.sendEvent('STOP')
	});
	$('.game_list_scr').click(function(e){
		e.preventDefault();
		$(this).hide();
		player.sendEvent('PLAY')
		checking_play = 1;
		
	});
	$('.game_list_layer').mouseover(function(){
		flag_div_mouseover = true;
		$(this).show();
	});
	$('#super_container').mouseover(function(){
		$('.game_list_layer').hide();
		if (checking_play == 1){
			player.sendEvent('STOP');
		}
	});
}); 

$.fn.gamelist_s = function(){
	$('#game_list_small').mouseover(function(){
		$('#game_list_small_div').show();
	});
	$('#game_list_small').mouseout(function(){
		$('#game_list_small_div').hide();
	});
	$('#game_list_small_div').mouseover(function(){
		$(this).show();
	});
	$('#game_list_small_div').mouseout(function(){
		$(this).hide();
	});

	$("#game_list_small_div div").each(function(){
		var gamelist_s = $(this).attr('class');
		$(this).hover(
			function () {
				$(this).attr('class',gamelist_s.replace('_off','_on'));
			}, 
			function () {
				$(this).attr('class',gamelist_s.replace('_on','_off'));
			}
		);
	})
}
