  jQuery(document).ready(function($) {
  
  goHome();
  
  if($.isPage('prodotti')) {
  	startScrollPane();
  }else if( $.isPage('categoria') ){
	//zoom();  
	startScrollPane();
  }else if( $.isPage('prodotto') ){
	startScrollPane();
  }else if( $.isPage('chi-siamo') || $.isPage('checkout') ){
	startScrollPane();
  }else if( $.isPage('dove-siamo') ){
	initializeMap();
  }else if( $.isPage('richiedi-il-catalogo') ){
  	$('form[name=richiediCatalogo]').validate({keyUp: true, shaker: false, returnClass: true});
  	
  	$('form[name=richiediCatalogo]')
  		.submit(
  			function(){
  				if($(this).hasClass('validato')){
					
					$.post('/wp-content/themes/open/lib/validateEmail.php', {email: $('input.mail').val()}, function(r){
						if(r == 'ko'){
							$('input.mail').addClass('error');
							$('input.mail').parent().children('span.required').show();
						}else{
							
							var nome 	= $('input[name=nome]').val();
							var cognome = $('input[name=cognome]').val();
							var email 	= $('input[name=email]').val();
							var azienda = $('input[name=azienda]').val();
							
							$.post('/wp-content/themes/open/lib/richiesteCatalogo.php', {nome: nome, cognome: cognome, email: email, azienda: azienda});
						
							var ajaxPage = $('input[name=ajaxPage]').val();
  							var link = 'Scarica il catalogo facendo <a href="'+ajaxPage+'scaricaCatalogo.php" target="_blank">click qui!</a>';
		  					$('p.theLink').html(link).show();
						}
					});
  					
  					return false;
  				}
  			}
  		);
  	
  }
  });
  
  
  
  //======FUNCTIONS======/
  
  // @info 	Check current pag
  // @usage	if($.isPage('pageName'))
  jQuery.isPage = function(checkFor) {
  
  var url = window.location.pathname;	
  var page = url.split('/');
  
  if(checkFor == page[1]){
  	return true;
  }else{
  	return false;
  }
  
  }
  
  //Move goHome
  function goHome() {
  
  //
  jQuery(".goTo").hover(	
  
  	function(){
	jQuery(this).stop().animate({marginTop: ("10px")}, 100);
	},
	
	function(){
	jQuery(this).stop().animate({marginTop: ("0px")}, 300);
	})
  }

  
  //Magnify
  function zoom() { 
  
	  var options = {
	  zoomWidth: 200,
	  zoomHeight: 200,
	  xOffset: 10,
	  yOffset: 0,
	  position: "right", //and MORE OPTIONS
	  showPreload: true,
	  lens:false
  
  	}
  jQuery('.zoom').jqzoom(options);
  
  }
  
  
  //Scrollpane
  function startScrollPane() { 
  
  	jQuery('.scrollpane').jScrollPane({showArrows:true});
  
  }
  
  
  //Google map
    function initializeMap() {
      if (GBrowserIsCompatible()) {
		 
		 //Setto le coordinate
		var coordsNewClinicLife = new GLatLng(45.650679,9.549462);
		
		//Creo la mappa 
		var mapNewClinicLife = new GMap2(document.getElementById("map"));
        
		mapNewClinicLife.setCenter(coordsNewClinicLife, 12);
        mapNewClinicLife.setUIToDefault();
			
		//Definisco il path per la tip.png
		var tip = new GIcon(G_DEFAULT_ICON);
		tip.iconSize = new GSize(200, 80);
		tip.shadowSize = new GSize(200, 80);
		tip.image = "http://www.openantinfortunistica.it/wp-content/themes/open/images/tipOpen.png";										  
			
		markerOptions = { icon:tip };
		
		//Creo le tip
		mapNewClinicLife.addOverlay(new GMarker(coordsNewClinicLife, markerOptions));
		
      }
    }
  
  
  
  
  
  
  
