




/************************
 * Cleans the prototype of an Object, and removes any 
 * extra methods that has been added to extend the functionality.
 * Written to deal with msn modifying javascripts Array object,
 * @param {Object} aFunction: the object to clean up.
 */
function cleanPrototype(aFunction)
{
	for(var extension in aFunction.prototype)
		delete aFunction.prototype[extension];
}
document.write("<div id=\"slideShowComponentContainer\"></div><div style=\"position:absolute;left:374px;top:1px;\"><div id=\"th1\" style=\"height:40px;\"></div><div id=\"th2\" style=\"height:40px;\"></div><div id=\"th3\" style=\"height:40px;\"></div><div id=\"th4\" style=\"height:40px;\"></div></div>");
cleanPrototype(Array);
var slides = new Array();
var slidesIndex = 0;
var slideTimer = 0;
var slideTimeout = 1000*15;
var startIndex = 0;
var numSlides = 10;
function startSlideShow(startIndex, numSlides)
{
    var url = "http://www.play22.com/flash/top_push/slides_top_push.jsp?startIndex="+startIndex+"&numSlides=" + numSlides;
    $.getJSON(url, null, function(data)
    {
    	for (var aSlide in data)
    		slides.push(data[aSlide]);
    	next();
    })
}
function next()
{
    clearInterval(slideTimer);
    loadSlide(slides[slidesIndex]);
    if (slidesIndex+1 < slides.length)
    {
        slidesIndex++;
    }
    else 
    {
        startSlideShow(startIndex+=numSlides, numSlides);
    }
    
    slideTimer = setInterval("next()",slideTimeout);
}
function loadSlide(slide)
{
  fo = new SWFObject(slide.url, "slideShowComponent", "368", "160", "9", "#000000");
  fo.addParam("scale", "noscale");
  fo.addParam("salign", "LT");
  fo.addParam("wmode", "opaque");
  fo.addParam("allowScriptAccess", "always");
  fo.addVariable("lang", slide.lang);
  for (var label in slide.translations)
  {
     fo.addVariable(label, slide.translations[label]);
  }
  if(slide.game_url)
  	fo.addVariable("game_url", slide.game_url);
  	
  fo.write("slideShowComponentContainer");  
  
  // Load the mini images of the 4 first top pushes
  if($("#th1").html() == "")
  {
	  // Show thumb icons of top pushes
	  var insertDiv = "<a href=\"javascript:forceSlide(0);\"><img src=\""+slides[0].small_url+"\"></a>";
	  $("#th1").html(insertDiv);
	 
	  insertDiv = "<a href=\"javascript:forceSlide(1);\"><img src=\""+slides[1].small_url+"\"></a>";
	  $("#th2").html(insertDiv);
	  
	  insertDiv = "<a href=\"javascript:forceSlide(2);\"><img src=\""+slides[2].small_url+"\"></a>";
	  $("#th3").html(insertDiv);
	  
	  insertDiv = "<a href=\"javascript:forceSlide(3);\"><img src=\""+slides[3].small_url+"\"></a>";
	  $("#th4").html(insertDiv);
  }
}
function onXMLError(e)
{
}

function forceSlide(nr)
{
    clearInterval(slideTimer);
    loadSlide(slides[nr]);
    if (nr+1 < slides.length)
        slidesIndex = nr+1;
    else
        slidesIndex = 0;
   
    slideTimer = setInterval("next()",slideTimeout);
}

$(function(){startSlideShow(startIndex, numSlides);});