﻿$(document).ready(function(){
    show = show.replace("&amp;","&").replace("'","&#39;");
    $.ajax(
    {
        type: "POST",
	    url: "/services/relatedcontent.asmx/RelatedGames",
	    beforeSend: function(xhr) {                            
	        xhr.setRequestHeader("Content-type", "application/json; charset=utf-8");
	    },
	    data: "{'show':'"+ show +"','genre':'"+ genre +"'}",
	    contentType: "application/json; charset=utf-8",
	    dataType: "json",
	    success: function(json)
        {  
            var gameData = json.d;
            if(gameData.length>0) {
		        $('#list-related-games').html('');
		        $('#related-games').show();
                for(var i=0; i<=2; i++) {
                    var thisGame = gameData[i];
                    var elm = '<a href="'+thisGame.Url+'" title="Play '+ thisGame.Show +' - '+ thisGame.Name +'">';
                    elm += '<span class="list-img">';
                    elm += '<img src="'+ thisGame.Thumb +'" alt="'+ thisGame.Name +'" />';
                    elm += '</span>';
                    elm += '<span class="list-show">'+ thisGame.Show +'</span>';
                    elm += '<span class="list-title">'+ thisGame.Name +'</span>';
                    elm += '</a>';                    
                    $('#list-related-games').append(elm);
                }
                if(ie7)
                {
                    $('#related-games a').unbind().click(function(){
                        window.location=$(this).attr('href'); 
                    });
                }
            }
        },
        error: function(){
            if($('#oldRelatedGames').html()==null) errorHandler('#related-games');
            else errorHandler('#oldRelatedGames'); 
       }
    });
});
