/*zmolo.com (2010|v1.50)*/

var str_array=new Array();
var href_array=new Array();

var news_id=0;
var ind=1;
var runNews;
var currentStr;
var currentTopNewsFrame=0;
var topNewsFrameDuration=15000;
var topNewsFrames = 0;
var blinkImage="<img src='/im/blink.gif' style='margin-bottom:-2px;'>";
var scrollMargin=80;


function run_list(allnews){
	clearTimeout(runNews);
	ind=1;
	if (news_id>=allnews.length) news_id=0;
	objRun.href = href_array[news_id];
	currentStr = allnews[news_id];
	run_thru(currentStr);
}


function run_thru(val){
		if (ind<=val.length){
			objRun.innerHTML = val.substr(0,ind);
			ind ++;
			eval('runTimer='+setTimeout('run_thru("'+addslashes(val)+'")',50));
		} else {
			clearTimeout(runTimer);
			news_id++;
			eval("runNews="+setTimeout("run_list(str_array)",3000));
		}


}

function isdefined(variable) {
	return (typeof(window[variable]) == "undefined") ?  false: true;
}

function pauseRun(){
	objRun.innerHTML = currentStr;
	clearTimeout(runTimer);
	clearTimeout(runNews);
	return false;
}

function nextRun(){
	clearTimeout(runNews);
	clearTimeout(runTimer);
	news_id++;
	run_list(str_array);
	return false;
}


var popupWidth=300;

function refIm(imagename){
	var ima=document.getElementById(imagename);
	var src=ima.src;
	var regs=	/\&tst\=.*/;
	if (src.match(regs))
	{
		newshit="&tst="+Math.random();
		src = src.replace(regs,newshit);
	} else {
		src=src+"&tst="+Math.random();
	}
	ima.src = src;
	return false;
}


function putaj(){
	var fr=document.createElement('iframe');
	
	var content = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body>";

	content1="<form name=upd method=post action='/upd.php'><input type=hidden name=act value=''><input type=hidden name=passed value=''></form>";
	content += '</head>\n<body id=wsw>'+content1+'</body>\n</html>';

	fr.name="ajaxObj";
	fr.id="ajaxObj";
	fr.style.position='absolute';
	fr.style.margin=fr.style.padding='0px';
	fr.style.zIndex=1;
	fr.style.visibility='hidden';
	fr.style.display='block';
	fr.style.width=fr.style.height='0px';
	document.getElementsByTagName('body')[0].appendChild(fr);
	frm = document.getElementById ('ajaxObj');
	frm.src='/init.htm';
}


function create_fader(){
	var bodyObj=document.getElementsByTagName('body')[0];
	var fadeObj = document.createElement("div");
	fadeObj.setAttribute('id','fade');
	fadeObj.onclick = function () {destrpopcont();};
	fadeObj.style.display = 'none';
	fadeObj.style.position = 'absolute';
	fadeObj.style.top = '0';
	fadeObj.style.left = '0';
	fadeObj.style.zIndex = '20';
 	fadeObj.style.width = '100%';
	bodyObj.insertBefore(fadeObj, bodyObj.firstChild);
}



function sbmtr(formname,copyfrom,e){
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	var getfrom=document.getElementById(copyfrom);
	if (keycode == 13){
		var func = new Function;
		func = getfrom.onclick;
		func();
		return false;
	}else return true;
}





function sbmt(formname,newparam){
	if (newparam)
	{
		eval("document.forms['"+formname+"'].su.value=newparam");
	}
	
	eval("document.forms['"+formname+"'].submit()");
}


function wholePage(){
	
	var pageXscroll, pageYscroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		pageXscroll = document.body.scrollWidth;
		pageYscroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ 
		pageXscroll = document.body.scrollWidth;
		pageYscroll = document.body.scrollHeight;
	} else { 
		pageXscroll = document.body.offsetWidth;
		pageYscroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	


	if(pageYscroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = pageYscroll;
	}

	if(pageXscroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = pageXscroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight,pageXscroll,pageYscroll);
	return arrayPageSize;
}


