


$(document).ready(function () {

    var lifidSA1 = $('.AlphaGamma.lifid-section1').height();
    var lifidSD1 = $('.Delta.lifid-section1').height();
    var lifidStjornuspa = $('.Delta.lifid-section1 .Stjornuspa').height();
    var lifidStjornuspaplus = lifidSA1 - lifidSD1;

    $('.Delta.lifid-section1 .Stjornuspa').height(lifidStjornuspa + lifidStjornuspaplus);

    /* Check ad spaces */
    var i = 0;
    for (i = 0; i <= 7; i++) {
        CheckForAd('ad_A' + i);
        CheckForAd('ad_B' + i);
        CheckForAd('ad_C' + i);
        CheckForAd('ad_D' + i);
        CheckForAd('ad_E' + i);
        CheckForAd('ad_F' + i);
        CheckForAd('ad_G' + i);
        CheckForAd('ad_H' + i);
        CheckForAd('ad_Z' + i);


    }
    CheckForAd('ad_Z');
    CheckForAd('ad_Script');

    if ($("#LifidSideScroll").length > 0) {
        $("#LifidSideScroll").jCarouselLite({
            btnNext: "#LifidSideScrollLeft",
            btnPrev: "#LifidSideScrollRight",
            vertical: true,
            visible: 3,
            speed: 250,
            afterEnd: function (a) {
                if ($("#scollDetails").is(":visible")) {
                    Popupscrollitem(a[1], true, true);
                }
            }
        });

        var ssheight = parseInt($('.lifeMainBox .mainLifeNews').height());
        $('#LifidSideScroll').height(ssheight - 38);

        $("#LifidAdScroll").jCarouselLite({
            btnNext: "#LifidAdScrollLeft",
            btnPrev: "#LifidAdScrollRight",
            visible: 3,
            speed: 250
        });

        $('.adScroller.horizontalscroll ul li').click(function () {
            Popupscrollitem(this, false, false);
        })


        $('.adScroller.vertical ul li').click(function () {
            Popupscrollitem(this, false, true);
        })
    }

    $('#Lifid_scroll_Selt ul li').click(function () {
        Popupscrollitem(this, false, false);
    })

    /* Tonlistin - Lķfiš */
    $('.tonlistinn .topTabs li a').click(function () {
        $('.tonlistinn .topTabs li a').removeClass("Selected");
        $(this).addClass("Selected");
    });

    /* Boltavaktin */


    $('#boltavaktin .tabs li a').click(function () {
        var deild = $(this).attr("title");
        var type = $(this).attr("rel");

        $('#boltavaktin .tabs li a').removeClass("Selected");

        if (type == 'stada') {
            getfootballstatus(deild, type, '#boltavaktin');
        }
        else {
            getfootballstatus(deild, type, '#boltavaktin');
        }
        $(this).addClass("Selected");

        return false;
    });
    /* Śtvarp Live */
    $('.listenradio').click(function () {
        window.open($(this).attr('href'), 'theplayer', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=482,height=456,left = 100,top = 100');
        return false;
    });
    bindTabArea();
    $(".cbvideo span a").each(function () {
        var id = $(this).closest('li').attr('data-fileid');
        $(this).colorbox({
            width: 710,
            innerHeight: 435,
            opacity: 0.8,
            href: '/section/MEDIA&template=cbvideo&fileid='+ id
        });
    });
});

function getfootballstatus(deild, type, target) {
    $("#boltavaktin .loading").ajaxStart(function () {
        $(this).show();
    });
    $(target + " .loading").ajaxStop(function () {
        $(this).hide();
    });
    if (type == 'stada') {
        $(target + ' .content').load('/section/IDROTTIR0102&template=stada_blank&deild=' + deild + '');
    }
    else if (type == 'vakt') {
        $(target + ' .content').load('/section/IDROTTIR0102&template=vakt_blank&deild=' + deild + '');
    }
    else if(type == 'ibeinni') {
        $(target + ' .content').load('/section/IDROTTIR&template=ibeinni_blank');
    }
    
} 


function getHash() {
    var hash = window.location.hash;
    return hash.substring(1);
}	

function closeMe(item) {
    $(item).fadeOut("fast");
}


function Popupscrollitem(item, visible, vertical) {
    if (vertical == true) {
        flow = "vertical"
    }
    else {
        flow = "horizontalscroll"
    }
            if ($('#scollDetails').length < 1) {
                $('body').append('<div id="scollDetails" class="' + flow + '" class="popup">Hlešur</div>');
            }

            var price = $(item).find('.price').html();
            var title = $(item).find('.texti').html();
            var description = $(item).find('.description').html();
            var link = $(item).find('.link').html();
            var img = $(item).find('img').attr('src');
            img = img.replace("MaxH=140&MaxW=150", "MaxH=260&MaxW=260");
            img = img.replace("MaxH=120&MaxW=120", "MaxH=260&MaxW=260");


            var s = '<div class="close" onclick="closeMe(\'#scollDetails\')"></div>';
            s += '<div class="content"><div class="image"><img src="' + img + '" /></div>';
            s += '<span class="title"><p>' + title + '</p></span>';
            if(description.length > 0){s += '<span class="description"><p>' + description + '</p></span>';}
            if(price.length > 0){s += '<span class="price"><p>Verš: ' + price + '</p></span>';}
            if(link.length > 0){s += '<span class="link"><p style="text-align:right;color:#636363">Nįnar į: <a style="color:#636363" href="http://' + link + '" target="_new"> ' + link + '</a></p></span>';}
            s += '</div><span class="bottom"><p>Kynning</p></span>';
            $('#scollDetails').html(s);
            var left = "40%"
            var top = $(item).offset().top - 120;

            if (vertical == true) {
                left = $(item).offset().left + 100 + "px;";
                top = $(item).offset().top - 170;
            }
            
            var style = 'top: ' + top + 'px; left: ' + left;

            $('#scollDetails').attr('style', style);

            if (visible == false) {
                $('#scollDetails').fadeIn("fast");
            }
            else {
                $('#scollDetails .content').fadeIn("slow");
                $('#scollDetails').show();
            }
            
           
}


/* Dropdown */
var maxHeight = 300;
$(function () {
    $(".longdropdown > li").hover(function () {
        var $container = $(this),
             $list = $container.find("ul"),
             $anchor = $container.find("a"),
             height = $list.height() * 1.1,       // make sure there is enough room at the bottom
             multiplier = height / maxHeight;     // needs to move faster if list is taller

        $list
            .show()
    }, function () {
        $container = $(this),
             $list = $container.find("ul"),
        // put things back to normal
        $list
            .hide()
    });
});

/* Dropdown 
var maxHeight = 300;
$(function(){
$(".longdropdown > li").hover(function() {
var $container = $(this),
$list = $container.find("ul"),
$anchor = $container.find("a"),
height = $list.height() * 1.1,       // make sure there is enough room at the bottom
multiplier = height / maxHeight;     // needs to move faster if list is taller
// need to save height here so it can revert on mouseout           
muti = multiplier;
$container.data("origHeight", $container.height());
// so it can retain it's rollover color all the while the dropdown is open
$anchor.addClass("hover");
// make sure dropdown appears directly below parent list item    
$list
.show()
.css({
paddingTop: $container.data("origHeight")
});
// don't do any animation if list shorter than max
if (multiplier > 1) {
$container
.css({
height: maxHeight,
overflow: "hidden"
})
.mousemove(function(e) {
var offset = $container.offset();
var relativeY = ((e.pageY - offset.top) * multiplier) - ($container.data("origHeight") * multiplier);
if (relativeY > $container.data("origHeight")) {
$list.css("top", -relativeY + $container.data("origHeight"));
};
});
}
}, function() {
var $el = $(this);
// put things back to normal
$el
.height($(this).data("origHeight"))
.find("ul")
.css({ top: 0 })
.hide()
.end()
.find("a")
.removeClass("hover");
});
});
*/




function KtCheck(strKt) {
    var intKtSum = 0;
    intKtSum = intKtSum + (strKt.charAt(0) * 3);
    intKtSum = intKtSum + (strKt.charAt(1) * 2);
    intKtSum = intKtSum + (strKt.charAt(2) * 7);
    intKtSum = intKtSum + (strKt.charAt(3) * 6);
    intKtSum = intKtSum + (strKt.charAt(4) * 5);
    intKtSum = intKtSum + (strKt.charAt(5) * 4);
    intKtSum = intKtSum + (strKt.charAt(6) * 3);
    intKtSum = intKtSum + (strKt.charAt(7) * 2);
    intKtSum = intKtSum - (parseInt(intKtSum / 11) * 11)
    intKtSum = 11 - intKtSum;
    if (intKtSum >= 11)
        intKtSum = 0;

    if (strKt.charAt(8) == intKtSum) {
        return 0;
    }
    else {
        return 1;
    }
}


function stripChars(inString) {
    var outString = '';
    for (i = 0; i < inString.length; i++) {
        mc = inString.charAt(i);
        if (mc == '') { mc = '-'; }
        if (mc == '') { mc = '"'; }
        if (mc == '') { mc = '"'; }
        if (mc == '') { mc = '"'; }
        outString = outString + mc;
    }
    return outString;
}


function Search(strFormElem, strSearchElem, strSearch_sourceElem, strCurrIP, strReferrer) {
    //searchForm = document.getElementById(strFormElem).value;
    source = document.getElementById("valinleit").value;
    search = document.getElementById("strSearchElem").value;


    if (search.length > 0) {
        if (source == 'visir') {
            document.location.href = 'http://leit.visir.is/leit.aspx?sort=Newest&search=' + search.replace(/ /g, '+');
        }

        else if (source == 'google') {
            window.open('http://www.google.is/search?q=' + escape(search) + '', '_leit');
        }
        else if (source == 'frettabladidsmall') {
            document.location.href = 'http://leit.visir.is/leit.aspx?sort=Newest&SearchType=6&search=' + search;
        }
        else if (source == 'yahoo') {
            window.open('http://search.yahoo.com/search?p=' + search + '', '_leit');
        }
        else if (source == 'ordabok') {
            window.open('http://ordabok.is/index.asp?ordabok=ISL&listaord=' + escape(search) + '', '_leit');
        }
        else if (source == 'wikipedia') {
            window.open('http://en.wikipedia.org/wiki/Special:Search?search=' + escape(search) + '', '_leit');
        }
        else if (source == 'ja') {
            window.open('http://ja.is/hradleit/?q=' + escape(search) + '', '_leit');
        }
        else if (source == 'youtube') {
            window.open('http://www.youtube.com/results?search_query=' + search + '', '_leit');
        }
        else if (source == 'facebook') {
            window.open('http://www.facebook.com/search/?q=' + search + '', '_leit');
        }

    } else {
        alert('Žś veršur aš skrifa inn leitarorš!');
    }
}





function check_email(efield) {
    ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

    for (i = 0; i < efield.length; i++) {
        if (ok.indexOf(efield.charAt(i)) < 0) {
            return (false);
        }
    }

    if (document.images) {
        re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
        re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
        if (!efield.match(re) && efield.match(re_two)) {
            return (-1);
        }
    }
}



function innslattur() {
    var tmp = document.forms.gsm_1.WPQ2skilabod.value.length;

    if (tmp <= 100) {
        document.forms.gsm_1.WPQ2telja.value = 100 - tmp;
    }
    else {
        document.forms.gsm_1.WPQ2telja.value = "0!";
        document.forms.gsm_1.WPQ2skilabod.value = document.forms.gsm_1.WPQ2skilabod.value.substring(0, 100);
    }
}


function SendaSkeyti() {
    var smstext = document.gsm_1.WPQ2skilabod.value;
    var sendto = document.gsm_1.WPQ2simi.value;
    if (sendto.length != 7) {
        alert("Sķmanśmer veršur aš vera 7 stafir.");
    }
    else {
        frames["sms_send"].location.href = "http://net.visir.is/sms/send.ashx?receiver=" + document.gsm_1.WPQ2simi.value + "&smstext=" + escape(smstext);
        document.gsm_1.WPQ2skilabod.value = "Skilabošin voru send";
        document.gsm_1.WPQ2simi.value = "";
    }
}

function CheckForEnter(myfield, e) {
    var keycode;
    var stringid = myfield.id;

    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;
    if (keycode == 13) {
        if (stringid == 'search') {
            Search('frmSearch', 'search', 'radioval', 'currip', 'referrer');
        }
        if (stringid == 'searchstring') {
            stringLengthCheck(myfield)
        }
        if (stringid == 'crit') {
            stringLengthCheck(myfield)
        }
        if (stringid == 'vm_crit') {
            stringLengthCheck(myfield)
        }

        return false;
    }
    else
        return true;
}


function stringLengthCheck(myfield) {

    if (myfield.value.length > 0) {
        if (myfield.id == 'searchstring')
        { document.__LeitForm.submit(); }
        if (myfield.id == 'crit')
        { document.LeitarForm.submit(); }
        if (myfield.id == 'vm_crit')
        { doSearch(); ; }
    }
    else {
        alert('Žś veršur aš slį inn leitarorš!');
        myfield.style.background = "yellow";
        myfield.focus();
        return false;
    }

}

var cur_lyr; // holds id of currently visible layer
function swapLayers(id) {
    if (cur_lyr) hideLayer(cur_lyr);
    showLayer(id);
    cur_lyr = id;
}

function showLayer(id) {
    var lyr = getElemRefs(id);
    if (lyr && lyr.css) lyr.css.visibility = "visible";
}


function hideLayer(id) {
    var lyr = getElemRefs(id);
    if (lyr && lyr.css) lyr.css.visibility = "hidden";
}

function toggleLayer_vis(id) {
    var lyr = getElemRefs(id);
    if (lyr && lyr.css) {
        if (lyr.css.visibility == "visible") { lyr.css.visibility = "hidden"; }
        else { lyr.css.visibility = "visible"; }
    }
}

function showItem(id) {
    var lyr = getElemRefs(id);
    var browserName = navigator.appName;
    if (browserName == "Microsoft Internet Explorer") {
        //alert("IE");
        if (lyr && lyr.css)
            if (lyr.css.display == "none")
                lyr.css.display = "block";
            else
                lyr.css.display = "none";
    }
    else {
        //alert("Annaš");
        if (lyr.css.display == "none")
            lyr.css.display = "block";
        else
            lyr.css.display = "none";
    }
}


function getElementsByClassName(oElm, strTagName, strClassName) {
    var arrElements = (strTagName == "*" && oElm.all) ? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/-/g, "\-");
    var oRegExp = new RegExp("(^|\s)" + strClassName + "(\s|$)");
    var oElement;
    for (var i = 0; i < arrElements.length; i++) {
        oElement = arrElements[i];
        if (oRegExp.test(oElement.className)) {
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}

function hideclass(classname) {
    arr = getElementsByClassName(document, "div", classname);
    for (i = 0; i < arr.length; i++)
        arr[i].style.display = 'none';
}

function toggleLayer_display(id, model) {
    if (model == null) { model = "block"; }
    var lyr = getElemRefs(id);
    if (lyr && lyr.css) {
        if (lyr.css.display == model) { lyr.css.display = "none"; }
        else { lyr.css.display = model; }
    }
}

function toggleLayer_display_link(id) {
    var model = "block";
    var lyr = getElemRefs(id);
    if (lyr && lyr.css) {
        if (lyr.css.display == model)
        { lyr.css.display = "none"; document.getElementById('link_' + id).src = '/images/visir_core/plus.gif' }
        else { lyr.css.display = model; document.getElementById('link_' + id).src = '/images/visir_core/minus.gif' }
    }
}


function getElemRefs(id) {
    var el = (document.getElementById) ? document.getElementById(id) : (document.all) ? document.all[id] : (document.layers) ? document.layers[id] : null;
    if (el) el.css = (el.style) ? el.style : el;
    return el;
}

function doKalender(form_name, dest) {
    window.open('/misc/kalender_isl.html?' + form_name + '.' + dest.name, '', 'menubar=0,titlebar=0,width=260,height=236');
}

function PopupPic(sPicURL) {
    newwindow = window.open("/misc/article_picture.html?" + sPicURL, "wndImgPopup", "resizable=1,height=200,width=200");
    if (window.focus) { newwindow.focus() }

}


/**************************************
» Autor: Jonas Raoni Soares Silva
» Site: http://www.joninhas.ath.cx:666
**************************************/

FormatMoneyCustom = function (n, c, d, t) {
    var m = (c = Math.abs(c) + 1 ? c : 2, d = d || ",", t = t || ".", /(\d+)(?:(\.\d+)|)/.exec(n + "")), x = m[1].length > 3 ? m[1].length % 3 : 0;
    return (x ? m[1].substr(0, x) + t : "") + m[1].substr(x).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + (+m[2] || 0).toFixed(c).substr(2) : "");
};

function ToggleTables(onTable, offTables) {
    document.getElementById(onTable).style.display = '';

    var tableArray = offTables.split(":");
    for (var i = 0; i < tableArray.length; i++) {
        document.getElementById(tableArray[i]).style.display = 'none';
    }
}
function ToggleHrefStyles(tabListId, selectedTabId) {
    var aElements = document.getElementById(tabListId).getElementsByTagName('a');
    for (var i = 0; i < aElements.length; i++) {
        if (aElements[i].className.indexOf('tabFirst') > -1) { aElements[i].className = 'tabFirst'; }
        else { aElements[i].className = 'tab'; }
    }
    var aElement = document.getElementById(selectedTabId)
    aElement.className = aElement.className + ' aSelected';
}

function ToggleHrefStyles2(tabListId, selectedTabId) {
    var aElements = document.getElementById(tabListId).getElementsByTagName('li');
    for (var i = 0; i < aElements.length; i++) {
        if (aElements[i].className.indexOf('current') > -1) { aElements[i].className = aElements[i].className.replace(/current/, ''); }
        //else                                                { aElements[i].className='tab'; }
    }
    var aElement = document.getElementById(selectedTabId)
    aElement.className = aElement.className + ' current';
}

//Currency functions
function Gengi(var1, var2) {
    this.Audkenni = var1;
    this.Gengi = var2;
    return this;
}

function CalculateConvert(var1, var2) {
    var gengiValue;
    for (i = 0; i < gengiArray.length; i++) {
        if (gengiArray[i].Audkenni == var2) {
            gengiValue = gengiArray[i].Gengi;
        }
    }
    var1 = ISNumberFormat.stringToNumber(var1);

    for (i = 0; i < gengiArray.length; i++) {
        if (gengiArray[i].Audkenni != var2) {
            var gengiElement = document.getElementById("c" + gengiArray[i].Audkenni + "item");

            if (gengiElement != null) {
                var fixValue = parseFloat(gengiValue) / parseFloat(gengiArray[i].Gengi) * parseFloat(var1);
                if (isNaN(fixValue)) {
                    gengiElement.value = '';
                }
                else {
                    gengiElement.value = FormatMoneyCustom(fixValue);
                }
            }
        }
        if (i > 35) {
            alert('Error: Currency index overloaded. (' + i + ')');
            break;
        }
    }
}

//*********************
// IsNumber Function
//*********************

// Empty constructor all methods are static
function ISNumberFormat() {

}

// Takes a string in the Icelandic numberformat(123.456.789,1234567)
//  and transforms it to the JavaScript Number datatype
ISNumberFormat.stringToNumber = function (str) {
    if (str == null) {
        return null;
    }
    if ((typeof str != "string" && str.constructor != String) || str.length == 0) {
        return null;
    }

    // Searching for alphanumeric character and return null if we find one
    var regex = /[a-z]/;
    if (str.search(regex) != -1) {
        return null;
    }

    // Searching for the comma sign(,) if there are more then one comma sign return null
    var commaIndexCount = 0;
    var searchIndex = 0;
    commaIndex = 0;

    if (searchIndex = str.indexOf(",") != -1) {
        while ((searchIndex = str.indexOf(",", searchIndex + 1)) != -1) {
            commaIndex = searchIndex;
            commaIndexCount++;
            if (commaIndexCount > 1) {
                return null;
            }
        }
    }
    else {
        commaIndex = str.length;
    }


    //Exploding the string to numbers
    var regex = /\d{1,}/g;
    var numberArray = str.match(regex);

    // Searching for dot sign(.)
    var dotIndex;
    var firstDotIndex = dotIndex = searchIndex = str.indexOf(".", searchIndex + 1);
    var resultNumber = 0;
    //with dots
    if (dotIndex != -1) {
        // If the first part of the string has more than 3 places return null
        // If there is a dot on the right side of the return null
        // If there is not constistentcy between the dots and the comma return null
        if (firstDotIndex > 3 || firstDotIndex > commaIndex || ((firstDotIndex - commaIndex) % 4) != 0) {
            return null;
        }
        // Searching for all dots and checking the following conditions
        // If dots are not 3 places apart return null
        // If there is a dot on the right side of the return null
        // If there is not constistentcy between the dots and the comma return null
        while ((searchIndex = str.indexOf(".", searchIndex + 1)) != -1) {
            if (searchIndex - dotIndex != 4 || commaIndex < searchIndex || ((searchIndex - commaIndex) % 4) != 0) {
                return null;
            }
            dotIndex = searchIndex;
        }
        //concat all the number parts
        var power = ((commaIndex - firstDotIndex) / 4) * 3;
        if (commaIndex == str.length) {
            for (var i = 0; i < numberArray.length; i++) {
                resultNumber += numberArray[i] * Math.pow(10, power);
                power -= 3;
            }
        }
        else {
            var i;
            for (i = 0; i < numberArray.length; i++) {
                if (power < 0) {
                    break;
                }
                resultNumber += numberArray[i] * Math.pow(10, power);
                power -= 3;
            }
            power = -(str.length - commaIndex - 1);
            var m = numberArray[i] * Math.pow(10, power);
            resultNumber += numberArray[i] * Math.pow(10, power);
        }

        return resultNumber;
    }
    // without dots
    else {
        if (numberArray.length == 1) {
            resultNumber = Number(str);
            return resultNumber;
        }
        else {
            resultNumber = Number(numberArray[0] + "." + numberArray[1]);
            return resultNumber;
        }
    }

}

// In parameter "num" must be either datatype "number" or of "Number"-object type
//   otherwise the function returns null.
// In parameter "places" decides how many places to round of the number
//   if not defined the function returns null.
// The function returns a "String"-object with the number formated in the Icelandic numberformat.

ISNumberFormat.numberToString = function (num, places) {
    //Type checking
    if (num == null || places == null || typeof num != "number" && num.constructor != Number) {
        return null;
    }
    if (num < Math.pow(10, -places)) {
        var postFix = "";
        for (var i = 0; i < places; i++) {
            postFix += "0";
        }
        return "0," + postFix;
    }
    // round of the number
    var tmpStr = new String(ISNumberFormat.rounding(num, places));
    var dotIndex = tmpStr.search(/\./);
    // check if it is an integer
    if (dotIndex != -1) {
        //sliceing the number in half where the dot
        preFix = tmpStr.slice(0, dotIndex);
        postFix = tmpStr.slice(dotIndex + 1);

        var resultArray = new Array();
        //finding the place where the first dot should be
        var firstDot = preFix.length % 3;
        if (firstDot == 0) {
            firstDot = 3;
        }
        // getting the first part of the number
        resultArray[0] = preFix.slice(0, firstDot);
        var index = 1;
        // getting the rest of the number in triplets
        for (var i = firstDot; i < preFix.length; i += 3) {
            resultArray[index] = preFix.slice(i, i + 3);
            index++;
        }
        //building the resultstring
        var resultString = "";
        for (i = 0; i < index - 1; i++) {
            resultString = resultString + resultArray[i] + ".";
        }
        /*
        if(postFix.length>places){
        var postFixNum = new Number("0."+postFix);
        postFix=new String(ISNumberFormat.rounding(postFixNum,places));
        dotIndex=postFix.search(/\./);
        postFix=postFix.slice(dotIndex+1);
        }
        */
        resultString = resultString + resultArray[index - 1] + "," + postFix;
        return resultString;
    }
    //the number is an integer
    else {
        var resultArray = new Array();
        //finding the place where the first dot should be
        var firstDot = tmpStr.length % 3;
        if (firstDot == 0) {
            firstDot = 3;
        }
        // getting the first part of the number
        resultArray[0] = tmpStr.slice(0, firstDot);
        var index = 1;
        for (var i = firstDot; i < tmpStr.length; i += 3) {
            resultArray[index] = tmpStr.slice(i, i + 3);
            index++;
        }
        //building the resultstring
        var resultString = "";
        for (i = 0; i < index - 1; i++) {
            resultString = resultString + resultArray[i] + ".";
        }
        resultString = resultString + resultArray[index - 1] //+","+"00";
        return resultString;
    }

}

// in parameter "num" must be either datatype "number" or of "Number"-object type
//   otherwise the function returns null
// in parameter "places" decides how many places to round of the number
// The function returns a rounded of "Number"
ISNumberFormat.rounding = function (num, places) {

    if (num == null || places == null) {
        return null;
    }
    if (typeof num != "number" && num.constructor != Number) {
        return null;
    }
    if (num < Math.pow(10, -places)) {
        return 0.0
    }
    var tmpNum = num * Math.pow(10, places);
    tmpNum = Math.round(tmpNum);
    tmpNum = tmpNum / Math.pow(10, places);
    return tmpNum;
}

ISNumberFormat.numberToPercent = function (num) {

    if (num == null) {
        return null;
    }
    if (typeof num != "number" && num.constructor != Number) {
        return null;
    }

    var tmpNum = num * Math.pow(10, 2);

    return ISNumberFormat.numberToString(tmpNum, 2);
}

ISNumberFormat.percentToNumber = function (str) {

    if (str == null) {
        return null;
    }
    if ((typeof str != "string" && str.constructor != String) || str.length == 0) {
        return null;
    }

    var tmpNum = ISNumberFormat.stringToNumber(str);
    if (tmpNum == null) {
        return null;
    }
    var tmpNum = tmpNum / Math.pow(10, 2);
    return tmpNum;
}

ISNumberFormat.stringToInt = function (num) {

    if (num == null) {
        return null;
    }
    if (typeof num != "string" && num.constructor != String) {
        return null;
    }
    // Searching for alphanumeric character and return null if we find one
    var regex = /[a-z]/;
    if (num.search(regex) != -1) {
        return null;
    }
    var tmpStr = new String(num);
    var dotIndex = tmpStr.search(/\./);
    if (dotIndex == -1) {
        return Number(num);
    }
    else {
        return null;
    }

}


function Set_Cookie(name, value, expires, path, domain, secure) {
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime(today.getTime());

    /*
    if the expires variable is set, make the correct 
    expires time, the current script below will set 
    it for x number of days, to make it for hours, 
    delete * 24, for minutes, delete * 60 * 24
    */
    if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date(today.getTime() + (expires));

    document.cookie = name + "=" + escape(value) +
	((expires) ? ";expires=" + expires_date.toGMTString() : "") +
	((path) ? ";path=" + path : "") +
	((domain) ? ";domain=" + domain : "") +
	((secure) ? ";secure" : "");
}


function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}




