$(document).ready(function()
{ 
	Date.format = 'yyyy-mm-dd';
	$('.date-pick').datePicker({clickInput:true, showYearNavigation:false});
	$('#checkin').bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#checkout').dpSetStartDate(d.addDays(1).asString());
			}
		}
	);
	$('#checkout').bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#checkin').dpSetEndDate(d.addDays(-1).asString());
			}
		}
	);

	if($('.left').height() > $('.right').height()) $('.right').height($('.left').height());

	$('#menu ul li.sub ul li:last-child a').each( function(){
		$(this).css('border-bottom-style', 'none');
		$(this).css('padding-bottom', '2px');
	});
	$('#menu ul li.sub').each(function(){
			var offset = $(this).prev('li').prev('li').offset();
			if($(this).prev().is('li.sep'))	var parent_width = $(this).prev('li').prev('li').width();
			else var parent_width = $(this).prev('li').width();
			var menu_width = $(this).width();
			var d =  menu_width - parent_width;
/*			$(this).prev().html($(this).prev().html() + d);
			if(parent_width < menu_width)	{
*/
			$(this).css('left',(offset.left - d/2 - 3)+'px');
			$(this).css('width',(parent_width + d + 1)+'px');
/*			}
			else {
				$(this).css('left',(offset.left - d)+'px');

//				$(this).css('width',(parent_width)+'px');
			}*/
	});

	$('#images').cycle({
		fx:     'scrollHorz',
		speed:   2000,
		timeout: 10000,
		prev:   '#prev-slide',
		next:   '#next-slide'
	});
	
	$('#gallery-text-container').css({
		opacity: .4
	});
	$('.box-title').css({
		opacity: .4
	});
	$('.post input, .post textarea').focus(function(){
		var id = $(this).attr('id');
		$('label[for='+id+']').css('color', '#6e140c');
 	});
	$('.post input, .post textarea').focusout(function(){
		var id = $(this).attr('id');
		$('label[for='+id+']').css('color', '#111');
 	});	
	$('.post.right input[name=email]').keypress( function(){
		if($(this).val().length > 0) $('.post.right input[name=tome]').removeAttr("disabled");
	});
	$('.post.right input[name=email]').focusout( function(){
		if($(this).val().length == 0) $('.post.right input[name=tome]').attr("disabled", true);
	});
	
	if($('input#name').length) $('input#name').focus();
	
	$("a[rel*='photos_group']").fancybox(
	{
		'centerOnScroll'	: true,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'titlePosition' 	: 'inside',
		'cyclic'			: true,
		'padding'			: 0,
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts)
		{
			return '<span id="fancybox-title-over">' + title + '&nbsp;&mdash;&nbsp;(' + (currentIndex + 1) + ' / ' + currentArray.length + ')<span>';
		}
	});
	$(".vt").fancybox({
		'centerOnScroll'	: true,
		'width'						: '100%',
		'height'					: '100%',
		'autoScale'				: false,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'titleShow'				: false,
		'type'						: 'iframe'		
	});
	$(".nl").fancybox({
		'centerOnScroll'	: true,
		'width'						: 730,
		'height'					: 402,
		'autoScale'				: false,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'titleShow'				: false,
		'type'						: 'iframe'		
	});	

	
});

function get_captcha(id)
{
	var timestamp = new Date().getTime();
	$('#'+id).attr('src', '/img/captcha.php?time='+timestamp);
}

function init_search(word, weather)
{
	$(document).ready(function()
	{
		$("#search").focusout( function() { if ($("#search").val() == word) { $("#search").val(''); } else if ($("#search").val() == "") { $("#search").val(word); }; $('#search').css('border-color', '#111'); } );
		$("#search").focusin( function() { if ($("#search").val() == word) { $("#search").val(''); } else { $("#search").select(); }; $('#search').css('border-color', '#6e140c'); }  );

		$(".weather").fancybox({
			'scrolling'				: 'no',
			'centerOnScroll'	: true,
			'width'						: 350,
			'height'					: 350,
			'margin'					: 5,
			'autoScale'				: false,
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'elastic',
			'titlePosition'		: 'inside',
			'type'						: 'iframe',
			'titleFormat'			: function(){
				return '<span id="fancybox-title-over">'+weather+': <a href="http://www.eweather.gr" target="_blank" title="'+weather+'">http://www.eweather.gr</a></span>';
			}
		});
	});
}
