$(document).ready(function() {
	function changeHeader(){
		var imm = new Array("bg_header_12.jpg","bg_header_11.jpg","bg_header_14.jpg","bg_header_10.jpg","bg_header_9.jpg","bg_header_8.jpg","bg_header_7.jpg", "bg_header_5.jpg", "bg_header_3.jpg", "bg_header_2.jpg", "bg_header.jpg");
		var randomnumber = Math.floor(Math.random()*imm.length);
		var immagine = "url(http://www.dgvtravel.com/img/"+imm[randomnumber]+")";
		$("div#header").css("background-image", immagine);
	}
	changeHeader();
	
	$("#loader_g").hide("slow");   
// --------- Tendina laterale !
	$(".left_li").hover(
		function () {
			$(this).addClass("selezionato");
		},
		function () {
			$(this).removeClass("selected");
		}
	);
	$(".left_li_li").hover(
		function () {
			$(this).find("ul").show();
			$("#scrollable_left").jScrollPane({height_ok:330});
		},
		function () {
			$(this).find("ul").hide();
			$("#scrollable_left").jScrollPane({height_ok:330});
		}
	);
	
	
// --------------light box
	
	$(function() {
		$("#containerscroll a").lightBox(); // Select all links in object with gallery ID
});
   // -------  bottoni foto reel	
	
	$("#btnscrollright").click(function(){
		var fr = $(this).attr("freccia");	
		if(fr == "true")
		{
		  $(this).attr("freccia", "false");
		  $("#btnscrollleft").attr("freccia", "false");
		  $("#btnscrollleft").show("slow");
		  var lar_1 = $("#containerscroll").width();
		  var lar_2 = $("#fixscroll").width();
		  var current_l = $("#containerscroll").position();
		  var delta_x = lar_1 - lar_2 + current_l.left;
		  if(delta_x > 0)
		  {
			  if(delta_x > 117)
			  {
			  	var arrivo = current_l.left-117;
			  }else{
				var arrivo = current_l.left-delta_x;
			  	$(this).hide("slow");
			  }
			  $("#containerscroll").animate({ 
				left: arrivo
			  }, 900, "swing", abilita);
		  }else{
			$(this).attr("freccia", "false");
			$(this).hide("slow");
		  	$("#btnscrollleft").attr("freccia", "true");
			
		  }
		}
		  
    });
	
	$("#btnscrollleft").click(function(){
		var fr = $(this).attr("freccia");							   
		if(fr == "true")
		{
		  $(this).attr("freccia", "false");
		  $("#btnscrollright").attr("freccia", "false");
		  $("#btnscrollright").show("slow");
		  var current_l = $("#containerscroll").position();
		  if(current_l.left < 0)
		  {
			  if(current_l.left < -117)
			  {  
				  var arrivo = current_l.left+117;
			  }else{
				   var arrivo = 0;
			  }
			  if(arrivo >=0)
			  {
					$(this).hide("slow");  
			  }
			  $("#containerscroll").animate({
				left: arrivo
			  }, 900, "swing", abilita);
		  }else{
			$(this).attr("freccia", "false");
			$(this).hide("slow");
		  	$("#btnscrollright").attr("freccia", "true");  
		  }
		}
		  
    });
	
	function abilita()
	{
		$("#btnscrollright").attr("freccia", "true");
		$("#btnscrollleft").attr("freccia", "true");
	}
	
	if ($.browser.msie) {
		$('.center').css("text-align","center");
		$('.scrollable_f').css("left",0);
	}else{
		$('.center').css("text-align","-moz-center");
	}
	if (document.location.pathname=="/disegna.php") {
	$('.scrollable_f').jScrollPane({height_ok:370}).onImagesLoad({
                                        callback: function(ref) {
                                                $(ref).jScrollPane({height_ok:370});
                                        }
                                });
	$('#scrollable_left').jScrollPane({height_ok:330});
	
	$('#search_result').jScrollPane({height_ok:500});
	}
	
	$("span.get_info").click(function(){
		var tipo = $(this).attr("tipo");	
		var id_it = $(this).attr("id_it");	
		if(tipo == "stampa" || tipo == "preventivo" || tipo == "stampa2")
		{
			if(tipo == "stampa")
			{
				window.location="http://www.dgvtravel.com/stampa.php?id="+id_it;
			}
                        if(tipo == "stampa2")
			{
				window.location="http://www.dgvtravel.com/stampa_1.php?id="+id_it;
			}
			if(tipo == "preventivo")
			{
				var tit_it = $(this).attr("tit_it");
				window.location="http://www.dgvtravel.com/preventivo_itinerari.php?tit_it="+tit_it;
			}

		}else{
			$("#cont_info2").remove();
			$("#info_div2").append('<div id="cont_info2" align="center"><img src="img/ajax-loader.gif"/></div>');
			$("#info_div2").show();
			$.ajax({
				type: "POST",
				url: "http://www.dgvtravel.com/inc/info_funcs.php",
				data: "op="+tipo+"&id_it="+id_it,
				success: function(html){
					$("#cont_info2").remove();
					$("#info_div2").append(html);
					$(".link_hotel").click(function(){	
						var id_it = $(this).attr("id_hotel");
						var tipo = "hotel2";
						$(this).parent().find(".link_hotel").removeClass("spesso");
						$(this).addClass("spesso");
						$.ajax({
							type: "POST",
							url: "http://www.dgvtravel.com/inc/info_funcs.php",
							data: "op="+tipo+"&id_it="+id_it,
							success: function(html){
								 $("#cont_info3").remove();
								 $("#td_cont_alberghi").append(html);
								 $('#cont_info_in3').jScrollPane({height_ok:330}).onImagesLoad({
                                                                        callback: function(ref) {
                                                                                $(ref).jScrollPane({height_ok:330});
                                                                        }
                                                                });
							}
						});
						
					});
					$('#cont_info_in2').jScrollPane({height_ok:330}).onImagesLoad({
                                                callback: function(ref) {
                                                        $(ref).jScrollPane({height_ok:330});
                                                }
                                        });
				}
			});
		}
		
	});

	$('#table_part').jScrollPane({height_ok:330}).onImagesLoad({
                                callback: function(ref) {
                                        $(ref).jScrollPane({height_ok:330});
                                }
                        });

	$(".close_info").click(function(){
		$(this).parent().hide("slow");
	});
	$('#data_part').DatePicker({
		format:'d/m/Y',
		date: $('#data_part').val(),
		current: $('#data_part').val(),
		starts: 1,
		position: 'right',
		onBeforeShow: function(){
			$('#data_part').DatePickerSetDate($('#data_part').val(), true);
		},
		onChange: function(formated, dates){
			$('#data_part').val(formated);
		}
	});
	
	
	$("#info_banner").click(function(){
		$("#cont_info").remove();
		$("#info_div").append('<div id="cont_info"><form name="mailform" id="mailform"><label for="nome_mail">Nome : </label><input id="nome_mail" name="nome_mail" type="text" value="" /><br /><label for="cognome_mail">Cognome : </label><input id="cognome_mail" name="cognome_mail" type="text" value="" /><br /><label for="ind_mail">E-mail per le risposte : </label><input id="ind_mail" name="ind_mail" type="text" value="" /><br /><label for="testo_mail">Messaggio : </label><br /><textarea id="testo_mail" name="testo_mail"></textarea><br /><br /><input type="button" id="sub_mail" value="invia" /><br /><br /><small style="font-size: 10px; font-style:italic;">tutti i campi sono obbligatori</small></form></div>');
		
		$("#sub_mail").click(function() {
		var errors = 0;
		
		if($('#nome_mail').val() == "") { 
			$('#nome_mail').css("color", "red"); 
			$('#nome_mail').val("campo necessario !!!"); 
			errors++; 
		}else{
			var nome_mail = $('#nome_mail').val();
		}
		if($('#cognome_mail').val() == "") { 
			$('#cognome_mail').css("color", "red"); 
			$('#cognome_mail').val("campo necessario !!!"); 
			errors++; 
		}else{
			var cognome_mail = $('#cognome_mail').val();
		}
		if($('#testo_mail').val() == "") { 
			$('#testo_mail').css("color", "red"); 
			$('#testo_mail').val("campo necessario !!!"); 
			errors++; 
		}else{
			var testo_mail = $('#testo_mail').val();
		}
		if($('#ind_mail').val() == "") { 
			$('#ind_mail').css("color", "red");
			$('#ind_mail').val("campo necessario !!!");
			errors++; 
		}else{
			var ind_mail = $('#ind_mail').val();
		}
		if(errors == 0)
		{
				$.ajax({
					type: "POST",
					url: "http://www.dgvtravel.com/inc/info_funcs.php",
					data: "op=email&nome_mail="+nome_mail+"&cognome_mail="+cognome_mail+"&testo_mail="+testo_mail+"&ind_mail="+ind_mail,
					success: function(html){
						$("#cont_info").remove();
						$("#info_div").append('<div id="cont_info">'+html+'</div>');
						
	
					}
					
				});
	
		}
	});
		
		$("#info_div").show();
	});
	
	
	
	
	
	
	
	
	$("#pul_offerte, #porta_off").click(function(){	
			$("#cont_info").remove();
			$("#info_div").append('<div id="cont_info" align="center"><img src="img/ajax-loader.gif"/></div>');
			$("#info_div").show();
			$.ajax({
				type: "POST",
				url: "http://www.dgvtravel.com/inc/info_funcs.php",
				data: "op=offerte",
				success: function(html){
					$("#cont_info").remove();
					$("#info_div").css("left",610);
					 $("#info_div").append(html);
					 $('#cont_info_in').jScrollPane({height_ok:300}).onImagesLoad({
                                                                                    callback: function(ref) {
                                                                                            $(ref).jScrollPane({height_ok:300});
                                                                                    }
                                                                            });
				}
			});
	});
	$("#link_regolamento").click(function(){
			$("#cont_info").remove();
			$("#info_div").append('<div id="cont_info" align="center"><img src="img/ajax-loader.gif"/></div>');
			$("#info_div").show();
			$.ajax({
				type: "POST",
				url: "http://www.dgvtravel.com/inc/info_funcs.php",
				data: "op=regolamento_gruppi&id_date="+$('#link_regolamento').attr('id_date'),
				success: function(html){
					$("#cont_info").remove();
					$("#info_div").css("left",610);
					 $("#info_div").append(html);
					 $('#cont_info_in').jScrollPane({height_ok:300}).onImagesLoad({
                                                                                    callback: function(ref) {
                                                                                            $(ref).jScrollPane({height_ok:300});
                                                                                    }
                                                                            });
				}
			});
	});
	
	$("#info").click(function(){	
			$("#cont_info").remove();
			$("#info_div").append('<div id="cont_info" align="center"><img src="img/ajax-loader.gif"/></div>');
			$("#info_div").show();
			$.ajax({
				type: "POST",
				url: "http://www.dgvtravel.com/inc/info_funcs.php",
				data: "op=info_azienda",
				success: function(html){
					$("#cont_info").remove();
					$("#info_div").css("left",610);
					 $("#info_div").append(html);
					 $('#cont_info_in').jScrollPane({height_ok:300}).onImagesLoad({
                                                callback: function(ref) {
                                                        $(ref).jScrollPane({height_ok:300});
                                                }
                                        });
				}
			});
	});
	
	$("#siti_amici").jScrollPane({height_ok:550}).onImagesLoad({
                                                callback: function(ref) {
                                                        $(ref).jScrollPane({height_ok:550});
                                                }
                                        });
	
	//CAMPI SOLO NUMERICI :
	$("#cap_viaggiatore").numeric();
	$("#tel_viaggiatore").numeric();
	$("#tel_agenzia").numeric();
        $(".numeric").numeric();


        //codici utenti
        $(".codice_ut").click(function(){
            var cod = $(this).attr("codice");
            $("#cont_info").remove();
            $("#info_div").css('top',600);
            $("#info_div").append('<div id="cont_info" align="center"><h2>Codice utente</h2><p>con questo codice è possibile riconoscere univocamente un viaggiatore nei casi di omonimia<p><b>'+cod+'</b></div>');
            $("#info_div").show();
	});
        
        $('#indietro_viaggiatori').click(function() {
            $('#porta_altri_partecipanti').stop(true, true );
            var l = parseInt($('#porta_altri_partecipanti').css('left'))+225;
            if(l <= 0){
                $('#porta_altri_partecipanti').stop().animate({ left: l }, 'fast');
            }
        });
        $('.avanti_viaggiatori').click(function() {

            $('#porta_altri_partecipanti').stop(true, true );
            var l = parseInt($('#porta_altri_partecipanti').css('left'))-225;
            if(l> -30*225){
                $('#porta_altri_partecipanti').animate({ left: l }, 'fast');
            }
        });




	// offerte pop up 
	function offy()
	{
		$.ajax({
			type: "POST",
			url: "http://www.dgvtravel.com/inc/info_funcs.php",
			data: "op=offerte2",
			success: function(html){
				$("#cont_info_off").remove();
				$("#porta_off").append(html);
				$("#porta_off").show("slow");
			}
		});	
	}
	offy();
	setTimeout('$("#porta_off").hide("slow")', 5000);


        if($.browser.msie && $.browser.version <= 6 ){
            $(".top_content").css({
                'height':'344px',
                'width':'830px',
                'position': 'relative',
                'left':'25px',
                'top':'0px',
                'background-image': 'url(http://www.dgvtravel.com/img/bg_page_content_l.jpg)',
                'background-position': '24px 37px',
                'background-repeat': 'no-repeat'
            });
            $(".top_content2").css({
                'height':'344px',
                'width':'830px',
                'position': 'relative',
                'left':'25px',
                'top':'0px',
                'background-image': 'url(http://www.dgvtravel.com/img/bg_page_content_l.jpg)',
                'background-position': '24px 37px',
                'background-repeat': 'no-repeat'
            });
        }
	
});