// Browser and platform Detection
var agt = navigator.userAgent.toLowerCase();
var platform = navigator.platform.toLowerCase();

var is_ie = (agt.indexOf("msie") != -1);
var is_ff = ((agt.indexOf("firefox") != -1) && (platform.indexOf("mac") == -1));


function createMediaPlayerArticle(containerID, urlToPlay, autostart) {
    var playerInput = "";

    if (is_ie) {

        // create the WMP for IE

        playerInput = "<object id=\"VefTVPlayer\" name=\"Player\" width=\"260\" height=\"190\" classid=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902\" standby=\"Windows Media Player\" type=\"application/x-oleobject\" data=\"" + urlToPlay + "\">";

    } else {

        // create it for FF.

        playerInput = "<object  id=\"VefTVPlayer\" name=\"Player\" width=\"260\" height=\"190\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902\" standby=\"Windows Media Player\" type=\"application/x-ms-wmp\" data=\"" + urlToPlay + "\">";

    }
    playerInput = playerInput + "<param name=\"url\" value=\"" + urlToPlay + "\" />";
    playerInput = playerInput + "<param name=\"FileName\" value=\"" + urlToPlay + "\" />";
    playerInput = playerInput + "<param name=\"src\" value=\"" + urlToPlay + "\" />";
    playerInput = playerInput + "<param name=\"stretchToFit\" value=\"true\" />";
    playerInput = playerInput + "<param name=\"AutoSize\" value=\"false\" />";
    ;
    if (is_ff) {
        playerInput = playerInput + "<param name=\"uiMode\" value=\"none\">";
    }
    if (is_ie) {
        playerInput = playerInput + "<param name=\"uiMode\" value=\"none\">";
    }
    playerInput = playerInput + "<param name=\"autoStart\" value=\"";

    if (autostart == '1') {
        playerInput = playerInput + "true";
    }
    else {
        playerInput = playerInput + "false";
    }
    playerInput = playerInput + "\" />";
    playerInput = playerInput + "<param name=\"showControls\" value=\"1\" />";
    playerInput = playerInput + "<param name=\"showPositionControls\" value=\"0\" />";
    playerInput = playerInput + "<param name=\"showTracker\" value=\"0\" />";
    //playerInput = playerInput + "<embed type=\"application/x-mplayer2\" pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/\" src=\"" + urlToPlay + "\" name=\"VefTVPlayer\" width=\"260\" height=\"190\" autostart=\"" + autostart + "\" showtracker=\"0\" showpositioncontrols=\"0\" transparentatstart=\"1\" autosize=\"0\" ></embed>";
    playerInput = playerInput + "</object>";


    document.getElementById(containerID).innerHTML = playerInput;

    if (is_ff || is_ie) {
        if (is_ie || document.getElementById('VefTVPlayer').versionInfo) {
            image0 = new Image();
            image0.src = "/images/visir_core/icon/player/volume_0.gif";
            image1 = new Image();
            image1.src = "/images/visir_core/icon/player/volume_1.gif";
            image2 = new Image();
            image2.src = "/images/visir_core/icon/player/volume_2.gif";
            image3 = new Image();
            image3.src = "/images/visir_core/icon/player/volume_3.gif";
            image4 = new Image();
            image4.src = "/images/visir_core/icon/player/volume_4.gif";
            image5 = new Image();
            image5.src = "/images/visir_core/icon/player/volume_5.gif";
            image6 = new Image();
            image6.src = "/images/visir_core/icon/player/volume_6.gif";
            image7 = new Image();
            image7.src = "/images/visir_core/icon/player/volume_7.gif";
            image8 = new Image();
            image8.src = "/images/visir_core/icon/player/volume_8.gif";
            image9 = new Image();
            image9.src = "/images/visir_core/icon/player/volume_9.gif";
            image10 = new Image();
            image10.src = "/images/visir_core/icon/player/volume_10.gif";

            var controlInput = "<input type=\"image\" src=\"/images/visir_core/icon/player/player_stoppa.gif\" onclick=\"stopVideo()\" />";
            document.getElementById('VefTVPlayerControl').innerHTML = controlInput;

            var volumeInput = "<input type=\"image\" src=\"/images/visir_core/icon/player/player_mute.gif\" onclick=\"toggleMute()\" />";
            volumeInput = volumeInput + "<input type=\"image\" src=\"/images/visir_core/icon/player/player_laekka.gif\" onclick=\"setVolume('d')\" />";
            volumeInput = volumeInput + "<span id=\"VolumeLevel\"><img src=\"/images/visir_core/icon/player/volume_5.gif\"></span>";
            volumeInput = volumeInput + "<input type=\"image\" src=\"/images/visir_core/icon/player/player_haekka.gif\" onclick=\"setVolume('u')\" />";
            document.getElementById('VolumeControl').innerHTML = volumeInput;
        }
        else {
            document.getElementById('VefTVPlayerControl').innerHTML = "Til aš myndbandiš virki best žarf aš hlaša inn <br />nżjasta WMP fyrir Firefox - <a href=\"http://port25.technet.com/pages/windows-media-player-firefox-plugin-download.aspx\" target=\"_new\">Sękja WMP.</a>";
        }
    }
    else {
        document.getElementById('VefTVPlayerControl').innerHTML = "";
    }

}
function playVideoOLD() {

    var wmp = document.getElementById('VefTVPlayer');
    wmp.controls.play();

    var controlInput = "<input type=image src=\"/images/visir_core/icon/player/player_stoppa.gif\" onclick=\"stopVideo()\" />";
    document.getElementById('VefTVPlayerControl').innerHTML = controlInput;
}
function stopVideo() {

    var wmp = document.getElementById('VefTVPlayer');
    var controlInput = "<input type=image src=\"/images/visir_core/icon/player/player_spila.gif\" onclick=\"playVideo()\" />";

    controlInput = controlInput
    document.getElementById('VefTVPlayerControl').innerHTML = controlInput;

    wmp.controls.stop();


}

