﻿var cHash = "";

// HashChange Watchdog (IE6 Workaround)
function hashWatch() {
    var hash = window.location.hash.replace(/^#/, '');

    if (cHash != hash) {
        loadContent(hash);
        removeIframe();
    }
    cHash = hash;
}

function ajaxian(navigation, container) {
    /**********************/
    /*** Initialisieren ***/
    /**********************/
    this.init = function () {
        if ((!isIE6) && (!isIE7)) {
            $(navigation + " a[href^='/']").each(function () {
                makeItAjax($(this));
            });

            // Navigation-Events
            if (canHashChange()) {
                $(window).bind('hashchange', function () {
                    loadContent(getURL());
                });
            } else {
                setInterval("hashWatch()", 500);
            }

            var regBaseUrl = new RegExp("^/([a-z]{2})/$");
            if (regBaseUrl.test(location.pathname)) {
                loadContent(getURL());
            }
        }
    }
}


/*********************/
/*** Content laden ***/
/*********************/
function loadContent(path) {
    $("#content").fadeOut(300, function () {
        // Startseite
        path = "/" + langKey + path;
        var regBase = new RegExp("^/([a-z]{2})/$");
        if (regBase.test(path)) {
            path = path + "default.aspx"
        }

        // Content (aktueller Pfad)
        var cPath = path;
        if (cPath.indexOf("?") > -1) {
            cPath = cPath + "&amp;ajax=1"
        } else {
            cPath = cPath + "?ajax=1"
        }

        // Content laden
        $.get(cPath, function (data) {
            var content = $(data).filter("#content").html();
            $("#content").html(content);
        }).success(function () {
            $("#content").fadeIn(300);
            $("#content a[href^='/']").each(function () {
                makeItAjax($(this));
            });
        });
        setActiveNodes();
    });
}

function frameHeight() {
    var wHeight = $(window).height();
    var cHeight = $("#masterframe").height();

    //alert(wHeight + " " + cHeight);

    if (wHeight >= cHeight) {
        $("#masterframe").css("height", (wHeight - 0) + "px");
        //alert("true");
    } else {
        $("#masterframe").css("height", "auto");
    }
}


// Scrollposition speichern
function getScroll() {
    var scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant   
        scrOfY = window.pageYOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant   
        scrOfY = document.body.scrollTop;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode   
        scrOfY = document.documentElement.scrollTop;
    }
    return scrOfY;
}


function saveScroll() {
    $.cookie('scrollPos', getScroll(), { path: '/', expires: 10 });
    // alert($.cookie('scrollPos'));
}

function setScroll() {
    window.scrollTo(0, parseInt($.cookie('scrollPos')));
}

$(window).scroll(function () {
    saveScroll();
});

$(window).load(function () {
    frameHeight();
});
$(window).resize(function () {
    frameHeight();
});
$(document).ready(function () {
    frameHeight();
    setScroll();

    // Infinit Slider Loop
    $(".one img:first").fadeIn(700, function () {
        $(".two img:first").fadeIn(700, function () {
            $(".three img:first").fadeIn(700, function () {
                startX(".one", 0);
                startX(".two", 900);
                startX(".three", 1800);
            });
        });
    });
});

function startX(container, cDelay) {
    $(container).cycle({ fx: 'fade', delay: cDelay, timeout: 4000 });
}

