/*  GUI     */
jQuery.noConflict();
jQuery(document).ready(function(){
    if (jQuery('#news_items').length) { 
        jQuery('#news_items').innerfade({ animationtype: 'fade', speed: 1000, timeout: 2500, type: 'sequence', containerheight: '30px' }); 
    }
    if (jQuery('#visual').length) { 
        jQuery('#visual > ul').innerfade({ animationtype: 'fade', speed: 2000, timeout: 4000, type: 'sequence', containerheight: '576px' }); 
    }
    //  Bind splash hover - top a's
    if(jQuery("#menu")) {
        jQuery("#menu > ul > li.page-item-21 > a").hover(
            function () {
                jQuery("#hover_hotel").fadeOut('slow');
                jQuery("#hover_golf").fadeIn('slow');
            }, function () {
            }
        );
        jQuery("#menu > ul > li.page-item-19 > a").hover(
            function () {
                jQuery("#hover_golf").fadeOut('slow');
                jQuery("#hover_hotel").fadeIn('slow');
            }, function () {
            }
        );
    }
    //  Bind intro hovers - a
    if(jQuery("#intro")) {
        jQuery("#golf > p > a").hover(
            function () {
                jQuery("#hover_hotel").fadeOut('slow');
                jQuery("#hover_golf").fadeIn('slow');
            }, function () {
            }
        );
        jQuery("#hotel > p > a").hover(
            function () {
                jQuery("#hover_golf").fadeOut('slow');
                jQuery("#hover_hotel").fadeIn('slow');
            }, function () {
            }
        );
    }
    if (jQuery('#top').length) {
        jQuery('#top').toggle(function() {
                    jQuery(this).animate({backgroundPosition: '(0 -0px)', height: '420px'});
                }, function() {
                    jQuery(this).animate({backgroundPosition: '(0 -140px)', height: '280px'});
                }
        );
    }
    set_current_menu();
    set_submenu();
    set_external_links();
});

function        set_submenu()
{
    var timeout;
    //  Bind hovers
    jQuery("#submenu > ul > li").hover(
        function () {
        if(timeout) {
            clearTimeout(timeout);
            timeout = null;
        }
        jQuery("#submenu > ul > li > ul").hide();
        jQuery("#submenu > ul > li > a").removeClass("active");
        jQuery(this).find("a").addClass("active");
        jQuery(this).find("ul").show();
        //  If no ul > no arrow
        if(jQuery(this).find("ul").length == 0) {
           jQuery(this).find("a").addClass("none");
        }
    }, 
    function () {
        //  After 5 seconds, change to current_menu
        timeout = setTimeout(function() {
            set_current_menu();
            timeout = null;
        },5000);
    }
    );
}

function        set_current_menu()
{
    //  Remove all actives
    jQuery("#submenu > ul > li > a").removeClass("active");
    //  Close all
    jQuery("#submenu > ul > li > ul").hide();
    //  Open current main
    jQuery("#submenu > ul > li.current_page_item").find("a").addClass("active");
    jQuery("#submenu > ul > li.current_page_item").find("ul").show();
    //  
    jQuery("#submenu > ul > li.current_page_ancestor").find("a").addClass("active");
    jQuery("#submenu > ul > li.current_page_ancestor").find("ul").show();
    
    //  If no ul > no arrow
    if(jQuery("#submenu > ul > li.current_page_item > ul").length == 0) {
       jQuery("#submenu > ul > li.current_page_item").find("a").addClass("none");
    }   
}

function        set_external_links()
{
    //  Set external links to blank target && standards compliant
    if(document.getElementsByTagName)
    {
        var anchors =   document.getElementsByTagName('a');
        for(var i = 0;i<anchors.length;i++)
        {
            var anchor  =   anchors[i];
            if(anchor.getAttribute('href') && anchor.getAttribute('rel') == 'external')
            {
                anchor.title    =   anchor.title + ' (er opent een nieuw scherm)';
                anchor.target   =   '_blank';
            }
        }
    }
}

