$(document).ready(function()
{ 
	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();
			var parent_width = $(this).prev('li').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');
			}*/
	});
	
	$('.box-title').css({
		opacity: .8
	});
	$('#gallery-text-container').css({
		opacity: .4
	});
	$('.post input[type=text], .post input[type=checkbox], .post textarea').focus(function(){
		var id = $(this).attr('id');
		$('label[for='+id+']').css('color', '#8b1424');
		$('input[id='+id+'], textarea[id='+id+']').css({'border-color': '#8b1424', 'background-color': '#fff'});	
 	});
	$('.post input[type=text], .post input[type=checkbox], .post textarea').focusout(function(){
		var id = $(this).attr('id');
		$('label[for='+id+']').css('color', '#666');
		$('input[id='+id+'], textarea[id='+id+']').css({'border-color': '#666', 'background-color': '#fff'});
 	});	
	$('.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);
	});

	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($('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>';
		}
	});
	$(".gb").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'		
	});	

	$('#images').delay(500).fadeIn(2000);
	$('#next-slide, #prev-slide').delay(500).fadeIn(2000);
	$('#gallery-text-container, #gallery-text').delay(2000).slideDown(500);
	
	$('#images').cycle({
		fx:     'scrollHorz', 
		speed:   2000,
		timeout: 10000,
		prev:   '#prev-slide', 
		next:   '#next-slide'
	});
});

function get_captcha(id)
{
	var timestamp = new Date().getTime();
	$('#'+id).attr('src', '/img/captcha.php?time='+timestamp);
}

function init_search(word, weather, vt)
{
	$(document).ready(function()
	{
		$("#search").focusout( function() { if ($("#search").val() == word) { $("#search").val(''); } else if ($("#search").val() == "") { $("#search").val(word); }; $('#search').css({'border-color': '#666', 'color': '#999', 'background-color':'transparent'}); } );
		$("#search").focusin( function() { if ($("#search").val() == word) { $("#search").val(''); } else { $("#search").select(); }; $('#search').css({'border-color': '#8b1424', 'color': '#666', 'background-color':'#fff'}); }  );

		$(".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>';
			}
		});

		$(".vt").fancybox({
			'scrolling'				: 'no',
			'centerOnScroll'	: true,
			'width'						: 740,
			'height'					: 416,
			'margin'					: 0,
			'autoScale'				: false,
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'elastic',
			'titlePosition'		: 'inside',
			'type'						: 'iframe',
			'titleFormat'			: function(){
				return '<span id="fancybox-title-over">'+vt+'</span>';
			}
		});
		
	});
}
