﻿var dagatal_Flipi_Moving = false;
var dagatal_Flipi_Direction = 0;
var dagatal_Flipi_Position = 540;
var dagatal_Item_Position = 280;
var dagatal_move_Left, dagatal_move_Right, dagatal_Wait;
var dagatal_item_move_Left, dagatal_item_move_Right, dagatal_item_Wait;
var SplashDay;
var mdX, mdY, py, px;
var popupImgId = 0;
var popupFldId = 0;
var myndFjoldi = 0;


function changeFrettaAr(ar) {
    var arin = document.getElementById("div_Arin").childNodes;
    for (i = 0; i < arin.length; i++) {
        if (arin[i].tagName == "DIV") {
            arin[i].style.display = "none";
        }
    }
    document.getElementById("div_Ar_" + ar).style.display = "block";
}


function highlight(it, px, barn) {
    it.style.backgroundPosition = "0px " + px + "px";
    if (barn == true) {
        it.getElementsByTagName("div")[0].style.backgroundPosition = "right " + px + "px";
    }
}
function highlightFontSize(it, px) {
    if (it.style.backgroundPosition != "0px 19px") {
        it.style.backgroundPosition = "0px " + px + "px";
    }
}

function toggleVefir() {
    var it = document.getElementById("divAdrirVefirList");
    if (it.style.display == "none") {
        it.style.display = "block";
    } else {
        it.style.display = "none";
    }
}

function tc(it, cls) {
    it.className = cls;
}
function show_Day(tDay, tMonth, tYear) {
    var d = new Date();
    d.setMonth(tMonth - 1);
    d.setYear(tYear);
    d.setDate(tDay);
    document.getElementById("Dagatal_Flipi_Header_Inner").innerHTML = tWeekday[d.getDay()] + ". " + tDay + ". " + monthname[tMonth] + ". " + tYear;
    document.getElementById("Dagatal_Flipi_Content_Inner").innerHTML = "";
    ShowSplash();
    fela_cal_item();
    dagatal_move_Left = setInterval("show_Day_Flipi()", 5)
    dagatal_item_move_Right = setInterval("hide_Day_Item()", 5);
    getXML("/getDay.aspx?dag=" + tDay + "&man=" + tMonth + "&ar=" + tYear + "&rnd=" + Math.random(), processDay)
}
function hide_day() {
    dagatal_Wait = setInterval("wait_hide_Day_Flipi()", 1500)
}

function cancel_hide_day() {
    clearInterval(dagatal_Wait);
}

function wait_hide_Day_Flipi() {
    fela_cal_item();
    dagatal_move_Right = setInterval("hide_Day_Flipi()", 5)
}