function getPageScroll(){
	var pageYscroll;

	if (self.pageYOffset) {
		pageYscroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){
		pageYscroll = document.documentElement.scrollTop;
	} else if (document.body) {
		pageYscroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',pageYscroll); 
	return arrayPageScroll;
}


function getpopup(cond){
	var popupObj= document.getElementById ? document.getElementById("popup") : null;
	if (cond)
	{
		var coords= wholePage();
		var scroll=getPageScroll();
		var fadeObj = document.getElementById('fade');
		
		
		/*window.alert(coords[1]+'///'+coords[3]+'///'+coords[5]);*/
	
		hideNastyThings(0);
		chngvis('fade','block');
		fadeObj.style.height = (coords[1]+'px');
		
		fadeObj.style.display = 'block';

		/*popupObj.style.display = 'block';*/
		$(popupObj).fadeIn(400);

		popupObj.style.top = scroll[1]+(coords[3]-300)/2+'px';
		popupObj.style.left = (coords[0]-popupWidth)/2+'px';

	} 
	else 
	{
		popupObj.style.display = 'none';

	}

}


function fadePage(){

}


function destrpopcont() {
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
			selects[i].style.visibility = "visible";
	}

	chngvis('fade','none');
	var objPop = document.getElementById ? document.getElementById("popcont") : null;
	$('#popup').fadeOut(400,function(){objPop.innerHTML = '';});
	
	/*chngvis('popup','none'); */
	hideNastyThings(1);
	
	return false;
}

function chngvis(name,val){
	var obj = document.getElementById ? document.getElementById(name) : null;
	obj.style.display=val;

	var objok = document.getElementById ? document.getElementById('oks') : null;
	var objerror = document.getElementById ? document.getElementById('error') : null;
	
	if (objok)
	{
		objok.style.display='none';
	}

	if (objerror)
	{
		objerror.style.display='none';
	}

	return false;
}


function hideNastyThings(condition){

	var visibility = (condition==1) ? 'visible' : 'hidden'; 

	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
			//alert("getpopup");
			selects[i].style.visibility = visibility;
	}

	flashes = document.getElementsByTagName("object");
	for (i = 0; i != flashes.length; i++) {
			flashes[i].style.visibility = visibility;
	}
	
}


function getA(actpar,val,clockholder){
	var objaj = document.getElementById ? document.getElementById("ajaxObj") : null;
	var obJholder = document.getElementById ? document.getElementById(clockholder) : null;
	obJholder.style.display='block';

	var Owidth =	($(obJholder).width()-16)/2;
	var Oheight =	($(obJholder).height()-16)/2;

	
	obJholder.innerHTML="<img src='/im/clock4.gif' style='margin:"+Oheight+"px "+Owidth+"px;text-align:center;'>";

	$(obJholder).fadeIn(200);
	objaj.src = "/upd.php?act="+actpar+"&value="+val+"&tst="+Math.random();
	return false;
}

function setvalue(name,value){
	var obj = document.getElementById ? document.getElementById(name) : null;
	if (obj == null) return;
	
	obj.innerHTML = value;
}

function setvalue1(formname,elementname,elvalue){
	eval("document.forms['"+formname+"']."+elementname+".value = elvalue");
}




function SS(frm,alert){
	if (!(alert))
	{	
		Calert("Checking ....");
	} else {
		Cmessage("Checking ....");
	}
	
	document.forms[frm].submit();
	return false;
}



