﻿//Topstory
var thread;
var lockTherad;
var mouseThread;
var selected = 0;
var toSelect = 0;
var lock = false;
var maxData = 4;
//var timeout = 10000;
var timeout = 15000;
var lockTime = 500;
var mouseOverLockTime = 1000;

document.writeln('<script language="javascript" type="text/javascript" src="/Library/js/jquery.innerfade.js"></script>');

$(document).ready(
	function(){
		$('.TPlagerImg').innerfade({
			speed: 'slow',
			timeout: timeout,
			type: 'sequence',
			containerheight: '305px'
		});
		$('.TitleText').innerfade({
			speed: 'slow',
			timeout: timeout,
			type: 'sequence',
			containerheight: '22px'
		});
		/*
		$('.GameType').innerfade({
			speed: 'slow',
			timeout: timeout,
			type: 'sequence',
			containerheight: '22px'
		});
		*/
		$('.DescritpTion').innerfade({
			speed: 'slow',
			timeout: timeout,
			type: 'sequence',
			containerheight: '50px'
        });
					
	}
);
thread = setInterval("NextStatus()", timeout);

function NextStatus()
{
	toSelect = selected + 1;
	if (toSelect >= maxData)
	{
		toSelect = 0;
		ChangeStatus(toSelect);
	}
	else
	{
		//alert(selected);
		ChangeStatus(toSelect);
	}
}

function ChangeStatus(to)
{
	if (lock == true)
	{
		return;
	}
	if (to == selected)
	{
		return
	}
	lock = true;
	for (i = 0; i < maxData; i++)
	{
		if (i != to) {
		    if (document.getElementById("SmallImage" + i) != null) {
		        document.getElementById("SmallImage" + i).className = "SmallImageNormal";
		    }
		}
		else {
		    if (document.getElementById("SmallImage" + i) != null) {
		        document.getElementById("SmallImage" + i).className = "SmallImageSelect";
		    }
		}
	}
	var settings = {
		'animationtype':    'fade',
		'speed':            'slow',
		'type':             'sequence',
		'timeout':          timeout,
		'containerheight':  'auto'
	};
	var elements = $('.TitleText').children();
		$(elements[selected]).hide();
		$(elements[to]).show();
	/*
	elements = $('.GameType').children();
		$(elements[selected]).hide();
		$(elements[to]).show();
	*/
	elements = $('.DescritpTion').children();
		$(elements[selected]).hide();
		$(elements[to]).show();
	elements = $('.TPlagerImg').children();
	$(elements[selected]).fadeOut(settings.speed);
	$(elements[to]).fadeIn(settings.speed, function() {
		removeFilter($(this)[0]);
	});
	selected = to;
	clearTimeout(thread);
	clearTimeout(lockTherad);
	clearTimeout(mouseThread);
	thread = setInterval("NextStatus()", timeout);
	NextStatus();
	//lockTherad = setInterval("setLock(false)", lockTime);
	setLock(false);
}

function setLock(key)
{
	lock = key;
}

function waitMouseover(to)
{
	clearTimeout(mouseThread);
    //mouseThread = setInterval("ChangeStatus(" + to + ")", mouseOverLockTime);
	ChangeStatus(to);
}

function createHTML(arItemTS) {
    var iTSCount = arItemTS.length;
    var strBigImage = "";
    var strSmallImage = "";
    var strTitle = "";
    var strGameType = "";
    var strDescription = "";

    if (iTSCount < maxData) {
        maxData = iTSCount
    }
    for (i = 0; i < maxData; i++) {
        strBigImage += '<li><a onfocus="this.blur();" hidefocus="" href="' + arItemTS[i][7] + '" title="' + arItemTS[i][2] + '"><img alt="' + arItemTS[i][2] + '" src="' + arItemTS[i][1] + arItemTS[i][5] + '" width="644px" height="305px"/></a></li>';
        if (i == 0) {
            strSmallImage += '<li class="SmallImageSelect" id="SmallImage' + i + '" onClick="ChangeStatus(' + i + ')" onmouseover="waitMouseover(' + i + ')"><a onfocus="this.blur();" hidefocus="" title="' + arItemTS[i][2] + '"><img alt="' + arItemTS[i][2] + '" src="' + arItemTS[i][1] + arItemTS[i][6] + '" class="game"/></a></li>';
        }
        else {
            strSmallImage += '<li class="SmallImageNormal" id="SmallImage' + i + '" onClick="ChangeStatus(' + i + ')" onmouseover="waitMouseover(' + i + ')"><a onfocus="this.blur();" hidefocus="" title="' + arItemTS[i][2] + '"><img alt="' + arItemTS[i][2] + '" src="' + arItemTS[i][1] + arItemTS[i][6] + '" class="game"/></a></li>';
        }

        strTitle += '<li><a href="' + arItemTS[i][7] + '">' + arItemTS[i][2] + '</a><a href="#" >'
        if (arItemTS[i][8] == '1') {
            strTitle += '<img class="videoIcon" alt="video" src="/Images/TopPromotion/videoIcon.gif" />';
        }
        strTitle += '</a></li>';
        strGameType += '<li>' + arItemTS[i][4] + '</li>';
        strDescription += '<li>';
		if(arItemTS[i][4] != "")
		{
			strDescription += '<p class="gametypehome">';
			strDescription += arItemTS[i][4];
			strDescription += '</p>';
		}
		strDescription += '<p class="descriptionhome">';		
		strDescription += arItemTS[i][3];
		strDescription += '</p>';
		strDescription += '</li>';
	}
    document.getElementById("TPlagerImg").innerHTML = strBigImage;
    document.getElementById("SmallImage").innerHTML = strSmallImage;
    document.getElementById("TitleText").innerHTML = strTitle;
    //document.getElementById("GameType").innerHTML = strGameType;
    document.getElementById("DescritpTion").innerHTML = strDescription;
}
