loading = false;
step = 3;
step_s = 8;
speed = 500;
function Sync(){
	pocet = $('#Scroller div.item').length;
	sirka = $('#Scroller div.item:first').width();
	celkove = (pocet-3)*sirka;
	var offset = $('#Scroller').offset().left - $('#Scroller div.act').offset().left;
	if(offset!=$('#Scroller').offset().left){
		if((-offset)<celkove-sirka){
			$('#Scroller').css('margin-left',(offset)+'px');
		}else{
			$('#Scroller').css('margin-left',-celkove+sirka+'px');
		}
	}

	// ADD Novak 6.10.2010	
	pocet_s = $('#sponzori div.i').length;
	sirka_s = $('#sponzori div.i:first').width();
	celkove_s = (pocet_s)*sirka_s;
	/*var offset = $('#sponzori').offset().left - $('#sponzori div.act').offset().left;
	if(offset!=$('#sponzori').offset().left){
		if((-offset)<celkove-sirka){
			$('#sponzori').css('margin-left',(offset)+'px');
		}else{
			$('#sponzori').css('margin-left',-celkove+sirka+'px');
		}
	}*/

}
$(document).ready(function(){
	checkTeam("teamSelect");
	$('a.popup').lightBox();
	$('#ArrowUp').click(function(){$('#NewsBox').scrollTo('-=120px', 1000 );}, function(){});
	$('#ArrowDown').click(function(){$('#NewsBox').scrollTo('+=120px', 1000 );}, function(){});
	setTimeout(function(){Sync();},100);
	$('#ScrollerLeft').click(function(){
		marginAkt = $('#Scroller').css('margin-left');
		marginNext = Math.round(marginAkt.replace('px',''))*1+step*sirka;
		if(!loading){
			if(marginNext<sirka){
				loading = true;
				$('#Scroller').animate({marginLeft:marginNext+'px'},speed,function(){ loading = false;});
			}else{
				loading = true;
				$('#Scroller').animate({marginLeft:0+'px'},speed,function(){ loading = false;});
			}		
		}
	});

	$('#ScrollerRight').click(function(){
		marginAkt = $('#Scroller').css('margin-left');
		marginNext = marginAkt.replace('px','')*1-step*sirka;
		if(!loading){
			if(-marginNext<celkove-sirka){
				loading = true;
				$('#Scroller').animate({marginLeft:marginNext+'px'},speed,function(){ loading = false;});
			}else{
				loading = true;
				$('#Scroller').animate({marginLeft:-celkove+sirka+'px'},speed,function(){ loading = false;});
			}
		}
	});

	// ADD Novak 6.10.2010
	$('#sponzorLeft').click(function(){
		marginAkt = $('#sponzori').css('margin-left');
		marginNext = Math.round(marginAkt.replace('px',''))*1+step_s*sirka_s;
		if(!loading){
			if(marginNext<sirka_s){
				loading = true;
				$('#sponzori').animate({marginLeft:marginNext+'px'},speed,function(){ loading = false;});
			}else{
				loading = true;
				$('#sponzori').animate({marginLeft:0+'px'},speed,function(){ loading = false;});
			}		
		}
	});
	// ADD Novak 6.10.2010
	$('#sponzorRight').click(function(){
		marginAkt = $('#sponzori').css('margin-left');
		marginNext = marginAkt.replace('px','')*1-step_s*sirka_s;
		if(!loading){
			if(-marginNext<celkove_s-sirka_s){
				loading = true;
				$('#sponzori').animate({marginLeft:marginNext+'px'},speed,function(){ loading = false;});
			}else{
				loading = true;
				$('#sponzori').animate({marginLeft:0+'px'},speed,function(){ loading = false;});
			}
		}
	});

	Menu();
	SlideShow('#switcher');
	SlideShow('#switcher-height');
	int_slideshow = setInterval(function(){NextSlide('#switcher');NextSlide('#switcher-height');},5000);
	setTimeout("sponzorRight()", 20000);

	$(".osobni_udaje table tr:odd").css("background", "#EDEDED");
        
        // ADD Kubis 26.10.2011
        // Dialog
        $('#dialog').dialog({
                autoOpen: false,
                modal: true,
                width: 300,
                height: 100,
                maxWidth: 800,
                maxHeight: 600,
                resizable: false,
                title: 'Odeslat PDF emailem',
                buttons: {
                        "Odeslat": function() { 
                                $("#dialog_form").submit();
                                
                                if ($("#dialog_form").size() == 0) {
                                    $(this).dialog("close");
                                }
                                
                        },
                        "Zavřít": function() {
                                $(this).dialog("close");
                        }
                }
        });
        // Dialog Link
        $('.dialog_link').click(function(){
                $('#dialog').dialog('open');
//                 $('#dialog').dialog({ title: 'Odeslat listinu emailem' });
                return false;
        });
});
var int_slideshow;

