;$(function() {
	
	if(typeof initDatePicker == 'function') {
		initDatePicker();
	} 
	
	$("#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").click(function(){
		form = $("#hotelsearch");
		$("input[name='hotel_id']",form).attr('value', $(this).attr('alt'));
		form.submit();
		return false;
	});

	$(".form-hotel-rooms").click(function(){
		form = $("#form-hotel-rooms");
		$("input[name='hotel_id']",form).attr('value', $(this).attr('data-hotel-id'));
		form.submit();
		return false;
	});
	
	$(".form-place-search").click(function(){
		form = $("#form-place-search");
		$("input[name='place_id']",form).attr('value', $(this).attr('data-place-id'));
		$("input[name='origine']",form).attr('value', $(this).attr('data-origine'));
		$("input[name='extend_space']",form).attr('value', $(this).attr('data-extend'));
		form.submit();
		return false;
	});

	$(".form-listing-sort").click(function(){
		form = $("#form-listing-sort");
		$("input[name='sort']",form).attr('value', $(this).attr('data-sort'));
		$("input[name='offset']",form).attr('value', $(this).attr('data-offset'));
		form.submit();
		return false;
	});
	
	$(".form-link").click(function(){
		$("#form_link").attr("action",$(this).attr('alt'))
					   .attr("target",$(this).attr('target'))
					   .submit();
		return false;
	});
	
	$(".pop-abstracts a").hover(
		function(event){
			$tip = $("#"+$(this).attr("alt"));
			offset = $(this).offset();
			l =  offset.left+$(this).width()+10;
			t = offset.top;
			$tip.css({top: t, left: l}); 
			$tip.show();
		},
		function(event){
			$("#"+$(this).attr("alt")).hide();
		}
	);
	
	$("strong.hiddenlink").click(function(){
		page = window.open($(this).attr("title"),"page","scrollbars=yes,width=400,height=400,resizable=yes");
		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;
			
			if(url.match(/.traveleurope./) && in_array(TEDomain, domain1)){	

				if($(this).attr("href").match(/:\/\/(.[^/]+)/) && url.search(CarLabel[0])<0 && url.search(CarLabel[1])<0 && url.search(CarLabel[2])<0
				 && url.search(CarLabel[3])<0 && url.search(CarLabel[4])<0){
					var domain2 = url.match(/:\/\/(.[^/]+)/)[1];

					if(domain1!=domain2 && in_array(TEDomain, domain2)){
						_gaq.push(['b._link', url]);	
						return false;
					}    		
				}			
			}
		}
	});	
	
	$("#filter :checkbox").click(function(e){
		e.stopPropagation();
		
		$checkbox = $(this);
		$form = $checkbox.parents('form').get(0);
		
		$li = $checkbox.parent('li');
		$li.addClass('checked');
		$form.submit();
	});
	
	$('#filter li').click(function(){
		$checkbox = $(':checkbox',this);
		$form = $checkbox.parents('form').get(0);
		
		$(this).addClass('checked');
		$checkbox.attr('checked', !$checkbox.is(':checked'));
		$form.submit();
	});
	
	<? if($lang=="ru" || $lang=="pt"){?>
	$("#header_nav").css("left","236px");
	<? } ?>
	
});


(function($) {
	var cache = [];
	$.preLoadImages = function() {
		var args_len = arguments.length;
		for (var i = args_len; i--;) {
	    	var cacheImage = document.createElement('img');
	    	cacheImage.src = arguments[i];
	    	cache.push(cacheImage);
	    }
	}
})(jQuery);

function in_array(thaArray, elem){
	for (var i=0; i<thaArray.length && thaArray[i]!=elem; i++);
	return thaArray[i]==elem;
}

