// JavaScript Document
	$(function() {
 
  //slider
	
  var currentPosition = 0;
  var slideWidth = 970;
  var slides = $('.slide');
  var numberOfSlides = slides.length;
  var interval;
  // Remove scrollbar in JS
  $('#slidesContainer').css('overflow', 'hidden');

  // Wrap all .slides with #slideInner div
  slides
    .wrapAll('<div id="slideInner"></div>')
    // Float left to display horizontally, readjust .slides width
	.css({
      'float' : 'left',
      'width' : slideWidth
    });

  // Set #slideInner width equal to total width of all slides
  $('#slideInner').css('width', slideWidth * numberOfSlides);

  // Insert controls in the DOM
  $('#slideshow')
    .prepend('<span class="control" id="leftControl">Previous</span>')
    .append('<span class="control" id="rightControl">Next</span>');

  // Hide left arrow control on first load
  manageControls(currentPosition);

  // Create event listeners for .controls clicks
  $('.control')
    .bind('click', function(){
    // Determine new position
	currentPosition = ($(this).attr('id')=='rightControl') ? currentPosition+1 : currentPosition-1;
    
	if($(this).attr('id')=='rightControl' && currentPosition == numberOfSlides){
		currentPosition	=0;		
	}
	
	// Hide / show controls
    manageControls(currentPosition);
    // Move slideInner using margin-left
    $('#slideInner').animate({
      'marginLeft' : slideWidth*(-currentPosition)
    });
	
	clearInterval(interval);
	 interval = setInterval("$('#rightControl').trigger('click')", 5000);
	
  });

  // manageControls: Hides and Shows controls depending on currentPosition
  function manageControls(position){
    // Hide left arrow if position is first slide
	if(position==0){ $('#leftControl').hide() } else{ $('#leftControl').show() }
	// Hide right arrow if position is last slide
    if(position==numberOfSlides-1){ $('#rightControl').hide() } else{ $('#rightControl').show() }
  }	

   //AUTOMATE THE SLIDESHOW
   interval = setInterval("$('#rightControl').trigger('click')", 5000);


//dialog modal box for inquiry
		var name = $("#iname"),
			email = $("#iemail"),
			address = $("#iaddress"),
			inquiry= $("#icomment"),
			allFields = $([]).add(name).add(email).add(address).add(inquiry),
			tips = $("#validateTips");

		function updateTips(t) {
			tips.text(t).effect("highlight",{},1500);
		}

		function checkLength(o,n,min,max) {

			if ( o.val().length > max || o.val().length < min ) {
				o.addClass('ui-state-error');
				updateTips(n + ": Minimum characters should be "+min+".");
				return false;
			} else {
				return true;
			}

		}

		function checkRegexp(o,regexp,n) {

			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass('ui-state-error');
				updateTips(n);
				return false;
			} else {
				return true;
			}

		}
		
		function checkSame(p,p1,p2)
		{
		//alert(p1);
		//alert(p2);
			if(p1!=p2){
				p.addClass('ui-state-error');
				updateTips("password mismatch");
				return false;
			}
			else {
			return true;
			}
		}
		
		$("#dialog").dialog({				
			bgiframe: true,
			autoOpen: false,
			height: 300,
			modal: true,
			buttons: {
				'Send': function() {
				//var pass1=$("#password").val();
				//var pass2=rtpword.val();
		
					var bValid = true;
					allFields.removeClass('ui-state-error');

					bValid = bValid && checkLength(name,"Name ",3,16);
				//	bValid = bValid && checkRegexp(name,/^[a-z]([0-9a-z_])+$/i,"username error");
					
					bValid = bValid && checkLength(email,"Email",6,80);
					
					
					
					// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
					bValid = bValid && checkRegexp(email,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"Please enter a valid email address");
					bValid = bValid && checkLength(address,"Address",6,80);
					bValid = bValid && checkLength(inquiry,"Inquiry",6,80);
				//	bValid = bValid && checkLength(password,"password",5,16);
				//	bValid = bValid && checkRegexp(password,/^([0-9a-zA-Z])+$/,"validate");
					
				
				//	bValid = bValid && checkSame(rtpword,pass1,pass2);
					

					
					if (bValid) {
						$('#users tbody').append('<tr>' +
							'<td>' + name.val() + '</td>' + 
							'<td>' + email.val() + '</td>' + 
							'<td>' + address.val() + '</td>' +
							'<td>' + inquiry.val() + '</td>' +
							'</tr>'); 
							
							//submit 
							$.ajax({
									type: "POST",
									url: "feedback.php",
									data: 'action=send_inquiry&'+prepareQuerystring($('#dialog')),
									dataType: "string",
									error: function(err){
										$("#validateTips").after('<span class="error">error</span>')
									},
									success: function(msg){
										msg = $.trim(msg);
										$('#loader').hide();
										msg = $.trim(msg);
										if(msg == 'already exists' || msg == 'duplicate'){
											msg = 'Could not send your inquiry. Please try again later';
											
										}
										else if(msg == 'created'){
											msg = 'Your inquiry is sent';
									
											
										}
										$("#validateTips").html(msg);
										//resetForm('#frmRegister');
									}
									});		
						//$(this).dialog('close');
					}
				},
				'Close': function() {
					$(this).dialog('close');
				}
			},
			close: function() {
				allFields.val('').removeClass('ui-state-error');
			}
		});
		
		
		
		$('#just').click(function() { 
			$('#dialog').dialog('open');
			})
			.hover(
			function(){ 
				//$(this).addClass("ui-state-hover"); 
			},
			function(){ 
				//$(this).removeClass("ui-state-hover"); 
			}
			).mousedown(function(){
			//$(this).addClass("ui-state-active"); 
			})
			.mouseup(function(){
				//$(this).removeClass("ui-state-active");
			});
			
		
		
		//book now
	/*	$('#book').click(function() {
			$('#booknow').dialog('open');
			})
		$("#booknow").dialog({				
			bgiframe: true,
			autoOpen: false,
			height: 300,
			modal: true,
			buttons: {
				'Send': function() {
				//var pass1=$("#password").val();
				//var pass2=rtpword.val();
		
					var bValid = true;
					allFields.removeClass('ui-state-error');

					bValid = bValid && checkLength(name,"Name ",3,16);
				//	bValid = bValid && checkRegexp(name,/^[a-z]([0-9a-z_])+$/i,"username error");
					
					bValid = bValid && checkLength(email,"email",6,80);
					
					
					
					// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
					bValid = bValid && checkRegexp(email,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"eg. username@yahoo.com");
					bValid = bValid && checkLength(address,"address",6,80);
					bValid = bValid && checkLength(inquiry,"inquiry",6,80);
				//	bValid = bValid && checkLength(password,"password",5,16);
				//	bValid = bValid && checkRegexp(password,/^([0-9a-zA-Z])+$/,"validate");
					
				
				//	bValid = bValid && checkSame(rtpword,pass1,pass2);
					

					
					if (bValid) {
						$('#users tbody').append('<tr>' +
							'<td>' + name.val() + '</td>' + 
							'<td>' + email.val() + '</td>' + 
							'<td>' + address.val() + '</td>' +
							'<td>' + inquiry.val() + '</td>' +
							'</tr>'); 
							
							//submit 
							$.ajax({
									type: "POST",
									url: "feedback.php",
									data: 'action=send_inquiry&'+prepareQuerystring($('#dialog')),
									dataType: "string",
									error: function(err){
										$("#validateTips").after('<span class="error">error</span>')
									},
									success: function(msg){
										msg = $.trim(msg);
										$('#loader').hide();
										msg = $.trim(msg);
										if(msg == 'already exists' || msg == 'duplicate'){
											msg = 'Could not send your inquiry. Please try again later';
											
										}
										else if(msg == 'created'){
											msg = 'Your inquiry is sent';
									
											
										}
										$("#validateTips").html(msg);
										//resetForm('#frmRegister');
									}
									});		
						//$(this).dialog('close');
					}
				},
				'Close': function() {
					$(this).dialog('close');
				}
			},
			close: function() {
				allFields.val('').removeClass('ui-state-error');
			}
		});*/
		
		
		//validate reservation form
		

	});
