//<![CDATA[

var Ziche = {

  // Utilizzare una variabile per fare riferimento al file SWF incorporato.

  DOMready: function () {
    if ($('#news').length > 0) { Ziche.news(); };
    if ($("a[rel=gallery]").length > 0) { Ziche.popupImg() };
    if ($('.popup').length > 0) { Ziche.popup() };

    if ($('.scroller').length > 0) { Ziche.scroller() };
    if ($('.redirectRegistrati').length > 0) { Ziche.RedirectRegistrati() };
    if ($('#staff').length > 0) { Ziche.staff() };

    if ($('.packinglist').length > 0) { Ziche.packinglist() };
    if ($('#staff-scheda').length > 0) { Ziche.staffContatta() };
    if ($('.toolTip').length > 0) { Ziche.toolTip() };
    if ($('#Mappa').length > 0) { Ziche.mappa() };
    if ($('#elenco-progetti').length > 0) { Ziche.openProgetto(); };
    if ($('.new-window').length > 0) { Ziche.OpenWindow(); };
    //
    if ($("p[rel*='traccia-registrazione']").length > 0) { Ziche.TracciamentoAnalytics('inviata-registrazione-' + lingua + '.html') }
    if ($("p[rel*='traccia-recupera-dati']").length > 0) { Ziche.TracciamentoAnalytics('inviata-recupero-dati-accesso-' + lingua + '.html') }
    if ($("p[rel*='traccia-staff-utente']").length > 0) { Ziche.TracciamentoAnalytics('inviata-informazioni-membro-staff-' + lingua + '.html') }
    if ($("p[rel*='traccia-contatti-utente']").length > 0) { Ziche.TracciamentoAnalytics('inviata-informazioni-membro-contatti-' + lingua + '.html') }
    if ($("p[rel*='traccia-freelance']").length > 0) { Ziche.TracciamentoAnalytics('inviata-freelance-' + lingua + '.html') }
    if ($("p[rel*='traccia-contatti']").length > 0) { Ziche.TracciamentoAnalytics('inviata-contatti-' + lingua + '.html') }

    if (!jQuery.browser.mobile) {
      if ($('.scroll').length > 0) { Ziche.scrollbar() };
      if ($('#elenco-prodotti').length > 0 && $('.materiale').length > 0) { Ziche.prodottiHover() };
      if ($('.video').length > 0) { Ziche.videoPlayer('player', 'http://www.ziche.com/swf/flowplayer-3.2.5.swf') }
      // decommentare x test su FF
      //$('html').addClass('mobile');
      //Ziche.mobile();

    }
    else {
      $('html').addClass('mobile');
      Ziche.mobile();
    }

  }, // fine DOMReady

  // 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
  /*
  flashInclude: function(obj, swfFile)
  {
  $(obj).flash( 
  { 
  // test.swf is the flash document 
  swf: swfFile,
  id: "movie",
  name: "movie",
  width: 800,
  height: 450,
  wmode: 'transparent',
  expressInstaller: 'swf/expressInstall.swf', // optional and temporary	
  flashvars:
  { 
  // VARS
  }			
  })
		
  }, // fine flashInclude
  */
  videoPlayer: function (obj, swfFile) {

    $(".video").css('clip', 'rect(0px 800px 380px 420px)')

    flowplayer(
			obj, { src: swfFile, wmode: 'transparent' },
			{
			  autoPlay: false,
			  play: { replayLabel: '', replayButton: 'none' },
			  clip:
				{
				  onStart: function () {
				    Ziche.openVideo('open');
				  },
				  onFinish: function () {
				    Ziche.openVideo('close');
				  },
				  onPause: function () {
				    Ziche.openVideo('close');
				  },
				  onResume: function () {
				    Ziche.openVideo('open');
				  }
				},
			  onLoad: function () {
			    Ziche.openVideo('open');
			  },
			  plugins:
				{
				  controls:
					{
					  url: 'flowplayer.controls-3.2.3.swf',

					  backgroundColor: "transparent",
					  backgroundGradient: "none",
					  sliderColor: '#FFFFFF',
					  sliderBorder: '1px solid rgba(160,160,160,0.7)',
					  volumeSliderColor: '#FFFFFF',
					  volumeBorder: '1px solid rgba(160,160,160,0.7)',

					  timeColor: '#ffffff',
					  durationColor: '#333333',

					  tooltipColor: 'rgba(255, 255, 255, 0.7)',
					  tooltipTextColor: '#333333'
					}
				}
			});
  }, // fine videoPlayer

  openVideo: function (action) {
    var coord
    switch (action) {
      case "open":
        coord = 'rect(0px 800px 380px 0px)'
        break;
      case "close":
        coord = 'rect(0px 800px 380px 420px)'
        break;
    }
    $(".video").stop().animate({ 'clip': coord }, 2000);
  },

  RedirectRegistrati: function () {
    //javascript:window.parent.location.href =     
    $(".redirectRegistrati").click(
							function () {
							  try { parent.$.fancybox.close(); }
							  catch (err) { }
							  window.parent.location.href = $(".redirectRegistrati").attr('href');
							  return false;
							});
  },

  openProgetto: function () {
    $('a.progetto').each(function () {
      /*myClip="config={&quot;autoPlay&quot;:true,&quot;play&quot;:{&quot;replayLabel&quot;:&quot;&quot;,&quot;replayButton&quot;:&quot;none&quot;},&quot;clip&quot;:{&quot;url&quot;:&quot;"+$(this).attr('rel')+"&quot;},&quot;playerId&quot;:&quot;playerProgetto&quot;}]}";*/
      myClip = "config={&quot;autoPlay&quot;:false,&quot;play&quot;:{&quot;replayLabel&quot;:&quot;&quot;,&quot;replayButton&quot;:&quot;none&quot;},&quot;clip&quot;:{&quot;url&quot;:&quot;" + $(this).attr('rel') + "&quot;},&quot;plugins&quot;:{&quot;controls&quot;:{&quot;url&quot;:&quot;flowplayer.controls-3.2.3.swf&quot;,&quot;backgroundColor&quot;:&quot;transparent&quot;,&quot;backgroundGradient&quot;:&quot;none&quot;,&quot;sliderColor&quot;:&quot;#FFFFFF&quot;,&quot;sliderBorder&quot;:&quot;1px solid rgba(160,160,160,0.7)&quot;,&quot;volumeSliderColor&quot;:&quot;#FFFFFF&quot;,&quot;volumeBorder&quot;:&quot;1px solid rgba(160,160,160,0.7)&quot;,&quot;timeColor&quot;:&quot;#ffffff&quot;,&quot;durationColor&quot;:&quot;#333333&quot;,&quot;tooltipColor&quot;:&quot;rgba(255, 255, 255, 0.7)&quot;,&quot;tooltipTextColor&quot;:&quot;#333333&quot;}},&quot;playerId&quot;:&quot;player&quot;,&quot;playlist&quot;:[{&quot;url&quot;:&quot;" + $(this).attr('rel') + "&quot;}]}"

      $(this).fancybox(
			{
			  'padding': 0,
			  'titleShow': false,
			  'width': 720,
			  'height': 576,
			  'swf': { 'wmode': 'transparent', 'flashvars': myClip} // <-- flashvars here 
			});

    });

  },

  videoPlayerProgetto: function (obj, swfFile, file) {
    flowplayer(
			obj, { src: swfFile, wmode: 'transparent' },
			{
			  autoPlay: true,
			  play: { replayLabel: '', replayButton: 'none' },

			  clip:
				{
				  url: file // Setto il Video da riprodurre
				},

			  plugins:
				{
				  controls:
					{
					  url: 'flowplayer.controls-3.2.3.swf',

					  backgroundColor: "transparent",
					  backgroundGradient: "none",
					  sliderColor: '#FFFFFF',
					  sliderBorder: '1px solid rgba(160,160,160,0.7)',
					  volumeSliderColor: '#FFFFFF',
					  volumeBorder: '1px solid rgba(160,160,160,0.7)',

					  timeColor: '#ffffff',
					  durationColor: '#333333',

					  tooltipColor: 'rgba(255, 255, 255, 0.7)',
					  tooltipTextColor: '#333333'
					}
				}
			});
  }, // fine videoPlayer

  toolTip: function () {
    $('.toolTip').tooltip({ showURL: false });
  }, /* fine toolTip */

  scrollbar: function () // Usata per la Scrollbar dei testi
  {   
    $('.scroll').jScrollPane({ verticalDragMinHeight: 100, verticalDragMaxHeight: 100 });
  },

  popup: function () {
    $(".popup").fancybox(
				{
				  'titleShow': false,
				  'autoDimensions': true
				}
			);
    $(".popup.puntaziche").fancybox(
				{
				  'titleShow': true,
				  'autoDimensions': true
				}
			);

    $(".login").fancybox(
				{
				  'width': 400,
				  'padding': 0,
				  'titleShow': false,
				  'autoDimensions': false,
				  'type': 'iframe'
				}
			);

    $(".freelance").fancybox(
				{
				  'width': 700,
				  'height': 400,
				  'padding': 0,
				  'titleShow': false,
				  'autoScale': false,
				  'transitionIn': 'fade',
				  'transitionOut': 'fade',
				  'type': 'iframe'
				}
			);

    $(".newsletter").fancybox(
				{
				  'width': 400,
				  'height': 360,
				  'padding': 0,
				  'titleShow': false,
				  'autoDimensions': false,
				  'type': 'iframe'
				}
			);

    $(".generica").fancybox(
				{
				  'width': 560,
				  'height': 480,
				  'padding': 0,
				  'titleShow': false,
				  'autoScale': false,
				  'transitionIn': 'fade',
				  'transitionOut': 'fade',
				  'type': 'iframe'
				}
			);

  }, // fine popup

  popupImg: function () {
    $("a[rel=gallery]").fancybox({
      'transitionIn': 'none',
      'titleShow': false,
      'transitionOut': 'none',
      'titlePosition': 'over'
    });
  },

  news: function () {
    $('#news').list_ticker({
      speed: 7000,
      effect: 'fade'
    })
  }, // Chiusura news

  scroller: function () // Usata per la Scrollbar dei testi
  {
    //$('.wrapper ul').ScrollPane();
    $(".scroller").smoothDivScroll(
					{
					  scrollingHotSpotLeft: ".scrollingHotSpotLeft",
					  scrollingHotSpotRight: ".scrollingHotSpotRight",
					  scrollWrapper: ".wrapper",
					  scrollableArea: ".scrollableArea",
					  scrollInterval: 5,
					  scrollStep: 7,
					  autoScroll: "onstart",
					  autoScrollDirection: "backandforth",
					  autoScrollStep: 1,
					  autoScrollInterval: 15,
					  visibleHotSpots: "always"
					});
  },

  staff: function () {
    //alert('staff')
    //$('#staff').ScrollPane();
    $("#staff li a").fancybox({
      'width': 600,
      'height': 400,
      'margin': 0,
      'padding': 0,
      'titleShow': false,
      'autoScale': false,
      'transitionIn': 'fade',
      'transitionOut': 'fade',
      'type': 'iframe'
    })
  }, // Chiusura staff

  staffContatta: function () {
    $(".contattaStaff").click(
							function () {
							  /*
							  var modulo = $("#contattaStaff");

							  modulo.fadeToggle()
							  modulo.children('fieldset').append($("#inLinkChiudi").attr('value'))

							  $(".chiudiModulo").click(
							  function () {
							  modulo.fadeToggle();
							  $(this).remove()
							  })
							  */
							}
							)
  }, // Chiusura staffContatta

  prodottiHover: function () {
    //alert('elenco prodotti')
    var materiale = $('img.materiale');
    var imageOld = materiale.attr('src');
    var loader = '<div id=\'loaderProdotti\' class=\'loader\'></div>'

    $('#elenco-prodotti li a').hover(
				function () // OVER
				{
				  var image = $(this).children('img').attr('src');
				  if (image != null) {
				    var imageHover = $(this).children('img').attr('longdesc'); //image.replace('.jpg', '_medium.jpg');

				    materiale.parent().append(loader)
				    materiale.attr('src', imageHover);
				    materiale.load(function () { $('#loaderProdotti').remove() })
				  }
				},
				function () // OUT
				{
				  materiale.attr('src', imageOld);
				  if ($('#loaderProdotti').length > 0)
				    $('#loaderProdotti').remove();
				}
				);
  }, // Chiusura prodottiHover  

  mappa: function () {
    //alert('staff')
    //$('#staff').ScrollPane();
    $("#Mappa area").fancybox({
      'width': 600,
      'height': 400,
      'padding': 0,
      'titleShow': false,
      'autoScale': false,
      'transitionIn': 'fade',
      'transitionOut': 'fade',
      'type': 'iframe'
    })
  }, // Chiusura mappa 

  packinglist: function () {
    $('.packinglist').each(function () {
      Ziche.TotaliCount($(this));
    })
  },

  TotaliCount: function (tabella) {

    // TOTALE DELLA TABELLA
    spanTotale = tabella.find('.spTotaleMq');
    totale = parseFloat("0.0");
    tabella.find('td input').each(function () {
      mqRiga = $(this).attr('rel');
      try {
        totale += parseFloat(mqRiga.replace(",", "."));
        totale = Math.round(totale * 100) / 100;
      }
      catch (e) { }
    })
    spanTotale.html(totale.toFixed(2));

    // GESTIONE PRENOTAZIONE
    Ziche.AddClickPrenota(tabella);
    spanTotalePrenotato = tabella.find('span.totalePrenotati');
    totalePrenotato = parseFloat("0.0");
    spanTotalePrenotato.html(totalePrenotato);
    tabella.find('td input').click(
    								function () // Click
    								{
    								  spanTotalePrenotato = tabella.find('span.totalePrenotati');
    								  totalePrenotato = parseFloat("0.0");
    								  tabella.find('td input').each(function () {
    								    mqRiga = $(this).attr('rel');
    								    try {
    								      if ($(this).attr('checked'))
    								        totalePrenotato += parseFloat(mqRiga.replace(",", "."));
    								      totalePrenotato = Math.round(totalePrenotato * 100) / 100;
    								    }
    								    catch (e) { }
    								  })
    								  spanTotalePrenotato.html(totalePrenotato.toFixed(2));
    								  Ziche.AddClickPrenota(tabella);
    								});
  }, // Chiusura TotaliCount  

  AddClickPrenota: function (tabella) {

    selAn = 0;
    tabella.find('td input').each(function () {
      try {
        if ($(this).attr('checked'))
          selAn = 1;
      }
      catch (e) { }
    })
    $('input[id$="btPrenota"]').unbind('click');
    if (selAn == 1) {
      $('input[id$="btPrenota"]').click(
    			function () {
    			  return confirm($('#ihPreConfirm').attr('value'));
    			});
    }
    else {
      $('input[id$="btPrenota"]').click(
    			function () {
    			  alert($('#ihPreAlert').attr('value')); return false;
    			});
    }
  },

  TracciamentoAnalytics: function (pagina) {
    try {
      var pageTracker = _gat._getTracker('UA-23302391-1');
      pageTracker._trackPageview(pagina);
    }
    catch (err) { }
  },

  OpenWindow: function () {
    $('.new-window').click(function () {
      window.open(this.href);
      return false;
    });
  },

  mobile: function () {
    $('.footer').appendTo('#content');
    $('.header').prependTo('#content');
  }

} // chiusura classe Ziche

///////////////////////////////////////////////////////

$(document).ready(function() { Ziche.DOMready() });
//]]>
