
var currentTab = 1;
var ImagepoolLoaded = false;
var totalchildren;
var $children;
var imagepoolHeight = 416;
var heightHasChanged = false;
var mapLoaded = false;
var isClickable = true;
var opened = new Array();
var tHeight;
var area;
var topHeight = new Array();
var imagepoolpage = 0;
var imageWidth = 200;
var pageHeight = new Array();
var googleMaps;
if(headerHeight == undefined)
{
    var headerHeight = 450;
}
$(document).ready(function(){
    var i = 0;
    $(window).bind( 'hashchange', function(e) {
        checkHash();
    });

    $('.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();
            $(this).parent().children('.off').slideDown(400);
            opened.push($(this).parent().children('.off'));
    });
    $('.tabimg .list.tab1 li').click(function(event){
            event.preventDefault();
            if(!$(this).hasClass('on')){
             if(isClickable){
                    isClickable = false;
                    window.location.hash = $(this).find('em').text();
                    $(this).addClass('on');
                    nr = $(this).attr('value');
                    $(this).siblings().removeClass('on');
                    $(this).addClass('on');
                    nextTab(nr,500);
                    currentTab = nr;
             }
            }
    });
    if(location.href != ""){
        checkHash();
    }
});
function setHeight(speed,newheight)
{
              $('.tabimg .img').animate({
                      height: newheight+"px"
              }, speed);
}
function fadePages(old,nieuw)
{
    $('#page'+old).fadeOut(300,function(){
    $('#page'+nieuw).fadeIn(300);
    isClickable = true;
    });
}
function loadAreaMap(area,obj){
    $.ajax({
       type: "GET",
       url: "/ajax/googlemaps/index/harbours",
       data: "location="+area+"&weather_month=5",
       success: function(msg){
             googleMaps = load_map(obj,msg);
             googleMaps.gotoArea(area);
             if(obj.weather){
                 
             }
       }
     });
}
function loadMap(port_ids,obj){
        $.ajax({
           type: "GET",
           url: "/ajax/googlemaps/index/harbours",
           data: "harbours="+port_ids,
           success: function(msg){
                 googleMaps = new Map(obj,msg);
                 if(obj.gotoArea){
                    googleMaps.gotoArea(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 swapImage(){
    imageNumber++;
    if(images.length <= imageNumber){
        imageNumber = 0;
    }
    if(imageNumber%2 == 0)
        {
            showId = "imgheader";
            hideId = "imgheader2";
        }else {
            hideId = "imgheader";
            showId = "imgheader2";
        }
        $('#'+showId).css({"z-index":1, "display":"block", "position":"absolute", "height": headerHeight+"px", "background-image":"url("+images[imageNumber]+")"});
        $('#'+hideId).css({"z-index":2, "display":"block", "position":"absolute", "height": headerHeight+"px"});
        $('#'+hideId).fadeOut(500);
    $('#'+showId).fadeIn(500);
}
function checkHash()
{
      var hash = location.hash;
      if(hash.length > 1)
      {
        gotoPage(hash.replace('#',''));
      }else {
          gotoPage("first");
      }
}
function gotoPage(itemname)
{
    if(itemname == 'Ship'){
        itemname = 'Schip';
    }
    if(itemname == "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(itemname == $(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;
                }
            }
    });
}
