/**
* Accessibility
*/

var fs_default   = 80;
var prefs_loaded = false;
var fs_current   = fs_default;
var skin_current = skin_default;
//
//  Modifiche Gagliardi x menù con spigoli arrotondati	(rilevazione resize dello schermo)
//
var ws;
var xfs;
var nw_100       = 272;
var doms         = new Array();

function setVal() {

	xfs = 112;
	if (ws < 800)
		ws = 800;
	else if (ws > 1280)
		ws = 1280;
	if (ws < 1003)
		xfs  = 112;
	else if (ws < 1259)
		xfs = 112;
}

function getScreen() {
	var myWidth = 0, myHeight = 0;

	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}    
//	alert(myWidth);
//	alert(myHeight);
	return myWidth;
} 

ws = getScreen();
setVal();
//
// Fine modifiche Gagliardi x menù con spigoli arrotondati 	(rilevazione resize dello schermo)
//

window.onload = prefs_load;
window.onunload = prefs_save;

function prefs_load(){
    if(!prefs_loaded){

        var c = Cookie.get('joomla_fs');
        fs_current = c ? c : fs_default;
        fs_set(fs_current);

        var s = Cookie.get('joomla_skin');
        skin_current = s ? s : skin_default;
        skin_set(skin_current);

        prefs_loaded = true;
    }
}

function prefs_save(){
        Cookie.set('joomla_fs', fs_current, {duration: 365})
        Cookie.set('joomla_skin', skin_current, {duration: 365})
}

function fs_change(diff){
    fs_current = parseInt(fs_current) + parseInt(diff * 8);
	if(fs_current > xfs){
        fs_current = xfs; 
    }else if(fs_current < 56){
        fs_current = 56;
    }
    fs_set(fs_current);
}

function skin_change(skin){
        if (skin == 'swap'){
                if (skin_current == 'white'){
                        skin = 'black';
                } else {
                        skin = 'white';
                }
        }
        skin_current = skin;
        skin_set(skin);
}

//
//  Modifiche Gagliardi x menù con spigoli arrotondati	
//
function back_dom(fs) {

	xnw = nw_100 * fs / 100;
	xem = 16 * fs/100;
	xnb = parseInt((ws-(xnw*1+xem*2)+(xem-16+((xem-16)/4)) - 1)/xem) - 1;
	
//	alert('screen:'+ws+', fs:'+fs+', nb:'+xnb+', nw:'+xnw);
	doms = document.getElementById("menu-top").getElementsByTagName("div");
	for (var x=0; x<doms.length; x++) {
		var dom = doms[x];
		if (dom.className.indexOf("moduletable_cerca") > -1)
			dom.style.width = (xnb)+'em';
	}
	for (var x=0; x<document.images.length; x++)
		if ((document.images[x].src.indexOf("back") > -1) && (document.images[x].alt.toLowerCase()=="banner"))
			document.images[x].width = xnw;
//			document.images[x].style.width = (xnw/xem)+'em';
		else if (document.images[x].name.indexOf("_img_") > -1) {
//
//  Modifiche Gagliardi x banner a larghezza liquida
//
			var c = 1, w = ws*.92;
			if (document.images[x].name.indexOf("_c_") > -1) {
				var i = document.images[x].name.indexOf("_c_") + 3;
				var l = document.images[x].name.indexOf("_img_") - i;
				if (l>0)
					c = parseInt(document.images[x].name.substr(i, l));
			}
			if (document.images[x].name.indexOf("_w_") > -1) {
				var i = document.images[x].name.indexOf("_w_") + 3;
				var l = document.images[x].name.indexOf("_c_") - i;
				if (l>0) {
					w = parseInt(document.images[x].name.substr(i, l));
					w = w * ws / 1280;
				}
			}
			document.images[x].width = (w / c);
		}
}
//
// Fine modifiche Gagliardi x menù con spigoli arrotondati e banner a larghezza liquida
//

function fs_set(fs){
//
//  Modifiche Gagliardi x menù con spigoli arrotondati (rilevazione resize dello schermo)
//
	ws = getScreen();
	setVal();
	if (fs > xfs)
		fs = xfs;
//
// Fine modifiche Gagliardi x menù con spigoli arrotondati (rilevazione resize dello schermo)
//
	fs_current = fs;
    $E('body').setStyle('font-size', fs + '%');
//
//  Modifiche Gagliardi x menù con spigoli arrotondati	
//
	back_dom(fs); 
}
//
// Fine modifiche Gagliardi x menù con spigoli arrotondati
//

function skin_set(skin){
    $E('body').setProperty('class', skin);
}
