var flashimages;var numFlash = 0;var spansFlash = '';var spanNumFlash = 0;
var maxudalost = ''; var actudalost = 0;
$(document).ready(function($) {
	flashimages = $('.flashimg');
	flashimages.each(function(){
		$(this).css('opacity','0');
	});
	if(flashimages.length > 0){
		$(flashimages[0]).css('opacity','1');
		flashHome();
		
		spansFlash = $('.flashtext div');
		fadeinspans();		
	}
	//highhand();
	$('p.textscrolling').css('display',"none");
	$.get("/ajax/get-pokerman-text",function(data){
		if(data != ''){
			var html = $('p.textscrolling').html();
			$('p.textscrolling').html(html + " | " + data);
		}
		$('p.textscrolling').css('display',"block");
		$('p.textscrolling').each(function(){
			var width = $(this).parent().width();
			$(this).attr('minscroll',$(this).width()*(-1));
			$(this).attr('maxscroll',width);
			$(this).css('width',width);
			$(this).parent().css('overflow','hidden');
			textScrolling($(this));
		});
	});
	
	$('.item .img .players').each(function(){
		var players = $(this).find('.player');
		countplayer = players.length;
		$(this).append("<div class='player'>" + $(players[0]).html() + "</div>");
		setTimeout(playerScrolling, 2000);
	});

	$('.udalosti').each(function(){
		var a = 1;
		$('.clanekimg').each(function(){
			a++;
		});
		maxudalost = a;
		a = a * 215;
		$('.udalostinner').width(a);
		checkudalost();
	});

});
function moveudalost(way,obj){
	if($(obj).hasClass('disabledThumbMove')) return;
	actudalost += way;
	checkudalost();
	$(".udalostinner").stop().animate({'margin-left': (actudalost*908*(-1)) },500);
}
function checkudalost(){

	if(actudalost+1 > (maxudalost/4)){
		$('.jQueryDeathBoxRightButThumbs').addClass('disabledThumbMove');
	}else{
		$('.jQueryDeathBoxRightButThumbs').removeClass('disabledThumbMove');
	}
	
	if(actudalost == 0){
		$('.jQueryDeathBoxLeftButThumbs').addClass('disabledThumbMove');
	}else{
		$('.jQueryDeathBoxLeftButThumbs').removeClass('disabledThumbMove');
	}	
}

var scrollplayer = 0;var countplayer = 0;
function playerScrolling(){
	$el = $('.item .img .players');
	scrollplayer++;
	$el.animate({'margin-top' : scrollplayer*(-70)}, 500 ,function(){
		if(scrollplayer == countplayer){
			$el.css('margin-top',0);
			scrollplayer = 0;
		}
		setTimeout(playerScrolling, 2000);
	});
}
function textScrolling($el){
	$el.css('margin-left',$el.attr('maxscroll')+'px');
	$el.animate({'margin-left':$el.attr('minscroll')},10000,'linear',function(){textScrolling($(this));});
}
function highhand(){
	$('.highhandanimate span').each(function(){
		if(typeof $(this).attr('data.highand') == 'undefined'){
			$(this).attr('data.highand',$(this).html());
			$(this).html('0');
		}
		var max = $(this).attr('data.highand');
		var next = ($(this).html())*1 + 100;
		if(max >= next){
			$(this).html(next);
			setTimeout(highhand,50);
		}else{
			setTimeout(highhandfull,300);
		}
	});
}
var counthand = 0;
function highhandfull(){
	var $high = $('.highhandanimate');
	var pocethand = 5;
	if(counthand <= pocethand){
		counthand++;
		if($high.css('visibility') == 'hidden')
			$high.css('visibility','visible');
		else
			$high.css('visibility','hidden');	
		setTimeout(highhandfull,300);
	}else{
		counthand = 0;
		var $span = $('.highhandanimate span');
		setTimeout(function(){$span.html('0'); highhand();},500);
	}
}
function flashHome(){
	var next = numFlash+1;
	if(typeof flashimages[next] == 'undefined') next = 0;
	$(flashimages[numFlash]).animate({"opacity":0},1500);
	$(flashimages[next]).animate({"opacity":1},1500,function(){
		numFlash = next;
		setTimeout('flashHome()',3000);
	});
}
function fadeinspans(){
	$s = $(spansFlash[spanNumFlash]);
	$s.css('margin-left',(spanNumFlash*60) + "px");
	$s.fadeIn('slow',function(){
		spanNumFlash++;
		if(typeof spansFlash[spanNumFlash] != 'undefined') 
			fadeinspans();
	});
}
function setMusic(){
	$.post('/ajax/setmusic',function(){});
	if($('#music img').length == 0){
		var data = "<img class='music' src='" + $('#music').attr('data-img') + "' alt='' />";
	}else{
		var url = $('#music').attr('data-obj');
		var data = '<object class="music" data="' + url + '" width="20" height="20"  type="application/x-shockwave-flash" id="music-player"><param value="' + url + '" name="movie"><param value="t" name="salign">\<param value="transparent" name="wmode"> <param value="#000000" name="bgcolor"></object>';
	}
	$('#music').html(data);
}
