/* -c- Casaccia Danilo */

//Opacità onmouseover and onmouseout sulle immagini della classe "paragrafo"
function init(){
	var allImg = document.getElementsByTagName("IMG");
	for (i=0;i<allImg.length;i++)
		if(allImg[i].className=="paragrafo"){
			if(allImg[i].addEventListener){
				allImg[i].style.opacity="0.70";
				allImg[i].addEventListener("mouseover",function (){this.style.opacity='1.0';}, false);
				allImg[i].addEventListener("mouseout",function (){this.style.opacity='0.70';}, false);
			}else if (allImg[i].attachEvent){
				allImg[i].style.filter="alpha(opacity=50)";
				allImg[i].attachEvent("onmouseover",(function (obj){return function (){obj.style.filter="alpha(opacity=100)"}})(allImg[i])); 
				allImg[i].attachEvent("onmouseout",(function (obj){return function (){obj.style.filter="alpha(opacity=70)"}})(allImg[i])); 
			}
	}
	//Cambio sfondo per la giusta risoluzione
	changeBackground();
    
    //Se internet explorer 6, aggiusto altezze
    if(getInternetExplorerVersion()=="6") setHeight();

    //Inizializza scrollbar personalizzate 
    $(function() {		    
        $('#scrollDx').jScrollPane({showArrows:true,scrollbarWidth: 11, arrowSize: 11});			
        $('#scrollSx').jScrollPane({showArrows:true,scrollbarWidth: 11, arrowSize: 11});			
    });  
}
//Cambia sfondo
function changeBackground(){

	//Calcolo risoluzione
	var res = (screen.width <=1680) ? "1680/" : ((screen.width <= 1920) ? "1920/" : "2560/" );

	//Identifica browser opera, eventualmente aggiusta il path	
	var s = (navigator.userAgent.indexOf('Opera') != -1) ? "Stile/" : "";

	//Navigo le regole CSS e cambio sfondo		
	cssPropertySet ("html","background","url(\""+s+res + "texture.jpg\") no-repeat fixed 0% 0% transparent");
	cssPropertySet ("#contenuto","background","url(\""+s+res + "texture_blur.jpg\") no-repeat fixed 0% 0% transparent");	
}
//Modifica proprietà CSS
function cssPropertySet (tag,selector,property){

	//Leggo regole CSS definite
	if (document.styleSheets[0].cssRules)
		var cssRules = document.styleSheets[0].cssRules;
	else if (document.styleSheets[0].rules)
		var cssRules = document.styleSheets[0].rules;  
		
	//Navigo le regole di stile, cerco il tag e setto la proprietà al selettore	
	for(i=0; i < cssRules.length; i++)
		if(cssRules[i].selectorText == tag || cssRules[i].selectorText == tag.toUpperCase())		
			cssRules[i].style[selector] = property;
}
//Ritorna la versione di Internet Explorer
function getInternetExplorerVersion(){
    var rv = -1; 
    if (navigator.appName == 'Microsoft Internet Explorer') {
    	var ua = navigator.userAgent;
        var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat( RegExp.$1 );
    }  
    return rv;
}
//Calcola altezze per Internet Explorer 6
function setHeight(){
    var bodyH = document.documentElement.clientHeight;
    var bodyW = document.documentElement.clientWidth;
    document.getElementById("contenuto").style.height=(bodyH-115)+"px"; 
    document.getElementById("cFooter").style.top=(bodyH-115)+"px"; 
    document.getElementById("rightbox").style.height=(bodyH-145)+"px";
    document.getElementById("leftbox").style.height=(bodyH-235)+"px";
    document.getElementById("scrollDx").style.height=parseInt(document.getElementById("rightbox").offsetHeight / 100 * 96)+"px";
    document.getElementById("scrollSx").style.height=parseInt(document.getElementById("leftbox").offsetHeight / 100 * 96)+"px";
}   
//Inizializza scrollbar al refresh
function refresh(){
    
    //Rimuovo scrollbar
    $('#scrollDx').jScrollPaneRemove();
    $('#scrollSx').jScrollPaneRemove();

    //Se internet explorer 6, aggiusto altezze
    if(getInternetExplorerVersion()=="6") setHeight();

    //Ri-inizializzo scrollbar
    $('#scrollDx').jScrollPane({showArrows:true,scrollbarWidth: 11, arrowSize: 11});    
    $('#scrollSx').jScrollPane({showArrows:true,scrollbarWidth: 11, arrowSize: 11});
}
//Associo funzioni ad eventi
//window.onload=init;
//window.onresize = refresh;
$(document).ready(function() {
    init();
});
$(window).resize(function() {
    refresh();
});

