var t_id = setInterval(animate,20);
var pos=0;
var dir=2;
var len=0;

function animate()
{
var elem = document.getElementById('progress');
if(elem != null) {
if (pos==0) len += dir;
if (len>32 || pos>79) pos += dir;
if (pos>79) len -= dir;
if (pos>79 && len==0) pos=0;
elem.style.left = pos;
elem.style.width = len;
}
}

function remove_loading() {
this.clearInterval(t_id);
var targelem = document.getElementById('loader_container');
targelem.style.display='none';
targelem.style.visibility='hidden';
var t_id = setInterval(animate,60);
}

$j(document).ready( function () {
	if (document.getElementById("livepanelscore")) {
		doMatchScore(true);
		$j("#loadinggif").hide();
		setInterval(doMatchScore, 1000*50);
	}
	if (document.getElementById("pplayers")) {
		if ($j.browser.msie) {
			//$j("#pplayers").css("position","relative").css("top", "-130px");
			//$j("#safari").css("z-index", "-99");
		}

	}
	if (document.getElementById("scaricavideo")) {
		$j("#downmp4").hide();
		$j("#scaricavideo").click(function () {$j("#downmp4").toggle("slow")});
	}
	if (document.getElementById("scaricaPuzzle")) {
		$j("#downPuzzle").hide();
		$j("#scaricaPuzzle").click(function () {$j("#downPuzzle").toggle("slow")});
	}
	//$j("b:contains('Turno di riposo')").html("sospesa");
	if (top.location.href=="http://www.fcmatera.it/index.php?option=com_joomleague&func=showResultsRank&p=1&Itemid=74") {
		aa =$j("tr > td:contains('Francavilla')")[3];
		bb = $j(aa).parent();
		cc = $j(bb).prev();
		$j(bb).after($j(cc));
		$j(bb).children("td:eq(0)").html(" 7");
		$j(cc).children("td:eq(0)").html(" 8");

		$j(bb).children("td:eq(1)").html('<img align="middle" title="" alt="" src="http://www.fcmatera.it/components/com_joomleague/frontend/default/images/same.png"/>');
/*
		var isc = $j("tr > td:contains('Ischia')")[2];
		var tur = $j("tr > td:contains('Turris')")[2];
		tur = $j(tur).parent();
		isc = $j(isc).parent();
		$j(tur).after($j(isc));

		$j(tur).children("td").css("background-color", "rgb(0, 204, 102)");
		$j(isc).children("td").css("background-color", "transparent");

		$j(tur).children("td:eq(0)").html(" 5");
		$j(isc).children("td:eq(0)").html(" 6");
		$j(tur).children("td:eq(1)").html('<img align="middle" title="" alt="" src="http://www.fcmatera.it/components/com_joomleague/frontend/default/images/up.png"/>');
		$j(isc).children("td:eq(1)").html('<img align="middle" title="" alt="" src="http://www.fcmatera.it/components/com_joomleague/frontend/default/images/down.png"/>');
*/
	}
});


function doShowLoading () {
	$j("#loadinggif").css("position", "relative").css("top", "-150px").css("left", "79px").fadeIn("slow");
}

function doGiornaleRanking (flag) {
	$j("tr.sectiontableentry1 td, tr.sectiontableentry2 td").css("font-size", "15px").css("color", "black");
	$j("a").css("color", "black");
	$j("tr.sectiontableheader > td:contains('sabato')").hide();
	$j("tr.sectiontableheader > td:contains('domenica')").hide()
	//$j("div#joomleague > div > table[width='96%']").css("width", "77%");
	if (flag) {
		$j("div > table[width=96%]").css("width", "77%");
	}
}

function doMatchScore(arg) {
	$j("#loadinggif").fadeOut("slow");
	$j("#livepanelscore").hide().load("http://www.fcmatera.it/livescore.html?rand="+Math.random(1970)).css("top", "-95px").fadeIn("slow");
	$j(".livepanelscorefinal").css("top","-121px");
	$j("#tempolive").hide().load("http://www.fcmatera.it/temposcore.html?rand="+Math.random(1970)).fadeIn("slow");
	setTimeout(doShowLoading, 40*1000);
	//$j("#livepanelscore").text($j(".tdmatch:contains('MATERA')").next().text());
	//$j(".tdmatch:contains('MATERA')").parent().css("color", "red");
	//$j(".tdmatch:contains('MATERA')").parent().css("font-weight", "bold");
	doLoadResult(true);
	if (!arg) {
		//if ($j(".contentpaneopen-livecomment").length > 0) 
		  if ($j("td.contentheading:contains('LIVE!')").length == 1)
			top.location.reload(true);
	}
}

function doLoadResult(arg) {
	if (!arg) {
		if ($j(".contentpaneopen-livecomment").length > 0) 
			top.location.reload(true);
	}
	$j("#liveresult").hide().load("http://www.fcmatera.it/result_table.html?&rand="+Math.random(1970));
	$j("#liveresult").fadeIn("slow"); 
	
}