$(document).ready(function() {


	// Main Menu effects
	$(function () {
		$('#navigation li')
			.removeClass('no-js')
			.find('a:not(div.reservation-links a)')
			.append('<span class="hover" />').each(function () {
				var $span = $('> span.hover', this).css('opacity', 0);
				$(this).hover(function (){
					$span.stop().fadeTo(400, 1);
				}, function () {
					$span.stop().fadeTo(700, 0);
				});
			});
	});


	// Book Travel Button effects
	$(function () {
		$('#book-travel')
			.removeClass('no-js')
			.find('a')
			.append('<span class="hover" />').each(function () {
				var $span = $('> span.hover', this).css('opacity', 0);
				$(this).hover(function (){
					$span.stop().fadeTo(300, 1);
				}, function () {
					$span.stop().fadeTo(500, 0);
				});
			});
	});
	
	// RSS in news Button effects
	$(function () {
		$('#rss')
			.removeClass('no-js')
			.find('a')
			.append('<span class="hover" />').each(function () {
				var $span = $('> span.hover', this).css('opacity', 0);
				$(this).hover(function (){
					$span.stop().fadeTo(300, 1);
				}, function () {
					$span.stop().fadeTo(500, 0);
				});
			});
	});

	// Menu Tickets effects
	$("#navigation a.tickets").click(function(){
		if(!$(".reservation-links").hasClass("visible")){
			$(".reservation-links").fadeIn();
			$(".reservation-links").addClass('visible');
		}else{
			$(".reservation-links").fadeOut();
			$(".reservation-links").removeClass('visible');
		}
		
	});
	
	
	//remove the link added for google
	$("#navigation a.destinations").attr("href", "javascript:void(0);");	
	
	//destination-select on news page
	$("#destination-select").change(function(){
		var destination = $("#destination-select").val();
		window.location = '/news/?destination='+destination;
	});
	
	//destination-select on travel page
	$("#travel-destination-select").change(function(){
		var destination = $("#travel-destination-select").val();
		window.location = '/travels/?destination='+destination;
	});
	
	
	//travels carousel
	$(".navigate-next").click(function(){
		var last_id = $("#types-browser .moving-part .type-item:last").attr("id");
		var temp = last_id.split("id");
		var items = temp[1];
		var left = $("#types-browser .moving-part").css("left");
		if(left == '0px'){
			$("#types-browser .moving-part").animate({left: "-812px"}, 750 );
		}else if(left == '-812px'){
			$("#types-browser .moving-part").animate({left: "-1624px"}, 750 );
		}else if(left == '-1624px'){
			if(items > 12 && items < 17){
				var go = -203*(items-4);
				$("#types-browser .moving-part").animate({left: go+"px"}, 750 );
			}else if(items == 12){
				$("#types-browser .moving-part").animate({left: "0px"}, 750 );
			}
		}else if(left == '-2436px'){
			if(items > 16 && items < 21){
				var go = -203*(items-4);
				$("#types-browser .moving-part").animate({left: go+"px"}, 750 );
			}else if(items == 12){
				$("#types-browser .moving-part").animate({left: "0px"}, 750 );
			}
		}else{
			//αν έχουμε items που είναι 13, 14, 15, 17, 18, 19 πάμε στην αρχή
			$("#types-browser .moving-part").animate({left: "0px"}, 750 );
		}
	});
	$(".navigate-previous").click(function(){
		/*
		var left = $("#types-browser .moving-part").css("left");
		if(left == '0px'){
			$("#types-browser .moving-part").animate({left: "-1624px"}, 1500 );
		}else if(left == '-812px'){
			$("#types-browser .moving-part").animate({left: "0px"}, 1500 );
		}else if(left == '-1624px'){
			$("#types-browser .moving-part").animate({left: "-812px"}, 1500 );
		}*/
		var last_id = $("#types-browser .moving-part .type-item:last").attr("id");
		var temp = last_id.split("id");
		var items = temp[1];
		var left = $("#types-browser .moving-part").css("left");
		if(left == '0px'){
			var go = -203*(items-4);
			$("#types-browser .moving-part").animate({left: go+"px"}, 750 );
		}else if(left == '-812px'){
			$("#types-browser .moving-part").animate({left: "0px"}, 750 );
		}else if(left == '-1624px'){
			$("#types-browser .moving-part").animate({left: "-812px"}, 750 );
		}else if(left == '-2436px'){
			$("#types-browser .moving-part").animate({left: "-1624px"}, 750 );
		}else{
			if(items > 16 && items < 21){
				$("#types-browser .moving-part").animate({left: "-2436px"}, 750 );
			}else if(items > 12 && items < 17){
				$("#types-browser .moving-part").animate({left: "-1624px"}, 750 );
			}
		}
	});
	
		
	
	//rotate ταξιδιωτικά νέα
	var news = $("#news a").size();
	new_interval = setInterval(news_rotate, 6000);
	
	var new_displayed = 0;
	function news_rotate(){
		//alert(items);
		if(news == '2'){
			if(new_displayed == 0){
				$("#news a:eq(0)").fadeOut(1000);
				$("#news a:eq(1)").fadeTo(1000, 1).fadeIn(500);
				new_displayed = 1;
			}else{
				$("#news a:eq(1)").fadeOut(1000);
				$("#news a:eq(0)").fadeTo(1000, 1).fadeIn(500);
				new_displayed = 0;
			}
		}else if(news == '3'){
			if(new_displayed == 0){
				$("#news a:eq(0)").fadeOut(1000);
				$("#news a:eq(1)").fadeTo(1000, 1).fadeIn(500);
				new_displayed = 1;
			}else if(new_displayed == 1){
				$("#news a:eq(1)").fadeOut(1000);
				$("#news a:eq(2)").fadeTo(1000, 1).fadeIn(500);
				new_displayed = 2;
			}else if(new_displayed == 2){
				$("#news a:eq(2)").fadeOut(1000);
				$("#news a:eq(0)").fadeTo(1000, 1).fadeIn(500);
				new_displayed = 0;
			}
		}else if(news == '4'){
			if(new_displayed == 0){
				$("#news a:eq(0)").fadeOut(1000);
				$("#news a:eq(1)").fadeTo(1000, 1).fadeIn(500);
				new_displayed = 1;
			}else if(new_displayed == 1){
				$("#news a:eq(1)").fadeOut(1000);
				$("#news a:eq(2)").fadeTo(1000, 1).fadeIn(500);
				new_displayed = 2;
			}else if(new_displayed == 2){
				$("#news a:eq(2)").fadeOut(1000);
				$("#news a:eq(0)").fadeTo(1000, 1).fadeIn(500);
				new_displayed = 3;
			}else if(new_displayed == 3){
				$("#news a:eq(3)").fadeOut(1000);
				$("#news a:eq(0)").fadeTo(1000, 1).fadeIn(500);
				new_displayed = 0;
			}
		}
	}
	
	
	
	$("#check-also div.moving-part").css("margin-top", '0px')
	check_also_interval = setInterval(check_also_move, 6000);
	function check_also_move(){
		var check_also_height = $("#check-also div.moving-part").height();
		if(check_also_height == 60){
			if($("#check-also div.moving-part").css("margin-top") == '0px'){
				$("#check-also div.moving-part").animate({marginTop: "-30px"}, 1500 );
			}else if($("#check-also div.moving-part").css("margin-top") == '-30px'){
				$("#check-also div.moving-part").animate({marginTop: "0px"}, 1500 );
			}
		}else{
			//do nothing, its 30
		}
	}
	
	$("#useful-links div.moving-part").css("margin-top", '0px')
	useful_links_interval = setInterval(useful_links_move, 6000);
	function useful_links_move(){
		var useful_links_height = $("#useful-links div.moving-part").height();
		if(useful_links_height == 60){
			if($("#useful-links div.moving-part").css("margin-top") == '0px'){
				$("#useful-links div.moving-part").animate({marginTop: "-30px"}, 1500 );
			}else if($("#useful-links div.moving-part").css("margin-top") == '-30px'){
				$("#useful-links div.moving-part").animate({marginTop: "0px"}, 1500 );
			}
		}else{
			//do nothing, its 30
		}
	}
	
	
	
	$("a.login-button").click(function(){
		//alert('yes');
		$("div#tooltip").toggle();
	});
	
	//change links that we added only for google to the normal ones
	//$("#navigation .destinations").attr("href", "javascript:void(0);");
	
	//$(".select-airline").insertBefore("#External_FlightFareSearch_PrefferedAirlines");

	
	$("a.cruises").tooltip({ 
		track: false, 
		delay: 0, 
		showURL: false, 
		opacity: 1, 
		fixPNG: true, 
		showBody: " - ", 
		bodyHandler: function() {
			return 'Η υπηρεσία αυτή δεν είναι ακόμα διαθέσιμη. Παρακαλώ προσπαθήστε αργότερα. Το site βρίσκεται σε beta φάση.';
		},
		extraClass: "pretty fancy", 
		top: -15, 
		left: 5 
	});
	

});
