﻿lang ="it_IT";

elementi = new Array();
ordCall = 0;

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}





function embedswfobject(swf,divId, width, height, ver ,atuoupdate ,flashVars,params,attributes) {
	
	swfobject.embedSWF(swf,divId, width, height, ver ,atuoupdate ,flashVars,params,attributes) ;
	
}



/*
function ReplaceHeaders(){
	headline_img_name = jQuery("div.visual h2").html().replace(/ /g,"_")+".png";
	headline_img_url = "../media/img/"+lang+"/heading/"+headline_img_name;
	callback = function() {
	
		jQuery("div.visual h2").html("<img src=\""+headline_img_url+" \" />");
		jQuery("div.visual h2 img").ifixpng();	
	
	}
	
	tmp = new Image;
	jQuery(tmp).load (callback);
	tmp.src = headline_img_url;

}
*/

function ReplaceH(sel,objtag)
{
	jQuery(sel).each(
		function()
		{
			headline_img_name = jQuery(this).html().replace(/ /g,"_")+".png"; 
			headline_img_url = "../media/img/"+lang+"/" + objtag + "/"+headline_img_name;
			callback = function() {
				jQuery(sel).html("<img class=\"" + objtag + "_replaced\" src=\""+headline_img_url+" \" />");
				jQuery(sel + " img").ifixpng();	
			}
			
			tmp = new Image;
			jQuery(tmp).load (callback);
			tmp.src = headline_img_url;
		}
	);
}


function ReplaceHe(sel,objtag)
{
    //var elementi = new Array();
    elementi[ordCall] = new Array();
    count = 0;
	jQuery(sel).each(
		function()
		{
            count++;
            elementi[ordCall][count] = jQuery(this);  
            elemento = elementi[ordCall][count];
            elemento["hin"] = jQuery(this).html().replace(/ /g,"_")+".png";
            elemento["hiu"] = "../media/img/"+ lang + "/" + objtag + "/"+ elementi[ordCall][count]["hin"];
            elemento["sel"] = sel;
            elemento["tag"] = objtag;
            elemento["tmp"] = new Image;
			elemento["tmp"].hin = jQuery(this).html().replace(/ /g,"_")+".png";      
            elemento["tmp"].hiu = "../media/img/"+ lang + "/" + objtag + "/"+ elementi[ordCall][count]["hin"];
			elemento["tmp"].sel = jQuery(this);
			elemento["tmp"].selstring = sel;
			elemento["tmp"].tag = objtag;

            function callback(event)
            {             
         
           
         	 	
             jQuery(event.currentTarget.sel).html("<img class=\"" + event.currentTarget.tag  + "_replaced\" src=\"" + event.currentTarget.hiu + " \" />");
 			 jQuery(event.currentTarget.selstring + "img").ifixpng();
            
			}

			/*headline_img_name = jQuery(this).html().replace(/ /g,"_")+".png"; 
			headline_img_url = "../media/img/"+lang+"/" + objtag + "/"+headline_img_name;
			callback = function() {
				jQuery(sel).html("<img class=\"" + objtag + "_replaced\" src=\""+headline_img_url+" \" />");
				jQuery(sel + " img").ifixpng();	
			}
			
			tmp = new Image;
			jQuery(tmp).load (callback);
			tmp.src = headline_img_url;*/
            
            //tmp = new Image;
            jQuery(elemento["tmp"]).load(callback);
            elemento["tmp"].src = elemento["hiu"];

		}
	);
    ordCall++;
}

function initmenu(){
		jQuery("ul.sf-menu").superfish({ 
        pathClass:  'current' 
    }); 	
}


function popup(){
  jQuery('#popup').jqm();
};





function initAllPopups() {
	popupStdClass = jQuery('#popup').attr('class');
	var popupOnShowCallback = function(hash) {

		var classList = jQuery(hash.t).attr('class');
		var classListArray = classList.split(" ");
		var modalClass="";
		for (i =0; i<classListArray.length; i++) {
			if (classListArray[i].indexOf("modal")>=0) {
				modalClass = classListArray[i].slice(5); 
			}
			
		}
		hash.w.attr('class',popupStdClass);
		
		var arrayPageScroll = getScrollXY();
		var winSizeArray = winSize();
		var popupTop = arrayPageScroll[1] + (winSizeArray[1]/20);


		hash.w.css({
		top:popupTop + 'px' });
		
		hash.w.addClass(modalClass);
		
		hash.w.fadeIn("fast"); 
		
	}
 
jQuery('#popup').jqm({ajax:"@href", trigger:'a.modpopup', toTop:true ,  onShow:popupOnShowCallback});


	
}

//utility




function getPageSize() {
	        
	    var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
	}

function winSize() {
	  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;
	  }
	return [ myWidth , myHeight];

}


function getScrollXY() {
	  var scrOfX = 0, scrOfY = 0;
	  if( typeof( window.pageYOffset ) == 'number' ) {
	    //Netscape compliant
	    scrOfY = window.pageYOffset;
	    scrOfX = window.pageXOffset;
	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	    //DOM compliant
	    scrOfY = document.body.scrollTop;
	    scrOfX = document.body.scrollLeft;
	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
	    //IE6 standards compliant mode
	    scrOfY = document.documentElement.scrollTop;
	    scrOfX = document.documentElement.scrollLeft;
	  }
	  return [scrOfX, scrOfY ];
	}


jQuery(document).ready(function(){
	
    //var elementi = new Array();

	initmenu();
	/*ReplaceH("div.visual h2","heading");
	ReplaceH("div#main h1","h1");
	ReplaceH("div#main h2","h2");
	ReplaceH("div#main h3","h3");
    ReplaceHe("div.visual h2", "heading");
    ReplaceHe("div#main h1","h1");
    ReplaceHe("div#main h2","h2");
    ReplaceHe("div#main h3","h3");*/
//	popup();
	initAllPopups();
	
//	jQuery('#popup').jqm({ajax:"../popup/prova", trigger:'a' });
	
	
//	jQuery('#vhp-racing').tabs({fxFade: true});
//	jQuery('.visual-second-lv').tabs({fxFade: true});

});












