function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Non è stato possibile impostare un gestore di eventi");
  }
}
//addEvent(window,'load',function (){swapMenu.init()},false);
addEvent(window,'load',init,false);

function init(){
	swapMenu.init();
	if(document.getElementById("print-scheda")){
		btnPrint = document.getElementById("print-scheda");
		btnPrint.onclick = function(){printScheda();}
		}
	if(document.getElementById("tool-swf")){
		writeTool();
		}	
	}


function getElementsByClass(searchClass,node,tag) {
    var classElements = new Array();
    if ( node == null )
        node = document;
    if ( tag == null )
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
    for (i = 0, j = 0; i < elsLen; i++) {
        if ( pattern.test(els[i].className) ) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}


var swapMenu={
pathImg : "/img/menutop/",
theBtn : null,
init : function(){
		var cmenu=document.getElementById('menu-top');
		var theImgs=cmenu.getElementsByTagName('img');
		for(i=0;i<theImgs.length;i++){
			swapMenu.theBtn=theImgs[i];
			var theLi=theImgs[i].parentNode.parentNode;
			if (theLi.className!='on') {
				theImgs[i].onmouseover=function(){swapMenu.fover(this)};
				theImgs[i].onmouseout=function(){swapMenu.fout(this)};
				continue;
				}
			}
		},
fover : function(el){
	
		var nome_img=el.id;
		el.src=this.pathImg+nome_img+"_on.jpg";

		},
fout : function(el){
		var nome_img=el.id;
		el.src=this.pathImg+nome_img+"_off.jpg";
		}

	}

function writeFlash(container,src,title,width,height,version,bgcolor){
	//alert("in");
	// <![CDATA[
	fo = new FlashObject(src, title, width, height, version, bgcolor);
	fo.addParam("quality", "high");
	fo.addParam("wmode", "transparent");
	//Per inserire flashvars:
	//fo.addVariable("msg", stringaF);
	fo.addParam("play","true");
	fo.write(container);
	// ]]>
}
	
function writeIeSwf(){
    theObjects = document.getElementsByTagName("object");
    for (var i = 0; i < theObjects.length; i++) {
    theObjects[i].outerHTML = theObjects[i].outerHTML;
}	
	}
	
function printScheda(){
	self.print();
	}
	
function writeTool(){
	
	//var fo = new FlashObject("http://www.pernigotti.it/swf/prodotti_ita_files/prodotti_ita_main.swf", "ToolProdotti", "700", "560", "8", "#FFFFFF");
	var fo = new FlashObject("http://cqpernigotti.domino.it/swf/prodotti_ita_files/prodotti_ita_main.swf", "ToolProdotti", "700", "560", "8", "#FFFFFF");
	//fo.addVariable("movieToLoad", "http://www.pernigotti.it/swf/prodotti_ita_files/prodotti_ita_main.swf");
	fo.addVariable("movieToLoad", "http://cqpernigotti.domino.it/swf/prodotti_ita_files/prodotti_ita_main.swf");
	fo.addParam("scale", "noscale");
	fo.addParam("quality", "high");
    fo.addParam("wmode", "transparent");
	fo.addParam("quality","high");
	fo.write("tool-swf");
	}	
