//----------------------------------------------------------------------------------------------------
// Constants
//----------------------------------------------------------------------------------------------------
var downfeatureDiv = null;
var downInfoDiv = null;
var DivContent = null;
var selectedGameId = new Array();
var iFirstVisibleItemIndex = 1;
var iLastVisibleItemIndex  = 0;
var itemsTotal = 0;
var iSelectedItemIndex = 1;
var iCurrentSelectedItem = 1;
var feedURL;
var NavUp = null;
var NavDn = null;
var PreItemBtn = null;
var NextItemBtn = null;
var DetailImage = null;
var DetailTitle = null;
var DetailDescription = null;
var playBtnImg = null;
var playBtn = null;
var playBtnImgRight = null;
var tryBtnImgRight = null;
var infoBtnImg = null;
var infoBtn = null;
var tryBtnImg = null;
var tryBtn = null;
var buyBtnImg = null;
var buyBtn = null;
var SelectedBgImage = "url('images/gamethumb-on.png')"
var MaxImageLength = 74;
var _slideshowTimeout = null;
var SLIDESHOW_TIMEOUT = 5000;
var insearchsession = false;
var selectedGameExist = false;
var scrollbase = null;
var scrollbar = null;
var scrollbarTop = 0;
var scrollbarHeight = 0;

