$(document).ready(function()
{
	/* Default easing algoarithm. */
	jQuery.easing.def = 'easeInOutQuad';

	/* Lazy-load images. */
	$('.collage-image').jail({effect: "fadeIn"});

	if (window.location.hash)
		$(window.location.hash + ' .work-screenshots img').jail({effect: "fadeIn"});

	/* Partially hide the header when we scroll down > 65 pixels */
	$(window).bind('scroll', function(){
		if ($(this).scrollTop() > 65) {
			$("#header-wrapper").addClass("hidden");
		} else {
			$("#header-wrapper").removeClass("hidden");
		}
	});

	/* Event handlers for navigation menu. */
	$('#nav-main').click(function(event) {
		event.preventDefault();

		if ($('#contact').hasClass('open')) {
			$('#contact').removeClass('open');
		} else if (window.location.hash == '#contact') {
			window.location.hash = '#close';
		}

		$('html, body').animate({scrollTop: $('#main').offset().top}, 700);
	});
	
	$('#nav-works').click(function(event) {
		event.preventDefault();

		if ($('#contact').hasClass('open')) {
			$('#contact').removeClass('open');
		} else if (window.location.hash == '#contact') {
			window.location.hash = '#close';
		}

		$('html, body').animate({scrollTop: $('#works').offset().top - 40}, 700);
	});
	
	$('#nav-contact').click(function(event) {
		event.preventDefault();

		if ($('#contact').hasClass('open')) {
			$('#contact').removeClass('open');
		} else if (window.location.hash == '#contact') {
			window.location.hash = '#close';
		} else {
			$('#contact').addClass('open');
			$("#header-wrapper").removeClass("hidden");
		}
	});

	$('.send-offer a').fancybox({
		'showCloseButton':	false,
		'padding':			0,
		'margin':			0,
		'type': 			'iframe',
		'width':			'100%',
		'height':			410,
		'autoScale':		false,
	});

	/* Event handlers for search form. */
	$('#search-form .search-inside').focus(function() {
		if ($(this).val() == 'Αναζήτηση')
			$(this).val('');
	});

	$('#search-form .search-inside').blur(function() {
		if ($(this).val() == '')
			$(this).val('Αναζήτηση');
	});

	/* Event handlers for service list. */
	$('.service-name a').click(function(event) {
		event.preventDefault();
		if ($(this.hash).hasClass('visible')) {
			$(this.hash).removeClass('visible');
			$(this.hash).height(0);
		} else if (window.location.hash == this.hash) {
			window.location.hash = '#close';
			$(this.hash).height(0);
		} else {
			$('#main-services .service-more').removeClass('visible');
			$('#main-services .service-more').height(0);
			$(this.hash).height($(this.hash + ' .service-description').height());
			$(this.hash).addClass('visible');
		}
	});

	/* Event handlers for work list. */
	$('#work-list .website-link').click(function(event) {
		event.preventDefault();
		$('html, body').animate({scrollTop: $('#works').offset().top - 40}, 300);
		if (window.location.hash != '')
			window.location.hash = '#close';
		$('#work-details .work-big').removeClass('visible');
		$(this.hash).addClass('visible');
		$(this.hash + ' .work-screenshots img').jail({effect: "fadeIn"});
	});

	/* Event handlers for contact form. */
	$('.contact-name').focus(function() {
		if ($(this).val() == 'Ονοματεπώνυμο')
			$(this).val('');
	});

	$('.contact-name').blur(function() {
		if ($(this).val() == '')
			$(this).val('Ονοματεπώνυμο');
	});

	$('.contact-email').focus(function() {
		if ($(this).val() == 'E-mail ή Τηλέφωνο')
			$(this).val('');
	});

	$('.contact-email').blur(function() {
		if ($(this).val() == '')
			$(this).val('E-mail ή Τηλέφωνο');
	});

	$('textarea').focus(function() {
		if ($(this).val() == 'Πληροφορίες')
			$(this).val('');
	});

	$('textarea').blur(function() {
		if ($(this).val() == '')
			$(this).val('Πληροφορίες');
	});
});


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

	/* Start slideshow for front page. */
	$('#photo-collage').flexslider({
		slideshowSpeed: 8000,
		directionNav: false,
		controlNav: false
	});

	/* Start slideshow for work pages. */
	$('.work-screenshots').flexslider({
		slideshow: false,
		directionNav: false
	});
});