function sponzorRight() {
		marginAkt = $('#sponzori').css('margin-left');
		marginNext = marginAkt.replace('px','')*1-step_s*sirka_s;
		if(!loading){
			if(-marginNext<celkove_s-sirka_s){
				loading = true;
				$('#sponzori').animate({marginLeft:marginNext+'px'},speed,function(){ loading = false;});
			}else{
				loading = true;
				$('#sponzori').animate({marginLeft:0+'px'},speed,function(){ loading = false;});
			}
		}
		setTimeout("sponzorRight()", 20000);
}

function SlideShow(id){
	$(id+" div.panel:first").addClass('active');
	$(id+" ul.filmstrip li:first").addClass('act');
	if (id == "#switcher") {
		setTimeout(function(){$(id+" ul.filmstrip img.pointer").css('top',$(id+" ul.filmstrip li img.thumb:first").offset().top+'px');},300);
	} else {
		setTimeout(function(){$(id+" ul.filmstrip img.pointer").css('left',$(id+" ul.filmstrip li img.thumb:first").offset().left+'px');},300);
	}
	$(id+" ul.filmstrip li img.thumb").click(function(){
								idcko = $(this).attr('id');
								$(id+" div.active").animate({opacity:'0'},500,function(){ClearInterval(id);}).removeClass('active');
								$(id+" div#panel_"+idcko).animate({opacity:'1'},500,function(){ClearInterval(id);}).addClass('active');
								$(id+" ul.filmstrip li.act").removeClass('act');
								$(this).parent().addClass('act');
								if (id == "#switcher") {
									posun = $(this).offset().top;
									$(id+" ul.filmstrip img.pointer").animate({top:posun+'px'},300,function(){ });
								} else {
									posun = $(this).offset().left;
									$(id+" ul.filmstrip img.pointer").animate({left:posun+'px'},300,function(){ });
								}
								});
}
function ClearInterval(id){
	clearInterval(int_slideshow);
	int_slideshow = setInterval(function(){NextSlide(id)},5000);
}
function NextSlide(id){
	if($(id+" div.panel").length>1){
		$act = $(id+" div.active");
		var $next =  $act.next().length ? $act.next() : $(id+' div.panel:first');
		$act_li = $(id+" ul.filmstrip li.act");
		var $next_li =  $act_li.next().length ? $act_li.next() : $(id+' ul.filmstrip li:first');
		$act.animate({opacity:'0'},500,function(){ClearInterval(id);}).removeClass('active');
		$next.animate({opacity:'1'},500,function(){ClearInterval(id);}).addClass('active');
		if (id == "#switcher") {
			posun = $next_li.offset().top;
		} else {
			posun = $next_li.offset().left;
		}
		$next_li.addClass('act');
		$act_li.removeClass('act');
		if (id == "#switcher") {
			$(id+" ul.filmstrip img.pointer").animate({top:posun+'px'},300,function(){ });
		} else {
			$(id+" ul.filmstrip img.pointer").animate({left:posun+'px'},300,function(){ });
		}
	}
}
var Submenu = 0;
function Menu(){
	$li = $("ul#menu > li.top");
	$li.mouseover(function(){
		$(this).find('ul').css('visibility','visible');
	    })
	   .mouseout(function(){
		$(this).find('ul').css('visibility','hidden');
	    });
}

/*
 * ADD Novak 1.10.2009
 * Prepinani tlacitek
 */
function changeButton(unactive, active) {
	$("#"+unactive).removeClass("butAll").addClass("butAllSelect");
	$("#"+active).removeClass("butAllSelect").addClass("butAll");

	$("#"+unactive+"_cont").show(0);
	$("#"+active+"_cont").hide(0);
}

/*
 * ADD Novak 9.3.2011
 * Zobrazeni filtru lig pro A tym
 */
function checkTeam(id) {
	var team_id = $("#"+id+" option:selected").val();
	if (team_id == 1) {
	    $("#leagueSelect").slideDown(300);
	} else {
	    $("#leagueSelect").slideUp(300);	  
	}
}

/**
 * ADD M.Samal 7.09.2011
 * Ajax call for this week matches tab
 */

function thisWeekChangeEvent() {
    timeout = 30000;
    var script_url = 'http://' + location.hostname + '/inc/this-week.php';
    var team_id = $("#this_week option:selected").val();
    
    $.ajax({
            url: script_url,
            type: "POST",
            data: 'tid='+team_id,
            timeout: timeout,
            dataType: "html",
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert(XMLHttpRequest.responseText);
                    return false;
            },
            success: function (RetData) {
                    $('#thisWeekMatches').html( RetData );
                    return true;
            }
    });
}