function toggleMute() {

    var wmp = document.getElementById('VefTVPlayer');

    if (wmp.settings.mute) {
        wmp.settings.mute = false;
        document.getElementById('VolumeLevel').innerHTML = "<img src=\"/images/visir_core/icon/player/volume_" + (wmp.settings.volume / 10) + ".gif\">";
    } else {
        wmp.settings.mute = true;
        document.getElementById('VolumeLevel').innerHTML = "<img src=\"/images/visir_core/icon/player/volume_0.gif\">";
    }



}

function setVolume(dir) {

    var wmp = document.getElementById('VefTVPlayer');

    wmp.settings.mute = false;

    switch (dir) {
        case "u":
            if (wmp.settings.volume < 100) {
                wmp.settings.volume += 10;
            }
            break;
        case "d":
            if (wmp.settings.volume > 0) {
                wmp.settings.volume -= 10;
            }
            break;
    }

    document.getElementById('VolumeLevel').innerHTML = "<img src=\"/images/visir_core/icon/player/volume_" + (wmp.settings.volume / 10) + ".gif\">";

}

function createMediaPlayer(containerID, urlToPlay, autostart) {
    var playerInput = "<object id=\"VefTVPlayer\" name=\"Player\" width=\"260\" height=\"190\" classid=\"CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902\" standby=\"Windows Media Player\" type=\"application/x-oleobject\">";
    playerInput = playerInput + "<param name=\"FileName\" value=\"" + urlToPlay + "\" />";
    playerInput = playerInput + "<param name=\"animationatStart\" value=\"false\" />";
    playerInput = playerInput + "<param name=\"AutoSize\" value=\"false\" />";
    playerInput = playerInput + "<param name=\"transparentatStart\" value=\"true\" />";
    playerInput = playerInput + "<param name=\"autoStart\" value=\"";
    if (autostart == '1') {
        playerInput = playerInput + "true";
    }
    else {
        playerInput = playerInput + "false";
    }
    playerInput = playerInput + "\" />";
    playerInput = playerInput + "<param name=\"showControls\" value=\"true\" />";
    playerInput = playerInput + "<param name=\"showPositionControls\" value=\"false\" />";
    playerInput = playerInput + "<param name=\"showTracker\" value=\"false\" />";
    playerInput = playerInput + "<embed type=\"application/x-mplayer2\" pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/\" src=\"" + urlToPlay + "\" name=\"VefTVPlayer\" width=\"260\" height=\"190\" autostart=\"" + autostart + "\" showtracker=\"0\" showpositioncontrols=\"0\" transparentatstart=\"1\" autosize=\"0\" ></embed>";
    playerInput = playerInput + "</object>";

    document.getElementById(containerID).innerHTML = playerInput;
}

