/* 
 * Flips through calendar, using a URL in the form of
 * http://www.example.com/?page=1&date=08-2011 for
 * navigating through dates.
 */

function flip_calendar(url)
{
	var href = new String(url);
	var tmp = href.split((/[=&]+/));

	var category = jQuery.inArray('category', tmp);
	var date = tmp[tmp.length - 1].split('-');

	if (category) {
		$('#calendar').fadeOut('fast', function() {
			$('#calendar-spacer').css({'background' : 'url("images/loading-small.gif") no-repeat center center'});
			$('#calendar-spacer').load('?page=1&category=' + tmp[category + 1] + '&date=' + date[0] + '-' + date[1] + ' #calendar', function() {
				$('#calendar').fadeIn('fast', function() {
					$('#calendar-spacer').css({'background' : ''});
				});
			});
		});
	} else {
		$('#calendar').fadeOut('fast', function() {
			$('#calendar-spacer').css({'background' : 'url("images/loading-small.gif") no-repeat center center'});
			$('#calendar-spacer').load('?page=1&date=' + date[0] + '-' + date[1] + ' #calendar', function() {
				$('#calendar').fadeIn('fast', function() {
					$('#calendar-spacer').css({'background' : ''});
				});
			});
		});
	}

	return false;
}

function toggle_events(id)
{
	$('#events .category').hide(300);
	$('#' + id).show(300);
}

function toggle_categories(id)
{
	if ($('#category-' + id).hasClass('hidden'))
		$('#category-' + id).removeClass('hidden').addClass('shown');
	else
		$('#category-' + id).addClass('hidden').removeClass('shown');
}

function move_related(move)
{
	var element = $('#related-slider > ul > li:visible');

	if(! $(element).is(':animated')) {
		if (move > 0) {
			if ($(element).next().length != 0) {
				if ($(element).next().next().length == 0)
					$('#related-news #slide-down').addClass('disabled');

				$('#related-news #slide-up').removeClass('disabled');
				$('#related-slider > ul > li').slideUp(500);
				$(element).next().slideDown(500);
			}
		} else if (move < 0) {
			if ($(element).prev().length != 0) {
				if ($(element).prev().prev().length == 0)
					$('#related-news #slide-up').addClass('disabled');

				$('#related-news #slide-down').removeClass('disabled');
				$('#related-slider > ul > li').slideUp(500);
				$(element).prev().slideDown(500);
			}
		}
	}
}

function open_popup(url)
{
	window.open(url, "", "menubar=no, toolbar=no, width=600, height=850");
	return false;
}

$(document).ready(function()
{
	$('#events #cinema').hide();
	$('#events #books').hide();

	$('#related-slider > ul > li').hide();
	$('#related-slider > ul > li:first-child').show();

	$('#related-news #slide-up').addClass('disabled');

	if ($('#related-slider > ul > li:first-child').next().length == 0) {
		$('#related-news #slide-down').addClass('disabled');
	}

	$(".article-album").fancybox();
	$(".photoday-album").fancybox();
	$(".photoday-thumbnail").fancybox();

	window.optgroup = $('#contact #size optgroup[label!="' + $('#contact #medium :first-child').val() + '"]').clone(true);
	$('#contact #size optgroup[label!="' + $('#contact #medium :first-child').val() + '"]').remove();

	$('#contact #medium').change(function() {
		window.optgroup.appendTo($('#contact #size'));
		window.optgroup = $('#contact #size optgroup[label!="' + $(this).val() + '"]').clone(true);
		$('#contact #size optgroup[label!="' + $(this).val() + '"]').remove();
	});
});

$(window).load(function()
{
	/* Remove .no-js class from body */
	$('body').removeClass('no-js');

	$('#photo-slider.flexslider').flexslider({
		animation: "slide",
		animationLoop: false,
		prevText: "Προηγούμενο",
		nextText: "Επόμενο",
		controlNav: false,
		slideshow: false
	});

	$('#header').flexslider({
		slideshowSpeed: 15000,
		controlNav: false,
		directionNav: false
	});
});