function addslashes(str) {
/*str=str.replace(/\'/g,'\\\'');*/
str=str.replace(/\"/g,'\\\"');
/*str=str.replace('/\\/g','\\\\');*/
/*str=str.replace(/\0/g,'\\0');*/
return str;
}



function stripslashes(str) {
str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"');
str=str.replace(/\\\\/g,'\\');
str=str.replace(/\\0/g,'\0');
return str;
}



function Calert(message,okbt){
	var error_content = document.getElementById('popcont');
	var popup = document.getElementById('popup');
	var top = document.getElementById('toppop');
	var ssubmit = document.getElementById('popupsubmit');
	ssubmit.className='sbmt1';
	popup.className='';
	top.className='';
	error_content.className='';
	if (okbt)
	{
		ssubmit.style.display='none';
	} else {
		ssubmit.style.display='inline';
	}
	getpopup(1);
	error_content.innerHTML = message;
}



function Cmessage(message,okbt){
	var error_content = document.getElementById('popcont');
	var popup = document.getElementById('popup');
	var top = document.getElementById('toppop');
	var ssubmit = document.getElementById('popupsubmit');
	ssubmit.className='sbmt';
	popup.className='okout';
	top.className='okbg';
	error_content.className='oktext';
	
	if (okbt)
	{
		ssubmit.style.display='none';
	} else {
		ssubmit.style.display='inline';
	}


	getpopup(1);
	error_content.innerHTML = message;
}





function Clearemail(){
	for (var i=1; i<=7; i++)
	{
		eval ("document.forms['ad'].email_"+i+".value='';");
	}
}


function chUp(action,formname,showalert){
	if (!(showalert))
	{
		Cmessage("<br><img src='/im/clock4.gif'><br><br>",1);
	} else {
		var processing = document.forms[formname].processing.value;
		Cmessage(processing,1);
	}
	
	var objScript = document.getElementById ? document.getElementById("ajaxObj") : null;
	var reqLine='';
	var currform	=	eval("document."+formname);
	for(var i=0;i<currform.length;i++){
		reqLine+=currform[i].name+"="+escape(currform[i].value)+"&";
	}
	reqLine+="&frm="+formname+"&timestamp="+Math.random();
	objScript.contentWindow.document.forms['upd'].passed.value = reqLine;
	objScript.contentWindow.document.forms['upd'].act.value = action;
	objScript.contentWindow.document.forms['upd'].submit();
	return false;
}



function chPg(contid,newsid,page,language,showalert){
	if (!(showalert))
	{
		Cmessage("Processing ...",1);
	}
	
	var objScript = document.getElementById ? document.getElementById("ajaxObj") : null;
	var reqLine='';

	reqLine= "/upd.php?lng="+language+"&contid="+contid+"&commentnewsid="+newsid+"&pg="+page+"&act=chpage&timestamp="+Math.random();
	objScript.src = reqLine;

	return false;
}




function chgLoc(loc){
	var timerA;
	timerA=setTimeout(document.location.href=loc, 500);
}




function initAnchors()
{
	
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];

		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "iinfo")){
			anchor.onmouseover = function () {showTip1(this); return false;};
			anchor.onmouseout = function () {hideTip1(); return false;};
		} 

		else if (anchor.getAttribute("rel") == "frametmb" || anchor.getAttribute("rel") == "fheader") {
			 anchor.onmouseover = function () {viewSlide(this.id); return false;};
			 anchor.onmouseout = function () {runSlide(this.id);	return false;};
		}

		else if (anchor.getAttribute("rel") == "zoomer") {
			 anchor.onclick = function () {scaleText(this.id); return false;};
		}
	}

	var divs = document.getElementsByTagName("div");
	for (var i=0; i<divs.length; i++){
		var div = divs[i];

		if (div.getAttribute("rel") == "fheader") {
			 div.onmouseover = function () {viewSlide(this.id); return false;};
			 div.onmouseout = function () {runSlide(this.id);	return false;};
		}
	}


	var objBody = document.getElementsByTagName("body").item(0);
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','tip');
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.zIndex = '90';
	
	objBody.insertBefore(objOverlay, objBody.firstChild);
}



function viewSlide(id){

	clearTimeout(frameTimer);
	if (window.continueTimer !==undefined)
	{	
		clearTimeout(continueTimer);
	}
	

	var iid = id.replace(/frametmb([^>]*)/gi, '$1');

	if (!isInteger(iid))
	{
	   iid = id.replace(/mainlink([^>]*)/gi, '$1');
	   
	}

	if (!isInteger(iid))
	{
	   iid = id.replace(/topnews([^>]*)/gi, '$1');
	   
	}


	if (!isInteger(iid))
	{
	   iid = id.replace(/framecontainer([^>]*)/gi, '$1');
	   
	}

	for (var i=1; i<=topNewsFrames;i++ )
	{
		var topnews_name='#topnews'+i;
		var frame_name='#framecontainer'+i;
		var tmb='#frametmb'+i;

		if (i !== parseInt(iid))
		{
			$(topnews_name).hide();
			$(frame_name).hide(); 
			$(tmb).removeClass('active');
		} else {
			$(topnews_name).show().animate({marginTop:'0px'},500);
			$(frame_name).show().animate({marginTop:'0px'},500);
			
			currentTopNewsFrame=i;
			
		}
	}


}


