$(function() {
	$("#header_callcenter a").hover(
			function () {$("#popup-callcenter").show();},
		    function () {$("#popup-callcenter").hide();}
	);
	
	$(".popper").click(function(){
		w = h = 0;
		s = r = "yes";
		switch($(this).attr("id")){
			case "geotrust":
				w = 400;
				h = 450;
				break;
			default :
				w = 400;
				h = 400;
				break;
		}
		geo = window.open($(this).attr("href"),"geo","scrollbars="+s+",width="+w+",height="+h+",resizable="+r);
		geo.focus();
		return false;
	});
	
	$("#hotelsearch").submit(function(){
		_gaq.push(['b._linkByPost', this]);
		return true;
	});	
	
	$("#listingsearch").submit(function(){
		_gaq.push(['b._linkByPost', this]);
		return true;
	});	
	
	$("a.hotelsearch").click(function(){
		form = $("#hotelsearch");
		$("input[name='hotel_id']",form).attr('value', $(this).attr('alt'));
		form.submit();
		return false;
	});
	
	$("a.listingsearch").click(function(){
		form = $("#listingsearch");
		$("input[name='place_id']",form).attr('value', $(this).attr('alt'));
		form.submit();
		return false;
	});
	
	$(".hiddenlink").click(function(){
		location.href = $(this).attr("id");
		return false;
	});
	
	$(".hotellink").click(function(){
		location.href = $(this).attr("alt");
		return false;
	});
	
	$("a.rollup").click(function(){
		if($(this).attr("href")){
			TEDomain = new Array();
			CarLabel = new Array();
			TEDomain[0] = "www.traveleurope.it";
			TEDomain[1] = "www.traveleurope.net";
			TEDomain[2] = "de.traveleurope.it";
			TEDomain[3] = "italie.traveleurope.it";
			TEDomain[4] = "italia.traveleurope.it";
			TEDomain[5] = "pt.traveleurope.it";
			TEDomain[6] = "ru.traveleurope.it";
			TEDomain[7] = "www.traveleurope.com";	
			CarLabel[0] = "car-rental";
			CarLabel[1] = "noleggio-auto";
			CarLabel[2] = "autovermietung";
			CarLabel[3] = "location-de-voitures";
			CarLabel[4] = "alquiler-de-coches";
			
			var url = $(this).attr("href");
			var domain1 = document.domain;
			var domain2 = false;
			var loc = location.href;

			if(loc.indexOf(CarLabel[0])<0 && loc.indexOf(CarLabel[1])<0 && loc.indexOf(CarLabel[2])<0 && loc.indexOf(CarLabel[3])<0 && loc.indexOf(CarLabel[4])<0){
				if(url.match(/.traveleurope./) && in_array(TEDomain, domain1)){	

					if($(this).attr("href").match(/:\/\/(.[^/]+)/)){
						var domain2 = url.match(/:\/\/(.[^/]+)/)[1];

						if(domain1!=domain2 && in_array(TEDomain, domain2)){
							_gaq.push(['b._link', url]);	
							return false;
						}    		
					}			
				}				
			}
		}
	});	
	
});

$(document).ready(function(){
	$("#contactLink").fadeTo("slow", 0.3).fadeTo("slow", 1.0).fadeTo("slow", 0.3).fadeTo("slow", 1.0);
	$("#contactLink").hover(function(){
	$("#contactLink").fadeTo("fast", 1.0);
		},function(){
			$("#contactLink").fadeTo("slow", 1.0);
		});
    $("#contactLink").click(function(){
        if ($("#contactForm").is(":hidden")){
            $("#contactForm").slideDown("slow");
        }
        else{
            $("#contactForm").slideUp("slow");
        }
    });
	
    $("input#email").focus(function () {
		  $("input#email").removeClass("mandatory").addClass("ok"); 
		  $("label#email").removeClass("mandatory").addClass("ok");
		        
	});
	$("input#email").blur(function() {  
      if (this.value == ''){  
          this.value = (this.defaultValue ? this.defaultValue : '');
		  $(this).removeClass("ok").addClass("mandatory"); 
		  $("label#email").removeClass("ok").addClass("mandatory");  
      } 
	   
  	});  

});

function in_array(thaArray, elem){
	for (var i=0; i<thaArray.length && thaArray[i]!=elem; i++);
	return thaArray[i]==elem;
}
