$(function(){

// up and down 
	$("#buttondown").hover(function(){ 
		c=$(".scrolling").parents("div").css('height');
		c=c.split('p');
		c=parseInt(c[0]);
		m=0-($(".scrolling").height())+c-50;
		if(c<$(".scrolling").height())$(".scrolling").animate({top: m+'px'},3000);
	},function(){$(".scrolling").stop();});

	$("#buttonup").hover(function(){ 
		c=$(".scrolling").parents("div").css('height');
		c=c.split('p');
		c=parseInt(c[0]);		
		if(c<$(".scrolling").height())$(".scrolling").animate({top: '0px'},3000);
	},function(){$(".scrolling").stop();});

	$("#buttondown").click(function(){ 
		c=$(".scrolling").parents("div").css('height');
		c=c.split('p');
		c=parseInt(c[0]);
		m=0-($(".scrolling").height())+c-50;
		if(c<$(".scrolling").height())$(".scrolling").stop().animate({top: m+'px'}, 1000);
	});		

	$("#buttonup").click(function(){if(c<$(".scrolling").height()){$(".scrolling").stop().animate({top: '0px'}, 1000);}});

//legal y creditos
	$('#legal, #confidencial, #creditos').colorbox({speed:1000, maxWidth:750});

// carga de datePicker
	$(".datepicker").datepicker({showOn: 'button', buttonImage: 'img/calendar.gif', buttonImageOnly: true, firstDay:1 ,dateFormat:'dd/mm/yy'});
	$.datepicker.setDefaults($.datepicker.regional['es']);
	
	/* Validar formularios */
	$('form').submit(function(){																											
		var errorChks=false;
		//var condiciones = $('label.condiciones',t);
		var eMust = $(this).find('.must');
		eMust.removeClass('error').each(function(){
			var tt = $(this);
			var t_valor = $('input,select',tt).val();
			if(t_valor==''||(tt.hasClass('email')&&!(checkEmail(t_valor)))){
				es_valido = false;
				tt.addClass('error');
			} else {
				tt.removeClass('error');
			};
		});
		if(!$('#chkTelefono').attr("checked")&&!$('#chkEmail').attr("checked")&&!$('#chkFax').attr("checked")){$('.chkMedio').addClass('error');errorChks=true;}else{$('.chkMedio').removeClass('error');errorChks=false;}
		if($('#lstbxHotelesHd').val()==''){errorChks=true;$('#lstbxHoteles').parent().addClass('error');}else{errorChks=false;$('#lstbxHoteles').parent().removeClass('error');}
		if (eMust.hasClass('error')||errorChks){$('p.error').show();$(".scrolling").animate({top: '0px'},1000);return false;}else{$('p.error').hide();return true;} 
	});
	
	if (enviado) {
		$.fn.colorbox({html:'<p style="margin:0 20px 31px 25px;" '+((enviado.indexOf('ERROR')!=-1)?'class="error"':'class="noError"')+'>'+enviado+'</p>', open:true});
	}
});

function checkEmail(d){
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(d);
}