function pausecomp(millis) {
    var date = new Date();
    var curDate = null;

    do { curDate = new Date(); }
    while (curDate - date < millis);
    alert('x');
}


function createMediaPlayerBig(containerID, urlToPlay, autostart) {

    var playerDiv = document.getElementById("mediaboxid");
    playerDiv.className += " player-active";
    if (is_ie) {
        // create the WMP for IE
        playerInput = "<object id=\"VefTVPlayer\" name=\"Player\" width=\"520\" height=\"320\" classid=\"CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902\" standby=\"Windows Media Player\" type=\"application/x-oleobject\">";
    } else {
        if (agt.indexOf("safari") != -1) {
            // create for Safari
            document.title = "zoxic";
            alert('Žvķ mišur getum viš enn sem komiš er bara spilaš fréttatķmann frį byrjun ķ Apple Quicktime.');
            playerInput = "<object  id=\"VefTVPlayer\" name=\"Player\" width=\"521\" height=\"380\" classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\" standby=\"Windows Media Player\" type=\"application/x-ms-wmp\" data=\"" + urlToPlay + "\">";
        }
        else {
            // create it for FF.
            playerInput = "<object  id=\"VefTVPlayer\" name=\"Player\" width=\"521\" height=\"360\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902\" standby=\"Windows Media Player\" type=\"application/x-ms-wmp\" data=\"" + urlToPlay + "\">";
            playerInput = playerInput + "<a></a>";
        }
    }
    playerInput = playerInput + "<param name=\"FileName\" value=\"" + urlToPlay + "\" />";
    playerInput = playerInput + "<param name=\"animationatStart\" value=\"false\" />";
    playerInput = playerInput + "<param name=\"AutoSize\" value=\"false\" />";
    playerInput = playerInput + "<param name=\"stretchToFit\" value=\"true\">";
    playerInput = playerInput + "<param name=\"transparentatStart\" value=\"true\" />";
    playerInput = playerInput + "<param name=\"autoStart\" value=\"";
    if (autostart == '1') {
        playerInput = playerInput + "true";
    }
    else {
        playerInput = playerInput + "false";
    }
    playerInput = playerInput + "\" />";
    playerInput = playerInput + "<param name=\"showControls\" value=\"true\" />";
    playerInput = playerInput + "<param name=\"showPositionControls\" value=\"false\" />";
    playerInput = playerInput + "<param name=\"showTracker\" value=\"false\" />";
    playerInput = playerInput + "<embed type=\"application/x-mplayer2\" pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/\" src=\"" + urlToPlay + "\" name=\"VefTVPlayer\" width=\"520\" height=\"360\" autostart=\"" + autostart + "\" showtracker=\"0\" showpositioncontrols=\"0\" transparentatstart=\"1\" autosize=\"1\"  stretchToFit=\"true\" ></embed>";

    playerInput = playerInput + "</object>";

    document.getElementById(containerID).innerHTML = playerInput;
}


