// JavaScript
	var standardHeight = 295;
	var currentTab = 1;
	var totalchildren;
	var $children;
	var portInfoWindow = 1;
	var heightHasChanged = false;
	var mapLoaded = false;
	var isClickable = true;
	var tHeight;
        var infoNumber = 0;
        var info_slider = "";
        var maximized = true;
        if(mapOnPage == undefined){
            var mapOnPage = 1;
        }
	tHeight = new Array();
	$(document).ready(function(){
		var i = 0;
		$('.tabimg .img').each(function(){
			tHeight.push($(this).children('.box1').height());
			$(this).children('.box1').find('.off').hide();
			i++;
		});
		i = 1;
		$children = $('.tabimg .list.tab1').children('li');
		totalchildren = $children.length;
		$children.each(function() {
			$(this).val(i);
			if(i>1){
				$('.tabimg .img.tab'+$(this).attr('value')).hide();
			}
			i++;
		});
		isClickable = true;
		$('.tabimg .list.tab1 li').click(function(event){
			event.preventDefault();
			if(!$(this).hasClass('on')){
			 if(isClickable){
				nr = $(this).attr('value');
				$(this).siblings().removeClass('on');
				$(this).addClass('on');
				isClickable = false;
				nextTab(nr);
			 }
			}
		});
		$('.tabimg .img .ico.plus2').click(function(event){
			event.preventDefault();
			$(this).parent().parent().children().children().children('.list').children('.off').show('slow');
			$(this).hide('slow');
			if(tHeight[currentTab-1]+40 < standardHeight){
				goto = standardHeight;
			}else {
				goto = tHeight[currentTab-1]+40;
			}
			moreInfo(goto,false,500);
		});
		$('.tabimg .img .ico.plus2').click(function(event){
			event.preventDefault();
			$(this).parent().parent().children().children().children('.list').children('.off').show('slow');
			$(this).hide('slow');
			if(tHeight[currentTab-1]+40 < standardHeight){
				goto = standardHeight;
			}else {
				goto = tHeight[currentTab-1]+40;
			}
			moreInfo(goto,false,500);
		});
                show_info(0,'#mapkaartinfo','port');
                show_info(0,'#portinfo','port');
                info_slider = window.setInterval(swap_show_info, 8000);
	});

        function toggleMaximize(but){
            if(maximized){
                minimize(but);
            }else {
                maximize(but);
            }
        }
        function minimize(but){

            $('.box3').fadeOut(300);
            $('.box1').fadeOut(300);
            closeBox('#mapkaartinfo');
            maximized = false;
            $(but).addClass('plus');
            moreInfo(40,false,300);
        }
        function maximize(but){
            $('.box3').fadeIn(300);
            $('.box1').fadeIn(300);
            maximized = true;
            if($(but).hasClass('plus')){
            $(but).removeClass('plus');
            }
            moreInfo(standardHeight,false,300);
        }
        
        function swap_show_info()
        {
            infoNumber++;
            if(infoNumber>4) infoNumber = 0;
            show_info(infoNumber,'#mapkaartinfo','port');
        }
        function closeBox(id)
        {
            if(info_slider!=""){
             window.clearInterval(info_slider);
            }
                $(id).fadeOut("slow");
        }

	function nextTab(id){
            if(info_slider!=""){
             window.clearInterval(info_slider);
            }
		$('.tabimg').find('.off').hide(300);
		var page = $('.tabimg .img.tab'+nr);

                if(!heightHasChanged){

			for(i = 1; i<totalchildren+1; i++){
					page.parent().children('.img.tab'+i).removeClass('on');
					page.parent().children('.img.tab'+i).fadeOut('slow');
			}
			currentTab = nr;
			if(nr == 5){
				if(mapLoaded == false){
					mapLoaded = true;
				}
			}
			$('#temptab').addClass('on');
			page.fadeIn('slow',function() {
				page.addClass('on');
				$('#temptab').removeClass('on');
				isClickable = true;
			});
		}else {
			moreInfo(standardHeight,true,300);
                        maximized = true;
                        $('.box3').fadeIn(300);
                        $('.box1').fadeIn(300);

                        if($('.toolbar').hasClass('plus')){
                            $('.toolbar').removeClass('plus');
                        }
			heightHasChanged = false;
		}
                if($('.tabimg').height() != $('.tabimg .img.tab'+nr+' .content').height()+50 && $('.tabimg .img.tab'+nr+' .content').height()+50 > standardHeight && id != 1){

                    setHeaderHeight(nr,$('.tabimg .img.tab'+nr+' .content').height()+50,300);
                }
	}
        function setHeaderHeight(currentTab,h,speed)
        {

                      $(".tabimg .img.tab"+currentTab).animate({
                            height: h+"px"
                      }, speed );
                      $(".tabimg .img.tab"+currentTab+" .layer_left").animate({
                            height: (h-14)+"px"
                      }, speed );
                      $(".tabimg .img.tab"+currentTab+" .layer_right").animate({
                            height: (h-14)+"px"
                      }, speed );
                      $(".tabimg .img.tab"+currentTab+" .layer_bottom").animate({
                            top: (h-7)+"px"
                      }, speed );
        }
	function moreInfo(h,isNextTab,speed){
		if(h != standardHeight){
			heightHasChanged = true;
		}
		if(speed == ''){
			 speed = 500;
		}
                   $('.tabimg').animate({
			height: h+"px"
		  }, speed );
                   $('#map').animate({
			height: h+"px"
		  }, speed );
		  $(".tabimg .img.tab"+currentTab).animate({
			height: h+"px"
		  }, speed );
		  $(".tabimg .img.tab"+currentTab+" .layer_left").animate({
			height: (h-14)+"px"
		  }, speed );
		  $(".tabimg .img.tab"+currentTab+" .layer_right").animate({
			height: (h-14)+"px"
		  }, speed );
		  $(".tabimg .img.tab"+currentTab+" .layer_bottom").animate({
			top: (h-7)+"px"
		  }, speed ,"swing", function(){
			  if(isNextTab){
					nextTab();
			  }
			});
	}


	function show_info(id,div,type)
	{
		if($(div).is(':hidden'))
		{
			$(div).fadeIn();
		}

		info = new Array();

		switch(type)
		{
			case 'port':
				info = getPortInfo(id);
			break;
			case 'rederij':
				info = get_rederij_info(id);
			break;
			default:
			break;
		}
		$(div).children('.content').children('h3').fadeOut('slow', function(){
			$(div).children('.content').children('h3').html(info.name);
			$(div).children('.content').children('h3').hide();
			$(div).children('.content').children('h3').fadeIn();
		});

		$(div).children('.content').children('p').fadeOut('slow', function(){
			$(div).children('.content').children('p').html(info.txt);

			if(info.readmore == 'true')
			{
				$(div).children('.content').children('.readmore').children('a').attr("href", info.url);
			}

			$(div).children('.content').children('p').hide();
			$(div).children('.content').children('p').fadeIn();
		});

		try
		{
			event.preventDefault();
		}
		catch (err)
		{

		};
	}

	function show_tab(nr){
		moreInfo(height1+standardHeight,false,400);
	}
	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: "/ajax/googlemaps/index/get_route",
	   data: "area=" + id,
	   success: function(msg){
		 eval(msg);
		 loadPorts('noNumbers');
		 gotoArea(id);
	   }
	 });
	}
        function loadAreaMap(area,obj){
		$.ajax({
		   type: "GET",
		   url: "/ajax/googlemaps/index/get_route",
		   data: "loaded=false&area="+area+"&route=false",
		   success: function(msg){
			 eval(msg);
			 load_map(obj);
		   }
		 });
	}
	function loadMap(port_ids,obj){
            if(obj.weather == true){
                weather = '&weather=true';
            }else {
                weather = '';
            }
            if(obj.overlays == true){
                overlays = '&overlays=true&theme_name='+obj.linkedItem;
            }else {
                overlays = '&overlays=false';
            }
		$.ajax({
		   type: "GET",
		   url: "/ajax/googlemaps/index/get_route",
		   data: "loaded=false&harbours="+port_ids+"&route=false"+weather+overlays,
		   success: function(msg){
			 load_map(obj,msg);
                        if(obj.weather == true){
                            load_weather();
                            ports_visible(false);
                        }
		   }
		 });
	}

	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);
	};