﻿// gamelist 
$(function(){ 

	$('.hglist li a').click(function(){ 
		
		if($(this).parent('li').hasClass('focus')){$('._tmp').remove();$(this).parent('li').removeClass('focus');return false;}
		
		var power = $(this).attr('powerleveling');
		var account = $(this).attr('account');
		
		if (power==0&&account==0){
			return true;
		} else { 
			$('.hglist li.focus').removeClass('focus');
			$(this).parent('li').addClass('focus');
			$('._tmp').remove();
			var href = $(this).attr('href');
			var gid = $(this).attr('account');
			var PowerStr	= power==0 ? '' : '<li class="_tmp power"><a  href="/power_leveling.asp?gid='+power+'">Buy PowerLeveling</a></li>'
			var AccountStr = account==0 ? '' : '<li class="_tmp account"><a  href="/account_items.asp?gid='+account+'">Buy Account & Items</a></li>';
			$(this).parent('li').after('<li class="_tmp gold"><a href="'+href+'">Buy Gold</a></li>'+PowerStr+AccountStr);
			return false;
		}
	});  
		
})

$(function(){

	$('.hotjump').change(function(){JumpTo($(this).val())})
	
	$('#gamesel option[value='+location.pathname+']').attr('selected',true);
	
	var currentGameLink = $('.hglist li a[href='+location.pathname+']');
	if(currentGameLink.length==1){ 
		currentGameLink.addClass('current');
		if(currentGameLink.attr('powerleveling')!=0 || currentGameLink.attr('account')!=0){currentGameLink.click();}
	}

	
	// server selected
	var urlArray = location.pathname.split('/');
	var serverurl = urlArray[urlArray.length-1];
	$('#selserver option[value='+serverurl+']').attr('selected',true);

	// currency
	$('#selcurrency').change(function(){
		var seltype = $(this).val();
		var currencyCode = $(this).children('option:selected').html();
		var nowRate = $(this).children('option:selected').attr('rate');
		setCookie('currencyID',seltype);
		$('.pro_price').each(function(){
			var price = $(this).html().split(' ')[0]; 
			var beforeCode = $(this).html().split(' ')[1];
			var beforeRate = $('#selcurrency option:contains("'+beforeCode+'")').attr('rate');
			$(this).html((price*beforeRate/nowRate).toFixed(2)+" "+currencyCode);
		});
	});
	$('#selcurrency option:first').attr("selected",true);
	$('#selcurrency').attr("disabled",false);
	// change server
	
	
	$('#selserver').attr("disabled",false).change(function(){
		window.location = $(this).val();													   
	});


	$('#orderarea').show();
	var currencyID = !!parseInt(getCookie("currencyID")) ? parseInt(getCookie("currencyID")):1;
	$('input[name=moneytype]').removeAttr('checked');
	$('input[name=moneytype]:eq('+(currencyID-1)+')').attr('checked',true);
	
	if($('input[name=moneytype]')[currencyID-1]){
		$('input[name=moneytype]')[currencyID-1].checked = true;
	}
	$('#serverlist option[value='+window.location.href+']').attr('selected','selected');
	
	//$(':text,:password').focus(function(){$(this).css('backgroundColor','#FFEEFF');}).blur(function(){$(this).css('backgroundColor','white');});
	
	//$('.ibtn').hover(function(){$(this).css({'cursor':'pointer'})},function(){$(this).css({'cursor':'default'})});
	

})

// a-z 
$(function(){ 
	if($('.slist li').length>200){ 
		var list = 'A B C D E F G H I J K L M N O P Q R S T U V W X Y Z'.split(' ');
		var title = '';
		for (var i=0;i<list.length;i++) { 
			title += ' <a href="#index'+list[i]+'">'+list[i]+'</a> '
			$('.slist li a[title^="'+list[i]+'"]').first().parent().before('<div class="line"><a name="index'+list[i]+'">'+list[i]+'</a><span class="top" onclick="window.scrollTo(0,0);">^top</span></div>');
		}
		$('.slist').before('<div class="aztitle">'+title+'</div>');
	}
})

