var selPart = true;
var barOpen = false;


$(document).ready(function(){

	$("#participate").hover(
      function () {
        $("#poP").fadeIn("fast");
      },
      function () {
      	  setTimeout(function(){
          	if(barOpen==false){$("#poP").fadeOut("fast")};
          }, 1500); // adjust your time here 
      }
	);
	
	$("#poP").mouseenter (
		function () {
			barOpen = true;
		}).mouseleave(
		function () {
			barOpen = false;
			setTimeout(function() {
			if (barOpen==false){
				$("#poP").fadeOut("fast");
			}
			}, 500);
		}
	);
	/*
	$(".buttons").mouseenter(function() {
		alert ('oi');
	}).mouseleave(function(){
		alert ('tchau');
    });*/
	
	
	$(".combo").toggle(
		function (e) {
			function getDim(el){
				for (var lx=0,ly=0;el!=null;
					lx+=el.offsetLeft,ly+=el.offsetTop,el=el.offsetParent);
				return {x:lx,y:ly}
			}
			mySpanDim = getDim(this);
			$("body").append("<div id=\"combo-info-"+this.id+"\"></div>");
			var options = $("#"+this.id+" select").children();
			var html = '<ul>';
			for (var x=0; x<options.length; x++) {
				html += '<li title="'+options[x].value+'"><a href="javascript:void(0)">'+options[x].innerHTML+'</a></li>';
			}
			html += '</ul>';
			$("#combo-info-"+this.id).html( html );
			$("#combo-info-"+this.id).addClass("combo-info");
			
			$("#combo-info-"+this.id+" ul li").click(
				function () {
					var nomeCombo = this.parentNode.parentNode.id.replace(/combo-info-/, '');
					$("#"+nomeCombo).click();
					$("#"+nomeCombo+" a").html(this.title);
					var options = $("#"+nomeCombo+" select").children();
					
					for (var x=0; x<options.length; x++) {
						if (options[x].value==this.title) {
							$("#"+nomeCombo+" select").attr('selectedIndex',x);
							break;
						}
					}
				}
			);
			
			var combowidth = $(".combo").width();
			var comboheight = $(".combo").height();
			$("#combo-info-"+this.id).css({
				"left" : (mySpanDim.x) + "px",
				"top": (mySpanDim.y + comboheight) + "px",
				"width": combowidth + "px",
				"display":"none"
				});
			$("#combo-info-"+this.id).slideDown("slow");
		},
		function () {
			$("#combo-info-"+this.id).slideUp("fast");
			window.setTimeout(function(){$("#combo-info-"+this.id).remove();},200); 
				$("body").unbind('click');
		}
	);
			$(function() {
				$("#hotel .form input").datepicker({
				dateFormat: 'dd/mm/yy',
				'monthNamesShort': ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez'],
				'monthNames': ['Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
				'showOn': 'button',
				'minDate': +1
				});
			});
			$("#botao_chegada").toggle(
		      function () {
		      	if ($("#data_partida").datepicker('getDate')!=null) $("#data_chegada").datepicker('option','minDate',$("#data_partida").datepicker('getDate'));
		      	else $("#data_chegada").datepicker('option','minDate','+1');
		      	$("#data_chegada").datepicker('show');
		      },
		      function() {
		      	if ($("#data_partida").datepicker('getDate')!=null) $("#data_chegada").datepicker('option','minDate',$("#data_partida").datepicker('getDate'));
		      	else $("#data_chegada").datepicker('option','minDate','+1');
		      	$("#data_chegada").datepicker('hide');
		      }
			);
			$("#botao_partida").toggle(
		      function () {
		      	if ($("#data_chegada").datepicker('getDate')!=null) $("#data_partida").datepicker('option','minDate',$("#data_chegada").datepicker('getDate'));
		      	else $("#data_partida").datepicker('option','minDate','+1');
		      	$("#data_partida").datepicker('show');
		      },
		      function() {
		      	if ($("#data_chegada").datepicker('getDate')!=null) $("#data_partida").datepicker('option','minDate',$("#data_chegada").datepicker('getDate'));
		      	else $("#data_partida").datepicker('option','minDate','+1');
		      	$("#data_partida").datepicker('hide');
		      }
			);
			
			euJaFui();

});

function combobox(b) {
	$(b).parent().find("ul").slideDown("slow");
	$(b).parent().mouseout(
		function () {
			$(b).parent().find("ul").slideUp("slow");
		}
	);
	return false;
}