var TierraLib = 
{
	main : {
		init : function() {
			//TierraLib.scrollpanel.init();
			//TierraLib.carousel.init();
			//TierraLib.shadowbox.init();
			//TierraLib.cufon.init();
			//TierraLib.toggle.init();
		}
	},	
	
	/** << Set scrollpanel 
	* ---------------------*/
	scrollpanel : {
		init : function() {
			$('.scroll-pane').jScrollPane();
		}
	},
	
	
	/** << Set carousel 
	* ---------------------*/
	carousel : {
		init : function() { 
			$('#mycarousel').jcarousel({
				auto: 1,
		        initCallback: mycarousel_initCallback,
				scroll:1
			});
			
			function mycarousel_initCallback(carousel)
			{
			    // Disable autoscrolling if the user clicks the prev or next button.
			    carousel.buttonNext.bind('click', function() {
			        carousel.startAuto(0);
			    });

			    carousel.buttonPrev.bind('click', function() {
			        carousel.startAuto(0);
			    });

			    // Pause autoscrolling if the user moves with the cursor over the clip.
			    carousel.clip.hover(function() {
			        carousel.stopAuto();
			    }, function() {
			        carousel.startAuto();
			    });
			};
		}
	},
	
	
	/** << Set tabs 
	* ---------------------*/
	tabs : {
		init : function() {
			$("#tabs").tabs();							
		}
		
	},
	
	
	/** << Set validate 
	* ---------------------*/
	validate : {
		init : function() {
								{
									validateForm(); setupInputMask();
								};
								
								function setupInputMask()
								{
									$("#nombre, #comentario").alpha({allow:" -"});
									$("#email").alphanumeric({allow:"-_.@"});
								}
								
								function validateForm()
								{
									var v = $("#contact-form").validate({
										errorElement : 'span',
										onkeyup: false,
										onblur: false,
										errorClass: "invalid",
										rules: {
											nombre: { required: true  },
											email: { required: true, email:true  },
											comentario: { required: true }
										},
										messages: {
											nombre: { required: '<br /> This field is required'  },
											email: { required: '<br /> This field is required' , email:'<br />Enter a valid email'  },
											comentario: { required: '<br /> This field is required' }
							
										},
										submitHandler: function(form) {
											form.submit();
										},
										success: function(span) { // set   as text for IE
											span.html(" ").addClass("checked");
										}
									});
								}
								
								
								
		}
		
	},
	
	
	
	/** << Set validate 
	* ---------------------*/
	reservas : {
		init : function() {
								
								
								{
									validateForm(); setupInputMask();
								};
								
								function setupInputMask()
								{
									$("#country, #name").alpha({allow:" -"});
									$("#dTo, #dFrom").numeric({allow:"-"});
									$("#email").alphanumeric({allow:"-_.@"});
								}
								
								function validateForm()
								{
									var v = $("#reservations-form").validate({
										errorElement : 'span',
										onkeyup: false,
										onblur: false,
										errorClass: "invalid",
										rules: {
											dFrom: { required: true  },
											dTo: { required: true  },
											name: { required: true  },
											email: { required: true, email:true  },
											country: { required: true }
										},
										messages: {
											dFrom: { required: ' '  },
											dTo: { required: ' '  },
											name: { required: '<br /> This field is required'  },
											email: { required: '<br /> This field is required' , email:'<br />Enter a valid email'  },
											country: { required: '<br /> This field is required' }
							
										},
										submitHandler: function(form) {
											form.submit();
										},
										success: function(span) { // set   as text for IE
											span.html(" ").addClass("checked");
										}
									});
								}
								
								
								
		}
		
	},	
	/** << Set cufon
	* ---------------------*/
	cufon : {
		init : function() { 
		
							Cufon.replace('.titulo','#gallery-container h2', {fontFamily:'BlackJack'});
		}
	},
	
	/** << Set toggle
	* ---------------------*/
	
	toggle : {
		init : function() {
        $('#minimizar').toggle (
            function(e) {
                e.preventDefault();
                $('#content-home, .ui-tabs-nav').hide({direction: "left"},500);
                $('img', this).attr('src','/images/botones/btn-max.png');
                $(this).attr('title','Maximizar');
            },
            function(e) {
                e.preventDefault();
                $('#content-home, .ui-tabs-nav').show({direction: "left"},500);
                $('img', this).attr("src","/images/botones/btn-min.png");
                $(this).attr('title','Minimizar');
            }
        );
	   }
	},
	
	
	
	/** << Set toggle
	* ---------------------*/
	
	calendar : {
		init : function() {
	
							$(
							function(){
								 setupCalendar();
							});
							
							/*function setupInputMask()
							{
								$("#name").alpha({allow:" -"});
								$("#telephone,#adults,#children").numeric({allow:"-"});
								$("#email").alphanumeric({allow:"-_.@"});
							}*/
							function setupCalendar()
							{
								 $("#dFrom,#dTo").datepicker({ 
									yearRange: "+0:+3", 
									minDate: "0d", 
									maxDate: "3y", 
									beforeShow: customRange,
									showAnim: "slideDown",
									dateFormat: "dd-mm-yy",
									showStatus: true, 
									showOn: "both", 
									buttonImage: "/images/bt-cal.png",
									buttonImageOnly: true,
									onSelect: function(dateText, inst) { 
										/*var isValid = $('#from,#to').validate();
											if (isValid) 
												$(this).addClass("checked").removeClass('invalid').next().next().remove();
											else 
											$(this).addClass("invalid");
										*/
									}
								})
							}
							
							function customRange(input)
							{ 
								return {minDate: (input.id == "dTo" ? $("#dFrom").datepicker("getDate") : "0d"), 
									maxDate: (input.id == "dFrom" ? $("#dTo").datepicker("getDate") : "3y")}; 
							}
	
	}
	},
	
	
	

			tooltip : {
					init : function() {
										$('.img-tooltip').hover (
												function(e) {
																  
										  e.preventDefault();
												   $('.text-tooltip').fadeIn();
												   
												},
												function(e) {
												  
										  e.preventDefault();
												   $('.text-tooltip').fadeOut();
												}
											);
								}
			},
	
	
	/** << Set shadowbox 
	* ---------------------*/
	shadowbox : {
		init : function() { 
							/*Shadowbox.loadSkin('classic', '/js/shadowbox-2.0/src/skin');
							Shadowbox.loadLanguage('en', '/js/shadowbox-2.0/src/lang');
							Shadowbox.loadPlayer(['html', 'iframe', 'img'], '/js/shadowbox-2.0/src/player');
							window.onload = function(){
							 Shadowbox.init( { 
									animSequence:'snyc'			
								}); 
							};*/
			Shadowbox.init({
			    handleOversize: "drag",
			    modal: true
			});


		}
	}
			
}

