$(function(){	 
	/***
	 * Generic functions that come out of the box
	 */
	
	$("#collapse-more").hide();
	if ($("#collapse-more").length && $("p#collapse-read_more").length) {
		$("p#collapse-read_more a").click(function() {
			$("#collapse-more").slideToggle(700, function() {
				$("p#collapse-read_more a").toggleClass("more-hide");
				($("p#collapse-read_more a").hasClass("more-hide")) ? $("p#collapse-read_more a").html("Read less") : $("p#collapse-read_more a").html("Read More");
	      		});
		  
			return false;
		});
	}
	
	$("form input[type=text]").not('.date-input').focus(function(){
		var $default = $(this).val();
		$(this).val("");
		$(this).blur(function(){
			if($(this).val()=="") $(this).val($default);
		});
	});

	if($("a[rel^='prettyPhoto']").size()>0){
		$("a[rel^='prettyPhoto']").prettyPhoto({
			animation_speed: 'fast',
			slideshow: '5000',
			autoplay_slideshow: true,
			show_title: false
		});
	}
	
    $("form[name=omni_reservation_form] input#CI_input").datepicker({
	    closeText: 'Close',
	    dateFormat: 'mm/dd/yy',
	    defaultDate: 0,
	    minDate: '+0',
	    //maxDate: '+1Y',
	    showAnim: 'slideDown',
	    showButtonPanel: true,
	    onSelect: function(date,thisPicker){
		date = $(this).datepicker("getDate");
		var dayIn = date.getDate("dd");
		var monthyearIn= ''+ (date.getMonth()+1) + date.getFullYear();
		$('#DateIn').val(dayIn);
		$('#MonthYearIn').val(monthyearIn);
		date.setDate(date.getDate()+1);
		$("form[name=omni_reservation_form] input#CO_input").datepicker("setDate",date);
	    }
	});
	
	$("form[name=omni_reservation_form] input#CO_input").datepicker({
	    closeText: 'Close',
	    dateFormat: 'mm/dd/yy',
	    defaultDate: +1,
	    minDate: '+1',
	    //maxDate: '+1Y',
	    showAnim: 'slideDown',
	    showButtonPanel: true,
	    onSelect: function(date,thisPicker){
                date = $(this).datepicker("getDate");
                var dayOut = date.getDate("dd");
                var monthyearOut= ''+ (date.getMonth()+1) + date.getFullYear();
		$('#DateOut').val(dayOut);
                $('#MonthYearOut').val(monthyearOut);
	    }
	});
	$('#adults_select').change(function(){
	    $('#adultsCount').val(this.options[this.selectedIndex].value);
	    
	});
	  $('#rooms_select').change(function(){
            $('#roomsCount').val(this.options[this.selectedIndex].value);
        });
	$('#children_select').change(function(){
	    $('#childrenCount').val(this.options[this.selectedIndex].value); 
	});
	$("form.styled .date").datepicker({
		buttonImage: '/extension/cdev_base/design/cdev_base/images/calendar.png',
		buttonImageOnly: true,
		closeText: 'Close',
		dateFormat: 'MM d, yy',
		minDate: '+0',
		//maxDate: '+1Y',
		showAnim: 'slideDown',
		showOn: 'both',
		showButtonPanel: true
	});

	$("form[name=omni_reservation_form]").submit(function(){
	    var action=$(this).attr("action");
	    var inputs=$("form[name=omni_reservation_form] input[type='hidden']");
	    var url="";
	    for(var i=0; i<inputs.length; i++){
		url+=$(inputs[i]).attr('name')+'='+$(inputs[i]).val()+'&';
	    }
	    action+='?'+url;
	    $(this).attr("action", action);
	});
													 
	
	$("form input.email-validate").addClass("email-invalid");
	$("form input.email-validate").each(function(){
		$(this).blur(function(){
			var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
			
			if(reg.test( $(this).val() ) == false)
				$(this).addClass("email-invalid");
			else
				$(this).removeClass("email-invalid");
		})
		
		$(this).parents("form").submit(function(){
			var valid; 
			
			$(this).find("input.email-validate").each(function(){
				if( $(this).hasClass("email-invalid") )
					valid = "false";
				else
					valid = "true";
			});
			
			if(valid=="true"){
				return true;
			}else{
				alert('Please enter a valid email');
				return false;
			}
		});
	});
	
	/**
	 * End Generic Functions
	 */
});

$(document).ready( function() {
	$('.readmore').click(function(){
		if ($(this).text() == 'Read less') {
			$(this).text('Read more');
			$('.text-more').slideToggle(300);
		}
		else {
			$(this).text('Read less');
			$('.text-more').slideToggle(300);
		}
		return false;
	
	});
	
} );