function createMediaPlayerComplete(containerID, urlToPlay) {
    var playerInput = '<object id="Player" name="Player" width="335" height="297" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902" standby="Windows Media Player" type="application/x-oleobject">';
    playerInput = playerInput + '<param name="FileName" value="' + urlToPlay + '" />';
    playerInput = playerInput + '<param name="animationatStart" value="false" />';
    playerInput = playerInput + '<param name="AutoSize" value="false" />';
    playerInput = playerInput + '<param name="transparentatStart" value="true" />';
    playerInput = playerInput + '<param name="autoStart" value="true" />';
    playerInput = playerInput + '<param name="showControls" value="true" />';
    playerInput = playerInput + '<param name="showPositionControls" value="true" />';
    playerInput = playerInput + '<param name="showTracker" value="true" />';
    playerInput = playerInput + '<param name="showStatusBar" value="true" />';
    playerInput = playerInput + '<param name="AllowChangeDisplaySize" value="true" />';
    playerInput = playerInput + '<param name="DisplaySize" value="false" />';
    playerInput = playerInput + '<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" src="' + urlToPlay + '" name="Player" id="Player" width="335" height="335" autostart="1" showtracker="1" showpositioncontrols="1" showstatusbar="1" transparentatstart="1" autosize="0" allowchangedisplaysize="1" displaysize="0" SendErrorEvents="1"></embed>';
    playerInput = playerInput + '</object>';

    document.getElementById(containerID).innerHTML = playerInput;
}


function mail_loginform() {
    toggleLayer_display('login_form_container', 'block');
    document.getElementById('login_form').target.value = "webmail";
}



function createDragableLayer(layerContent, leftPos, topPos, layerWidth, layerHeight, layerBG) {
    if (document.layers) {
        document.write('<layer left="' + leftPos + '" top="' + topPos + '" width="' + layerWidth + '" ' + (layerHeight ? ('height="' + layerHeight + '" ') : '') + (layerBG ? ('bgcolor="' + layerBG + '" ') : '') + 'onmouseover="this.captureEvents(Event.MOUSEDOWN);this.onmousedown=dragIsDown;">' + layerContent + '</layer>');
    } else {
        document.write('<div style="position:absolute;left:' + leftPos + 'px;top:' + topPos + 'px;width:' + layerWidth + 'px;' + (layerHeight ? ('height:' + layerHeight + 'px;') : '') + (layerBG ? ('background-color:' + layerBG + ';') : '') + '" onmouseover="this.onmousedown=dragIsDown;" ondragstart="return false;" onselectstart="return false;">' + layerContent + '</div>');
    }
}

function dragMousePos(e) {
    //get the position of the mouse
    if (!e) { e = window.event; } if (!e || (typeof (e.pageX) != 'number' && typeof (e.clientX) != 'number')) { return [0, 0]; }
    if (typeof (e.pageX) == 'number') { var xcoord = e.pageX; var ycoord = e.pageY; } else {
        var xcoord = e.clientX; var ycoord = e.clientY;
        if (!((window.navigator.userAgent.indexOf('Opera') + 1) || (window.ScriptEngine && ScriptEngine().indexOf('InScript') + 1) || window.navigator.vendor == 'KDE')) {
            if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft)) {
                xcoord += document.documentElement.scrollLeft; ycoord += document.documentElement.scrollTop;
            } else if (document.body && (document.body.scrollTop || document.body.scrollLeft)) {
                xcoord += document.body.scrollLeft; ycoord += document.body.scrollTop;
            } 
        } 
    }
    return [xcoord, ycoord];
}

function dragIsDown(e) {
    //make note of starting positions and detect mouse movements
    if ((e && (e.which > 1 || e.button > 1)) || (window.event && (window.event.which > 1 || window.event.button > 1))) { return false; }
    if (document.onmouseup == dragIsMove) { document.onmousemove = storeMOUSEMOVE; document.onmouseup = window.storeMOUSEUP; } //mouseup was over chrome
    window.msStartCoord = dragMousePos(e); window.lyStartCoord = this.style ? [parseInt(this.style.left), parseInt(this.style.top)] : [parseInt(this.left), parseInt(this.top)];
    if (document.captureEvents && Event.MOUSEMOVE) { document.captureEvents(Event.MOUSEMOVE); document.captureEvents(Event.MOUSEUP); }
    window.storeMOUSEMOVE = document.onmousemove; window.storeMOUSEUP = document.onmouseup; window.storeLayer = this;
    document.onmousemove = dragIsMove; document.onmouseup = dragIsMove; return false;
}

function dragIsMove(e) {
    //move the layer to its newest position
    var msMvCo = dragMousePos(e); if (!e) { e = window.event ? window.event : (new Object()); }
    var newX = window.lyStartCoord[0] + (msMvCo[0] - window.msStartCoord[0]);
    var newY = window.lyStartCoord[1] + (msMvCo[1] - window.msStartCoord[1]);
    //reset the mouse monitoring as before - delay needed by Gecko to stop jerky response (hence two functions instead of one)
    //as long as the Gecko user does not release one layer then click on another within 1ms (!) this will cause no problems
    if (e.type && e.type.toLowerCase() == 'mouseup') { document.onmousemove = storeMOUSEMOVE; document.onmouseup = window.storeMOUSEUP; }
    if (navigator.product == 'Gecko') { window.setTimeout('dragIsMove2(' + newX + ',' + newY + ');', 1); } else { dragIsMove2(newX, newY); }
}

function dragIsMove2(x, y) { var oPix = (document.childNodes ? 'px' : 0), theLayer = (window.storeLayer.style ? window.storeLayer.style : window.storeLayer); theLayer.left = x + oPix; theLayer.top = y + oPix; }

/**************************************************
* dom-drag.js
* 09.25.2001
* www.youngpup.net
**************************************************
* 10.28.2001 - fixed minor bug where events
* sometimes fired off the handle, not the root.
**************************************************/

