function $(id){
	return document.getElementById(id);
}					

currentHotGame=1;
function changeHotGame(n,fileName){
	$('smallHotGames'+currentHotGame).style.display = "none";
	currentHotGame = n;
	$('smallHotGames'+currentHotGame).style.display = "block";	
	changeHotGamePic(fileName);
}

function changeHotGamePic(fileName){
	var regExpFileName = /[^\/]+$/ig;
	var oImg = $('bigHotGameImg');

	//oImg.src = oImg.src.replace(regExpFileName,fileName);
	oImg.src = fileName;
}

function PopupWin(link, title)
{
    var win = window.open('','preview','width=50,height=50,left=0,top=0,screenX=0,screenY=0,resizable=no,scrollbar=no,status=no,menubar=no,titlebar=no,location=no,scrolling=no');
    var winDoc = win.document;
    var content = '<html><head><title>' + title + '</title><style>body{overflow: auto; padding:0; margin:0}img{border:0;}div{padding:5px; margin: 0 5px;}*div{padding:5px; margin: 0 5px;}html>body div {padding:0px 5px; margin: 0 5px;}</style>' + '</head><body><div><a href="javascript:self.close()"><img src="' + link + '" alt="' + title + '" id="image" title="Закрыть" /></a></div></body></html>';
    win.document.write(content);
    winDoc.body.onload = function() {
			var obj = winDoc.getElementById('image');
			var w = obj.width, h = obj.height;
			
			var iHeight= document.body.clientHeight, iWidth = self.innerWidth;
			var left = (self.opera ? iWidth : screen.availWidth)/2 - w/2;
			var top = (self.opera ? iHeight : screen.availHeight)/2 - h/2;

			win.resizeTo(w+25, h+58);
			
			win.moveTo(left, top);
    }
    win.onload = winDoc.body.onload; // special for Mozilla
    // !!! Important statement: popup onload won't execute without it!
    win.document.close();
    win.focus();
} 

function PopupScr(link, title)
{
    var win = window.open('','preview','width=640,height=480,left=0,top=0,screenX=0,screenY=0,resizable=no,scrollbar=no,status=no,menubar=no,titlebar=no,location=no,scrolling=no');
    var winDoc = win.document;
    var content = '<html><head><title>' + title + '</title>' + 
    '<style>body{overflow: auto; padding:0; margin:0}img{border:0;}div{padding:5px; margin: 0 5px;}*div{padding:5px; margin: 0 5px;}html>body div {padding:0px 5px; margin: 0 5px;}</style>' + '</head><body><div><a href="javascript:self.close()">' +
    '<img alt="' + title + '" id="image" title="Close" src="' + link + '" /></a></div></body></html>';
    win.document.write(content);
    winDoc.body.onload = function() {
			var obj = winDoc.getElementById('image');
			var w = obj.width, h = obj.height;
			
			var iHeight= document.body.clientHeight, iWidth = self.innerWidth;
			var left = (self.opera ? iWidth : screen.availWidth)/2 - w/2;
			var top = (self.opera ? iHeight : screen.availHeight)/2 - h/2;

			win.resizeTo(w+25, h+58);
			
			win.moveTo(left, top);
    }
    win.onload = winDoc.body.onload; // special for Mozilla
    // !!! Important statement: popup onload won't execute without it!
    win.document.close();
    win.focus();
}

var switcher = {
	slideInterval: 5000,
	slideHandler: null,
	currentCardIndex: 0,
	maxCardIndex: 0,
	controlStatus: 'playing', /*  playing/paused */
	controlObject: null,
	
	cardMenuCollection: null,
	cardsCollection: [],
	init: function (switcherId, defaultCardIndex){
		this.cardMenuCollection = $(switcherId+"CardMenu").getElementsByTagName("TD");
		this.maxCardIndex = this.cardMenuCollection.length - 1;
		for(var i=0; i<this.cardMenuCollection.length; i++){
			this.cardMenuCollection[i].onclick = function(i){return function(){switcher.clickOnCard(i)}}(i);		
		}	
		
		var tCardObj = $(switcherId+'CardsArea').getElementsByTagName('DIV')[0];
		
		for(var i=0; i<this.maxCardIndex+1; i++){
			this.cardsCollection[i] = tCardObj;
			do{
				tCardObj = tCardObj.nextSibling;
			} while(tCardObj && tCardObj.nodeName && tCardObj.nodeName != "DIV");			
		}		
		
		this.controlObject = $(switcherId+"Control");
		this.controlObject.onclick = function(){switcher.clickOnControl();return false};
		
		this.setCardFast(defaultCardIndex);		
		this.setControlStatus("playing");	
						
	}
	,
	
	clickOnControl: function (){
		this.setControlStatus((this.controlStatus=='playing')?'paused':'playing');		
	}
	,
	
	clickOnCard: function (index){
		this.setCard(index);
		this.setControlStatus('paused');		
	}
	,	
	
	nextCard: function (){
		var index = (this.currentCardIndex == this.maxCardIndex)? 0 : this.currentCardIndex + 1;
		this.setCard(index);
	}
	,		

	setControlStatus: function (status) {
		if(status == "paused") {
			this.controlStatus = "paused";			
			this.controlObject.className = "control paused";
			clearInterval(this.slideHandler);
		}
		else {
			this.controlStatus = "playing";					
			this.controlObject.className = "control playing";
			this.slideHandler = setInterval(function(){switcher.nextCard()},this.slideInterval)		
		
		}
	}
	,
	
	setCard: function (index) {
		if(index != this.currentCardIndex) {
			this.cardMenuCollection[this.currentCardIndex].className = "";
			this.cardsCollection[this.currentCardIndex].style.zIndex = 10;
	
			this.cardMenuCollection[index].className = "selected";				
			this.cardsCollection[index].style.zIndex = 20;
			this.floatingCard (index,0,this.currentCardIndex);
			this.currentCardIndex = index;	
		}					
	} 
	,
	
	floatingCard: function (index,v,prevIndex){
		if(v==1){
			this.cardsCollection[prevIndex].style.zIndex = 1;			
			this.cardsCollection[index].style.zIndex = 10;						
		}
		else{
			v = v+.30;
			v = (v>1)?1:v;
			this.setOpacity(this.cardsCollection[index],v);	
			setTimeout(function(index,v,prevIndex){ return function(){switcher.floatingCard(index,v,prevIndex);} }(index,v,prevIndex),50);		
		}
	}
	,
	
	setCardFast: function (index) {
			this.cardMenuCollection[this.currentCardIndex].className = "";
			this.cardsCollection[this.currentCardIndex].style.zIndex = 1;
	
			this.cardMenuCollection[index].className = "selected";				
			this.cardsCollection[index].style.zIndex = 10;
			this.setOpacity(this.cardsCollection[index],1);	
			this.currentCardIndex = index;	
	} 
	,	
	
	setOpacity: function (o,v) {
		if(o.currentStyle) {
			if(/MSIE ((5\.5)|[6])/.test(navigator.userAgent) && navigator.platform == "Win32"){
			}
			else {
				o.style.filter = "alpha(opacity="+(100*v)+")";	
			}
		}
		else {
			o.style.opacity = v;
		}
	}

}

function showPost(id) {
	v = document.getElementById('a'+id);
	if (v) {
		v.style.display = v.style.display=='none'?'block':'none';
	}
	return false;
}