var loadingTimer; var loadingFrame = 1;
$(document).ready(function()
{
	$('#wrapper').addClass('js-enabled');
	
	$("a[rel*='photos_group']").fancybox(
	{
		'centerOnScroll'	: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'cyclic'			: true,
		'padding'			: 0,
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts)
		{
			return '<span id="fancybox-title-over">Εικόνα ' +  (currentIndex + 1) + ' / ' + currentArray.length + '<br />' + title + '</span>';
		}
	});

	$("a.hotel_preview").fancybox(
	{
		'centerOnScroll'	: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'padding'			: 0,
		'height'			: 'auto',
		'titleShow'			: false,
		'overlayColor'		: '#000000',
		'type'				: 'iframe',
		'width'				: 570,
		'height'			: '100%'
	});

	$("a.large-map").fancybox(
	{
	    'padding'           : 5,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'width'				: '90%',
		'height'			: '90%',
		'type'				: 'iframe',
		'titlePosition' 	: 'outside',
		'centerOnScroll'	: true
	});

	//$("[type='checkbox'], [type='radio'], #content .ui-tabs-vertical a").each(function () { $(this).click(function(){ $(this).blur(); }); });

	$('.cycle').cycle({ 
		fx					: 'fade', 
		speed				: 500,
		timeout				: 5000,
		pager				: '#flash-preview',
		slideExpr			: 'img',
		pagerAnchorBuilder	: function(idx, slide)
		{
			return '<a href="#"><img src="' + slide.src + '" width="72" height="50" alt="' + (slide.alt) + '" title="' + (slide.title) + '" /></a>'; 
		},
		after: function()
		{
			var count = 0;
			$('.photo-inf').each(function()
			{
				if ($('#flash'+count).is(':visible')) { var s = $(this).html(); $('.photo-desc').html(s); };
				count++;
			});
		},
		next:   '#forward', 
		prev:   '#backward'
	});

	$('.cycle-vacations').cycle({ 
		fx		: 'fade', 
		speed	: 500,
		timeout	: 3000,
		pager	: '#vacation-flash-preview',
		pagerAnchorBuilder	: function(idx, slide)
		{
			return '<a href="#">' + (idx+1) + '</a>'; 
		}
	});
	
	$('.images_holder').cycle(
	{ 
		fx			: 'fade', 
		speed		: 200,
		timeout		: 5000,
		slideExpr	: 'a',
		slideResize	: 0,
		after		: function()
		{
			var count = 1;
			$('.flash-inf').each(function()
			{
				if ($('#flash_ref_'+count).is(':visible')) { var s = $(this).html(); $('.banner_content').html(s); };
				count++;
			});
		}
	});

	$('#search').tabs();

	$("#triple").tabs().addClass('ui-tabs-vertical');

	$("#triple li, #triple .ui-tabs-panel").removeClass('ui-corner-bottom').removeClass('ui-corner-top').removeClass('ui-corner-right').removeClass('ui-corner-left').removeClass('ui-corner-all');

	$('#search select').selectmenu(
	{
		style		:	'dropdown',
		width		:	'320',
		direction	:	'down'
	});
	
	$(".submit-search").button();
	
	$('.scroller').SetScroller(
	{
		velocity	: 10,
		direction	: 'vertical'
	});

	//$(document).click(function(){ $('.ui-selectmenu-open').hide(); });

	if ($("#right-bar").height() > $("#content .content_holder iframe").height()) { $("#content .content_holder iframe").height($("#right-bar").height()); }

	clearInterval(loadingTimer);
	loadingTimer = setInterval(animate_windmill, 150);

});

animate_windmill = function()
{
	$(document).ready(function()
	{
		$('.windmill').css('background-position', '0px ' + (loadingFrame * -70) + 'px');
		loadingFrame = (loadingFrame + 1)%10;
	});
};

function show_preloader(state) { if (state == true) { $('#preloader').show(); } else { $('#preloader').hide(); } }

function toggle_div(id) { $(document).ready(function() { $('#' + id).toggle(); }); }

function submit_form(id) { $(document).ready(function() { $('#' + id).submit(); }); }

function show_area(elem, ind, show_header)
{
	$(document).ready(function()
	{
		$("input[type=submit]").attr("disabled", "disabled");
		$.fancybox.showActivity();
		
		$.get("area_change.php", { 'id': ind, 'header': show_header }, function(data)
		{
			$("#"+elem).selectmenu('destroy');
			$("#"+elem).html(data); $("#"+elem).trigger("change"); $.fancybox.hideActivity();
			
			$("#"+elem).selectmenu(
			{
				style		:	'dropdown',
				width		:	'320',
				direction	:	'down'
			});
			$("input[type=submit]").removeAttr("disabled");
		});
	});
}

function get_captcha(id)
{
	var timestamp = new Date().getTime();
	$('#'+id).attr('src', 'http://www.focusgreeece.com/sbin/img/captcha.php?time='+timestamp);
}