var Drag = {

    obj: null,

    init: function (o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper) {
        o.onmousedown = Drag.start;

        o.hmode = bSwapHorzRef ? false : true;
        o.vmode = bSwapVertRef ? false : true;

        o.root = oRoot && oRoot != null ? oRoot : o;

        if (o.hmode && isNaN(parseInt(o.root.style.left))) o.root.style.left = "0px";
        if (o.vmode && isNaN(parseInt(o.root.style.top))) o.root.style.top = "0px";
        if (!o.hmode && isNaN(parseInt(o.root.style.right))) o.root.style.right = "0px";
        if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

        o.minX = typeof minX != 'undefined' ? minX : null;
        o.minY = typeof minY != 'undefined' ? minY : null;
        o.maxX = typeof maxX != 'undefined' ? maxX : null;
        o.maxY = typeof maxY != 'undefined' ? maxY : null;

        o.xMapper = fXMapper ? fXMapper : null;
        o.yMapper = fYMapper ? fYMapper : null;

        o.root.onDragStart = new Function();
        o.root.onDragEnd = new Function();
        o.root.onDrag = new Function();
    },

    start: function (e) {
        var o = Drag.obj = this;
        e = Drag.fixE(e);
        var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);
        var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right);
        o.root.onDragStart(x, y);

        o.lastMouseX = e.clientX;
        o.lastMouseY = e.clientY;

        if (o.hmode) {
            if (o.minX != null) o.minMouseX = e.clientX - x + o.minX;
            if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX - o.minX;
        } else {
            if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
            if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
        }

        if (o.vmode) {
            if (o.minY != null) o.minMouseY = e.clientY - y + o.minY;
            if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY;
        } else {
            if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
            if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
        }

        document.onmousemove = Drag.drag;
        document.onmouseup = Drag.end;

        return false;
    },

    drag: function (e) {
        e = Drag.fixE(e);
        var o = Drag.obj;

        var ey = e.clientY;
        var ex = e.clientX;
        var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);
        var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right);
        var nx, ny;

        if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
        if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
        if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
        if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

        nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
        ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

        if (o.xMapper) nx = o.xMapper(y)
        else if (o.yMapper) ny = o.yMapper(x)

        Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
        Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
        Drag.obj.lastMouseX = ex;
        Drag.obj.lastMouseY = ey;

        Drag.obj.root.onDrag(nx, ny);
        return false;
    },

    end: function () {
        document.onmousemove = null;
        document.onmouseup = null;
        Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]),
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
        Drag.obj = null;
    },

    fixE: function (e) {
        if (typeof e == 'undefined') e = window.event;
        if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
        if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
        return e;
    }
};

/*****************
Checks input for events
******************/

function event_checkform(f) {
    //msgele = document.getElementById("form_message");
    msgele = "";
    if (f.form.FromDate.value == "")
        msgele += "\n\"Frį degi\" mį ekki vera tómt.";

    t = document.getElementById("tegund_vidburdar");
    if (t.options[t.selectedIndex].value == 0)
        msgele += "\nVeldu \"Tegund višburšar\".";

    if (f.form.Title.value == "")
        msgele += "\nŽaš vantar fyrirsögn.";
    if (f.form.Tekst.value == "")
        msgele += "\nŽaš vantar lżsingu.";
    if (f.form.Location.value == "")
        msgele += "\nŽaš vantar stašsetningu.";
    if (f.form.Streetaddress.value == "")
        msgele += "\nŽaš vantar heimilisfang.";

    t = document.getElementById("Mailingaddress");
    if (t.options[t.selectedIndex].value == 0)
        msgele += "\nŽaš vantar póstfang.";
    if (f.form.Tlf.value == "")
        msgele += "\nŽaš vantar sķmanśmer.";

    if (msgele.length > 0) {
        msgele = "Athugašu eftirfarandi og reyndu aftur:\n" + msgele;
        alert(msgele);
    } else { f.form.submit(); }

}

function popUp(URL) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=280,height=280');");
}

function popUpDynamic(URL, width, height, resize, scroll) {
    if (!resize) { resize = "yes"; }
    if (!scroll) { scroll = "yes"; }
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=" + scroll + ",location=0,statusbar=0,menubar=0,resizable=" + resize + ",width=" + width + ",height=" + height + "');");
}

function CheckForAd(elementid) {
    if ($("#" + elementid + " div[id^='beacon_']").length == 0) {
        $("#" + elementid).css("display", "none");
    }
}

/*
function CheckForAd(elementid) {
var z = document.getElementById(elementid);
if (z != null) {
var i = z.getElementsByTagName("img");
if (i.item(0) != null) {
if (i.item(0).src.indexOf("t.gif") > -1) {
z.style.display = 'none';
}
}
}
}
*/

function homepageButton() {
    if ($.browser.msie) {
        $('body').prepend('<span id="hp" style="behavior:url(#default#homepage)"></span>');
        var hp = $('#hp')[0];
        var hpVisir = hp ? (hp.isHomePage('http://www.visir.is/')) : 0;
        if (hpVisir) {

            location = '/section/frontpage&template=heimasida&fp=1';

        }
        else {
            document.body.setHomePage('http://www.visir.is/');
            location = '/section/frontpage&template=heimasida&fp=2';
        }
    }
    else {
        location = '/section/frontpage&template=heimasida&fp=3';
    }
}

function GetraunFormCheck(nsForm) {

    var KtErr = 0;
    var ktStipped = stripChars(nsForm.form.kt.value);

    var chEmail = check_email(nsForm.form.email.value);
    var KtErr = KtCheck(ktStipped);
    var msgele = "";


    if (!chEmail) {
        msgele += "\n\nAthugiš: Žetta viršist ekki vera gilt netfang.";
    }
    if (nsForm.form.pwd.value == "" || nsForm.form.pwd.value != nsForm.form.pwd_confirm.value)
    { msgele += "\n\nAthugiš: Lykilorš og stašfest lykilorš passa ekki saman."; }

    if (ktStipped == "" || KtErr > 0) {
        msgele += "\n\nAthugiš: Žetta viršist ekki vera gild kennitala.\n";
    }

    if (msgele.length > 0) {
        {
            msgele = "Athugašu eftirfarandi og reyndu aftur:\n" + msgele;
            alert(msgele);
        }
    } else {
        nsForm.form.kt.value = ktStipped
        nsForm.form.submit();
    }



}


//Weather station selection with Ajax

function getSpa(cat, stationchoice) {

    if (stationchoice == null || stationchoice == '') {
        // Get the value of a cookie:
        var kaka = $.cookie('wstation');
        if (kaka == null) { kaka = '1' }
    }
    else {
        kaka = stationchoice
    }

    //Create (or update) the value of a cookie to expire in x days:
    $.cookie('wstation', kaka, { expires: 365 });

    // Delete a cookie:
    //$.cookie('wstation', null);

    $(".vedur_dropdown").val(kaka)

    displaySpa(kaka, cat);
}

function displaySpa(wstation, cat) {
    $.ajax({
        url: "/section/" + cat + "&template=vedur_spa&id=" + wstation,
        cache: false,
        success: function (html) {
            $("#spa_cont").html(html);
        }
    });
}
function showPaper() {

    $(function () {
        $(".anyClass").jCarouselLite({
            btnNext: ".next",
            btnPrev: ".prev",
            visible: 2,
            mouseWheel: true
        });
    });

    var sHref = document.getElementById('paper_tab').href;
    var sHref_arr = sHref.split(";");
    sHref = sHref_arr[0] + ";" + sHref_arr[1];
    document.getElementById('paper_tab').href = sHref;

}
function displayAjax(url, target) {
    var target_div = "#results";
    if (target) { target_div = "#" + target; }

    $.ajax({
        url: url,
        cache: false,
        success: function (html) {
            $(target_div).html(html);
        }
    });
}

function postAjax(url, target) {
    var target_div = "#results";
    var formdata = $("#surveyform").serialize();
    if (target) { target_div = "#" + target; }

    $.ajax({
        type: 'POST',
        url: url,
        data: formdata,
        success: function (html) {
            $(target_div).html(html);
        }
    });
}

function openPopResults(id, event) {

    var lyr = getElemRefs(id);

    var y = mouseY(event) - 240;

    lyr.style.top = (y + 'px');

    lyr.css.display = "block";

}

function closePopResults(id) {
    var divid = "#" + id;
    $(divid).appendTo($("#pagebody"))
    var lyr = document.getElementById(id);
    lyr.innerHTML = "";
    lyr.css.display = "none";



}

function mouseY(evt) {
    if (evt.pageY) return evt.pageY;
    else if (evt.clientY)
        return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    else return null;
}

function mouseX(evt) {
    if (evt.pageX) return evt.pageX;
    else if (evt.clientX)
        return evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
    else return null;
}
function printDivOnly(divid) {
    divid = "#" + divid;
    var appString = "<style type='text/css'>@media print {body * {display:none} .thisprint {display:block; position:absolute; top: 0px; left: 0px; overflow:visible; max-width:1040px } }</style>";


    //$("body *").css("display","none");
    $(divid).appendTo($("body"));
    $(appString).appendTo($("head"));
    $(divid).css("top", "0");
    $("#focuspoint").focus();
    window.print()

}


/*
var c = getCookie('visir_upphafx');
if (c == null) {
var dt=new Date();
if( dt.getDate() < 23 && dt.getMonth() == 10 ) {
Set_Cookie('visir_upphafx', 1, 1,"/");
popUp('http://net.visir.is/SetHomeVisir/');
}
}



*/


/**  draggable html 

<script type="text/javascript" language="javascript1.2"><!--
createDragableLayer(
'This layer is dragable', //contents of dragable layer (can contain HTML etc.)
10,                       //left coordinate of dragable layer
100,                      //top coordinate of dragable layer
150,                      //width of dragable layer
30,                       //optional: height of dragable layer (use null for default)
'#ff0000'                 //optional: background colour of dragable layer (use null for default)
);


*/