var Drag = {
  obj : null,
  init : function(o, minY, maxY)
  {
	o.onmousedown  = Drag.start;
	o.root = o;
	o.minY  = minY;
	o.maxY  = maxY;
	o.root.onDragStart  = new Function();
	o.root.onDragEnd  = new Function();
	o.root.onDrag  = new Function();
  },

  start : function(e)
  {
    var o = Drag.obj = this;
    e = Drag.fixE(e);
    var y = parseInt(o.root.style.top);
    o.root.onDragStart(y);

    o.lastMouseY  = e.clientY;
	if (o.minY != null)  o.minMouseY  = e.clientY - y + o.minY;
	if (o.maxY != null)  o.maxMouseY  = o.minMouseY + o.maxY - o.minY;
   
    document.onmousemove  = Drag.drag;
    document.onmouseup  = Drag.end;

    return false;
  },

  drag : function(e)
  {
    e = Drag.fixE(e);
    var o = Drag.obj;
    var ey  = e.clientY;
    var y = parseInt(o.root.style.top);
    var nx, ny;

    if (o.minY != null) ey = Math.max(ey, o.minMouseY);
    if (o.maxY != null) ey = Math.min(ey, o.maxMouseY);

    ny = y + (ey - o.lastMouseY);
    Drag.obj.root.style.top  = ny + "px";
	
    Drag.obj.lastMouseY  = ey;
	scrollbarTop = ny;
    Drag.obj.root.onDrag(ny);
    return false;
  },

  end : function()
  {
    document.onmousemove = null;
    document.onmouseup   = null;
    Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style,top));
    Drag.obj = null;
  },

  fixE : function(e)
  {
    if (typeof e == 'undefined') e = window.event;
    if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
    return e;
  }
};
//----------------------------------------------------------------------------------------------------
// Loading games list
//----------------------------------------------------------------------------------------------------
function Initialize(total, url, firstRun, isSearch, latestPlayed) 
{	
	insearchsession = isSearch;
	feedURL = url;
	downfeatureDiv = document.getElementById('downfeature_div');
	downfeatureDiv.style.display = "block";
	
	downInfoDiv = document.getElementById('downInfo_div');
	downInfoDiv.style.display = "none";
	
	scrollbase = document.getElementById("scrollbase");
	scrollbar = document.getElementById("scrollbar");
	scrollbase.style.display ="none";
	scrollbar.style.display ="none";
	
	DivContent = document.getElementById('gamelisting');
	DivContent.scrollTop = 0;
	DetailImage = document.getElementById("game-detail-image");
	DetailImage.style.visibility="hidden";
	
	NavUp = document.getElementById('scrolltop-img');
    NavDn = document.getElementById('scrollbtm-img');
	
    DetailTitle = document.getElementById("game-detail-title");
    DetailTitle.style.visibility="hidden";
    
    DetailDescription = document.getElementById("game-detail-description");
    DetailDescription.style.visibility="hidden";
    
    playBtnImg = document.getElementById("playBtnImg");
	playBtn = document.getElementById("playBtn");
	playBtnImgRight = document.getElementById("playBtnImgRight");
	playBtnImg.style.display = "none";
	playBtn.style.display = "none";
	playBtnImgRight.style.display = "none";
	
	infoBtnImg = document.getElementById("infoBtnImg");
	infoBtn = document.getElementById("infoBtn");
	infoBtnImg.style.display = "none";
	//infoBtn.innerHTML = "Info";
	infoBtn.style.display = "none";
	
	// infoBtnImg.onclick = function(evt){
		// showInfoDiv();
		// //changeDownDiv();
	// }
	
	// infoBtn.onclick = function(evt){
		// showInfoDiv();
		// //changeDownDiv();
	// }
	
	tryBtnImg = document.getElementById("tryBtnImg");
	tryBtn = document.getElementById("tryBtn");
	tryBtnImgRight = document.getElementById("tryBtnImgRight");
	tryBtnImg.style.display = "none";
	tryBtn.style.display = "none";
	tryBtnImgRight.style.display = "none";
	
	buyBtnImg = document.getElementById("buyBtnImg");
	buyBtn = document.getElementById("buyBtn");
	buyBtnImg.style.display = "none";
	buyBtn.style.display = "none";
    
	NavUp.onclick = function(evt){
		PageUp();
	}
	
	NavUp.onmousedown = function(evt){
		if (iFirstVisibleItemIndex != 1)  
			NavUp.setAttribute("src", "images/scrollt-down.png");
	}
	
	NavUp.onmouseover = function(evt){
		if (iFirstVisibleItemIndex != 1)  
			NavUp.setAttribute("src", "images/scrollt-over.png");
	}
	
	NavUp.onmouseout = function(evt){
		AdjustPageBar();
	}
	
	NavDn.onclick = function(evt){
		PageDown();
	}
	
	NavDn.onmousedown = function(evt){
		if ((iFirstVisibleItemIndex + 9) < iLastVisibleItemIndex)  
			NavDn.setAttribute("src", "images/scrollb-down.png");
	}
	
	NavDn.onmouseover = function(evt){
		if ((iFirstVisibleItemIndex + 9) < iLastVisibleItemIndex)  
			NavDn.setAttribute("src", "images/scrollb-over.png");
	}
	
	NavDn.onmouseout = function(evt){
		AdjustPageBar();
	}
	
    PreItemBtn = document.getElementById('PreItemBtn');
    NextItemBtn = document.getElementById('NextItemBtn');
    
    PreItemBtn.onclick = function(evt){
		ScrollItem(-1); 
    }
    
    NextItemBtn.onclick = function(evt){
		ScrollItem(1); 
    }
    // For Mozilla:
    if (window.addEventListener) document.addEventListener('DOMMouseScroll', OnMouseWheel, false);

    // For IE/OPERA, etc:
    document.onmousewheel = OnMouseWheel;
    document.onkeydown = OnKeyDown;
	//
    // End: add event listeners.
    iFirstVisibleItemIndex = 1;
    iSelectedItemIndex = iFirstVisibleItemIndex;
	itemsTotal = total;
	if(total<20) 	iLastVisibleItemIndex = total;
	else if (latestPlayed == true) iLastVisibleItemIndex = total;
	else iLastVisibleItemIndex = 20;
    //var lastItemID = document.getElementById("id_last");
    //iLastVisibleItemIndex  = parseInt(lastItemID.innerHTML);
    AdjustPageBar();
	
	if(total > 0){
		displayGameDetail('1');
	
		if(firstRun){
		document.onclick = OnGlobalClick;
		_slideshowTimeout =setInterval(function() {
					ScrollItem(1); 
				}, SLIDESHOW_TIMEOUT);
		}
		
	}
};
//----------------------------------------------------------------------------------------------------
//Constants
//----------------------------------------------------------------------------------------------------
function displayGameDetail(id){
	if(itemsTotal == 0) return;

	iCurrentSelectedItem = parseInt(id);
	
	selectedGameId["id"] = 'id_div_Content_' + id;
	selectedGameId["image"] = 'id_Content_Img_' + id;
	selectedGameId["title"] = 'id_Content_title_' + id;
	selectedGameId["description"] = 'id_Content_description_' + id;
	selectedGameId["playLink"] = 'id_width_swf_' + id;
	selectedGameId["tryLink"] = 'id_Trylink_' + id;
	selectedGameId["buyLink"] = 'id_Buylink_' + id;
	selectedGameId["ExternalID"] = 'id_ExternalID_' + id;
	selectedGameId["systemRequirement"] = 'id_SystemRequirements_' + id;
	
	var srcImg = document.getElementById(selectedGameId["image"]);
	if(srcImg != null){
		DetailImage.setAttribute('src', srcImg.getAttribute('src'));
	}
	
	/*
	var originalImgDiv = document.getElementById('id_div_Img_' + id);
	var imageHeight = Number(originalImgDiv.getAttribute("height"));
	var imageWidth = Number(originalImgDiv.getAttribute("width"));
	if(imageHeight > imageWidth)
	{
		imageWidth = Math.floor((MaxImageLength*imageWidth)/imageHeight);
		imageHeight = MaxImageLength;
	}else{
		imageHeight = Math.floor((MaxImageLength*imageHeight)/imageWidth);
		imageWidth = MaxImageLength;
	}	
	DetailImage.setAttribute("width", imageWidth);
	DetailImage.setAttribute("height", imageHeight);
	*/
	DetailImage.style.visibility = "visible";
	
	var srcTitle = document.getElementById(selectedGameId["title"]);
	DetailTitle.innerHTML = srcTitle.innerHTML;
	DetailTitle.style.visibility = "visible";
	
	var srcDescription = document.getElementById(selectedGameId["description"]);
	var descriptionString = srcDescription.innerHTML;
	if(descriptionString.length > 110)
			descriptionString = descriptionString.substring(0,110) + "...";
	DetailDescription.innerHTML=descriptionString;
	DetailDescription.style.visibility = "visible";
	
	var ExternalID = document.getElementById(selectedGameId["ExternalID"]);
	var gameExist = CheckRegistry(ExternalID.innerHTML );
	
	if(gameExist){
		selectedGameExist = true;
		playBtnImg.style.display = "inline-table";
		playBtn.style.display = "inline-table";
		playBtnImgRight.style.display = "inline-table";
		infoBtnImg.style.display = "block";
		infoBtn.style.display = "block";
		tryBtnImg.style.display = "none";
		tryBtn.style.display = "none";
		tryBtnImgRight.style.display = "block";
		buyBtnImg.style.display = "block";
		buyBtn.style.display = "block";
	}
	else{
		selectedGameExist = false;
		var playLink = document.getElementById(selectedGameId["playLink"]);
		if((playLink!=null) &&(playLink.innerHTML != "")&&(playLink.innerHTML != 0)){
			playBtnImg.style.display = "inline-table";
			playBtn.style.display = "inline-table";
			playBtnImgRight.style.display = "inline-table";
		}
		else{
			playBtnImg.style.display = "none";
			playBtn.style.display = "none";
			playBtnImgRight.style.display = "none";
		}
		
		infoBtnImg.style.display = "block";
		infoBtn.style.display = "block";
		
		var tryLink = document.getElementById(selectedGameId["tryLink"]);
		if((tryLink!=null) &&(tryLink.innerHTML != "")&&(tryLink.innerHTML != 0)){
			tryBtnImg.style.display = "block";
			tryBtn.style.display = "block";
			tryBtnImgRight.style.display = "block";
		}
		else{
			tryBtnImg.style.display = "none";
			tryBtn.style.display = "none";
			tryBtnImgRight.style.display = "none";
		}
		
		var buyLink = document.getElementById(selectedGameId["buyLink"]);
		if((buyLink!=null) &&(buyLink.innerHTML != "")&&(buyLink.innerHTML != 0)){
			buyBtnImg.style.display = "block";
			buyBtn.style.display = "block";
		}
		else{
			buyBtnImg.style.display = "none";
			buyBtn.style.display = "none";
		}
	}
	
	if(iSelectedItemIndex != iCurrentSelectedItem){
		var SelectedTable = document.getElementById('id_div_Content_' + iSelectedItemIndex);
		SelectedTable.style.backgroundImage ="";
	}
	
	var CurrentTable = document.getElementById('id_div_Content_' + iCurrentSelectedItem);
	CurrentTable.style.backgroundImage = SelectedBgImage;
	iSelectedItemIndex = iCurrentSelectedItem;
	
	if(insearchsession){
		var typeid = document.getElementById('id_gameType_' + iCurrentSelectedItem).innerHTML;
		var categoryid = document.getElementById('id_categoryType_' + iCurrentSelectedItem).innerHTML;
		changeLeftMenu(typeid,categoryid);
	}
	AdjustNextBar();
}

