/*
  main.js - SAPO Desport Javascript file
 */

/*
 Variables
 */

var
	textSize = 1.1,
	mrecTag = null,
	tab_list = [];



/*
  Article font size +/-
 */

function biggerText ( ) {

	textSize += 0.1;
	applyTextSize();
	saveTextSize();

	return false;

}

function lowerText ( ) {

	textSize -= 0.1;
	applyTextSize();
	saveTextSize();

	return false;

}

function applyTextSize ( ) {

	$$(".article-intro")[0].style.fontSize = textSize+"em";
	$$(".article-txt")[0].style.fontSize = textSize+"em";

}

function loadTextSize ( ) {

	var
		size = parseFloat(getCookie("textSize"));

	if ( !size ) return;
	textSize = size;
	applyTextSize();

}

function saveTextSize ( ) {

	setCookie("textSize",textSize.toFixed(2),10);

}



/*
  Util functions
 */

// Cookies

function getCookie(name) {

	var
		allCookie = ""+document.cookie,
		ind = allCookie.indexOf(name),
		ind1;

	if (ind == -1 || name == "")
		 return null;

	ind1 = allCookie.indexOf(';',ind);
	if (ind1 == -1)
		ind1 = allCookie.length; 

	return unescape(allCookie.substring(ind+name.length+1,ind1));

}

function setCookie(name,value,days) {

	var
		today = new Date(),
		expire = new Date();

	if ( days == null || days == 0)
		days = 1;

	expire.setTime(today.getTime() + 3600000*24*days);
	document.cookie = name+"="+ escape(value) + ";expires="+expire.toGMTString();
}



/*
  Simulate a site interaction
 */

function siteInteraction ( affiliate ) {

	var
		mrec;


	// Identify MREC

	if ( ((mrec = document.getElementById('mrec')) == null) && ((mrec = document.getElementById('pub300x250')) == null) )
		return true;
	if ( mrec.nodeName.toLowerCase() == 'div' )
		mrec = (mrec.getElementsByTagName("IFRAME"))[0];

	// Refresh MREC

	if ( mrec ) {
		if ( mrecTag == null ) mrecTag = mrec.src;
		mrec.src = mrecTag;
/*
		if ( affiliate == null )
			mrec.src = mrecTag;
		else
			mrec.src = mrecTag+"&affiliate="+affiliate;
*/
	}

	// Hit Netscope

	if ( typeof(w_counter) != 'undefined' )
		w_counter.count();
	if ( typeof(nsAccounts) != 'undefined' ) {
		for ( var x = 0 ; x < nsAccounts.length ; x++ ) {
			if ( nsAccounts[x].obj ) nsAccounts[x].obj.count();
		}
	}

	return true;

}


/*
  Tabs
*/

function TabAdd(id) { tab_list.push(id); }
function TabsShow() { for(var x = 0; x < tab_list.length ; x++) new Fabtabs(tab_list[x]); }


/*
  Events
 */


// On load

function onLoad ( ) {

	loadTextSize();

}

function onDOMend ( ) {

	TabsShow();

}


// Register page load event

if (Event) Event.observe(window,"load",onLoad);



/*
  Load other useful scripts
 */

document.write("<script language=\"JavaScript\" type=\"text/javascript\" src=\"http://imgs.sapo.pt/js/DESPORTO/1.0.4/sapotabs.js\"></script>");
document.write("<script language=\"JavaScript\" type=\"text/javascript\" src=\"http://imgs.sapo.pt/js/DESPORTO/1.0.4/elements.js\"></script>");
document.write("<script language=\"JavaScript\" type=\"text/javascript\" src=\"http://imgs.sapo.pt/js/DESPORTO/1.0.4/polls.js\"></script>");
