/*-----------------------------------------------------------------------------
Web Site:			Ask Leopold

CteatedDate:		21.05.2009
Autor:				AnnaG

LastChangedDate:	04.06.2009
LastChangedBy:		AnnaG
-----------------------------------------------------------------------------*/

jQuery(document).ready(function() {

    /* =Pseudo-pages
    ------------------------------------------------------------------------ */
    var sHref = document.location.href.match(/.*#(.+)/);
    var PageID;

    if (sHref && jQuery(".page[rel*='" + sHref[1] + "']").length) {
        // show page with PageID -------------
        showPage(sHref[1]);

    } else {
        // hide all, show first --------------
        if (jQuery(".switch-nav a.switch:first").attr("href")) {
            PageID = jQuery(".switch-nav a.switch:first").attr("href").match(/#(.+)/)[1];
            showPage(PageID);
        }
    }

    // click on switch link  -----------------
    jQuery(".switch-nav a.switch").bind("click", function(e) {
        var PageID = jQuery(this).attr("href").match(/#(.+)/)[1];
        showPage(PageID);
    });


    /* =Pop menu for main navigation
    ------------------------------------------------------------------------ */
    var menuID = "popup-menu";
    var parentClass = "main-nav-block";
    var menuWidth = 150;
    var itemList, menuContainer, parentContainer, menuContainerInner, itemOffset = {};

    parentContainer = jQuery("." + parentClass);

    // create container for menu and hide it
    jQuery('<div id="' + menuID + '"><div class="inner"></div></div>').appendTo(parentContainer).hide();

    menuContainer = jQuery("#" + menuID);
    menuContainerInner = jQuery("#" + menuID + " .inner");

    jQuery(".primary-nav ul li").bind("mouseover", function() {
        if (jQuery(this).is(":has(ul)")) {
            itemList = jQuery(this).find("ul");

            // add menu to container
            if (!menuContainer.is(":has(ul)"))
                itemList.clone().appendTo(menuContainerInner);
            else
                menuContainer.find("ul").replaceWith(itemList.clone());

            // bind page switch to links of menu
            menuContainer.find("a").bind("click", function(e) {
                var PageID = jQuery(this).attr("href").match(/#(.+)/)[1];
                showPage(PageID);
            });

            // add offset to container
            itemOffset = jQuery(this).position();
            var itemWidth = jQuery(this).innerWidth();

            var menuTop = itemOffset.top + 32;
            var menuLeft = Math.ceil(itemOffset.left + (itemWidth / 2) - (menuWidth / 2));

            menuContainer.css({
                'left': menuLeft + 'px',
                'top': menuTop + 'px'
            });

            // show container
            menuContainer.show();
        }
    });

    jQuery(parentContainer).bind("mouseleave", function() {
        menuContainer.hide();
    });

});



/* =Show page for inner pseudo-pages
------------------------------------------------------------------------ */
function showPage(PageID) {

    // hide all, show page with PageID -----------
    jQuery(".page").each(function() {
        var jContent = jQuery(this);

        if (jContent.is("[rel*='" + PageID + "']")) {

            // show page
            jContent.queue(function() {
                jQuery(this).removeClass("hide");
                jQuery(this).dequeue();
            });

            // replace H2  --------------------------------
            sIFReplacePageHeaders();

            // set current navigation item ---------------
            jQuery(".switch-nav a.switch").parent().removeClass("current");
            jQuery(".switch-nav a.switch[href*='" + PageID + "']").parent().addClass("current");

        } else {
            // hide page
            jContent.addClass("hide");
        }
    });

    return false;
}


/* = Hide/Show textfield value
------------------------------------------------------------------------ */
function setOnFocus(keywords, control) {
    if (control.value == keywords) {
        control.value = '';
    }
}

function setOnBlur(keywords, control) {
    if (control.value == '') {
        control.value = keywords;
    }
}

/* = sIFR functions
------------------------------------------------------------------------ */
function sIFReplaceOverviewH2() {
    sIFR.replace(georgia, {
        selector: '.overview-block h2'
        , forceWidth: 'true'
        , wmode: 'transparent'
        , css: [
            '.sIFR-root { color: #ffffff; font-size: 15px; letter-spacing: 0.3; font-weight: normal; text-align: left; leading: -2;}'
        ]
    });
}

function sIFReplaceSignUpH4() {
    sIFR.replace(georgia, {
        selector: '.secondary-content .sign-up h4'
        , forceWidth: 'true'
        , wmode: 'transparent'
        , css: [
            '.sIFR-root { color: #ffffff; font-size: 16px; font-weight: normal; text-align: left; leading: -2;}'
        ]
    });
    
     sIFR.replace(georgia, {
        selector: '.sign-up h4'
        , forceWidth: 'true'
        , wmode: 'transparent'
        , css: [
            '.sIFR-root { color: #ffffff; font-size: 20px; font-weight: normal; text-align: left; leading: -2;}'
        ]
    });
}

function sIFReplacePageHeaders() {
    sIFR.replace(georgia, {
        selector: '.page h2'
        , forceWidth: 'true'
        , wmode: 'transparent'
        , css: [
            '.sIFR-root { color: #ffffff; font-size: 26px; text-align: left; leading: -2;} strong{ font-weight:normal; font-size:20px; }'
            , 'a { text-decoration: none }'
            , 'a:link { color: #ffffff }'
            , 'a:hover { color: #ffffff }'
        ]
    });
    sIFR.replace(georgia, {
        selector: '.page h3, .page .h4'
        , forceWidth: 'true'
        , wmode: 'transparent'
        , css: [
            '.sIFR-root { color: #ffffff; font-size: 16px; font-weight: normal; text-align: left; leading: -2;}'
            , 'strong { font-weight: normal; }'
        ]
    });
}
