$(function(){
	$("#hitofround ul").cycle({
		pause: 1, 
		pauseOnPagerHover: 1, 
		fx:     'scrollHorz', 
		speed:  'slow', 
		timeout: 5000, 
		next:   '#hor-right', 
		prev:   '#hor-left' 
	});	
	$("#topsubnav.clubs ul").bxSlider({
		auto: true,
		pause: 4000,
		speed:750,
		displaySlideQty: 13,
      moveSlideQty: 5,
      autoHover: true,
      prevSelector: '#cl-left',
      nextSelector: '#cl-right',
      prevText: 'Předchozí',
      nextText: 'Další'
	});
	$("#boxes .slides").cycle({
		pause: 1, 
    	pauseOnPagerHover: 1,
    	pager: '#boxpager',
    	speed: 'fast',
    	timeout: 6000
	});
	$("a[rel^='prettyPhoto']").prettyPhoto({
		social_tools: false,
		overlay_gallery: false
	});
	$("#loginbox").hover(function(){
		rozbalitMenu();
	},function(){
		zabalitMenu();
	});

	rozbalitMenu();
	var st = setTimeout("if(!$('#loginmenu').ismouseover()) zabalitMenu();", 2 * 1000);

	$('#topsubnav.clubs a').tooltip({ 
	    track: true, 
	    delay: 0, 
	    showURL: false, 
	    top: -1,
	    left: 20,
	    fade: 200 
	});

	$('.tt').tooltip({ 
	    track: true, 
	    delay: 0, 
	    showURL: false, 
	    top: -1,
	    left: 20,
	    fade: 200 
	});
});


(function($){ 
jQuery.mlp = {x:0,y:0}; // Mouse Last Position
$(document).mousemove(function(e){
    jQuery.mlp = {x:e.pageX,y:e.pageY}
});
function notNans(value){
    if(isNaN(value)){
        return 0;
    } else {
        return value
    }
}
$.fn.ismouseover = function(overThis) {  
    var result;
    this.eq(0).each(function() {  
            var offSet = $(this).offset();
            var w = Number($(this).width())
            + notNans(Number($(this).css("padding-left").replace("px","")))
            + notNans(Number($(this).css("padding-right").replace("px",""))) 
            + notNans(Number($(this).css("border-right-width").replace("px","")))
            + notNans(Number($(this).css("border-left-width").replace("px",""))) ;
            var h = Number($(this).height()) 
            + notNans(Number($(this).css("padding-top").replace("px",""))) 
            + notNans(Number($(this).css("padding-bottom").replace("px","")))
            + notNans(Number($(this).css("border-top-width").replace("px","")))
            + notNans(Number($(this).css("border-bottom-width").replace("px","")));
            if(offSet.left<jQuery.mlp.x && offSet.left + w > jQuery.mlp.x
             && offSet.top<jQuery.mlp.y &&  offSet.top + h > jQuery.mlp.y)
            {
                result = true;
            } else {
                result = false;
            }
    });  
    return result;
    };  
})(jQuery); 

function isFilled(elementId) 
{
	return document.getElementById(elementId).innerHTML.length ? true : false;
}

function loadContent(elementId, url) 
{
	$('#'+elementId).load(url);
}

function clearContent(elementId) 
{
	$('#'+elementId).html('');
}


function loadBanner(ban, type, id, ids, langId)
{
	clearTimeout(ban);

	$.get
	(
		'/banner.php',
		{
			'type': type,
			'id': id,
			'ids': ids,
			'langId': langId
		},
   	function(data)
		{
			if(data)
			{
				$('#banner-'+type).html(data);
			}
   	}
	);
}

function OpenCompTipDialog(url)
{
	var iframe = document.getElementById('CompTipIframe');
	iframe.src = url;
	$('#CompTipDialog').dialog('open');
}

function RegistrationClub()
{
	if (document.getElementById('Typeclub').checked)
	{
		//showChildren(document.getElementById('KlubBox'), true, false);
		document.getElementById('KlubBox').style.display = '';
	}
	else
	{
		document.getElementById('KlubBox').style.display = 'none';
	}
}

var lastMatchInfoZapas = '';
function MatchInfoReload(zapasID, url, placeID)
{
	var zapas = document.getElementById(zapasID);
	if (!zapas)
		return;
	
	if (lastMatchInfoZapas == zapas.value)
		return;
	
	lastMatchInfoZapas = zapas.value;
	
	var div = document.getElementById(placeID);
	
	if (zapas.value.length != 7)
	{
		div.innerHTML = '';
		return;
	}
	else
	{
		AjaxLoader(url+'&zapas='+zapas.value, placeID);
	}
}


/* AJAX ============================================================================================================ */
function AjaxLoader(url, place)
{
	if (window.ActiveXObject)
	{
		httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		httpRequest = new XMLHttpRequest();
	}
	
	if (!httpRequest)
		return false;
	
	httpRequest.open('GET', url);
	httpRequest.onreadystatechange = function () { AjaxResult(place); };
	httpRequest.send(null);
}

function AjaxResult(place)
{
	if (httpRequest.readyState == 4)
	{
		if(httpRequest.status == 200)
		{
			var oPlace = document.getElementById(place);
			if (oPlace)
			{
				$(oPlace).html(httpRequest.responseText);
				if (document.getElementById('AjaxMessageText') && document.getElementById('AjaxMessageText').value.length)
				{
					var tmp = document.getElementById('AjaxMessageText').value;
					document.getElementById('AjaxMessageText').id = '';
					alert(tmp);
				}
			}
		}
	}
}

function ShowPoznamka(id)
{
	var s = document.getElementById('PoznamkaSmall'+id);
	var b = document.getElementById('PoznamkaBig'+id);
	
	if (s && b)
	{
		s.style.display = 'none';
		b.style.display = '';
	}
}

function ClearInput(obj, text)
{
	obj.value = obj.value == text ? '' : obj.value;
}

function rozbalitMenu()
{
	$("#loginmenu").show(200);
}

function zabalitMenu()
{
	$("#loginmenu").hide(200);
	st = null;
}