function ShowSplash() {
    try {
        if (!SplashDay) {
            SplashDay = new SplashScreen(24, true, document.getElementById("NedriHaus_Center"));
            SplashDay.setTitle("Sæki atburði");
            SplashDay.setWidth(100);
        }
        SplashDay.show();
    } catch (e) { }
}
function SplashScreen(tSize, autoDisplay, parentobj) {
    var myself = this;
    this.auto_display = true;
    if (autoDisplay) { this.auto_display = autoDisplay };
    this.title = "";
    if (parentobj)
        this.parentObject = parentobj;
    else
        this.parentObject = document.body;

    var divOuter = document.createElement("div");
    divOuter.style.visibility = "hidden";
    divOuter.className = "divSplashOuter";
    var divTitle = document.createElement("div");
    divTitle.className = "divSplashTitle";
    divOuter.appendChild(divTitle);
    var divImg = document.createElement("div");
    divImg.className = "divSplashImg";
    divOuter.appendChild(divImg);
    var img = document.createElement("img");
    img.src = "/img/hringir_" + tSize + ".gif";
    img.width = tSize;
    img.height = tSize;
    divImg.appendChild(img);
    var divLinur = document.createElement("div");
    divLinur.className = "divSplashLinur";
    divOuter.appendChild(divLinur);
    document.body.appendChild(divOuter);

    this.mainFrame = divOuter;
    this.title = divTitle;
    this.Linur = divLinur;

    this.AddEvent = function (tObject, tEvent, tFunc) {
        if (document.attachEvent) {
            tObject.attachEvent("on" + tEvent, tFunc);
        }
        else {
            tObject.addEventListener(tEvent, tFunc, false);
        }
    };

    this.RemoveEvent = function (tObject, tEvent, tFunc) {
        if (document.detachEvent) {
            tObject.detachEvent(tEvent, tFunc);
        }
        else {
            tObject.removeEventListener(tEvent, tFunc, false);
        }
    };

    this.findPosX = function (obj) {
        var curleft = 0;
        if (obj.offsetParent) {
            while (obj.offsetParent) {
                curleft += obj.offsetLeft;
                obj = obj.offsetParent;
            } 
        }
        else if (obj.x) {
            curleft += obj.x;
        }
        return curleft + document.body.offsetLeft;
    };

    this.findPosY = function (obj) {
        var curtop = 0;
        if (obj.offsetParent) {
            while (obj.offsetParent) {
                curtop += obj.offsetTop;
                obj = obj.offsetParent;
            }
        }
        else if (obj.y) {
            curtop += obj.y;
        }

        return curtop + document.body.offsetTop;
    };


    this.setPosition = function () {
        myself.mainFrame.style.left = myself.findPosX(myself.parentObject) + (myself.parentObject.clientWidth - myself.mainFrame.clientWidth) / 2 + "px";
        myself.mainFrame.style.top = myself.findPosY(myself.parentObject) + (myself.parentObject.clientHeight - myself.mainFrame.clientHeight) / 2 + "px";
    };

    this.show = function () {
        this.setPosition();
        this.AddEvent(window, "resize", this.setPosition);
        this.mainFrame.style.visibility = "visible";
    };


    this.hide = function () {
        this.RemoveEvent(document, "resize", this.setPosition);
        this.mainFrame.style.visibility = "hidden";
    };


    this.setTitle = function (tTitle) {
        this.title.innerHTML = tTitle;
    };


    this.setWidth = function (tWidth) {
        this.mainFrame.style.width = tWidth + "px";
    };


    this.addLine = function (nText) {
        var element = document.createElement("div");
        element.innerHTML = nText;
        this.Linur.appendChild(element);
        if (this.auto_display) { this.show() }
        return element;
    };


    this.removeLine = function (it) {
        if (it.parentNode) {
            it.parentNode.removeChild(it);
        }
        if (this.Linur.getElementsByTagName("div").length == 0 && this.auto_display == true) {
            this.hide();
        }
    };
}











function getXML(tUrl, tHandler) {
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = tHandler;
        req.open("GET", tUrl, true);
        req.send(null);
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = tHandler;
            req.open("GET", tUrl, true);
            req.send();
        }
    }
}





function myndaMappa(id, mId, mSrc, mTxt, mFjoldi) {
    var it = new MakemyndaMappa(id, mId, mSrc, mTxt, mFjoldi)
}