function OnGlobalClick(e)
	{
		clearSlideshowTimeout();
	};
	
function clearSlideshowTimeout(){
		if (_slideshowTimeout != null){
			clearTimeout(_slideshowTimeout);
			_slideshowTimeout = null;
		}
};

function OnMouseWheel(e)
{
	if (!e) e = window.event;  

	var delta = 0; 
	if (e.wheelDelta) {						// IE & Opera
		delta = e.wheelDelta > 0 ? -1 : 1;
		if (window.opera) delta = -delta;	// Opera 9 and earlier, (we don't need this!)
	} else if (e.detail) { 					// FF (W3C)
		delta = e.detail < 0 ? -1 : 1;
	};
	if(downfeatureDiv.style.display == "block"){
		clearSlideshowTimeout();
		ScrollItem(delta);
	}
	else if(downInfoDiv.style.display == "block"){
		scrollinfopanel(delta);
	}
};

function OnKeyDown(e) 
{
	if (!e) e = window.event;  
	  
	var delta = 0;
	if (e.keyCode == 38) {			// UP key was pressed
		delta = -1;
	} else if (e.keyCode == 40) {	// DOWN key was pressed
		delta = 1;
	} else if (e.keyCode == 27) {	// ESC was pressed
		gamePanelClose();
		return;
	} else {
		return;						// This is not a navigation key, exiting
	};
	if(downfeatureDiv.style.display == "block"){
		clearSlideshowTimeout();
		ScrollItem(delta);
	}
	else if(downInfoDiv.style.display == "block"){
		scrollinfopanel(delta);
	}
};

