// JavaScript CRUISE TABS
	var currentTab = 1;
	var totalchildren;
	var $children;
	var heightHasChanged = false;
	var mapLoaded = false;
	var loading = false;
	var isClickable = true;
	var opened = new Array();
	var tHeight;
	var topHeight = new Array();
	var pageHeight = new Array();
	var ImagepoolLoaded = false;
	var imageWidth = 200;
        var googlemap;
	if(headerHeight == undefined)
	{
		var headerHeight = 230;
	}

	var params = {
	  menu: "false",
	  allowFullScreen: "true",
	  wmode: "transparent"
	};



	$(document).ready(function()
	{
		pricesLoaded = false;
		zooverLoaded = false;

                $(window).bind( 'hashchange', function(e) {
                    checkHash();
                });
		var i = 0;
		$('.tabimg .img').each(function(){
			$(this).children('.box1').find('.off').hide();
			i++;
		});
		i = 1;
		$children = $('.tabimg .list.tab1').children('li');
		totalchildren = $children.length;
		$children.each(function() {
			$(this).val(i);
			topHeight.push($(this).children('.box1').height());
			pageHeight.push($('#page'+i).height());
			if(i>1){
				$('.tabimg .img.tab'+$(this).attr('value')).hide();
				$('#page'+(i)).hide();
			}
			i++;
		});
		isClickable = true;
		$('#dekplannen a').click(function(event){
			event.preventDefault();
			if(!$(this).parent().children('.off').hasClass('down'))
			{
				$(this).parent().children('.off').slideDown(400);
				opened.push($(this).parent().children('.off'));
			}
			else
			{
				$(this).parent().children('.off').slideUp(400);
				opened.push($(this).parent().children('.off'));
			}

			$(this).parent().children('.off').toggleClass('down');
		});
		$('.tabimg .list.tab1 li').click(function(event){
			event.preventDefault();
			if(!$(this).hasClass('on')){
			 if(isClickable){
				nr = $(this).attr('value');
				$(this).siblings().removeClass('on');
                                window.location.hash = $(this).find('em').text();
				$(this).addClass('on');
				isClickable = false;
				nextTab(nr,500);
				currentTab = nr;
			 }
			}
		});
               get_flight_price("#flight_price");

                if(location.hash != ""){
                    checkHash();
                }else {
                    loadMap(route_id, new Object({scroll:false,route:true,hide_overlay:"yes",weather:true}));
                }
	});

        function get_flight_price(id)
        {
            $.ajax({
               type: "POST",
               url: "/ajax/bookingengine/flightprice/getprice/rangeID/"+rangeID+"",
               data: "",
               success: function(msg){
                   if(msg == "hide")
                   {
                       $(id).hide();
                   }else{
                        $(id).html(msg);
                   }
               }
             });
        }
	function gotoPage(pagename){
		i = 0;
		switch(pagename){
			case 'ship':
                            $(this).scrollTo($('h2'),400);
			dutchname = 'Schip';
			$('.tabimg .list.tab1 li').each(function() {
				i++;
				if(dutchname == $(this).find('em').text()){
					$(this).addClass('on');
					id = i;
				}else {
					$(this).removeClass('on');
				}
			});
			nextTab(id,300);
			currentTab = id;
			break;
			case 'price':
                            $(this).scrollTo($('h2'),400);
			dutchname = 'Prijzen';
			$('.tabimg .list.tab1 li').each(function() {
				i++;
				if(dutchname == $(this).find('em').text()){
					$(this).addClass('on');
					id = i;
				}else {
					$(this).removeClass('on');
				}
			});
			nextTab(id,300);
			currentTab = id;
			break;
		}
                if(i == 0){

                    if(pagename == "first")
                    {
                        var first;
                        first = $('.tabimg .list.tab1 li:first');
                        first.addClass('on');
                        nr = first.attr('value');
                        first.siblings().removeClass('on');
                        first.addClass('on');
                        nextTab(nr,500);
                        currentTab = nr;
                    }
                    var i = 0;
                    var nr;
                    $('.tabimg .list.tab1 li').each(function() {
                            i++;
                            if(pagename == $(this).find('em').text()){
                                if(!$(this).hasClass('on')){
                                        $(this).addClass('on');
                                        nr = $(this).attr('value');
                                        $(this).siblings().removeClass('on');
                                        $(this).addClass('on');
                                        nextTab(nr,500);
                                        currentTab = nr;
                                }
                            }
                    });
                }
	}

    function checkHash()
    {
          var hash = location.hash;
          if(hash.length > 1)
          {
                gotoPage(hash.replace('#',''));
          }else {
                gotoPage("first");
          }
          
    }
    function nextTab(id,speed){
        $('.box3').fadeOut("fast");
        $('.but_weather').hide();
        switch(id){
            case 8:
                $('.gmap').css("height", "457px");
                $('.gmap').fadeIn(300);
                $('.pricetag').fadeIn("slow");
                $("#flightprice").show();
                if(parseInt($.browser.version) < 8 && $.browser.msie){
                }else {
                    $('.but_weather').show();
                }
                setHeight(speed,450);
                loadMap(route_id, new Object({scroll:false,route:true,hide_overlay:"yes",weather:true}));
                $('.weer').show();
                break;
            case 1:
                $('.gmap').css("height", "230px");
                $('.gmap').fadeIn(300);
                $('.pricetag').fadeIn("slow");
                $("#flightprice").show();
                setHeight(speed,230);
                loadMap(route_id, new Object({scroll:false,route:true,hide_overlay:"yes",weather:true}));
                $('.weer').hide();
                break;
          case 7:
                     $('.pricetag').hide();
                  $("#flightprice").hide();
                     $('.gmap').fadeOut(300);
                if(ImagepoolLoaded == false){
                    loadImagepool($('#page'+id));
                 }else {
                     setHeight(speed,headerHeight);
                 }
                break;
          case 5:
                getPrices();
                $("#flightprice").hide();
                $('.gmap').fadeOut(300);
                $('.pricetag').hide();
                setHeight(speed,1);
                break;
          case 6:
                getZoover();
                $("#flightprice").hide();
                $('.gmap').fadeOut(300);
                $('.pricetag').hide();
                setHeight(speed,1);
                break;
          case 9:
                $('.tabimg .img').css('background','url(/images/sunset.jpg) no-repeat');
                $("#flightprice").hide();
                $('.gmap').fadeOut(300);
                $('.pricetag').hide();
                setHeight(speed,120);
                break;
          default:

                  $("#flightprice").hide();
              $('.gmap').fadeOut(300);
                $('.pricetag').hide();
                setHeight(speed,1);
                break;

        }
        fadePages(currentTab,id);
        for(var i=0;i<opened.length;i++){
                opened[i].hide();
        }
        opened = [];
    }

    function fadePages(old,nieuw)
    {
        $('#page'+old).fadeOut(300,function(){
        $('#page'+nieuw).fadeIn(300);
        isClickable = true;
        });
    }

    function setHeight(speed,newheight)
    {
                  $('.tabimg .img').animate({
                          height: newheight+"px"
                  }, speed);
    }

	function newRoute(id) {
            $.ajax({
               type: "GET",
               url: "get_route.php",
               data: "harbours=" + id,
               success: function(msg){
                     eval(msg);
                     loadRoute();
                     loadPorts();
               }
             });
	}

	function newArea(id) {
	$.ajax({
	   type: "GET",
	   url: "get_route.php",
	   data: "area=" + id,
	   success: function(msg){
		 eval(msg);
		 loadPorts('noNumbers');
		 gotoArea(id);
	   }
	 });
	}

	function loadMap(portids,obj){
            //alert('check');
            if(mapLoaded || loading){
                if(mapLoaded){
                    googlemap.initMap();
                }
                return;
            }else {
//                todo
            }
            loading = true;
            $.ajax({
               type: "GET",
               url: "/ajax/googlemaps/index/route",
               data: "route_id="+portids+"&weather_month="+departureMonth,
               success: function(msg){
                    mapLoaded = true;
                    loading = false;
                    googlemap = load_map(obj,msg);
               }
             });
	}

	function loadAreaMap(area,obj){
            $.ajax({
               type: "GET",
               url: "/ajax/googlemaps/index/get_route",
               data: "loaded=false&area="+area,
               success: function(msg){
                     eval(msg);
                     load_map(obj);
               }
             });
	}

	function showCruises(){
		window.location('?area=' +area);
	}

	function hideButton(buttonId){
		$(buttonId).hide();
	}

	function showButton(buttonId){
		$(buttonId).show();
	}

	function changeButton(nr){
		$("#show_cruises").html("Toon alle cruises in "+worldLocations[nr].name);
	};

    function simpleSlider(target, clicked, txt){
        $(target).find('.off').each(function(i){
            $(this).show(200);
        });
        if(clicked != null){
            if(txt == null){
                $(clicked).hide(200);
            }else {
                $(clicked).text(txt);
            }
        }
        return false;
    }

