
function breyta() {
    var uriLocation = top.location.href;
    var hashLocator = uriLocation.split("#");
    
    if (hashLocator.length > 1) {
        document.location.replace(hashLocator[1]);
    } else {
        document.location.replace("/frettir/");
    }
}

var lastHash = '';
var doRunAddressPoll = true;
function pollDeepLinkedHash() {
    // If hash has changed
    if(lastHash !== top.location.hash)
    {
        // Save the current hash
        lastHash = top.location.hash;
        // Run the deep link renderer again if this isn't the first loop after a refresh
        if (doRunAddressPoll === true)
        {
            breyta();
        }
        else
        {
            // Only skip first loop
            doRunAddressPoll = true;
        }
    }
}

function pageload(hash)
{
    if(hash)
    {
        top.document.location.replace(top.document.location.protocol + "//" +
                                      top.document.location.host + "#" +
                                      hash);
    }
}

function intervalTest()
{
    alert('muu');
}

function checkbigbjorn() {
    var uriLocation = window.parent.location.href;
    var hashLocator = uriLocation.split("#");

    if (hashLocator.length === 1 && parent.window.location.pathname.length > 1) {
        top.document.location.replace(top.document.location.protocol + '//' +
                                      top.document.location.host + '#' +
                                      top.document.location.pathname);
    }
}

$(document).ready(function() {

    checkbigbjorn();

    if (/webkit/.test( navigator.userAgent.toLowerCase()) == false) {
        if (window.parent.didFramesetLoad === false) {

            top.document.location.replace(top.document.location.protocol + "//" +
                                          top.document.location.host + "#" +
                                          document.location.pathname);
            lastHash = top.location.hash;
        } else {
            doRunAddressPoll = false;
        }

        setInterval(pollDeepLinkedHash, 500);
		window.parent.didFramesetLoad = false;
    }

});
