$j(document).ready(function() { 
    var width = $j(window).width();
    var height = $j(window).height();
    var ChangeSizeSideMenu = true;

    if(location.hash != ''){
        curPos = location.hash.replace('#panel-','');
    }
    var prevPos = curPos;
    setResize();
    $j(window).resize(function(){
        width = $j(window).width();
        height = $j(window).height();
        setResize();
    });
    ///////////////////////////////////// Wanneer er wordt gelklikt op ��n van de items uit het header menu. ///////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    $j('a[rel=panel]').click(function (){
    // zet fakefooter op hoge z-index zodat alles er achterdoor schuift (fakefooter is een div van 15 px breed helemaal rechts naast de footer).
    $j('#fake_footer').css('z-index','1900');

    var pageHref = $j(this).attr('href').replace(s_site_url,'');
        pageHref = pageHref.replace('/','');

        

    curPos = objectHoofdMenuPos2[pageHref];
    
    if(veranderd || prevPos != curPos){         
            var page = s_site_url+'content/'+pageHref+'.php';
            var foto = s_site_url+'fotos/'+pageHref+'.php';
    
            if((!sideMenuClicked == "") && prevPos == curPos){
                $j("#foto"+curPos).hide("slide", { direction: "right" }, 1000, function(){
                    aRelHoofdmenuClickLoad(page,foto,true,curPos);
                });
                sideMenuClicked = "";
            } else {
                /// Deze maakt niet gebruik van de aRelHoofdmenuClickLoad functie omdat de preloader de afbeeldingen vertraagd en deze als gevolg later binnen sliden //
                $j('#content'+curPos).load(page, function() {
                    $j('#foto'+curPos).load(foto, function(){
                        callSlider();
                        changeColor();
                    });
                });
            }
            if(parseInt($j('#panel').css('left')) != 0-((curPos-1)*width)){
                $j('#panel').animate({
                    left: (0-((curPos-1)*width))+'px'
                }, 700,function(){
                    //De z-index van fake_footer wordt op 0 gezet zodat de scrollbalk er overheen kan komen
                    $j('#fake_footer').css('z-index','0');
                    setResize();
                });
                sideMenuClicked = "";
            }
            prevPos=curPos;
    }
    veranderd = false;
    return false;
    });
    //Hoofmenu (menu links) Animatie//
    var prev_div;
    var is_animating = false;
    $j('.hoofdmenu div').each(function(index, value){
    var div = $j(this);
    var divClass = div.attr('class');
    
    if(divClass != "white_stripe" && divClass != "empty_stripe"){
            div.hide();
    }
    });
    ///////////////////////////////////// Wanneer er wordt gelklikt op ��n van de items uit het menu Links menu. ////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    var is_animating = false;
    var curr_div;
    $j('a[rel="hoofdmenu"]').click(function(){
    if(!is_animating){
            is_animating = true;

            var pageHref = $j(this).attr('href').replace(s_site_url,'');
            //pageHref = pageHref.replace('/','');
            var a_href = pageHref.split('/');
            var s_page = a_href[0];
            var s_subPage = a_href[1];

            if(s_subPage != '' && s_subPage != undefined){
                var s_pageurl = s_page+'/'+s_subPage;
            } else {
                var s_pageurl = s_page;
                var parentDiv = $j(this).parent();
                if(parentDiv){
                    curr_div = parentDiv.attr('class').replace('_Menu_Btn','_div');
                    $j("."+prev_div).hide("slow");
                    $j("."+curr_div).show("slow", function() {
                        prev_div = curr_div;
                    });
                }
            }
            var page = s_site_url+'content/'+s_pageurl+'.php';
            var foto = s_site_url+'fotos/'+s_pageurl+'.php';

            //  if(sideMenuClicked != s_page)
            if(sideMenuClicked){
                if(sideMenuClicked==""){
                    $j("#foto"+curPos).hide("slide", { direction: "right" }, 1000, function(){
                        aRelHoofdmenuClickLoad(page,foto,true);
                    });
                } else{
                    $j("#foto"+curPos).hide("slide", { direction: "right" }, 1000, function(){
                        aRelHoofdmenuClickLoad(page,foto,true);
                    });
                }
                sideMenuClicked = s_page;
            } else {
                aRelHoofdmenuClickLoad(page,foto,false);
            }
            veranderd = true;
    }
    return false;
    });
    $j('.clicks').click(function (){
        $j('#lunchsuggestie').focus();
    });
    //$j('.print').click(function (){
        //var id = $j(this).attr("id");
        //alert ('tests');
        //$j("#print_"+id).jqprint();
    //});
    // Functions ////////////////////////////////////////////////////////
    function aRelHoofdmenuClickLoad(page,foto,doFoto){
    $j('#content'+curPos).load(page, function() {
            if(doFoto){
                var foto_html;
                $j(function() {;
                     $j.get(foto, function(data) {
                        foto_html = data;
                        $j("#foto"+curPos).empty();
                        $j("#foto"+curPos).append(foto_html);
                        $j("#foto"+curPos+' img').imgpreload(function(){
                            $j("#foto"+curPos).show("slide", { direction: "right" }, 1000);
                            aRelHoofdmenuClickLoadDone();
                        });
                    });
                });
            } else {
                aRelHoofdmenuClickLoadDone();
            }
    });
    }
    function aRelHoofdmenuClickLoadDone(){
    callSlider();
    changeColor();
    setResize();
    is_animating = false;
    }
    function changeColor(){
    var currentColor = $j(("#kleur"+curPos)).css("background-color");
    $j("h2").css("color",currentColor);
    $j("h4").css("color",currentColor);
    $j(".style2").css("color",currentColor);    
    if(curPos == '1' ){
            kleur = 'geel';
    }
    if(curPos == '3'){
            kleur = 'paars';
    }
    if(curPos == '2'){
            kleur = 'rood1';
    }
    if(curPos == '4'){
            kleur = 'rood';
    }
    if(curPos == '5'){
            kleur = 'paars2';
    }
    $j(".print img").attr("src",s_site_url+"img/print_"+kleur+".png");
    }
    function setResize(){
        $j('#mask').css({'width':width+'px','height':(height-parseInt($j('#mask').css('top')))+'px'});
        $j('#panel').css({'width':(width * $j('#panel div').length)+'px','left':(0-((curPos-1)*width))+'px'});
        $j('#panel .panelItem').each(function(i, val) {
            $j(this).css({
                'left':(i*width)+'px',
                'width':width+'px',
                'height':(height-parseInt($j('#mask').css('top')))+'px'
            });
        });
    $j('.content_scroll').css("height",height-parseInt($j('#header').css('height')));
    $j('.content').css("height",height-parseInt($j('#header').css('height')));
    
    if($j('#panel-'+curPos+' .content_scroll').height() < $j('#panel-'+curPos+' .content_text').height()+50 ){
            $j('#panel-'+curPos+' .hoofdmenu').css("height",$j('#panel-'+curPos+' .content_text').height()+50);
    } else {
            $j('.hoofdmenu').css("height",height-parseInt($j('#header').css('height')));
    }
    
    var verschil;
    var container;
    var Container;
    
    Container = 1600;
    var verschil = $j('.content_scroll').width() - Container;
    verschil = 850 + verschil;
    //document.title = Container+"/contentscroll:width"+$j('.content_scroll').width()+'/verschil:'+verschil+'/googlemaps:width'+$j('#googlemapsIframe').width()+'/'+verschil+'/maps:'+$j('#googlemapsIframe').css('width');
    if(verschil < 860){
            $j('.maps_img_container').width(verschil-15);
                //document.title = $j('#googlemapsIframe').css('width');
    } else {
            $j('.maps_img_container').width(860);
    }
    }
});
