MyApp = {
	Main : {
		init : function() 
		{
		}
	},
	home : {
		slide : function()
		{
    		$('#slide').cycle({ 
			fx: 'fade',
			speed:       1000, 
			timeout:     5000, 
			pager:      '#nav',
            before: function(){
                /*$(".contentTextSlide").hide().delay(1000).fadeIn('');*/
                //alert('Alert');
            },
            after:   function(curr, next, opts){
               // var index = opts.currSlide;
                //alert(index);
				
				//var index = $(".conatinerSlide").index(this);
  				//$("span").text("That was div index #" + index);

				/*$(".contentTextSlide").hide().delay(500).fadeIn('');*/
				
               // var indexv = $(".conatinerSlide").index(index);
				
                //$(".conatinerSlide .contentTextSlide p").hide()
                //indexv.innerHTML = 'Josd'+index;
				
               // $(".conatinerSlide .contentTextSlide p").eq(index).html("byyyyy"+index);
				
                //$(".conatinerSlide .contentTextSlide p").html("Index " + indexv + " was clicked");
                //$('#contentTextSlide p').html('red');
                /*if(index == 0)
                {
                    $('#prevBoutique').removeClass();
                    $('#prevBoutique').addClass('sliders-prev');
                    
                }else{
                    $('#prevBoutique').removeClass();
                    $('#prevBoutique').addClass('sliders-prev-on');
                }
                
                if(index == opts.slideCount - 1)
                {
                    $('#nextBoutique').removeClass();
                    $('#nextBoutique').addClass('sliders-next');
                }else{
                    $('#nextBoutique').removeClass();
                    $('#nextBoutique').addClass('sliders-next-on');
                }*/
            }
			});
		}
	},
	
	menu :{
		init : function(){
				jQuery('ul.sf-menu').superfish();
			}
	},
		
	
	SlideText : {
		init : function(){
			$(".textSlide").hide().delay(500).fadeIn('');	
			$(".textSlide2").hide().delay(500).fadeIn('');		
		}
	},
	
	
	
	jcarousel : {
		init : function(){
			jQuery('#mycarousel').jcarousel({scroll:1});
		}
	},	
	
	contactForm : {
		init : function()
		{
			MyApp.contactForm.validate();
			MyApp.contactForm.defaultInputValues();
			MyApp.contactForm.LimpiarCampos();
		},
		validate : function()
		{
			$("#name, #lastName").alphanumeric({allow:" -"});
			$("#phone").numeric({allow:"-"});
			$("#email").alphanumeric({allow:"-_.@"});
			
			var v = $("#FormQuoteRequest").validate({
				errorElement : 'span',
				onkeyup: false,
				onblur: false,
				errorClass: "invalid",
				rules: {
					name: { required: true  },
					lastName: { required: true  },
					phone: { required: true  },
					email: { required: true, email:true  }
				},
				messages: {
					name: { required: '<br>This field is required'  },
					lastName: { required: '<br>This field is required'  },
					phone: { required: '<br>This field is required'  },
					email: { required: '<br>This field is required' , email:'<br>Enter a valid email' }
				},
				submitHandler: function(form) {
					//form.submit();
                    var data = $('#FormQuoteRequest').serialize();
                    $("#botonSend").attr("disabled", true);
                    $('#viewLoading').show();
                    $.ajax({
                        type: "post",
                        url: WWW_ROOT+langShort+'/frontcompany/index/sendquoterequest',
                        data: data,
                        dataType: "html",
                        success: function(data) {
                            var arrJson = JSON.parse(data);
                            if(arrJson.success)
                            {
                                $('.viewFromQuoteRequest').hide();
                                $('#viewLoading').hide();
                                $('.viewThanksFromQuoteRequest').show();
                            }
                        }
                    });
				},
				success: function(span) { // set   as text for IE
					span.html(" ").addClass("checked");
				}
			});
		},
		defaultInputValues : function()
		{
			$('input:text').click(function(){
				if($(this).val()== $(this).attr("title")){
					$(this).val("");
				}							 
			});
			$('input:text').focusout(function(){
					if($(this).val()== ""){
						$(this).val($(this).attr("title"));
					}							 
				});
				
			$("textarea").focus(function(){
					if($(this).html()==$(this).attr("title")){
						$(this).html('');
					}							 
				});
			
			$("input[type=text]").focus(function(){
				$("#comments").html($("#comments").attr("title"));
			});	
		},		
		LimpiarCampos: function()
		{ 
			$("#botonSend").click(function(){
				$('input:text').each(function (i) {
					if($(this).val()== $(this).attr("title")){
							$(this).val("");
						}	
			 	 });
				/*alert("Es una prueba");*/
			});
		}
	},	
	
	
	contactFormSeccion : {
		init : function()
		{
			$("#name, #lastName").alphanumeric({allow:" -"});
			$("#phone").numeric({allow:"-"});
			$("#email").alphanumeric({allow:"-_.@"});
			
			
			var v = $("#contactUsForm").validate({
				errorElement : 'span',
				onkeyup: false,
				onblur: false,
				errorClass: "invalid",
				rules: {
                    name: { required: true  },
					lastName: { required: true  },
					phone: { required: true  },
					email: { required: true, email:true  },
                    city: { required: true }
				},
				messages: {
                    name:{ required: '<br>This field is required'},
					lastName: { required: '<br>This field is required'  },
					phone: { required: '<br>This field is required'  },
					email: { required: '<br>This field is required' , email:'<br>Enter a valid email' },
                    city:{ required: '<br>This field is required'}
				},
				submitHandler: function(form) {
					//form.submit();
                    var data = $('#contactUsForm').serialize();
                    $("#btnContact").attr("disabled", true);
                    $('#viewLoading').show();
                    $.ajax({
                        type: "post",
                        url: WWW_ROOT+langShort+'/frontcompany/index/sendcontactus',
                        data: data,
                        dataType: "html",
                        success: function(data) {
                            var arrJson = JSON.parse(data);
                            if(arrJson.success)
                            {
                                var url = $('#urlThanks').val();
                                $(location).attr('href',url);
                            }
                        }
                    });
				},
				success: function(span) { // set   as text for IE
					span.html(" ").addClass("checked");
				}
			});
		}
	},
	
	AddComments : {
		init : function()
		{
			$("#nameComments, #sumamesComments, #comments").alphanumeric({allow:" -"});
			$("#emailComments").alphanumeric({allow:"-_.@"});
			
			var v = $("#formCommtens").validate({
				errorElement : 'span',
				onkeyup: false,
				onblur: false,
				errorClass: "invalid",
				rules: {
					nameComments: { required: true  },
					sumamesComments: { required: true  },
					comments: { required: true  },
					emailComments: { required: true, email:true  }
				},
				messages: {
					nameComments: { required: '<br>This field is required'  },
					sumamesComments: { required: '<br>This field is required'  },
					comments: { required: '<br>This field is required'  },
					emailComments: { required: '<br>This field is required' , email:'<br>Enter a valid email' }
				},
				submitHandler: function(form) {
					//form.submit();
                    var data = $('#formCommtens').serialize();
                    $("#sendQuickRequestForm").attr("disabled", true);
                    $("#viewLoading2").show();
                    $.ajax({
                        type: "post",
                        url: WWW_ROOT+langShort+'/frontnews/index/sendcomment',
                        data: data,
                        dataType: "html",
                        success: function(data) {
                            var arrJson = JSON.parse(data);
                            if(arrJson.success)
                            {
                                $("#viewLoading2").hide();
                                $('#formCommtens').resetForm();
                                //$('#viewThanks').show('slow');
                                $("#viewThanks").fadeIn(1000);
                                
                                setTimeout(function(){
                                    $("#viewThanks").fadeOut(1000);    
                                }, 4000);
                                
                                //var url = WWW_ROOT+'tourlist/index/thanks';    
                                //$(location).attr('href',url);
                            }
                        }
                    });
				},
				success: function(span) { // set   as text for IE
					span.html(" ").addClass("checked");
				}
			});
		}
	},	
	
	calendar : {
		init : function() {	
						{
							 $("#departureDate,#arrivalDate").datepicker({ 
								yearRange: "+0:+3", 
								minDate: "0d", 
								maxDate: "3y", 
								beforeShow: customRange,
								showAnim: "slideDown",
								dateFormat: "mm-dd-yy",
								showStatus: true, 
								showOn: "both", 
								buttonImage: WWW_ROOT+"images/quoteRequest/imgCalendar.jpg",  
								buttonImageOnly: true
								})
							}
							
							function customRange(input)
							{ 
								return {minDate: (input.id == "dTo" ? $("#dFrom").datepicker("getDate") : "0d"), 
									maxDate: (input.id == "dFrom" ? $("#dTo").datepicker("getDate") : "3y")}; 
							}
	
		}
	},
	
	calendarDestination : {
		init : function() {	
						{
							 $("#dFromDestination,#dToDestination").datepicker({ 
								yearRange: "+0:+3", 
								minDate: "0d", 
								maxDate: "3y", 
								beforeShow: customRange,
								showAnim: "slideDown",
								dateFormat: "mm-dd-yy",
								showStatus: true, 
								showOn: "both", 
								buttonImage: WWW_ROOT+"js/calendarnew/images/imgCalendar.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 == "dToDestination" ? $("#dFromDestination").datepicker("getDate") : "0d"), 
									maxDate: (input.id == "dFromDestination" ? $("#dToDestination").datepicker("getDate") : "3y")}; 
							}
	
		}
	},
	
	calendarReservations : {
		init : function() {	
						{
							 $("#depart,#return").datepicker({ 
								yearRange: "+0:+3", 
								minDate: "0d", 
								maxDate: "3y", 
								beforeShow: customRange,
								showAnim: "slideDown",
								dateFormat: "mm-dd-yy",
								showStatus: true, 
								showOn: "both", 
								buttonImage: WWW_ROOT+"js/calendarnew/images/imgCalendar.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 == "return" ? $("#depart").datepicker("getDate") : "0d"), 
									maxDate: (input.id == "depart" ? $("#return").datepicker("getDate") : "3y")}; 
							}
	
		}
	},
	
	comboboxReservations : {
		init : function(){
			this.setupCombobox();
		},
		
		setupCombobox : function(){
			
			var _quickSearchComboboxLarge = null;
			var _animationType = "slide";
			var comboboxSettings = { animationSpeed: 50 };
			var options = {
					comboboxContainerClass: "comboboxContainer",
					comboboxValueContentContainerClass: "comboboxValueContainer",
					comboboxValueContentClass: "comboboxValueContent",
					comboboxDropDownClass: "comboboxDropDownContainer",
					comboboxDropDownButtonClass: "comboboxDropDownButton",
					comboboxDropDownItemClass: "comboboxItem",
					comboboxDropDownItemHoverClass: "comboboxItemHover",
					comboboxDropDownGroupItemHeaderClass: "comboboxGroupItemHeader",
					comboboxDropDownGroupItemContainerClass: "comboboxGroupItemContainer"
			};
			
			var _quickSearchComboboxLarge = $('#from, #to').combobox(options,{ animationType: _animationType, width:190 });
			var _quickSearchComboboxLarge = $('#adults, #children, #room').combobox(options,{ animationType: _animationType, width:58 });
			
		}
	},
	
	comboboxContact : {
		init : function(){
			this.setupCombobox();
		},
		
		setupCombobox : function(){
			
			var _quickSearchComboboxLarge = null;
			var _animationType = "slide";
			var comboboxSettings = { animationSpeed: 50 };
			var options = {
					comboboxContainerClass: "comboboxContainer",
					comboboxValueContentContainerClass: "comboboxValueContainer",
					comboboxValueContentClass: "comboboxValueContent",
					comboboxDropDownClass: "comboboxDropDownContainer",
					comboboxDropDownButtonClass: "comboboxDropDownButton",
					comboboxDropDownItemClass: "comboboxItem",
					comboboxDropDownItemHoverClass: "comboboxItemHover",
					comboboxDropDownGroupItemHeaderClass: "comboboxGroupItemHeader",
					comboboxDropDownGroupItemContainerClass: "comboboxGroupItemContainer"
			};
			
			var _quickSearchComboboxLarge = $('#country').combobox(options,{ animationType: _animationType, width:300 });
			//var _quickSearchComboboxLarge = $('#city').combobox(options,{ animationType: _animationType, width:132 });
			//var _quickSearchComboboxLarge = $('#questions').combobox(options,{ animationType: _animationType, width:637 });
			
		}
	},	
	
	
	comboboxReserve : {
		init : function(){
			this.setupCombobox();
			this.setupComboboxSmall();
			this.setupComboboxMedium();
		},
		
		setupCombobox : function(){
			
			var _quickSearchComboboxLarge = null;
			var _animationType = "slide";
			var comboboxSettings = { animationSpeed: 50 };
			var options = {
					comboboxContainerClass: "comboboxContainer",
					comboboxValueContentContainerClass: "comboboxValueContainer",
					comboboxValueContentClass: "comboboxValueContent",
					comboboxDropDownClass: "comboboxDropDownContainer",
					comboboxDropDownButtonClass: "comboboxDropDownButton",
					comboboxDropDownItemClass: "comboboxItem",
					comboboxDropDownItemHoverClass: "comboboxItemHover",
					comboboxDropDownGroupItemHeaderClass: "comboboxGroupItemHeader",
					comboboxDropDownGroupItemContainerClass: "comboboxGroupItemContainer"
			};
			
			//var _quickSearchComboboxLarge = $('#arrivalCity, #departureCity').combobox(options,{ animationType: _animationType, width:181 });
            //var _quickSearchComboboxLarge = $('#packagesTours, #destinationsTours').combobox(options,{ animationType: _animationType, width:155 });
            
            var selectDestinationsTours = $('#destinationsTours').combobox(options,{ animationType: _animationType, width:170 });
            var selectPackagesTours = $('#packagesTours').combobox(options,{ animationType: _animationType, width:170 });
            
            selectDestinationsTours.combobox.onChange = function(){
                var paii_id = $("#destinationsTours").val();
                $.post(WWW_ROOT+langShort+"/fronttour/index/packagestours", { paii_id: paii_id }, function(data){
                    selectPackagesTours.combobox.remove();
                    $("#packagesTours").html(data);
                    $('#packagesTours').combobox(options,{ animationType: _animationType, width:170 });
                });
                
            };
            
            var selectDestinations = $('#destinations').combobox(options,{ animationType: _animationType, width:170, height:200 });
            var selectPackages = $('#packages').combobox(options,{ animationType: _animationType, width:170 });
            
            selectDestinations.combobox.onChange = function(){
                var paii_id = $("#destinations").val();
                $.post(WWW_ROOT+langShort+"/fronttour/index/packagespecial", { paii_id: paii_id }, function(data){
                    selectPackages.combobox.remove();
                    $("#packages").html(data);
                    $('#packages').combobox(options,{ animationType: _animationType, width:170 });
                });
                
            };
			//var _quickSearchComboboxLarge = $('#destinations, #packages, #packagesTours, #destinationsTours').combobox(options,{ animationType: _animationType, width:155 });
		},
		
		setupComboboxSmall : function(){
			
			var _quickSearchComboboxSmall = null;
			var _animationType = "slide";
			var comboboxSettings = { animationSpeed: 50 };
			var options = {
					comboboxContainerClass: "comboboxContainer",
					comboboxValueContentContainerClass: "comboboxValueContainer",
					comboboxValueContentClass: "comboboxValueContent",
					comboboxDropDownClass: "comboboxDropDownContainer",
					comboboxDropDownButtonClass: "comboboxDropDownButton",
					comboboxDropDownItemClass: "comboboxItem",
					comboboxDropDownItemHoverClass: "comboboxItemHover",
					comboboxDropDownGroupItemHeaderClass: "comboboxGroupItemHeader",
					comboboxDropDownGroupItemContainerClass: "comboboxGroupItemContainer"
			};
			
			var _quickSearchComboboxSmall = $('#adults, #children').combobox(options,{ animationType: _animationType, width: 39 });
		},
		
		
		setupComboboxMedium : function(){
			
			var _quickSearchComboboxMedium = null;
			var _animationType = "slide";
			var comboboxSettings = { animationSpeed: 50 };
			var options = {
					comboboxContainerClass: "comboboxContainer",
					comboboxValueContentContainerClass: "comboboxValueContainer",
					comboboxValueContentClass: "comboboxValueContent",
					comboboxDropDownClass: "comboboxDropDownContainer",
					comboboxDropDownButtonClass: "comboboxDropDownButton",
					comboboxDropDownItemClass: "comboboxItem",
					comboboxDropDownItemHoverClass: "comboboxItemHover",
					comboboxDropDownGroupItemHeaderClass: "comboboxGroupItemHeader",
					comboboxDropDownGroupItemContainerClass: "comboboxGroupItemContainer"
			};
			
			var _quickSearchComboboxMedium = $('#pais, #ciudad').combobox(options,{ animationType: _animationType, width: 146 });
		}
	},	
	
	/*slideReserve: {
		init : function(){
			$("#contentReserve img").live("click", function() {
				$("#contentReserveslideNow").slideDown("slow");
			});	
			$("#contentReserve img.up").live("click", function() {
				$("#contentReserveslideNow").slideUp("slow");
			});
		}
	},*/
	slideReserve : {
		init : function() {
			$('.bookYourFlight img.down').toggle(
				function ()  {
					$('#contentReserveslideNowFlight').animate({ top: '0px' }, 1000 );			
					$('.chooseDestination img.down2').animate({ top: '316px' }, 1000 );
					/*$('.chooseDestination #contentReserveslideNowDestination').css({ 'visibility': 'hidden' } );*/
					$('#contentReserveslideNowFlight').css({ 'z-index': '10' });
				}, 
				function () {
					$('#contentReserveslideNowFlight').animate({ top: '-317px' }, 1000 );		
					$('.chooseDestination img.down2').animate({ top: '0px' }, 1000 );
					/*$('.chooseDestination #contentReserveslideNowDestination').css({ 'visibility': 'visible' } );*/
				}
			);
			$('.chooseDestination img.down2').toggle(
				function () {			
					$('#contentReserveslideNowDestination').animate({ top: '18px' }, 1000 );
					/*$('.chooseDestination #contentReserveslideNowDestination').css({ 'visibility': 'visible' } );*/
				}, 
				function () {
					$('#contentReserveslideNowDestination').animate({ top: '-343px' }, 1000 );	
				}
			);
		}
	},
	
	
	curvyCorners: {
		init : function()
			{
			settings = {
			  tl: { radius: 10 },
			  tr: { radius: 10 },
			  bl: { radius: 10 },
			  br: { radius: 10 },
			  autoPad: true,
			  validTags: ["div"]
		  }	
		  
		  $('#Promotions').corner(settings);
		}
	}
	
}
MyApp.Main.init();