function scrollinfopanel(delta){
	var infoContentDiv = document.getElementById("infoContent");
	infoContentDiv.scrollTop += 9 * delta;
	scrollbarTop +=  3 * delta;
	if(scrollbarTop<=0) scrollbarTop = 0;
	else if(scrollbarTop + scrollbarHeight >= 210) scrollbarTop = 210 - scrollbarHeight;
	scrollbar.style.top = scrollbarTop +"px";
};

function movescrollbar(e){
	var mouseY = 0;
	if(navigator.userAgent.indexOf("MSIE") != -1)
		mouseY = event.clientY + document.body.scrollTop;
	else 
		mouseY = e.pageY;
	var scrollbarY = 0;
	var oElement = scrollbar;
	while( oElement != null ) {
		scrollbarY += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	if(mouseY<scrollbarY) scrollinfopanel(-5);
	else if (mouseY > scrollbarY + scrollbarHeight) scrollinfopanel(5);
};

function ScrollItem(iDirection) 
{
	if (((iSelectedItemIndex + iDirection)>=1) && ((iSelectedItemIndex + iDirection)<=iLastVisibleItemIndex))
	{
		if((iSelectedItemIndex + iDirection) > (iFirstVisibleItemIndex + 9)){ 
			iFirstVisibleItemIndex = iFirstVisibleItemIndex + 10;
			var height = (Math.floor(iFirstVisibleItemIndex/10))*174;
			DivContent.scrollTop = height;
			if(((iFirstVisibleItemIndex + 10) >=iLastVisibleItemIndex) &&(iLastVisibleItemIndex< itemsTotal)){
					var startAt=iLastVisibleItemIndex;
					loadnewFeed(feedURL,startAt);
			};
			AdjustPageBar();
		}
		else if ((iSelectedItemIndex + iDirection) < iFirstVisibleItemIndex){ 
			iFirstVisibleItemIndex = iFirstVisibleItemIndex - 10;
			var height = (Math.floor(iFirstVisibleItemIndex/10))*174;
			DivContent.scrollTop = height;
			AdjustPageBar();
		}
		displayGameDetail(iSelectedItemIndex + iDirection);
	}
	else{
			if(_slideshowTimeout != null)
			{		
					clearTimeout(_slideshowTimeout);
					DivContent.scrollTop = 0;
					iFirstVisibleItemIndex = 1;
					displayGameDetail(1);
					_slideshowTimeout =
					setInterval(
						function() {
							ScrollItem(1); 
						}, SLIDESHOW_TIMEOUT);
					

			}else
				displayGameDetail(iSelectedItemIndex);
		}
	if(downInfoDiv.style.display == "none")
		showDownDiv();
	else
		showInfoDiv();
};

function AdjustPageBar()
{	
	if (iFirstVisibleItemIndex == 1) { 
		NavUp.setAttribute("src", "images/scrollt-disable.png");	// Top item is visible, show the top scroll control.
		NavUp.style.cursor ="default";
	} else {
		NavUp.setAttribute("src", "images/scrollt.png");// Top item is not visible, show the top scroll control.
		NavUp.style.cursor ="pointer";
	};
	
    if ((iFirstVisibleItemIndex + 9) >= iLastVisibleItemIndex ) {
		NavDn.setAttribute("src", "images/scrollb-disable.png");	// Bottom item is visible, hide the bottom scroll control. 
		NavDn.style.cursor ="default";
	} else {
		NavDn.setAttribute("src", "images/scrollb.png");	// Bottom item is not visible, show the bottom scroll control. 
		NavDn.style.cursor ="pointer";
	};
	
	if(navigator.userAgent.indexOf("MSIE") != -1)
	{
		var arVersion = navigator.appVersion.split("MSIE");
		var version = parseFloat(arVersion[1]);
		if ((version >= 5.5) && (version < 7))
			fixPngImages();
	}
};

function setLastVisiableItem(){
	if ((iLastVisibleItemIndex+10)<itemsTotal) 
		iLastVisibleItemIndex += 10;
	else 
		iLastVisibleItemIndex = itemsTotal;
		
	AdjustPageBar();
}

function AdjustNextBar()
{
	if (iSelectedItemIndex == 1) { 
		PreItemBtn.setAttribute("src", "images/btn-previous-over.png");	// Top item is visible, show the top scroll control.
		PreItemBtn.style.cursor ="default";
	} else {
		PreItemBtn.setAttribute("src", "images/btn-previous.png");// Top item is not visible, show the top scroll control.
		PreItemBtn.style.cursor ="pointer";
	};
	
    if (iSelectedItemIndex >= iLastVisibleItemIndex ) {
		NextItemBtn.setAttribute("src", "images/btn-next-over.png");	// Bottom item is visible, hide the bottom scroll control. 
		NextItemBtn.style.cursor ="default";
	} else {
		NextItemBtn.setAttribute("src", "images/btn-next.png");	// Bottom item is not visible, show the bottom scroll control. 
		NextItemBtn.style.cursor ="pointer";
	};
};

function showDownDiv(){
	//infoBtn.innerHTML = "Info";
	downInfoDiv.style.display = "none";
	downfeatureDiv.style.display = "block";
};

function changeDownDiv(){
	if(downInfoDiv.style.display == "none")
		showInfoDiv();
	else
		showDownDiv();
};

function showInfoDiv(){
	//infoBtn.innerHTML = "Back";
	downfeatureDiv.style.display = "none";
	var downInfoContent = "";
	downInfoContent += "<div><a href='#' onclick='showDownDiv(); return false;' >Back</a>&nbsp;</div><br/>";

	var srcDescription = document.getElementById(selectedGameId["description"]);
	if (srcDescription != null &&(srcDescription.innerHTML != "")&&(srcDescription.innerHTML != 0)){
		downInfoContent +="<div style='color: #77BA01;font-size: 13px;'>Game Description:</div>";
		downInfoContent +="<div>";
		downInfoContent += srcDescription.innerHTML;
		downInfoContent += "</div><br/>";
	}

	var systemRequirement = document.getElementById(selectedGameId["systemRequirement"]);
	if((systemRequirement!=null) &&(systemRequirement.innerHTML != "")&&(systemRequirement.innerHTML != 0)){
		downInfoContent +="<div style='color: #77BA01;font-size: 13px;'>System Requirement:</div>";
		var reqStr = systemRequirement.innerHTML;
		downInfoContent += "<div>";
		var lines = reqStr.split(/\r\n|\n|\r/);
		for (var i in lines) {
			downInfoContent += (lines[i].replace(/^\s|\s$/, "") + "<br/>");
		}
		downInfoContent += "</div><br/>";
	}

	var currency = document.getElementById('id_Currency_'+ iSelectedItemIndex);
	var Price = document.getElementById('id_Price_' + iSelectedItemIndex);
	if (Price) {					// Looking for the bug 6151 fix
		if(Price.innerHTML == 0)
			downInfoContent +="<div>Price: &nbsp; Free</div>";
		else{
			downInfoContent +="<div>Price: &nbsp;";
			downInfoContent +=currency.innerHTML + "$" + Price.innerHTML;
			downInfoContent +="</div>";
		}
	}
	
	var rating = document.getElementById('id_Rating_' + iSelectedItemIndex);
	if((rating!=null) &&(rating.innerHTML != "")&&(rating.innerHTML != 0)){
		downInfoContent +="<div>Rating: &nbsp;";
		downInfoContent +=rating.innerHTML;
		downInfoContent +="</div>";
	}

	var NumberOfDownloads = document.getElementById('id_NumberOfDownloads_' + iSelectedItemIndex);
	if((NumberOfDownloads!=null) &&(NumberOfDownloads.innerHTML != "")&&(NumberOfDownloads.innerHTML != 0)){
		downInfoContent +="<div>Number of Downloads: &nbsp;";
		downInfoContent +=NumberOfDownloads.innerHTML;
		downInfoContent +="</div>";
	}

	var FileSize = document.getElementById('id_FileSize_' + iSelectedItemIndex);
	if((FileSize!=null) &&(FileSize.innerHTML != "")&&(FileSize.innerHTML != 0)){
		downInfoContent +="<div>File Size: &nbsp;";
		downInfoContent +=FileSize.innerHTML;
		downInfoContent +="</div>";
	}

	var GameLanguage = document.getElementById('id_GameLanguage_' + iSelectedItemIndex);
	if((GameLanguage!=null) &&(GameLanguage.innerHTML != "")&&(GameLanguage.innerHTML != 0)){
		downInfoContent +="<div>Game Language: &nbsp;";
		downInfoContent +=GameLanguage.innerHTML;
		downInfoContent +="</div>";
	}

	downInfoContent += "<div style='float: right;'><a href='#' onclick='showDownDiv(); return false;' >Back</a>&nbsp;</div>";
	var infoContentDiv = document.getElementById("infoContent");
	infoContentDiv.innerHTML = downInfoContent;
	downInfoDiv.style.display = "block";
	if(infoContentDiv.scrollHeight<=204) {
			scrollbase.style.display ="none";
			scrollbar.style.display ="none";
			scrollbar.style.visibility = "hidden";
	}
	else{
		scrollbarHeight = Math.floor(210 /(infoContentDiv.scrollHeight/210));
		scrollbar.style.height = scrollbarHeight + 'px';
		scrollbar.style.top = "0px";
		infoContentDiv.scrollTop = 0;
		scrollbase.style.display ="block";
		scrollbar.style.display ="block";
		scrollbar.style.visibility = "visible";
		Drag.init(scrollbar, 0 , 210- scrollbarHeight);
		scrollbar.onDrag=function(y){
			infoContentDiv.scrollTop = 3*y;
		}
	}
};

function PageUp(){
	//debugger;
	if((iFirstVisibleItemIndex -10) > 0){
	iFirstVisibleItemIndex = iFirstVisibleItemIndex - 10;
	var height = (Math.floor(iFirstVisibleItemIndex/10))*174;
	DivContent.scrollTop = height;
	displayGameDetail(iFirstVisibleItemIndex);
	}
	AdjustPageBar();
}

function PageDown(){
	if((iFirstVisibleItemIndex + 10)<=iLastVisibleItemIndex){
		iFirstVisibleItemIndex = iFirstVisibleItemIndex + 10;
		var height = (Math.floor(iFirstVisibleItemIndex/10))*174;
		DivContent.scrollTop = height;
		displayGameDetail(iFirstVisibleItemIndex);
		if(((iFirstVisibleItemIndex + 10) >=iLastVisibleItemIndex) &&(iLastVisibleItemIndex< itemsTotal)){
			var startAt=iLastVisibleItemIndex;
			loadnewFeed(feedURL,startAt);
		};
	}
	AdjustPageBar();
}

function getLink(){
	var link = "";
	try{
		link = document.getElementById("id_Content_link_" + iSelectedItemIndex).firstChild.data;
	}catch(e){
		link = document.getElementById("id_Content_link_" + iSelectedItemIndex).innerHTML;
	}
	
	return link;
}

function getSWF(){
	var swflink=document.getElementById("id_Content_swf_" + iSelectedItemIndex);
	return swflink.innerHTML;
}

function getTryLink(){
	var trylink= "";
	try{
		trylink = document.getElementById("id_Trylink_" + iSelectedItemIndex).firstChild.data; 
	}catch(e){
		trylink = document.getElementById("id_Trylink_" + iSelectedItemIndex).innerHTML;
	}
	return trylink;
}

function getBuyLink(){
	var buylink = "";
	try{
		buylink = document.getElementById("id_Buylink_" + iSelectedItemIndex).firstChild.data; 
	}catch(e){
		buylink = document.getElementById("id_Buylink_" + iSelectedItemIndex).innerHTML;
	}	
	return buylink;
}

function getSwfWidth(){
	var swfWidth = document.getElementById("id_width_swf_" + iSelectedItemIndex);
	return swfWidth.innerHTML;
}

function getSwfHight(){
	var swfHight = document.getElementById("id_hight_swf_" + iSelectedItemIndex);
	return swfHight.innerHTML;
}

function getDescription(){
	var getDescription = "";
	
	try{
		getDescription =  document.getElementById("id_Content_description_" + iSelectedItemIndex).firstChild.data;
	}catch(e){
		getDescription =  document.getElementById("id_Content_description_" + iSelectedItemIndex).innerHTML;
	}
	
	return getDescription;
}

function getRegKey(){
	if(selectedGameExist){
		var ExternalID = document.getElementById("id_ExternalID_" + iSelectedItemIndex);
		return ExternalID.innerHTML;
	}
	else 
		return false;
}


function getTitle(title_id){
	if(title_id==null) title_id = iSelectedItemIndex;
	
 	var gametitle = "";
	
	try {
		gametitle = document.getElementById("id_Content_title_" + title_id).firstChild.data;
	}catch(e){
		gametitle = document.getElementById("id_Content_title_" + title_id).innerHTML;
	}
	return gametitle;
}

function getGameContent(game_id){
	if(!game_id) game_id = iSelectedItemIndex;
	var GameContent = new Array;
	
	GameContent["title"] = getTitle(game_id);
	GameContent["image"] = document.getElementById("id_Content_Img_" + game_id).getAttribute("src");
	GameContent["description"] = getDescription();
	GameContent["gameTypeid"] = document.getElementById("id_gameType_" + game_id).innerHTML;
	GameContent["categoryTypeid"] = document.getElementById("id_categoryType_" + game_id).innerHTML;
	GameContent["SystemRequirements"] = document.getElementById("id_SystemRequirements_" + game_id).innerHTML;
	GameContent["Trylink"] = getTryLink();
	GameContent["Buylink"] = getBuyLink(); 
	GameContent["Contentswf"] = document.getElementById("id_Content_swf_" + game_id).innerHTML;
	GameContent["width"] = document.getElementById("id_width_swf_" + game_id).innerHTML;
	GameContent["hight"] = document.getElementById("id_hight_swf_" + game_id).innerHTML;
	GameContent["Feedfrom"] = document.getElementById("id_Feedfrom_" + game_id).innerHTML;
	GameContent["FileSize"] = document.getElementById("id_FileSize_" + game_id).innerHTML;
	GameContent["Price"] = document.getElementById("id_Price_" + game_id).innerHTML;
	GameContent["Currency"] = document.getElementById("id_Currency_" + game_id).innerHTML;
	GameContent["NumberOfDownloads"] = document.getElementById("id_NumberOfDownloads_" + game_id).innerHTML;
	GameContent["Rating"] = document.getElementById("id_Rating_" + game_id).innerHTML;
	GameContent["DateAdded"] = document.getElementById("id_DateAdded_" + game_id).innerHTML;
	GameContent["GameLanguage"] = document.getElementById("id_GameLanguage_" + game_id).innerHTML;
	GameContent["ExternalID"] = document.getElementById("id_ExternalID_" + game_id).innerHTML;
	
	return GameContent;
}
