/* Nome Cliente 	il Mosnel */
/* Creato:			19/02/2009 */
/* Autore:			simone@evoluzionetelematica.it */
/* Ultima Modifica:	gg/mm/aaaa	Autore: Nome Cognome */

//<![CDATA[

var ilmosnel = {

    // Utilizzare una variabile per fare riferimento al file SWF incorporato.
	

	startLoad: function(){
		if ($('flashContent') && ilmosnel.flashDetect()) ilmosnel.injectFlash();
		if ($$('.scroll') != '') ilmosnel.scrollbar();
		if ($('banner')) ilmosnel.initBanner();
		if ($('depliant')) ilmosnel.initDepliant();
	},
	
	startDomReady: function(){

		var deviceIphone = "iphone";
		var deviceIpod = "ipod";
		//Initialize our user agent string to lower case.
		var uagent = navigator.userAgent.toLowerCase();
		
		//**************************
		// Detects if the current device is an iPhone.
		if (!(uagent.search(deviceIphone) > -1))
			if ($$('.boxed') != '') ilmosnel.initSqueezeBox()


		//if ($('flashContent')) ilmosnel.injectFlash()
		
		if ($$('.tips') != '') ilmosnel.toolTip()

		if (ilmosnel.flashDetect())
		{
			//$('flashContent').setStyle('background', 'none');
			$('flashContent').addClass("loading")
		}
	},	

	// metodo usato per ottenere il percorso giusto in base alla posizione
	returnPath: function()
	{
		var path = location.pathname;
		var li = path.length;
		var lf = path.replace(/\//g,'').length;
		// Windows var n = li-lf-2;
		var n = li-lf-1;
		var resultPath = "";
		
		for(var i=0; i<n; i++)
		{
		  resultPath += "../";
		}
		
		return resultPath
	}, // fine returnPath
	
	injectFlash: function() // inietto il file swf nel codice
	{
		// calcolo le dimensioni da assegnare al movie, "flashContent" varia in base alle sezioni
		var w = $('flashContent').getStyle('width').toInt();
		var h = $('flashContent').getStyle('height').toInt();
		var swf = ilmosnel.returnPath() + 'swf/main.swf';
		
		var myFlash = new Swiff(swf, {
			id: "main",
			width:  w,
			height: h,
			container: $('flashContent'),
			vars:
			{
				path: ilmosnel.returnPath(),
				xmlFile: _xmlFile,
				menuAttivo: _menuAttivo
				//xmlPath: ilmosnel.returnPath() + 'xml/'+_xmlPath+'.xml',
			},
			params:
			{
				salign: "lt"
    		},
			events:
			{
				onLoad: function() {
					// elimino l'img di fondo che funge da loader
					$('flashContent').setStyle('background', 'none');
				}
			}
		});
	},// end unjectFlash
	
	
	initBanner: function() // Usata per la Scrollbar dei testi
	{
		var bannerList = $$('#banner li.banner1')
		
		bannerList.each(function(element) {
			
			element.set('tween', {duration: 900});
			element.tween('margin-left', '432');
			
			element.addEvents({
				'mouseenter': function(){
					element.tween('margin-left', '0');
				},
				'mouseleave': function(){
					element.tween('margin-left', '432');
				}
			});
		
		})


		var bannerList2 = $$('#banner li.banner2')
		
		bannerList2.each(function(element) {
			
			element.set('tween', {duration: 900});
			element.tween('margin-left', '432');
			
			element.addEvents({
				'mouseenter': function(){
					element.tween('margin-left', '272');
				},
				'mouseleave': function(){
					element.tween('margin-left', '432');
				}
			});
		
		})


	},

	initDepliant: function() // Usata per la Scrollbar dei testi
	{
		var depliant = $$('#depliant ul')
		
		depliant.set('tween', {duration: 900});
		depliant.tween('margin-bottom', '-110');
		
		depliant.addEvents({
			'mouseenter': function(){
				depliant.tween('margin-bottom', '0');
			},
			'mouseleave': function(){
				depliant.tween('margin-bottom', '-110');
			}
		});		
		
		/*
		bannerList.each(function(element) {
			
			element.set('tween', {duration: 900});
			element.tween('margin-left', '220')
			
			element.addEvents({
				'mouseenter': function(){
					element.tween('margin-left', '0');
				},
				'mouseleave': function(){
					element.tween('margin-left', '220');
				}
			});
		
		})
		*/

	},
	
	scrollbar: function() // Usata per la Scrollbar dei testi
	{
		var myScroll = new MooScroll({selector:'.scroll', disabledOpacity:0});
	},
	

	initSqueezeBox: function() // Inizializzo lo squuezebox x effetto lightbox x iFrame
	{
		SqueezeBox.assign($$('.boxed'), {
			parse: 'rel'
		});
	}, // Fine initSqueezeBox()
	
	toolTip: function () 
	{
		var tooltips = $$('.tips');
		 
		var toolTips = new Tips(tooltips, {
			showDelay: 100,    //default is 100
			hideDelay: 100,   //default is 100
			className: 'tips', //default is null
			//this sets the x and y offets
			offsets: {
				'x': -100,       //default is 16
				'y': -45        //default is 16
			},
			fixed: false,      //default is false
			onShow: function(toolTipElement){
				toolTipElement.fade(1);
			},
			onHide: function(toolTipElement){
				toolTipElement.fade(0);
			}
		});


	}, // fine tooltip
	
	flashDetect: function()
	{
	
		flash_versions = 10;
		flash_installed = false;
		flash_version = '0.0';
		
		// Netscape style plugin detection
		if (navigator.plugins && navigator.plugins.length) {
			for (x = 0; x < navigator.plugins.length; x++) {
				if (navigator.plugins[x].name.indexOf('Shockwave Flash') != -1) {
					flash_version = navigator.plugins[x].description.split('Shockwave Flash ')[1];
					flash_installed = true;
					break;
				}
			}
		}
		// ActiveX style plugin detection
		else if (window.ActiveXObject) {
			for (x = 2; x <= flash_versions; x++) {
				try {
					oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + x + "');");
					if (oFlash) {
						flash_installed = true;
						flash_version = x + '.0';
					}
				}
				catch(e) { }
			}
		}
		
		return flash_installed;
	}
	
	
} // chiusura classe ilMosnel

///////////////////////////////////////////////////////

window.addEvent('domready', ilmosnel.startDomReady);
window.addEvent('load', ilmosnel.startLoad);
//]]>