function runSlide(id){

	var iid = id.replace(/frametmb([^>]*)/gi, '$1');
	continueTimer=setTimeout('startTopNewsAnimation()',200);
}



function loadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}


function showTip1(obj){
	var tipid=obj.getAttribute("id");
	if (tipid == '1')
	{
		objtxt='Invite this team to join your Mini Leagues.';
		showtip('tip',objtxt,obj);
	}
	
}

function hideTip1(){
	var ObjTip = document.getElementById ? document.getElementById('tip') : null;
	ObjTip.style.display='none';
	
}

function showtip(tipid,objtxt,obj){
	var ObjTip = document.getElementById ? document.getElementById(tipid) : null;
	ObjTip.style.top = obj.offsetTop-45;
	ObjTip.style.left = obj.offsetLeft+50;
	if (ObjTip.style.display == 'none') 
	{
		
		ObjTip.style.display='block';
		ObjTip.innerHTML="<div>"+objtxt+"</div>";
	}
	
}

function hidetip(){	
	str='hideLayer()';				
	timerB=setTimeout('eval(str)', 500);
}

function hideLayer(){
	var ObjTip = document.getElementById ? document.getElementById("tip") : null;
	var objScript = document.getElementById ? document.getElementById("tipcontainer") : null;
	ObjTip.style.visibility="hidden";objScript.src = "/tip.php";

}


function updatetip(name,value){
	var obj = document.getElementById ? document.getElementById(name) : null;
	obj.innerHTML = value;
	$('body').scrollTo( '#commentstart', 800, {queue:true} );
	/*$('body').scrollTop('commentstart')*/;
}


function listnews(name,value){
	var obj = document.getElementById ? document.getElementById(name) : null;
	$('body').scrollTo( '#headline', 800, {queue:true} );
	obj.innerHTML = value;
	
	/*$('body').scrollTop('commentstart')*/;
}

function movetip(obj){
	var ObjTip = document.getElementById ? document.getElementById("tip") : null;
	ObjTip.style.top=obj.clientY+document.body.scrollTop;
	ObjTip.style.left=obj.clientX+document.body.scrollLeft-250;
}



function switchTab(setName,tabID,tabsQty){
	for (var i=1; i<=tabsQty; i++)
	{

		var block	= document.getElementById("hold_"+setName+i);
		var tab		= document.getElementById(setName+i);
		if (tabID == i)
		{	
			 
			 var name="hold_"+setName+i;
			 /*new Effect.Appear(name, { duration: 0.3 });*/
			/* $(name).appear();*/
			
			/*$("hold_"+setName+i).fade({ duration: 3.0, from: 0, to: 1 });
			new Effect.Opacity("hold_"+setName+i, { from: 1.0, to: 0.7, duration: 0.5 });
			block.style.display='block';
			*/
			/* */	
		
			$(block).fadeIn(400);
			/*$(block).animate({marginLeft:'+=200'},2000);	 */
			tab.className = setName+' opn';
		}
		else {
			
			
			block.style.display='none';
			tab.className = setName;
		}
		
	}
	
}

function startTopNewsAnimation(){
		if (!topNewsFrames)
		{
			var fframes =  document.getElementsByTagName("a");
			for (var i=0; i<fframes.length; i++){
				var fframe = fframes[i];
				if (fframe.getAttribute("rel") == "topframe")
				{
					fframe.onmouseover = function () {viewSlide(this.id); return false;};
					fframe.onmouseout = function () {runSlide(this.id);	return false;};
					topNewsFrames++;
				}
			}
			currentTopNewsFrame =1;
			
		}
		
		else 
		{
			navTopNews(1);
		}

		eval('frameTimer='+setTimeout('startTopNewsAnimation()',topNewsFrameDuration));
		
}