function MakemyndaMappa(id, mId, mSrc, mTxt, mFjoldi) {
    var myself = this;
    this.mappaId = id;
    this.myndId = 0;
    this.myndFjoldi = 0
    this.myndSrc = "";
    this.myndTxt = "";
    this.pos = 1;
    var itm = 0;
    while (document.getElementById("mndMappa_" + itm)) { itm = itm + 1; }
    if (mId) { this.myndId = mId };
    if (mSrc) { this.myndSrc = mSrc };
    if (mTxt) { this.myndTxt = mTxt };
    if (mFjoldi) { this.myndFjoldi = mFjoldi };
    this.AddEvent = function (tObject, tEvent, tFunc) { if (document.attachEvent) { tObject.attachEvent("on" + tEvent, tFunc) } else { tObject.addEventListener(tEvent, tFunc, false) } }
    this.RemoveEvent = function (tObject, tEvent, tFunc) { if (document.detachEvent) { tObject.detachEvent("on" + tEvent, tFunc); } else { tObject.removeEventListener(tEvent, tFunc, false); } }

    this.showLarge = function () {
        setPopupImage(myself.myndId, myself.mappaId, "t", myself.myndFjoldi);
    }
    this.showNext = function () {
        myself.requestXML("r");
    }
    this.showPrev = function () {
        myself.requestXML("l");
    }

    this.requestXML = function (pn) {
        div6.style.display = "block";
        var tUrl = "/getMynd.aspx?MyndId=" + this.myndId + "&FloId=" + this.mappaId + "&Pos=" + pn + "&rnd=" + Math.random();
        if (window.XMLHttpRequest) {
            req = new XMLHttpRequest();
            req.onreadystatechange = this.responseXML;
            req.open("GET", tUrl, true);
            req.send(null);
        } else if (window.ActiveXObject) {
            req = new ActiveXObject("Microsoft.XMLHTTP");
            if (req) {
                req.onreadystatechange = responseXML;
                req.open("GET", tUrl, true);
                req.send();
            }
        }
    }

    this.responseXML = function () {
        if (req.readyState == 4) {
            if (req.status == 200) {
                response = req.responseXML.documentElement;
                var items = response.getElementsByTagName("*");
                if (items.length > 7) {
                    myself.myndId = items[0].firstChild.data;
                    myself.myndSrc = items[3].firstChild.data;
                    try { myself.myndTxt = items[4].firstChild.data; } catch (e) { myself.myndTxt = ""; }
                    var lr = items[8].firstChild.data;
                    myself.pos = myself.pos + parseInt(lr);
                    if (myself.pos == 0) { myself.pos = myself.myndFjoldi }
                    if (myself.pos > myself.myndFjoldi) { myself.pos = 1 }
                    divPos.innerHTML = myself.pos + " af " + myself.myndFjoldi;
                    div5.style.backgroundImage = "url(/images/128/" + myself.myndSrc + ")";
                    div10.innerHTML = myself.myndTxt;
                }
            }
            div6.style.display = "none";
        }
    }

    var div0 = retObj("DIV", "", "mr_outer", "");
    var div1 = retObj("DIV", "", "mr_h1", "");
    var div2 = retObj("DIV", "", "mr_h2", "");
    var div3 = retObj("DIV", "", "mr_h3", "");
    var imgShow = retObj("IMG", "", "mr_gler"); imgShow.src = "/img/rammi/gler.gif"; myself.AddEvent(imgShow, "click", myself.showLarge);
    var imgRight = retObj("IMG", "", "mr_or_r"); imgRight.src = "/img/rammi/or_right.gif"; myself.AddEvent(imgRight, "click", myself.showNext);
    var imgLeft = retObj("IMG", "", "mr_or_l"); imgLeft.src = "/img/rammi/or_left.gif"; myself.AddEvent(imgLeft, "click", myself.showPrev);
    var divPos = retObj("DIV", "", "mr_Pos", "")
    var div4 = retObj("DIV", "", "mr_m1", "");
    var div5 = retObj("DIV", "", "mr_m2", "");
    var div6 = retObj("DIV", "", "mr_m3", "");
    var div7 = retObj("DIV", "", "mr_b1", "");
    var div8 = retObj("DIV", "", "mr_b2", "");
    var div9 = retObj("DIV", "", "mr_b3", "");
    var div10 = retObj("DIV", "", "mr_b4", "");
    div0.appendChild(div1);
    div1.appendChild(div2);
    div2.appendChild(div3);
    div3.appendChild(imgShow);
    div3.appendChild(imgRight);
    div3.appendChild(imgLeft);
    div3.appendChild(divPos);
    div0.appendChild(div4);
    div4.appendChild(div5);
    div5.appendChild(div6);
    div0.appendChild(div7);
    div7.appendChild(div8);
    div8.appendChild(div9);
    div9.appendChild(div10);
    div5.style.backgroundImage = "url(/images/128/" + mSrc + ")"; myself.AddEvent(div5, "click", myself.showLarge)
    div10.innerHTML = mTxt;
    divPos.innerHTML = "1 af " + mFjoldi
    document.write('<span id="mndMappa_' + itm + '"></span>');
    document.getElementById("mndMappa_" + itm).appendChild(div0);
}

function retObj(tType, tId, tClass, tStyle) {
    var it = document.createElement(tType);
    if (tId) { it.setAttribute("id", tId) }
    if (tClass) { it.className = tClass }
    if (tStyle) { it.style.cssText = tStyle }
    return it;
}










function setActiveStyleSheet(tTitle) {
    var i, a, main;
    for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
        if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
            a.disabled = true;
            if (a.getAttribute("title") == tTitle) {
                a.disabled = false;
            }
        }
    }
    title = tTitle;
    setButtons(tTitle);
}

function window_load() {
    var cookie = readCookie("style");
    title = cookie ? cookie : getPreferredStyleSheet();
    setActiveStyleSheet(title);
    runSlideShow()
}

