
// This Javascript is written by Peter Velichkov (http://blog.creonfx.com)
// and is distributed under the following license : http://creativecommons.org/licenses/by-sa/3.0/
// Use and modify all you want just keep this comment. Thanks
// Modified by Ali Aougar : www.vigisante.com

var headID = document.getElementsByTagName("head")[0];
var cssNode = document.createElement("style");
cssNode.type = 'text/css';
cssNode.id="resizingText";

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function loadCss(vSz){
	try{
		var cssStr = '\
		#thebody {font-size:' + vSz +'px;}\
		';
		if(cssNode.styleSheet){
			cssNode.styleSheet.cssText = cssStr; // for IE
		} else {
			var cssText = document.createTextNode(cssStr);
			cssNode.appendChild(cssText); // breaks ie
			//cssNode.innerHTML = cssStr; // breaks saffari
		}
		if(!document.getElementById("resizingText"))headID.appendChild(cssNode);
	}catch(err){ 
		// some debugging code
	}
	Vigi_boldSelectedAnchor(vSz);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function Vigi_boldFontSize(){
	var vSavedSz = readCookie('textsize')
	if (vSavedSz && vSavedSz!='') {
		vSavedSz = parseInt(vSavedSz);
		loadCss(vSavedSz);
	} 
	else{
		createCookie('textsize',13,1); 
		loadCss(13);
	}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function Vigi_setFontSize() {

	var vSavedSz = readCookie('textsize')
	if (vSavedSz && vSavedSz!='') 
	{
		vSavedSz = parseInt(vSavedSz);
		switch (vSavedSz){
		case 13: 
			vSavedSz = 15;
			break;
		case 15: 
			vSavedSz = 17;
			break;
		case 17:
			vSavedSz = 13;
			break;
		default:
			vSavedSz = 13;
		}	
		loadCss(vSavedSz);
		createCookie('textsize',vSavedSz,1); 
	}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function Vigi_getElById(idVal)
{
	if (document.getElementById != null){
		return document.getElementById(idVal);
	}else{
		if (document.all != null)
			return document.all[idVal];
		else
			return null;
	}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function Vigi_boldSelectedAnchor(vSz)
{
	var vImgObj1 = Vigi_getElById('aa1');
	var vImgObj2 = Vigi_getElById('aa2');
	var vImgObj3 = Vigi_getElById('aa3');
	
	switch (vSz){
	case 13: 
		if (vImgObj1 != null){
			vImgObj1.style.fontSize = '13px';
			vImgObj1.style.fontWeight = 'bolder';
		}
		if (vImgObj2 != null){
			vImgObj2.style.fontSize = '15px';
			vImgObj2.style.fontWeight = '';
		}
		if (vImgObj3 != null){
			vImgObj3.style.fontSize = '17px';
			vImgObj3.style.fontWeight = '';
		}
		break;
	case 15: 
		if (vImgObj1 != null){
			vImgObj1.style.fontSize = '13px';
			vImgObj1.style.fontWeight = '';
		}
		if (vImgObj2 != null){
			vImgObj2.style.fontSize = '15px';
			vImgObj2.style.fontWeight = 'bolder';
		}
		if (vImgObj3 != null){
			vImgObj3.style.fontSize = '17px';
			vImgObj3.style.fontWeight = '';
		}
		break;
	case 17:
		if (vImgObj1 != null){
			vImgObj1.style.fontSize = '13px';
			vImgObj1.style.fontWeight = '';
		}
		if (vImgObj2 != null){
			vImgObj2.style.fontSize = '15px';
			vImgObj2.style.fontWeight = '';
		}
		if (vImgObj3 != null){
		
			vImgObj3.style.fontSize = '17px';
			vImgObj3.style.fontWeight = 'bolder';
		}
		break;
	default:
		if (vImgObj1 != null){
			vImgObj1.style.fontSize = '13px';
			vImgObj1.style.fontWeight = 'bolder';
		}
		if (vImgObj2 != null){
			vImgObj2.style.fontSize = '15px';
			vImgObj2.style.fontWeight = '';
		}
		if (vImgObj3 != null){
			vImgObj3.style.fontSize = '17px';
			vImgObj3.style.fontWeight = '';
		}
	}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//function eraseCookie(name) {
//	createCookie(name,"",-1);
//}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//eraseCookie('textsize');