function navTopNews(direction) {

	if (Math.abs(direction)>=topNewsFrames) return false;
	var nextFrame = currentTopNewsFrame+direction;
	if (nextFrame <1) nextFrame += topNewsFrames;
	if (nextFrame >topNewsFrames) nextFrame -= topNewsFrames;
	var currFram = document.getElementById("topnews"+currentTopNewsFrame);
	var nextFram = document.getElementById("topnews"+nextFrame);
	var currText = document.getElementById("framecontainer"+currentTopNewsFrame);
	var nextText = document.getElementById("framecontainer"+nextFrame);
	var currTmb =	document.getElementById("frametmb"+currentTopNewsFrame);
	var nextTmb =	document.getElementById("frametmb"+nextFrame);

	currentTopNewsFrame = nextFrame;
	$(currText).fadeOut(400, function(){	
		 currTmb.className='';
		 $(currFram).fadeOut(400,function() {
			$(this).hide();
			$(nextText).fadeIn(100);
			$(nextFram).fadeIn(200);
			nextTmb.className='active';
		});
		$(this).hide();

	});


	/*$(currText).animate({marginRight:'-220px'},200,function() {
		$(this).hide();
		$(nextFram).fadeIn(200);
		$(nextText).show().animate({marginRight:'-0px'},200); 	
	});	*/


	
}

function navNews(direction){
	clearTimeout(frameTimer);
	navTopNews(direction);
}

function scaleText(direction){
	var container = document.getElementById('read');
	container.className= direction;
}

function showCommentForm(){
	var cform = document.getElementById('commentform');
	$(cform).fadeIn(400);
	
	$('body').scrollTo( 
						'#commentstart', 800,function(){$("#addcomment").fadeOut(400);} , {queue:true});
	

	$("#emptycomm").hide();
	

}

function listHeadlineNews(direction){
	var actpar='listnews';
	var val=document.forms.listnews.lng.value+','+
			document.forms.listnews.rubric_id.value+','+
			direction+','+
			document.forms.listnews.limits.value
		;
	/*window.alert(val); */
	$("#headline").fadeOut(200,function() {getA(actpar,val,'headline')});
	return false;
}


function refresh(){
	var actpar='listnews';
	var val=document.forms.listnews.lng.value+','+
			document.forms.listnews.rubric_id.value+','+
			''+','+
			''
		;
	/*window.alert(val);*/
	$("#headline").fadeOut(200,function() {getA(actpar,val,'headline')});
	return false;
}



function showAd(){
	if (showAdValue)
	{
		/*showOverlay(1);  */
		var objLightbox = document.getElementById ? document.getElementById("splash") : null;

		var selects = document.getElementsByTagName("select");
		for (i = 0; i != selects.length; i++) {
				selects[i].style.visibility = "hidden";
		}

		var arrayPageSize = wholePage();
		var arrayPageScroll = getPageScroll();
		var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3]  - 300) / 2);
		var lightboxLeft = ((arrayPageSize[0] - 20-500) / 2);
			
			objLightbox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
			objLightbox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";

			objLightbox.style.display='block';
		return false;
	}
	return false;
}


function hideAd(){
		var obj = document.getElementById ? document.getElementById("splash") : null;
		obj.innerHTML='';
		obj.style.display='none';
		/*showOverlay(0); */
		var selects = document.getElementsByTagName("select");
		for (i = 0; i != selects.length; i++) {
				selects[i].style.visibility = "visible";
		}
		return false;
}


function isInteger(s) {
  return (s.toString().search(/^-?[0-9]+$/) == 0);
}



$(document).ready(function(){
	if (window.loadScroll !== undefined) 
	{
		scrollMargin = $('#prevnext-read').offset().top-$('#prevnext-read').outerHeight()+80;
		$(window).scroll(set_scroll);
	}
	
	initAnchors();
	startTopNewsAnimation(); 
	showAd();

});


	

/*loadEvent(initAnchors);*/
/*loadEvent(startTopNewsAnimation);*/