function setButtons(tTitle) {
    var a = document.getElementById("imgA");
    var aa = document.getElementById("imgAA");
    switch (tTitle) {
        case "Size2":
            a.style.backgroundPosition = "0px 0px";
            a.style.cursor = "pointer";
            aa.style.backgroundPosition = "0px 0px";
            aa.style.cursor = "pointer";
            break;
        case "Size3":
            a.style.backgroundPosition = "0px 0px";
            a.style.cursor = "pointer";
            aa.style.backgroundPosition = "0px -28px";
            aa.style.cursor = "default";
            break;
        default:
            a.style.backgroundPosition = "0px -28px";
            a.style.cursor = "default";
            aa.style.backgroundPosition = "0px 0px";
            aa.style.cursor = "pointer";
    }
}

function fontLarger() {
    if (title == "Size1" || title == "") {
        setActiveStyleSheet("Size2");
    } else {
        if (title == "Size2") {
            setActiveStyleSheet("Size3");
        }
    }
}
function fontSmaller() {
    if (title == "Size3") {
        setActiveStyleSheet("Size2");
    } else {
        if (title == "Size2") {
            setActiveStyleSheet("Size1");
        }
    }
}

function window_unload() {
    var title = getActiveStyleSheet();
    createCookie("style", title, 7);
}
function getPreferredStyleSheet() {
    var i, a;
    for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
        if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title"))
            return a.getAttribute("title");
    }
    return null;
}
function getActiveStyleSheet() {
    var i, a;
    for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
        if (a.getAttribute("rel").indexOf("style") != -1
			&& a.getAttribute("title")
			&& !a.disabled) return a.getAttribute("title");
    }
    return null;
}
function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}


function popupDoMove(e) {
    if (!e) { e = event };
    var it = document.getElementById("popup");
    var bx = e.screenX;
    var by = e.screenY;
    it.style.left = (px + bx - mdX) + "px";
    it.style.top = (py + by - mdY) + "px";

}
function popupStopMove(e) {
    funRemoveEvent(document, "mousemove", popupDoMove);
    funRemoveEvent(document, "mouseup", popupStopMove);
}
function popupMove(e) {
    if (!e) { e = event };
    var it = document.getElementById("popup");
    px = it.offsetLeft;
    py = it.offsetTop;
    mdX = e.screenX;
    mdY = e.screenY;
    funAddEvent(document, "mousemove", popupDoMove);
    funAddEvent(document, "mouseup", popupStopMove);

}
function funAddEvent(tObject, tEvent, tFunc) {
    if (document.attachEvent) {
        tObject.attachEvent("on" + tEvent, tFunc)
    } else {
        tObject.addEventListener(tEvent, tFunc, false)
    }
}
function funRemoveEvent(tObject, tEvent, tFunc) {
    if (document.detachEvent) {
        tObject.detachEvent("on" + tEvent, tFunc)
    } else {
        tObject.removeEventListener(tEvent, tFunc, false)
    }
}
function setPopupImage(imgId, fldId, dir) {
    popupFldId = fldId;
    document.getElementById("popupMdl4").style.backgroundImage = "url(/img/null.gif)";
    if (document.getElementById("popup").style.visibility == "hidden") {
        funAddEvent(document, "selectstart", retFalse);
        setPopupSize(320, 240);
        document.getElementById("popup").style.visibility = "visible";
    }

    requestImage(imgId, fldId, dir)
}
function retFalse() {
    return false;
}

function closePopup() {
    document.getElementById("popup").style.visibility = "hidden";
    funRemoveEvent(document, "selectstart", retFalse);
    popupImgId = 0;
    popupFldId = 0;
}
function doNextImage() {
    requestImage(popupImgId, popupFldId, "r");
}
function doPrevImage() {
    requestImage(popupImgId, popupFldId, "l");
}

function requestImage(imgId, fldId, pn) {
    var tUrl = "/getMynd.aspx?MyndId=" + imgId + "&FloId=" + fldId + "&Pos=" + pn + "&size=l&rnd=" + Math.random();
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = this.responseImage;
        req.open("GET", tUrl, true);
        req.send(null);
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = responseImage;
            req.open("GET", tUrl, true);
            req.send();
        }
    }
}

