// JavaScript Document


$(document).ready(function(){
	
	
	$(".detailstotal a").click(function(){
		
		//$(this).html("Hide Details");
		
		$(this).parent().parent().parent().parent().find(".cotizacion_pre").stop().fadeIn(300);
		
		
		/*$(".detailstotal a").click(function(){
				$(this).parent().parent().parent().parent().find(".cotizacion_pre").stop().fadeOut(300);
				$(this).html("Details");
			});
			*/
			$(".ocultadetalles a").click(function(){
				$(this).parent().parent().parent().parent().find(".cotizacion_pre").stop().fadeOut(300);
				//$(this).html("Details");
			});
		
		});
	
	$("#seleccionar_suite a").click(function(){
		
		$("#selectorsuites").stop().fadeIn(300);
		
			$(".cerrarselector a").click(function(){
			
			
			$("#selectorsuites").stop().fadeOut(300);
			
			
			});
		
		
		
		});
		
		$("#selectorsuites input").change(function(){
				
					$("#seleccionar_suite a").html("Change Selection");
				});
	
	//$("a[rel^='gallery']").prettyPhoto({
//		animationSpeed: 'normal', /* fast/slow/normal */
//		padding: 30, /* padding for each side of the picture */
//		opacity: 0.85, /* Value betwee 0 and 1 */
//		showTitle: true, /* true/false */
//		allowresize: true, /* true/false */
//		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
//		theme: 'light_square', /* light_rounded / dark_rounded / light_square / dark_square */
//		hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
//		modal: false, /* If set to true, only the close button will close the window */
//		changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
//		callback: function(){} /* Called when prettyPhoto is closed */
//	});
	
	/*$('#galleryhome').galleria({
        width:983,
        height:280
    });*/
	$('ul#slider').fadeIn(300);
	$('ul#slider').simpleSlider({
			/*alpha: Caption opacity (default '0.7'),
			bgColor: Caption background color (default '#000'),
			bgSpeed: Background image fade speed ( 'slow', 'normal', 'fast' or number of milliseconds) default 'slow'
			captionSpeed: Caption slideUp/slideDown speed ( 'slow', 'normal', 'fast' or number of milliseconds) default 'slow'
			height: Caption height (default '50px')
			titleStyle: CSS Object for title ( default { color: '#fff', fontSize: '14px', fontFamily: 'Arial', margin: '0 10px 0 10px', textAlign: 'left' } )
			subtitleStyle: CSS Object for subtitle (default { color: '#fff', fontSize: '10px', fontFamily: 'Verdana', margin: '0 10px 0 10px', textAlign: 'left' } )
			timeOut: Milliseconds interval between slide ( default 4000 )*/
			alpha: '0',
			titleStyle: { color: '#fff', fontSize: '14px', fontFamily: 'Adamina', margin: '5px 10px 0 10px', textAlign: 'left' },
			subtitleStyle: { color: '#fff', fontSize: '15px', fontFamily: 'Adamina', margin: '0 10px 0 10px', textAlign: 'left' }
			
		});

	/*$('.date-pick')
		.datePicker({createButton:false})
		.bind(
			'click',
			function()
			{
				$(this).dpDisplay();
				this.blur();
				return false;
			}
		)
		.bind(
			'dateSelected',
			function(e, selectedDate, $td)
			{
				console.log('You selected ' + selectedDate);
			}
	);*/
	
	
	
	
	jQuery(".engine").find(".date-pickb").each(function() {
    //removing jquery added attribute as this is causing the dynamically
    // added DOM elem referring old DOM element from it is copied.
    if (jQuery.browser.msie) {
        var jqaddedattr;
        jQuery(this.attributes).each(function() {
            if (this.name.search(/jQuery/) != -1) {
                jqaddedattr = this;
            }
        });
        if (jqaddedattr) {
            jQuery(this).removeAttr(jqaddedattr.name);
        }
    }
	
	$(this).datePicker({createButton:false})
	$('.checkin')
	.bind(
			'click',
			function()
			{
				$(this).dpDisplay();
				this.blur();
				return false;
			}
		)
	.bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('.checkout').dpSetStartDate(d.addDays(1).asString());
			}
		}
	);
	$('.checkout')
	.bind(
			'click',
			function()
			{
				$(this).dpDisplay();
				this.blur();
				return false;
			}
		)
	.bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('.checkin').dpSetEndDate(d.addDays(-1).asString());
			}
		}
	);
	});
	
	
	
	
	jQuery(".engine").find(".date-pick").each(function() {
    //removing jquery added attribute as this is causing the dynamically
    // added DOM elem referring old DOM element from it is copied.
    if (jQuery.browser.msie) {
        var jqaddedattr;
        jQuery(this.attributes).each(function() {
            if (this.name.search(/jQuery/) != -1) {
                jqaddedattr = this;
            }
        });
        if (jqaddedattr) {
            jQuery(this).removeAttr(jqaddedattr.name);
        }
    }
	$(this).datePicker({createButton:false})
	//$('.date-pick').datePicker({createButton:false})
	$('#checkin')
	.bind(
			'click',
			function()
			{
				$(this).dpDisplay();
				this.blur();
				return false;
			}
		)
	.bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#checkout').dpSetStartDate(d.addDays(1).asString());
			}
		}
	);
	$('#checkout')
	.bind(
			'click',
			function()
			{
				$(this).dpDisplay();
				this.blur();
				return false;
			}
		)
	.bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#checkin').dpSetEndDate(d.addDays(-1).asString());
			}
		}
	);
	});
	
	
	
	
	
	
	
		
		
		$("#pageflip").hover(function() {
		$("#pageflip img , .msg_block").stop()
		.animate({ 
			width: '307px',
			height: '319px'
		}, 500);
		} , function() {
		$("#pageflip img").stop()
		.animate({
			width: '50px',
			height: '52px'
		}, 220);
		$(".msg_block").stop()
		.animate({
			width: '50px',
			height: '50px'
		}, 200);
		});
		
		
		// Ahora twitter
		
	
	$('#jTweets').jTweetsAnywhere({
	
    username: 'cabo_vacations',
    count: 3,
    showFollowButton: true,
	showTweetBox: { label: '<span style="color: #D1C7BA">Spread the word ...</span>',width: 250 },
	});
	
	
	$('#jTweets_full').jTweetsAnywhere({
	
    username: 'cabo_vacations',
    count: 10,
    showFollowButton: true,
	showTweetBox: { label: '<span style="color: #D1C7BA">Spread the word ...</span>',width: 850 },
	});
	
	
	//$("#timepick1").timePicker();
	
	
	
	$('form[id=reservaciones] .inputcant').change(function(){
		
		
		//nextstep
		//total_parcial
		
		$('form[id=reservaciones] .nextstep').fadeOut(200);
		$('form[id=reservaciones] .total_parcial').fadeOut(200);
		$('form[id=reservaciones]').attr('method','get');
		$('form[id=reservaciones]').attr('action','../bengine/pre.php?scr=true');
		//../bengine/reservation.php?scr=true
		$('form[id=reservaciones] .recalcular').fadeIn(200);
		
	});
	
	$('form[id=form2] .inputcant').change(function(){
		
		if($(this).val() == 0){
			
		alert("Please enter at least 1 suite to upgrade");
		$('#upgradestep').focus();	
		$('form[id=form2] #upgradestep').fadeOut(200);
		} else {
		$('form[id=form2] #upgradestep').fadeIn(200);
		}
	});
		
});

function activasuite(quesuite){
	
	$('.cotizacion').each(function(){
		
		$(this).hide();
		});
	$('#cotizacion'+quesuite).fadeIn(300);	
	
	
	
}


function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }

