$(function(){
$("a.fancybox").fancybox({
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic',
				'easingIn'      : 'easeOutBack',
				'easingOut'     : 'easeInBack',
				'titlePosition'  : 'inside',
				'width'         : 800,
				'height'        : 600,
				'autoScale'     : true,
				'overlayColor': '#fff'
				
	});

//	Room details
	var image_position	=	0;
	$('.image_nav .top').css({opacity:0.5}).mouseover(function() {
		$(this).css({opacity:1});
	}).mouseleave(function() {
		$(this).css({opacity:0.5});
	}).click(function() {
		var images = $(this).parent().find('.thumbs div').length;
		if(images > 3 && image_position > 0) {
			image_position--;
			$(this).parent().find('.thumbs .slider').animate({top:'-' + (image_position * 60) + 'px'}, 250);
		}
	});
	$('.image_nav .bottom').css({opacity:0.5}).mouseover(function() {
		$(this).css({opacity:1});
	}).mouseleave(function() {
		$(this).css({opacity:0.5});
	}).click(function() {
		var images = $(this).parent().find('.thumbs div').length;
		if(images > 3 && (image_position + 4) < images) {
			image_position++;
			$(this).parent().find('.thumbs .slider').animate({top:'-' + (image_position * 60) + 'px'}, 250);
		}
	});
	$('.image_nav .thumbs .slider img').click(function() {
		$(this).parents('.image_nav').prev().find('a img').attr('src', $(this).attr('src').replace('thumb', 'small'));
		$(this).parents('.image_nav').prev().find('a').attr('href', $(this).attr('src').replace('thumb_', ''));
	});
	
})

function getPrice(opt,calender,room_id){

var room_dates=calender.multiDatesPicker('getDates');
var options = [];
opt.each(function(index) { options.push($(this).val());});

$.ajax({
					  type: 'POST',
					  dataType:'json',
					  url: '/welcome/get_rooms_price',
					  data: { 'room_dates': room_dates, 'room_id': room_id,'options':options},
					  success: function(data){
					  
					  target=calender.parents('.tabs-wrapper').next().next();
					  target.find('.price-room-euro').html(data.price);
					  target.find('.price-options-euro').html(data.option_price);
					  target.find('.less-days-euro').html(data.extra_fee);
					  target.find('.price-borg-euro').html(data.borg);
					  target.find('.price-total-euro').html(data.total);
					  }
					  
});
			
}



/*
Strip whitespace from the beginning and end of a string
Input : a string
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

/*
Make sure that textBox only contain number
*/
function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}

/*
	Check if a form element is empty.
	If it is display an alert box and focus
	on the element
*/
function isEmpty(formElement, message) {
	formElement.value = trim(formElement.value);
	
	_isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	
	return _isEmpty;
}

/*
	Set one value in combo box as the selected value
*/
function setSelect(listElement, listValue)
{
	for (i=0; i < listElement.options.length; i++) {
		if (listElement.options[i].value == listValue)	{
			listElement.selectedIndex = i;
		}
	}	
}
function trimAll( strValue ) {
/************************************************
DESCRIPTION: Removes leading and trailing spaces.

PARAMETERS: Source string from which spaces will
  be removed;

RETURNS: Source string with whitespaces removed.
*************************************************/
 var objRegExp = /^(\s*)$/;

    //check for all spaces
    if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }

   //check for leading & trailing spaces
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(strValue)) {
       //remove leading and trailing whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}

function validateNotEmpty( strValue ) {
/************************************************
DESCRIPTION: Validates that a string is not all
  blank (whitespace) characters.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
*************************************************/
   var strTemp = strValue;
   strTemp = trimAll(strTemp);
   if(strTemp.length > 0){
     return true;
   }
   return false;
}



function validateEmail( strValue) {
/************************************************
DESCRIPTION: Validates that a string contains a
  valid email pattern.

 PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS: Accounts for email with country appended
  does not validate that email contains valid URL
  type (.com, .gov, etc.) or valid country suffix.
*************************************************/
var objRegExp  = /^([0-9a-zA-Z]+([_.-]?[0-9a-zA-Z]+)*@[0-9a-zA-Z]+[0-9,a-z,A-Z,.,-]*(.){1}[a-zA-Z]{2,4})+$/;

  //check for valid email
  return objRegExp.test(strValue);
}

