// JavaScript Document
var imageArray = ['home.jpg','gold.jpg','pl.jpg','item.jpg','cdk.jpg','contact.jpg','new.jpg','faq.jpg','quickbuy.jpg','login02.jpg','register.jpg','search.jpg','img01.jpg','img02.jpg','img03.jpg','img04.jpg','img05.jpg','sign_up.jpg','wow_img01.jpg','wow_img02.jpg','wow_img03.jpg','wow_img04.jpg','wow_img05.jpg','wow_gold.jpg','wow_item.jpg','wow_cdk.jpg','buy.png','tera_gold.jpg','swtor_gold_bg.jpg','swtor_pl_bg.jpg'];
$.each(imageArray,function(n,value) {  
	var strSearch = 'img[src$="/images/' + value + '"] , input:image[src$="/images/' + value + '"]';
	var img = $(strSearch);	
	if ( img.size() > 0)
	{
		var srcimg = img[0].src;
		if(srcimg.indexOf("jpg")>-1)
		{
		srcimg = value.replace(".jpg","");	
		(new Image()).src = "/images/" + srcimg + "_hover.jpg";
		img.bind("mouseover", function(){ this.src="/images/" + srcimg + "_hover.jpg"; });
		img.bind("mouseout", function(){ this.src="/images/" + srcimg + ".jpg"; });
		}
		else if(srcimg.indexOf("png")>-1)
		{
			srcimg = value.replace(".png","");	
		(new Image()).src = "/images/" + srcimg + "_hover.png";
		img.bind("mouseover", function(){ this.src="/images/" + srcimg + "_hover.png"; });
		img.bind("mouseout", function(){ this.src="/images/" + srcimg + ".png"; });
		}
		else
		{
		srcimg = value.replace(".gif","");	
		(new Image()).src = "/images/" + srcimg + "_hover.gif";
		img.bind("mouseover", function(){ this.src="/images/" + srcimg + "_hover.gif"; });
		img.bind("mouseout", function(){ this.src="/images/" + srcimg + ".gif"; });
		}
	}
});
	
$('.switcher').bind('click', function() {
	$(this).find('.coption').slideToggle('fast');
});
$('.switcher').bind('mouseleave', function() {
	$(this).find('.coption').slideUp('fast');
}); 
	

function quickbuy()
{
	if($("#selectGame").val() != 0 && $("#selectBlock").val() != 0)
	{
		window.location.href = "/fillorder/fillgoldorder/"+$("#selectServer").val()+"/"+$("#selectBlock").val()+"/42"; 
	}

}


function ajaxAddOptions(url, target, id, text){  
     target.empty();  
     $.getJSON(url, function(json){  
         $(json).each(function(i){  
             var x = json[i];  
             target.append("<option value='" + eval("x." + id) + "'>" + eval("x." + text) + "</option>" );  
         })  
     });  
}

$("#selectGame").bind('change',function()
{
	ajaxAddOptions("/quickbuy/getGameServer/" + $("#selectGame").val() , $("#selectServer"), "id", "text");
	ajaxAddOptions("/quickbuy/getGameFirstBlock/" + $("#selectGame").val()  , $("#selectBlock"), "id", "text");
});

$("#selectServer").bind('change',function()
{
	ajaxAddOptions("/quickbuy/getGameBlock/" + $("#selectGame").val() + "/" + $("#selectServer").val()  , $("#selectBlock"), "id", "text");
});