function setPopupSize(x, y) {
    document.getElementById("popup").style.width = parseInt(x + 28) + "px";
    document.getElementById("imgPopup").style.width = x + "px";
    document.getElementById("imgPopup").style.height = y + "px";
    document.getElementById("popupMdl2").style.width = parseInt(x + 20) + "px";
    if (popupImgId == 0) {
        setPopupPosition();
    }
}
function setPopupPosition() {
    var myself = document.getElementById("popup");
    myself.style.left = (document.body.clientWidth - myself.clientWidth) / 2 + "px";
    myself.style.top = (document.body.clientHeight - myself.clientHeight) / 3 + "px";
}
function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curleft += obj.offsetLeft;
            obj = obj.offsetParent;
        } 
    }
    else if (obj.x) {
        curleft += obj.x;
    }
    return curleft + document.body.offsetLeft;
};

function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curtop += obj.offsetTop;
            obj = obj.offsetParent;
        } 
    }
    else if (obj.y) {
        curtop += obj.y;
    }
    return curtop + document.body.offsetTop;
};

function responseImage() {
    if (req.readyState == 4) {
        if (req.status == 200) {
            try {
                response = req.responseXML.documentElement;
                var items = response.getElementsByTagName("*");
                if (items.length > 7) {
                    document.getElementById("popupMdl4").style.backgroundImage = "url(/images/" + items[3].firstChild.data + ")";
                    setPopupSize(parseInt(items[1].firstChild.data), parseInt(items[2].firstChild.data));
                    document.getElementById("popupHeading").innerHTML = items[9].firstChild.data;
                    try { document.getElementById("popupTxt").innerHTML = items[4].firstChild.data; } catch (e) { document.getElementById("popupTxt").innerHTML = ""; }
                    popupImgId = parseInt(items[0].firstChild.data)

                    //       alert(items[3].firstChild.data);
                    //       myself.myndId=items[0].firstChild.data;
                    //       myself.myndSrc=items[3].firstChild.data;
                    //       try{myself.myndTxt=items[4].firstChild.data;}catch(e){myself.myndTxt="";}
                    var lr = items[8].firstChild.data;
                    var pos = pos + parseInt(lr);
                    if (pos == 0) { pos = myndFjoldi }
                    if (pos > myndFjoldi) { pos = 1 }
                    document.getElementById("popupPos").innerHTML = pos + " af " + myndFjoldi;
                    //       div5.style.backgroundImage="url(/images/128/"+myself.myndSrc+")";
                    //       div10.innerHTML=myself.myndTxt;
                }
            } catch (e) {
                alert("Því miður hefur komið upp villa\nog því ekki hægt að birta myndina.\n\nVinsamlegast reynið aftur síðar");
                closePopup()
            }
        }
        //div6.style.display="none";
    }
}

function askrift(SID_ID, VEF_ID) {
    gluggi_askrift = window.open('http://nepal.vefurinn.is/fastar/postlistaskraning_1.asp?ASK_SID_ID=' + SID_ID + '&VEF_ID=' + VEF_ID, 'image', "toolbar=0,scrollbars=0,location=0,status=0,menubar=0,width=350,height=300");
}




// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 5000

// Duration of crossfade (seconds)
var crossFadeDuration = 3

// Specify the image files
var Pic = new Array() // don't touch this
// to add more images, just continue
// the pattern, adding to the array below

Pic[0] = '/img/rnd1.jpg'
Pic[1] = '/img/rnd2.jpg'
Pic[2] = '/img/rnd3.jpg'
Pic[3] = '4.jpg'
Pic[4] = '5.jpg'

// =======================================
// do not edit anything below this line
// =======================================

var t
var j = 0
var p = Pic.length

var preLoad = new Array()
for (i = 0; i < p; i++) {
    preLoad[i] = new Image()
    preLoad[i].src = Pic[i]
}

function runSlideShow() {
    if (document.all) {
        document.images.SlideShow.style.filter = "blendTrans(duration=2)"
        document.images.SlideShow.style.filter = "blendTrans(duration=crossFadeDuration)"
        document.images.SlideShow.filters.blendTrans.Apply()
    }
    document.images.SlideShow.src = preLoad[j].src
    if (document.all) {
        document.images.SlideShow.filters.blendTrans.Play()
    }
    j = j + 1
    if (j > (p - 1)) j = 0
    t = setTimeout('runSlideShow()', slideShowSpeed)
}
