$(document).ready(function()
{
	$(".photos_group").fancybox(
	{
		'centerOnScroll'	: true,
		'titlePosition' 	: 'over',
		'cyclic'			: true,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
	});

	$(".map").fancybox(
	{
		'centerOnScroll'	: true,
		'width'				: '100%',
		'height'			: '100%',
		'autoScale'			: false,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'titleShow'			: false,
		'type'				: 'iframe'
	});

	$(".cycle").each(
		function(intIndex)
		{
			var n = Math.floor(Math.random()*10);
			var s = (((intIndex+1)+3)/2)*1000;
			$(this).cycle(
			{ 
				fx		: 'fade', 
				speed	: s, 
				timeout	: 2500, 
				pause	: 0
			});
		}
	);

	$('.flash-images').cycle(
	{ 
		fx		: 'fade', 
		speed	: 5000,
		timeout	: 2500,
    	pager	: '#flash-preview',
		pagerAnchorBuilder	: function(idx, slide)
		{
			return '<a href="#"><img src="' + slide.src + '" width="20" height="20" alt="' + (idx+1) + '" title="' + (idx+1) + '" /></a>'; 
		}
	});

	$(".date-pick").datePicker({startDate:'01-01-2000'});


	$('#scrolling').SetScroller(
	{
		velocity	: 60,
		direction	: 'horizontal',
		startfrom	: 'right',
		loop		: 'infinite',
		movetype	: 'linear',
		onmouseover	: 'pause',
		onmouseout	: 'play',
		onstartup	: 'play',
		cursor		: 'pointer'
	});

});

function init_search(word, img, src)
{
	$(document).ready(function()
	{
		$("#search").focusout( function() { if ($("#search").val() == word) { $("#search").val(''); } else if ($("#search").val() == "") { $("#search").val(word); }; } );
		$("#search").focusin( function() { if ($("#search").val() == word) { $("#search").val(''); } else { $("#search").select(); }; } );
		$(".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">'+src+': <a href="http://www.eweather.gr" target="_blank" title="'+src+'">http://www.eweather.gr</a></span>';
			}
		});
		$("a[rel*='photos_group']").fancybox(
		{
			'centerOnScroll'	: true,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'over',
			'cyclic'			: true,
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts)
			{
				return '<' + 'span' + ' id="fancybox-title-over">'+img+' ' +  (currentIndex + 1) + ' / ' + currentArray.length + '<' + 'br' + ' />' + title + '</' + 'span>';
			}
		});
	});
}


function get_captcha(id)
{
	var timestamp = new Date().getTime();
	$('#'+id).attr('src', '/captcha.php?time='+timestamp);
}

function select_property(id, table, name)
{
	$(document).ready(function()
	{
		$.get("/classes/select.php", { 'table': table, 'name': name }, 
		function(data)
		{
			$("#"+id).html(data);
			if ($('#properties').length)
			{
				if ($('#properties').val() == '0')
				{
					$('#send_offer').attr('disabled', 'disabled');
					$('#properties').css({'border': '1px solid #ff0000', 'background-color': '#FA7E16'});
				}
				else
				{
					$('#properties').css({'border': '1px solid inherit', 'background-color': '#ffffff'});
					$('#send_offer').removeAttr('disabled');
				}
			}
		});
	});
}

function toggle_div(id)
{
	$(document).ready(function()
	{
		$('#' + id).slideToggle('fast', function()
		{
			if ($('#properties').length)
			{
				if ($('#properties').val() == '0')
				{
					$('#send_offer').attr('disabled', 'disabled');
					$('#properties').css({'border': '1px solid #ff0000', 'background-color': '#FA7E16'});
				}
				else
				{
					$('#properties').css({'border': '1px solid inherit', 'background-color': '#ffffff'});
					$('#send_offer').removeAttr('disabled');
				}
			}
		});
	});
}
