$(document).ready(function(){
	$('.clicknclear').click(function() {
		$(this).attr('rel', $(this).val());
		$(this).val('');
	}).blur(function() {
		if ($(this).val().length < 1)
			$(this).val($(this).attr('rel'));
	});
	
	// Apply date picker if loaded
	if (typeof jQuery.fn.datepicker == 'function')
		$('input.selectdate').datepicker({dateFormat: 'dd/mm/yy', showOn: 'both', buttonImage: '/skin/images/icon-calendar.gif', buttonImageOnly: true});
		
    $('#bp_submit').click(function() {
        if ($('#bp_check_in_date').val() == 'Click for calendar')
          return false;
        
        var date_parts = $('#bp_check_in_date').val().split(/\//);
        var num_of_nights = ($("#bp_num_of_nights").attr('value'));
        var co_date = new Date();
        co_date.setFullYear(parseInt(date_parts[2], 10), parseInt(date_parts[1], 10) - 1, parseInt(date_parts[0], 10));
        co_date.setDate(co_date.getDate()+ parseInt(num_of_nights));
        
        function _num_fmt (num) { if (num <= 9) return '0' + num; else return '' + num; } 
        $('#bp_check_out_date').val(_num_fmt(co_date.getDate() ) + '/' + _num_fmt(co_date.getMonth() + 1) + '/' + co_date.getFullYear());
        document.resbookingform.submit();
        return false; 
    });

	$(".printme").click(function () {
		window.print();
		return false;
	});
	
	$(".closeme").click(function () {
		window.close();
		return false;
	});

	if (typeof jQuery.fn.popupwindow == 'function') {
		$('.popupwindow').attr('rel', 'popupwindow').popupwindow({popupwindow: {height: 600, width:750, createnew:0, scrollbars:1, center:1}});
	}
	
	if (typeof jQuery.fn.ckeditor == 'function')
	{
		$('textarea.editor').ckeditor(function() { }, {
			format_tags: 'p;h2;h3;h4;h5;h6;pre;div',
            contentsCss: '/skin/css/ckeditor.css',
			toolbar: [
			  ['Format', 'Bold','Italic','Underline','StrikeThrough', 'BulletedList', 'NumberedList', 'Undo', 'Redo'],
			  ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
			  ['Link','Unlink','Table']
			]
		});
	}
	
	// FANCYBOX - Gallery
	if (typeof jQuery.fn.fancybox == 'function') {
		$('a.gallery-item').fancybox({
			'overlayOpacity': 0.7,
			'overlayColor':		'#000',
			'titlePosition'		: 'over'
		});
	}

	
});

