$(document).ready( function()
{

/* MENU */

	$("ul.menu-item li").hover(
		function() { 
			$(this).children("ul").show(10);
		},
		function() { 
			$(this).children("ul").hide(10);
		}
	);


/* Rozmiar czcionki i print */		
		
	$("#navi span").click(
		function() { 
			var option = $(this).attr('class');
			var text1 = $("div.news");
			var text2 = $("div#left");
			var text3 = $("div.info-cont");
			var currsize = text1.css("font-size");
			var currsize = text2.css("font-size");
			var currsize = text3.css("font-size");
			var finalsize = parseFloat(currsize, 10);
			
			switch(option) {
				case("plus"):
					finalsize += 1;
					break;
					
				case("minus"):
					finalsize -= 1;
					break;
					
				case("print"):
					window.printWebPart('left');
					return false;
			}
			text1.css("font-size", finalsize);
			text2.css("font-size", finalsize);
			text3.css("font-size", finalsize);
			return false;
		}
	);
	
/**
 * Galeria
 */	
	$("a#single").fancybox();
	
	/* Using custom settings 
	*/
	
	$("a#inline").fancybox({
		'hideOnContentClick': true
	});

	$("a[rel=group]").fancybox({
		'hideOnContentClick': true,
		'zoomSpeedIn':	300, 
		'zoomSpeedOut':	300, 
		'overlayShow':	true
	});
	
	$("span.gallery").click(
			function(){
				$("tr.gallery-group").toggle();
			});
});


function printWebPart(tagid){
    if (tagid) {
        //build html for print page
        var html = "<HTML>\n<HEAD>\n"+
            $("head").html()+
            "\n</HEAD>\n<BODY>\n"+
            $("#"+tagid).html()+
            "\n</BODY>\n</HTML>";
        //open new window
        var printWP = window.open("","printWebPart");
        printWP.document.open();
        //insert content
        printWP.document.write(html);
        printWP.document.close();
        //open print dialog
        printWP.print();
    }
}

/* MATCH DESCRIPTION */

function matchDesc()
{ 
	var desc = $("tr.match-desc");
	if (desc.text() != null) {
	  desc.toggle().is(':visible').css('display', 'table-row');
		
	}
}


/* Paginacja */	

function getPastMatch(cnt, catid) {
	if(catid != 0) {
		requestData = "pmweek="+cnt+"&catid="+catid;
	} else {
		requestData = "pmweek="+cnt;
	}
 
	$.ajax({
		type: "post",
		url: "/main/past",
		data: requestData,
		success: function(response){
	     	$('#past-match').html(response);
	   	}
	 });
}
	

function getNextMatch(cnt, catid) {
	if(catid != 0) {
		requestData = "nmweek="+cnt+"&catid="+catid;
	} else {
		requestData = "nmweek="+cnt;
	}

	$.ajax({
		type: "post",
		url: "/main/next",
		data: requestData,
		success: function(response){
	     	$('#next-match').html(response);
	   	}
	 });
};


function getResults(cnt, catid) {
	if(catid != 0) {
		requestData = "resweek="+cnt+"&catid="+catid;
	} else {
		requestData = "resweek="+cnt;
	}

	$.ajax({
		type: "post",
		url: "/main/results",
		data: requestData,
		success: function(response){
	     	$('#results').html(response);
	   	}
	 });
};


function getOlderNews(cnt, sectionid, catid) {
	if(catid != 0) {
		requestData = "page="+cnt+"&catid="+catid;
	}
	else if(sectionid != 0) {
		requestData = "page="+cnt+"&sectionid="+sectionid;
	} else {
		requestData = "page="+cnt;
	}

	$.ajax({
		type: "post",
		url: "/main/olderNews",
		data: requestData,
		success: function(response){
	     	$('#oldnews').html(response);
	   	}
	 });
};