function displayFlash(url, autostart, target, width, height, server, url_600, url_300, qplugin, adplugins,categoryid,live,ctrlbar,endt,startt,livemsg, backgr, connectionpoint) {
    var logohide = true;
    var clipPlayer = "clipPlayer";
    var swidth = "500";
    var sheight = "375";
    if (target) { clipPlayer = target };
    if (width) { swidth = width };
    if (height) { sheight = height };
    var streamer;
    var skin = "glow3.zip";
    if (server == 1) { streamer = 'rtmp://klippur.visir.is/vod/_definst_/' };
    if (server == 2) { streamer = 'rtmp://utsending.visir.is/live/' };
    if (server == 4) { streamer = 'rtmp://visirfs.fplive.net/visir/' };
    if (server == 5) { streamer = 'rtmp://utsending.visir.is/rtplive/' };
    if (server == 6) { streamer = 'rtmp://' + connectionpoint + '/beint/' };
    if (server == 2 || server == 6) { skin = "glow2.zip" }
    if (server == 3) { skin = "glow.zip" }
    if (!server | server == 0 | server == "") { url = url.replace(/^\//, "http://www.visir.is/"); }
    if (url_600 == '') { url_600 = url };
    if (url_300 == '') { url_300 = url };
    if (live == 'live') { logohide = false; }
    var bimg = '';
    if (!ctrlbar || ctrlbar == '') { ctrlbar = 'bottom' };
    if (backgr == null || backgr == '') {
        if (startt == null || startt == '') {
            bimg = 'none';
        }
        else {
            bimg = '/jwplayer/assets/thumb.png';
        }
    }
    else { bimg = backgr; };
    var playerconfig = {
        autostart: autostart,
        controlbar: ctrlbar,
        skin: "/jwplayer/"+skin,
        flashplayer: "/jwplayer/player58.swf",
        width: swidth,
        height: sheight,
        image: bimg,
        stretching: "exactfit",
        bufferlength: 10,
        levels: [
            { bitrate: 1200, file: url, width: 700 },
            { bitrate: 600, file: url_600, width: 700 },
            { bitrate: 300, file: url_300, width: 320 }
        ],
        provider: "rtmp"
    }
    
    if (adplugins == 1) { playerconfig.plugins = { gapro: { accountid: "UA-1570473-1" }, adtvideo: { config: "http://net.visir.is/adPortal/xml.aspx?catid=" + categoryid + "&type=v"} }; }
    else if (adplugins == 2) { playerconfig.plugins = { gapro: { accountid: "UA-1570473-1" }, "/jwplayer/livestream.js": { end: endt, start: startt, title: livemsg} }; }
    else if (adplugins == 3) { playerconfig.plugins = { gapro: { accountid: "UA-1570473-1" }, adtvideo: { config: "http://net.visir.is/adPortal/xml.aspx?catid=" + categoryid + "&type=v" }, adttext: { config: "http://net.visir.is/adPortal/augl.xml"} }; }
    else if (adplugins == 4) { playerconfig.file = url; playerconfig.plugins = { gapro: { accountid: "UA-1570473-1" }, adtvideo: { config: "http://net.visir.is/adPortal/xml.aspx?catid=" + categoryid + "&type=v"} }; }
    else if (adplugins == 5) { playerconfig.file = url; playerconfig.plugins = { gapro: { accountid: "UA-1570473-1" }, adttext: { config: "http://net.visir.is/adPortal/augl.xml"} }; }
    else if (adplugins == 6) { playerconfig.file = url; playerconfig.plugins = { gapro: { accountid: "UA-1570473-1" }, adtvideo: { config: "http://net.visir.is/adPortal/xml.aspx?catid=" + categoryid + "&type=v" }, adttext: { config: "http://net.visir.is/videoads/xml.aspx?catid=" + categoryid + "&type=t"} }; }
    else if (adplugins == 7) {
    var adtvid = "http://lp.longtailvideo.com/5/adtvideo/adtvideo.swf";
    var adtex = "http://lp.longtailvideo.com/5/adttext/adttext.swf";
    
    playerconfig = {
        autostart: autostart,
        controlbar: ctrlbar,
        skin: "/jwplayer/glow3.zip",
        flashplayer: "/jwplayer/player58.swf",
        width: swidth,
        image: bimg,
        height: sheight,
        stretching: "exactfit",
        bufferlength: 10,
        levels: [
            { bitrate: 1200, file: url, width: 700 },
            { bitrate: 600, file: url_600, width: 700 },
            { bitrate: 300, file: url_300, width: 320 }
        ],
        provider: "rtmp",
        plugins: 'gapro,'+ adtex +','+ adtvid +'',
        'gapro.accountid': 'UA-1570473-1',
        'adttext.config': "http://net.visir.is/videoads/xml.aspx?catid=" + categoryid + "&type=t",
        'adtvideo.config': "http://net.visir.is/videoads/xml.aspx?catid=" + categoryid + "&type=v"
        
    };
        playerconfig.file = url;
        }

    else { playerconfig.plugins = { gapro: { accountid: "UA-1570473-1"} }; }
    if (qplugin == 1) { playerconfig.plugins = 'qualitymonitor-1 ,gapro: { accountid: "UA-1570473-1"}'; }
    if (server == 1 | server == 2 | server == 4 | server == 5 | server == 6) { playerconfig.streamer = streamer; } else if (server == 3) { playerconfig.provider = "youtube"; } else { playerconfig.provider = "http"; }

    jwplayer(clipPlayer).setup(playerconfig)

}



function displayHtml5Mov(url, width, height, target, streamer) {
    var rootUrl;
    //var url2= url.replace(/^\//g, '');
    if (streamer == 1) { rootUrl = 'http://m3.visir.is/' + url }
    if (streamer == 2) { rootUrl = 'http://utsending.visir.is:1935/live/' + url + '/playlist.m3u8' }
    if (streamer == 3) { rootUrl = 'http://194.144.249.130/beint/_definst_/beint1-iphone/playlist.m3u8' }

    if (streamer == 1) {
        source = "<source src=\"http://klippur.visir.is:1935/vod/_definst_/mp4:" + url.replace(/^\//g, '') + "/playlist.m3u8\" type=\"video/mp4; codecs='avc1.58A01E, mp4a.40.2'\"/>"
    } else { source = "<source src=\"" + rootUrl + "\" type=\"video/mp4; codecs='avc1.58A01E, mp4a.40.2'\"/>" }

    //$('#'+ target).html("<video height=\"" + height +  "\" width=\"" + width + "\" controls=\"controls\" src=\"" + rootUrl + "\" id=\"player\" tabindex=\"0\">HTML5 Video-tag not supported?</video>");

    $('#' + target).html(
"<video height=\"" + height + "\" width=\"" + width + "\" controls=\"controls\"  id=\"player\" >" + source + "HTML5 Video-tag not supported?</video>"

)

}

function displayHtml5Mus(url, target, streamer) {
    var rootUrl;

    if (streamer == 1) { rootUrl = 'http://m3.visir.is/' + url }
    if (streamer == 2) { rootUrl = 'http://utsending.visir.is:1935/live/vlc.sdp/playlist.m3u8' }

    $('#' + target).html("<audio src=\"" + rootUrl + "\" controls=\"controls\" style=\"width: 700px;\">Your browser does not support the audio element.</audio>")
}

function toggleTabsJQ(divid, classid, classaction) {
    if (!classaction) { classaction = 'opid' };
    $('.' + classid).removeClass(classaction);
    $('#' + divid).addClass(classaction);
}

/* Beinar utsendingar upp/nidur takkar */
function buMoveDn() {
    var placement = function () {
        var strMarginNow = $('.beinUtsending').css('margin-top').replace('px', '');
        var iMarginNow = parseInt(strMarginNow);
        var height = $('.beinUtsending').height() * -1;
        if (iMarginNow > height + 200)
            return iMarginNow - 41 + 'px';
        else
            return iMarginNow + 'px';
    }
    $('.beinUtsending').animate({ marginTop: placement() }, 200);
}

function buMoveUp() {
    var placement = function () {
        var strMarginNow = $('.beinUtsending').css('margin-top').replace('px', '');
        var iMarginNow = parseInt(strMarginNow)
        var height = $('.beinUtsending').height();
        if (iMarginNow < -40)
            return iMarginNow + 41 + 'px';
        else
            return strMarginNow + 'px';
    }
    $('.beinUtsending').animate({ marginTop: placement() }, 200);
}

function showMainNews(p) {

    /*document.getElementById("forsidufrett1").style.display = "none"
    document.getElementById("forsidufrett2").style.display = "none"
    document.getElementById("forsidufrett3").style.display = "none"
    document.getElementById("forsidufrett4").style.display = "none"*/

    document.getElementById("forsidufrett_show").innerHTML = document.getElementById("forsidufrett" + p).innerHTML

    document.getElementById("frett1").className = "frett"
    document.getElementById("frett2").className = "frett"
    document.getElementById("frett3").className = "frett"
    document.getElementById("frett4").className = "frett"

    document.getElementById("frett" + p).className = "frett valin"
    //document.getElementById("forsidufrett"+p).style.display = "block"

}

function changeTitleTag(newtext, add) {
    if (!add | add == '') { add = 1 }
    if (add == 1) { $('title').append(newtext); }
    if (add == 0) { $('title').html(newtext); }
}



function scroll_popup(img, title, max, top, left, link) {
    if (!max) { max = '300' };
    if (!top) { top = '800' };
    if (!left) { left = '400' };

    $('#scroll_popup').css("display", "block");

    $('#scroll_popup').css("max-width", max + "px");
    $('#scroll_popup').css("top", top + "px");
    $('#scroll_popup').css("left", left + "px");

    $('#scroll_popup_title').html(title);
    $('#scroll_popup_img').attr("src", img + "&MaxH=" + max + "&MaxW=" + max);
    if (link) { $('#scroll_popup_link').html("Nįnar į <a href=http://" + link + " target=\"_blank\"> " + link + "</a>"); }

    //Google Analytics Tracker
    _gaq.push(
      ['_setAccount', 'UA-1570473-1'],
      ['_setDomainName', '.visir.is'],
      ['_setCustomVar', 1, 'Section', 'SKODANIR', 3],
      ['_setCustomVar', 2, 'Sub-Section', 'SKODANIR07', 3],
      ['_trackPageview']
    );
    //Yahoo analytics
    YWATracker.submit();
    //Virkvefmęling
    addVirkCount();


}

function scroll_popup_close() { $('#scroll_popup').css("display", "none"); }

function setHeaderImg() {
    var datenow = new Date();
    var daytoday = datenow.getDate()

    $(".brand").css('background', 'url(/img/hmcountdown/' + daytoday + '.png) no-repeat scroll 0 0 transparent');
}
/* Gardķnu banner */
function displayGardina(gardinaSmall, gardinaBig, cookieName) {
    var smallContainer = '<object width="982" height="30" type="application/x-shockwave-flash" id="visir_gardina1" class="advert" data="/ads/xz/' + gardinaSmall + '"><param name="allowscriptaccess" value="always"><param name="wmode" value="opaque"><param name="Movie" value="/ads/xz/' + gardinaSmall + '"></object>';
    var bigContainer = '<object width="982" height="350" type="application/x-shockwave-flash" id="visir_gardina2" class="advert" data="/ads/xz/' + gardinaBig +'"><param name="allowscriptaccess" value="always"><param name="wmode" value="opaque"><param name="Movie" value="/ads/xz/' + gardinaBig + '"></object>';
    $("#ad_Z").css({ 'float':'left','width':'982px','height':'100%' });
    $('<div id="adContainer">' + smallContainer + '</div><div id="adContainerLarge">' + bigContainer + '</div>').appendTo("#ad_Z");
    if (cookieName != null && cookieName != '') {
        gardinaCookie(cookieName);
    }
}
function visir_gardina_opna() {
    var gardinaB = $("#visir_gardina2").attr('data');
    $("#adContainer").hide();
    $("#adContainerLarge").show();
    $("#adContainerLarge").html('<object width="982" height="350" type="application/x-shockwave-flash" id="visir_gardina2" class="advert" data="' + gardinaB + '"><param name="allowscriptaccess" value="always"><param name="wmode" value="opaque"><param name="Movie" value="' + gardinaB + '"></object>');
}
function visir_gardina_loka() {
    var gardinaS = $("#visir_gardina1").attr('data');
    $("#adContainerLarge").hide();
    $("#adContainer").show();
    $("#adContainer").html('<object width="982" height="30" type="application/x-shockwave-flash" id="visir_gardina1" class="advert" data="' + gardinaS + '"><param name="allowscriptaccess" value="always"><param name="wmode" value="opaque"><param name="Movie" value="' + gardinaS + '"></object>');
}
function gardinaCookie(cookieName) {
    var testCookie = getCookie(cookieName);
    if (testCookie != 'Bingo') {
        visir_gardina_opna()
        Set_Cookie(cookieName, 'Bingo', 1, '/');
        window.setTimeout('visir_gardina_loka()', 12000);
    }
    else {
        visir_gardina_loka();
    }
}
function iSwipe(divid, nextID, prevID) {
    if (navigator.userAgent.match(/iPad/i) != null || navigator.userAgent.match(/iPhone/i) != null || navigator.userAgent.match(/Android/i) != null) {
        $(divid).touchwipe({
            wipeLeft: function () { $(nextID).click() },
            wipeRight: function () { $(prevID).click() },
            min_move_x: 20,
            preventDefaultEvents: true
        });
    }
}
function bindTabArea() {
    $('.tabarea').each(function () {
        if ($(this).find('ul.tabs li.current').length < 1) {
            $(this).find('ul.tabs li:eq(0)').addClass('current');
            $(this).find('.tabContent:eq(0)').show();
        }
    });

    $('.tabarea ul.tabs li').click(function () {
        var ind = $(this).parents('ul.tabs').find('li').index(this);

        $(this).parents('.tabarea').find('.tabContent').hide();
        $(this).parents('.tabarea').find('.tabContent:eq(' + ind + ')').show();

        $(this).parents('ul.tabs').find('li').removeClass('current');
        $(this).addClass('current');

        return false;
    });
}
/*Spilin from scroll.js*/
function getCard() {
    var randomnumber = Math.floor(Math.random() * 77)
    var spur = "";
    if (document.getElementById("spur").value == "Skrifašu spuringuna hér...") {
        spur = "";
    } else {
        spur = "" + document.getElementById("spur").value;
    }
    location.href = "/section/lifid&template=spilin&SpilID=" + randomnumber + "&spur=" + escape(spur)
}

function SpilNidur(p) {
    //tala = document.getElementById('card'+p).style.top;
    //tala =  tala.replace("px", "");
    //if (tala == 10) {
    //	setTimeout("spilScrollDown(0,"+tala+",'card"+p+"')", 1);
    //} else {
    document.getElementById('card' + p).style.top = "0px"
    //}
}
function SpilUp(p) {
    tala = document.getElementById('card' + p).style.top;
    tala = tala.replace("px", "");
    if (tala == 0) {
        setTimeout("spilScrollUp(10,0,'card" + p + "')", 1);
    } else {
        document.getElementById('card' + p).style.top = "10px"
    }

}
function spilScrollDown(b, i, d) {
    var begin_pos = i;
    var end_pos = b
    if (i == b) {
        document.getElementById('' + d).style.top = b + "px";
    } else {
        document.getElementById('' + d).style.top = i + "px";
        i = i - 1
        setTimeout("spilScrollDown(" + end_pos + "," + i + ",'" + d + "')", 1);
    }
}

function spilScrollUp(b, i, d) {
    var begin_pos = i;
    var end_pos = b
    if (i == b) {
        document.getElementById('' + d).style.top = b + "px";
    } else {
        document.getElementById('' + d).style.top = i + "px";
        i = i + 1
        setTimeout("spilScrollUp(" + end_pos + "," + i + ",'" + d + "')", 1);
    }
}
function fbs_click() {
    u = location.href;
    t = document.title;
    window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=626,height=436'); return false;
}

/** New video function -  used on buisness and xmas**/
function playVideo(url, autostart, target, width, height, server, url_600, url_300, ctrlbar, endt, startt, livemsg, backgr) {
    if (width) { swidth = width };
    if (height) { sheight = height };
    if (server == 1) { streamer = 'rtmp://klippur.visir.is/vod/_definst_/' };
    if (server == 2) { streamer = 'rtmp://utsending.visir.is/live/' };
    if (server == 4) { streamer = 'rtmp://visirfs.fplive.net/visir/' };
    if (server == 5) { streamer = 'rtmp://utsending.visir.is/rtplive/' };
    if (server == 3) {
        if (url.match('http://(www.)?youtube|youtu\.be')) {
            var youtube_id = url.split(/v\/|v=|youtu\.be\//)[1].split(/[?&]/)[0];
        }
        bimg = 'http://i.ytimg.com/vi/' + youtube_id + '/hqdefault.jpg';
    }
    else if (backgr == null && server != 3 || backgr == '' && server != 3) {
        if (startt == null || startt == '') {
            bimg = 'none';
        }
        else {
            bimg = '/jwplayer/assets/thumb.png';
        }
    }
    else { bimg = backgr; };
    //var adtvid = "http://lp.longtailvideo.com/5/adtvideo/adtvideo.swf";
    //var adtex = "http://lp.longtailvideo.com/5/adttext/adttext.swf";
    var playerconfig = {
        id: target,
        autostart: autostart,
        controlbar: ctrlbar,
        skin: "/jwplayer/glow.zip",
        flashplayer: "/jwplayer/player58.swf",
        width: swidth,
        height: sheight,
        image: bimg,
        stretching: "exactfit",
        bufferlength: 10,
        wmode: 'window',
        levels: [
            { bitrate: 1200, file: url, width: 700 },
            { bitrate: 600, file: url_600, width: 700 },
            { bitrate: 300, file: url_300, width: 320 }
        ],
        provider: "rtmp"
    };
    playerconfig.plugins = { gapro: { accountid: "UA-1570473-1"} };
    playerconfig.file = url;
    if (server == 1 | server == 2 | server == 4 | server == 5) { playerconfig.streamer = streamer; } else if (server == 3) { playerconfig.provider = "youtube"; } else { playerconfig.provider = "http"; }
    jwplayer(target).setup(playerconfig)
}
