﻿
$(document).ready(function() {
    toggleLesMer();
    toggleLesMerBunn();


    jQuery("#search input.sokboks").liveSearch({ ajaxURL: 'search' });
    

    //    $('#dialog').jqm({
    //        onHide: function(h) { 
    //      t.html('Please Wait...');  // Clear Content HTML on Hide.
    //      h.o.remove(); // remove overlay
    //      h.w.fadeOut(888); // hide window

    //        });

//    var removeStuff = function() {


//        var s1 = new SWFObject('/flvtools/player.swf', 'ply', '360', '270', '9', '#FFFFFF');
//        s1.addParam('allowfullscreen', 'true'); s1.addParam('allowscriptaccess', 'always');
//        s1.addParam('flashvars', 'file=../uploads/media/633915546644910795-a.flv&image=../uploads/media/633915546644910795-a.jpg&skin=../uploads/media/nacht.swf');
//        s1.write('container');

//    };
//    var swapStuff = function() {
//        s.html("");
//        s.append(t);
//    }
//    var t = $('#container');
//    var s = $('#dialog2');
//    s.append(t);
//    $('#dialog2').jqm({
//        //trigger: 'a.ex4Trigger',
//        //ajax: '@href', /* Extract ajax URL from the 'href' attribute of triggering element */
//        //target: s,
//        //modal: true, /* FORCE FOCUS */

//        onHide: function(h) {
//            s.html('Please Wait...');  // Clear Content HTML on Hide.
//            // remove overlay
//            //setTimeout(removeStuff, 444);
//            h.w.fadeOut(888, function() {
//                h.o.remove();
//                swapStuff();
//            });
//        }
//    });


    //alert(s.html)



    //$.blockUI({ message: $('#dialog') });
    //$('.blockOverlay').attr('title', 'Trykk for å stenge vindu').click($.unblockUI);







});
function toggleLesMer() {
    //brukes på produkter. 
    var maxTextHeight = 185;
    var tekster = $("#standard_sok .kolonne");
    tekster.each(function() {
        var $this = $(this);
        var text = $this.text();
        if ($this.height() > maxTextHeight) {
            $this.after($("<span style='display:none'/>").append($this.height()))
            $this.height(205);
        }
        else {
            $this.next().hide();
        }
    });

    $("#standard_sok .lesMer").click(function() {
        var $this = $(this);
        var toggledHeight = $this.prev().prev();
        var origHeight = $this.prev();
        var height = toggledHeight.height();
        var newheight = origHeight.text();
        toggledHeight.animate({ height: newheight + "px" }, 1000); //height( newheight + "px");

        origHeight.text(height);

        if ($(this).hasClass('vist')) {
            $(this).removeClass("vist").addClass("skjult");
            $this.text("Vis alle");

        } else {
            $(this).removeClass("skjult").addClass("vist");
            $this.text("Vis mindre");

        }
        return false;
    });

}
function toggleLesMerBunn() {
    //brukes på produkter. 
    var maxTextHeight = 190;
    var tekster = $("#standard_sok_bunn .kolonne");
    tekster.each(function() {
        var $this = $(this);
        var text = $this.text();
        if ($this.height() > maxTextHeight) {
            $this.after($("<span style='display:none'/>").append($this.height()))
            $this.height(205);
        }
        else {
            $this.next().hide();
        }
    });

    $("#standard_sok_bunn .lesMer").click(function() {
        var $this = $(this);
        var toggledHeight = $this.prev().prev();
        var origHeight = $this.prev();
        var height = toggledHeight.height();
        var newheight = origHeight.text();
        toggledHeight.animate({ height: newheight + "px" }, 1000); //height( newheight + "px");

        origHeight.text(height);

        if ($(this).hasClass('vist')) {
            $(this).removeClass("vist").addClass("skjult");
            $this.text("Vis alle");

        } else {
            $(this).removeClass("skjult").addClass("vist");
            $this.text("Vis mindre");

        }
        return false;
    });

}
// Her legges javascript-funksjoner
function settHoyde() {
    var siste_produkt = $('#toggle').slideToggle('fast', '');
    var siste_produkt = $('#toggle2').slideToggle('fast', '');
    if ($('#togglelink').text().indexOf('Se alle >>') != -1) {
        $('#togglelink').text('Lukk');
    }
    else {
        $('#togglelink').text('Se alle >>');
    }
}

function toolTip(element_name) {
    if (document.getElementById(element_name)) {
        $("#" + element_name).show();
        setTimeout(function() { $('#' + element_name).slideUp() }, 3000);
    }
}
function close_toolTip(element_name) {
    $("#" + element_name).hide();
}
function toggleHandlekurv() {
    var pnl = document.getElementById("ctl00_mk_handlekurv_wrapper");
    if (pnl) {
        if (pnl.style.visibility == 'hidden')
            pnl.style.visibility = 'visible';
        else if (pnl.style.visibility == 'visible')
            pnl.style.visibility = 'hidden';
        else
            pnl.style.visibility = 'visible';
    }
}
function sendmail(user, domain, suffix) {
    document.write('<a href="' + 'mailto:' + user + '@' + domain + '.' + suffix + '">' + user + '@' + domain + '.' + suffix + '</a>');
}
function Historie(visibility) {
    var pnl = document.getElementById("dropdown");
    if (pnl)
        pnl.style.visibility = visibility;
}
function addOnClick() {
    document.onclick = myClickHandler;
}
function myClickHandler() {
    Historie("hidden");
}

// Seek nested NN4 layer from string name
function seekLayer(doc, name) {
    var theObj;
    for (var i = 0; i < doc.layers.length; i++) {
        if (doc.layers[i].name == name) {
            theObj = doc.layers[i];
            break;
        }
        // dive into nested layers if necessary
        if (doc.layers[i].document.layers.length > 0) {
            theObj = seekLayer(document.layers[i].document, name);
        }
    }
    return theObj;
}

// Convert object name string or object reference
// into a valid element object reference
function getRawObject(obj) {
    var theObj;
    if (typeof obj == "string") {
        if (isW3C) {
            theObj = document.getElementById(obj);
        } else if (isIE4) {
            theObj = document.all(obj);
        } else if (isNN4) {
            theObj = seekLayer(document, obj);
        }
    } else {
        // pass through object reference
        theObj = obj;
    }
    return theObj;
}

// Convert object name string or object reference
// into a valid style (or NN4 layer) reference
function getObject(obj) {
    var theObj = getRawObject(obj);
    if (theObj && isCSS) {
        theObj = theObj.style;
    }
    return theObj;
}

// Position an object at a specific pixel coordinate
function shiftTo(obj, x, y) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isCSS) {
            // equalize incorrect numeric value type
            var units = (typeof theObj.left == "string") ? "px" : 0
            theObj.left = x + units;
            theObj.top = y + units;
        } else if (isNN4) {
            theObj.moveTo(x, y)
        }
    }
}

// Move an object by x and/or y pixels
function shiftBy(obj, deltaX, deltaY) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isCSS) {
            // equalize incorrect numeric value type
            var units = (typeof theObj.left == "string") ? "px" : 0;
            theObj.left = getObjectLeft(obj) + deltaX + units;
            theObj.top = getObjectTop(obj) + deltaY + units;
        } else if (isNN4) {
            theObj.moveBy(deltaX, deltaY);
        }
    }
}

// Set the visibility of an object to visible
function show(obj) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.visibility = "visible";
    }
}

// Set the visibility of an object to hidden
function hide(obj) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.visibility = "hidden";
    }
}

// Retrieve the x coordinate of a positionable object
function getObjectLeft(obj) {
    var elem = getRawObject(obj);
    var result = 0;
    if (document.defaultView) {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("left");
    } else if (elem.currentStyle) {
        result = elem.currentStyle.left;
    } else if (elem.style) {
        result = elem.style.left;
    } else if (isNN4) {
        result = elem.left;
    }
    return parseInt(result);
}

// Retrieve the y coordinate of a positionable object
function getObjectTop(obj) {
    var elem = getRawObject(obj);
    var result = 0;
    if (document.defaultView) {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("top");
    } else if (elem.currentStyle) {
        result = elem.currentStyle.top;
    } else if (elem.style) {
        result = elem.style.top;
    } else if (isNN4) {
        result = elem.top;
    }
    return parseInt(result);
}

var scrollEngaged = false;
var scrollInterval;
var scrollBars = new Array();

function getElementStyle(elemID, IEStyleAttr, CSSStyleAttr) {
    var elem = document.getElementById(elemID);
    if (elem.currentStyle) {
        return elem.currentStyle[IEStyleAttr];
    } else if (window.getComputedStyle) {
        var compStyle = window.getComputedStyle(elem, "");
        return compStyle.getPropertyValue(CSSStyleAttr);
    }
    return "";
}

function scrollBar(ownerID, ownerContentID, sliderbar, upID, dnID) {
    this.ownerID = ownerID;
    this.ownerContentID = ownerContentID;
    this.index = 0; //scrollBars.length;
    this.upButton = document.getElementById(upID);
    this.dnButton = document.getElementById(dnID);
    this.slButton = document.getElementById(sliderbar);
    this.upButton.index = this.index;
    this.dnButton.index = this.index;
    this.slButton.index = this.index;
    this.ownerWidth = parseInt(getElementStyle(this.ownerID, "width", "width"));
    this.scrollWidth = parseInt(getElementStyle(this.ownerContentID, "width", "width"));
    this.initScroll = initScroll;
}

function initScroll() {
    this.upButton.onmousedown = handleScrollClick;
    this.upButton.onmouseup = handleScrollStop;
    this.upButton.oncontextmenu = blockEvent;

    this.dnButton.onmousedown = handleScrollClick;
    this.dnButton.onmouseup = handleScrollStop;
    this.dnButton.oncontextmenu = blockEvent;

    this.slButton.onmousedown = handleScrollClick;
    this.slButton.onmouseup = handleScrollStop;
    this.slButton.oncontextmenu = blockEvent;

    var isIEMac = (navigator.appName.indexOf("Explorer") != -1 && navigator.userAgent.indexOf("Mac") != -1);
}

function handleScrollStop() {
    scrollEngaged = false;
}

function blockEvent(evt) {
    evt = (evt) ? evt : event;
    evt.cancelBubble = true;
    return false;
}
var scrolling = false;
function handleScrollClick(evt) {
    evt = (evt) ? evt : event;
    var target = (evt.target) ? evt.target : evt.srcElement;
    var index = target.index;
    var px = 5;
    if (target.className != "DragContainer" && target.className != "DragBox") {
        px = (target.className == "linedown") ? px : -px;
        scrollEngaged = true;
        scrollBy(index, px);
        scrollInterval = setInterval("scrollBy(" + index + ", " +
            px + ")", 10);

        evt.cancelBubble = true;
        return false;
    }
    else if (target.className == "DragContainer") {
        if (!scrolling) {
            var slider = document.getElementById("Item1");
            var cont = document.getElementById("dragcontainer");
            var content = document.getElementById("scrollcontent");
            var main = document.getElementById("scrollmain");
            var pos = getPosition(cont);
            var mousePos = mouseCoords(evt);



            var newpos = (mousePos.x - pos.x - 53);
            if (newpos > 823) {
                newpos = 823;
                slider.style.left = 823 + "px";
            }
            else if (newpos < 0) {
                newpos = 0;
                slider.style.left = 0 + "px";
            }
            else {
                slider.style.left = newpos + "px";
            }

            var scrollengde = content.offsetWidth - main.offsetWidth;
            var ratio = scrollengde / 823;

            scrolling = true;
            setTimeout('timeout(' + newpos + ', ' + scrollengde + ', ' + ratio + ')', 20);
        }
        evt.cancelBubble = true;
        return false;
    }
}
function timeout(newpos, scrollengde, ratio) {
    var content = document.getElementById("scrollcontent");
    var nowpos = content.offsetLeft;

    var newcontpos = -(ratio * newpos);
    var diff = nowpos - newcontpos;
    var move = diff * 0.2;

    if (move < 1 && move > 0)
        move = 1;
    if (move < 0 && move > -1)
        move = -1;

    var newleft = nowpos + -move;

    content.style.left = newleft + "px";
    if (parseInt(newleft) == parseInt(newcontpos)) {
        content.style.left = newcontpos + "px";
        scrolling = false;
        return;
    }
    if ((parseInt(-newcontpos) - parseInt(newleft)) < 2) {
        content.style.left = newcontpos + "px";
        scrolling = false;
        return;
    }
    setTimeout('timeout(' + newpos + ', ' + scrollengde + ', ' + ratio + ')', 30);
}

function scrollBy(index, px) {

    //Verdier nedenfor her varierer alt ettersom hvor lang slideren er
    var scroller = scrollBars[index];
    var owner = document.getElementById(scroller.ownerID);
    var elem = document.getElementById(scroller.ownerContentID);
    var slider = document.getElementById("Item1");
    var sliderholder = document.getElementById("dragcontainer");


    var venstre = parseInt(elem.offsetLeft);
    var lengde = parseInt(elem.offsetWidth) - parseInt(owner.offsetWidth);
    var sliderlengde = parseInt(slider.offsetWidth);
    var sliderholderlengde = parseInt(sliderholder.offsetWidth);
    var ratio = (sliderholderlengde - sliderlengde) / lengde;


    ratio = ratio - (ratio * 0.00466585);
    var slidvenstre = parseInt(ratio * venstre)
    slider.style.left = -slidvenstre + "px";

    if (px > 0) {
        if (scrollEngaged && (elem.offsetLeft < 0)) {
            shiftBy(elem, px, 0);
        } else {
            clearInterval(scrollInterval);
        }
    }
    else {
        if (scrollEngaged && (elem.offsetLeft >= (parseInt(scroller.ownerWidth) - parseInt(scroller.scrollWidth)))) {
            shiftBy(elem, px, 0);
        } else {
            clearInterval(scrollInterval);
        }
    }
}
/////////////
// iMouseDown represents the current mouse button state: up or down
/*
lMouseState represents the previous mouse button state so that we can
check for button clicks and button releases:

if(iMouseDown && !lMouseState) // button just clicked!
if(!iMouseDown && lMouseState) // button just released!
*/
var mouseOffset = null;
var iMouseDown = false;
var lMouseState = false;
var dragObject = null;

// Demo 0 variables
var DragDrops = [];
var curTarget = null;
var lastTarget = null;
var dragHelper = null;
var tempDiv = null;
var rootParent = null;
var rootSibling = null;
var topp = null;
var orgleft;
var orgmaxleft;

Number.prototype.NaN0 = function() { return isNaN(this) ? 0 : this; }

function CreateDragContainer() {
    /*
    Create a new "Container Instance" so that items from one "Set" can not
    be dragged into items from another "Set"
    */
    var cDrag = DragDrops.length;
    DragDrops[cDrag] = [];

    /*
    Each item passed to this function should be a "container".  Store each
    of these items in our current container
    */
    for (var i = 0; i < 1; i++) {//arguments.length; i++){
        var cObj = arguments[i];
        DragDrops[cDrag].push(cObj);
        cObj.setAttribute('DropObj', cDrag);

        /*
        Every top level item in these containers should be draggable.  Do this
        by setting the DragObj attribute on each item and then later checking
        this attribute in the mouseMove function
        */
        for (var j = 0; j < cObj.childNodes.length; j++) {

            // Firefox puts in lots of #text nodes...skip these
            if (cObj.childNodes[j].nodeName == '#text') continue;

            cObj.childNodes[j].setAttribute('DragObj', cDrag);
        }
    }
}
function getPosition(e) {
    var left = 0;
    var top = 0;
    while (e.offsetParent) {
        left += e.offsetLeft + (e.currentStyle ? (parseInt(e.currentStyle.borderLeftWidth)).NaN0() : 0);
        top += e.offsetTop + (e.currentStyle ? (parseInt(e.currentStyle.borderTopWidth)).NaN0() : 0);
        e = e.offsetParent;
    }


    left += e.offsetLeft + (e.currentStyle ? (parseInt(e.currentStyle.borderLeftWidth)).NaN0() : 0);
    top += e.offsetTop + (e.currentStyle ? (parseInt(e.currentStyle.borderTopWidth)).NaN0() : 0);

    return { x: left, y: top };

}

function mouseCoords(ev) {
    if (ev.pageX || ev.pageY) {
        return { x: ev.pageX, y: ev.pageY };
    }
    return {
        x: ev.clientX + document.body.scrollLeft - document.body.clientLeft,
        y: ev.clientY + document.body.scrollTop - document.body.clientTop
    };
}


function getMouseOffset(target, ev) {
    ev = ev || window.event;

    var docPos = getPosition(target);
    var mousePos = mouseCoords(ev);
    return { x: mousePos.x - docPos.x, y: mousePos.y - docPos.y };
}

function mouseMove(ev) {
    ev = ev || window.event;

    /*
    We are setting target to whatever item the mouse is currently on

	Firefox uses event.target here, MSIE uses event.srcElement
    */
    var target = ev.target || ev.srcElement;
    var mousePos = mouseCoords(ev);

    // mouseOut event - fires if the item the mouse is on has changed
    if (lastTarget && (target !== lastTarget)) {
        // reset the classname for the target element
        var origClass = lastTarget.getAttribute('origClass');
        if (origClass) lastTarget.className = origClass;
    }

    /*
    dragObj is the grouping our item is in (set from the createDragContainer function).
    if the item is not in a grouping we ignore it since it can't be dragged with this
    script.
    */
    var dragObj = target.getAttribute('DragObj');

    // if the mouse was moved over an element that is draggable
    if (dragObj != null) {

        // mouseOver event - Change the item's class if necessary
        /*if(target!=lastTarget){
        var oClass = target.getAttribute('overClass');
        if(oClass){
        target.setAttribute('origClass', target.className);
        target.className = oClass;
        }
        }*/

        // if the user is just starting to drag the element
        if (iMouseDown && !lMouseState) {
            // mouseDown target
            curTarget = target;
            // Record the mouse x and y offset for the element
            rootParent = curTarget.parentNode;
            rootSibling = curTarget.nextSibling;

            mouseOffset = getMouseOffset(target, ev);

            // We remove anything that is in our dragHelper DIV so we can put a new item in it.
            for (var i = 0; i < dragHelper.childNodes.length; i++) dragHelper.removeChild(dragHelper.childNodes[i]);

            // Make a copy of the current item and put it in our drag helper.
            dragHelper.appendChild(curTarget.cloneNode(true));
            dragHelper.style.display = 'block';

            // set the class on our helper DIV if necessary
            var dragClass = curTarget.getAttribute('dragClass');
            if (dragClass) {
                dragHelper.firstChild.className = dragClass;
            }

            // disable dragging from our helper DIV (it's already being dragged)
            dragHelper.firstChild.removeAttribute('DragObj');

            /*
            Record the current position of all drag/drop targets related
            to the element.  We do this here so that we do not have to do
            it on the general mouse move event which fires when the mouse
            moves even 1 pixel.  If we don't do this here the script
            would run much slower.
            */
            var dragConts = DragDrops[dragObj];

            /*
            first record the width/height of our drag item.  Then hide it since
            it is going to (potentially) be moved out of its parent.
            */
            curTarget.setAttribute('startWidth', parseInt(curTarget.offsetWidth));
            curTarget.setAttribute('startHeight', parseInt(curTarget.offsetHeight));
            curTarget.setAttribute('startoffleft', parseInt(curTarget.offsetLeft) - 25);
            //alert(curTarget.style.pixelLeft);
            curTarget.style.display = 'none';


            // loop through each possible drop container
            for (var i = 0; i < dragConts.length; i++) {
                with (dragConts[i]) {
                    var pos = getPosition(dragConts[i]);

                    /*
                    save the width, height and position of each container.

					Even though we are saving the width and height of each
                    container back to the container this is much faster because
                    we are saving the number and do not have to run through
                    any calculations again.  Also, offsetHeight and offsetWidth
                    are both fairly slow.  You would never normally notice any
                    performance hit from these two functions but our code is
                    going to be running hundreds of times each second so every
                    little bit helps!

					Note that the biggest performance gain here, by far, comes
                    from not having to run through the getPosition function
                    hundreds of times.
                    */
                    setAttribute('startWidth', parseInt(offsetWidth));
                    setAttribute('startHeight', parseInt(offsetHeight));
                    setAttribute('startLeft', pos.x);
                    setAttribute('startTop', pos.y);
                }
                // loop through each child element of each container
            }
        }
    }

    // If we get in here we are dragging something
    if (curTarget) {
        // move our helper div to wherever the mouse is (adjusted by mouseOffset)
        var d = document;
        var n = navigator;
        var nav = n.appVersion;
        var nan = n.appName;
        var nua = n.userAgent;
        var ie = ((nua.indexOf('MSIE') != -1));
        var str_pos;
        var nu;
        var brow;
        if (ie) {
            str_pos = nua.indexOf('MSIE');
            nu = nua.substr((str_pos + 5), 3);
            brow = 'Microsoft Internet Explorer';
        }
        var ie6 = (ie && (nu.substring(0, 1) == 6));

        //Verdiene nedenfor her må varieres alt ettersom hvor lang slideren er
        var dragConts = DragDrops[curTarget.getAttribute('DragObj')];
        var sjekk = dragConts[0];
        var left = sjekk.getAttribute('startLeft');
        var maxmin = mousePos.x - mouseOffset.x;
        if (ie6)
            dragHelper.style.top = 372 + "px";
        else
            dragHelper.style.top = 370 + "px";
        var curleft = curTarget.getAttribute('startoffleft');
        if (maxmin > (parseInt(left) - 2) && maxmin < (parseInt(left) + 824)) {
            var midt = document.getElementById("scrollcontent");
            var main = document.getElementById("scrollmain");
            var times = (parseInt(midt.offsetWidth) - parseInt(main.offsetWidth)) / 823;
            midt.style.left = (-(parseInt((mousePos.x - mouseOffset.x)) - parseInt(left)) * times) + "px";
            dragHelper.style.left = (parseInt(mousePos.x - mouseOffset.x) - parseInt(curleft)) + "px";
            curTarget.style.left = (parseInt((mousePos.x - mouseOffset.x)) - parseInt(left)) + "px";
        }


        var activeCont = null;

        var xPos = mousePos.x - mouseOffset.x + (parseInt(curTarget.getAttribute('startWidth')) / 2);
        var yPos = mousePos.y - mouseOffset.y + (parseInt(curTarget.getAttribute('startHeight')) / 2);

        // check each drop container to see if our target object is "inside" the container


        for (var i = 0; i < dragConts.length; i++) {
            with (dragConts[i]) {
                if (((getAttribute('startLeft')) < xPos) &&
					((getAttribute('startTop')) < yPos) &&
					((getAttribute('startLeft') + getAttribute('startWidth')) > xPos) &&
					((getAttribute('startTop') + getAttribute('startHeight')) > yPos)) {

                    /*
                    our target is inside of our container so save the container into
                    the activeCont variable and then exit the loop since we no longer
                    need to check the rest of the containers
                    */
                    activeCont = dragConts[i];

                    // exit the for loop
                    break;
                }
            }
        }

        // Our target object is in one of our containers.  Check to see where our div belongs
        if (activeCont) {
            // beforeNode will hold the first node AFTER where our div belongs
            var beforeNode = null;

            // loop through each child node (skipping text nodes).
            for (var i = activeCont.childNodes.length - 1; i >= 0; i--) {
                with (activeCont.childNodes[i]) {
                    if (nodeName == '#text') continue;

                    // if the current item is "After" the item being dragged
                    if (
						curTarget != activeCont.childNodes[i] &&
						((getAttribute('startLeft') + getAttribute('startWidth')) > xPos) &&
						((getAttribute('startTop') + getAttribute('startHeight')) > yPos)) {
                        beforeNode = activeCont.childNodes[i];
                    }
                }
            }

            // the item being dragged belongs before another item
            if (beforeNode) {
                if (beforeNode != curTarget.nextSibling) {
                    activeCont.insertBefore(curTarget, beforeNode);
                }

                // the item being dragged belongs at the end of the current container
            } else {
                //if((curTarget.nextSibling) || (curTarget.parentNode!=activeCont)){
                activeCont.appendChild(curTarget);
                //}
            }

            // make our drag item visible
            if (curTarget.style.display != '') {
                //curTarget.style.display  = '';
            }
        } else {

            // our drag item is not in a container, so hide it.
            if (curTarget.style.display != 'none') {
                curTarget.style.display = 'none';
            }
        }
    }
    // track the current mouse state so we can compare against it next time
    lMouseState = iMouseDown;

    // mouseMove target
    lastTarget = target;

    // track the current mouse state so we can compare against it next time
    lMouseState = iMouseDown;

    // this helps prevent items on the page from being highlighted while dragging
    return false;
}

function mouseUp(ev) {
    if (curTarget) {
        // hide our helper object - it is no longer needed
        dragHelper.style.display = 'none';

        // if the drag item is invisible put it back where it was before moving it
        if (curTarget.style.display == 'none') {
            if (rootSibling) {
                rootParent.insertBefore(curTarget, rootSibling);
            } else {
                rootParent.appendChild(curTarget);
            }
        }

        // make sure the drag item is visible
        curTarget.style.display = '';
    }
    curTarget = null;
    iMouseDown = false;
}

function mouseDown() {

    iMouseDown = true;
    //if(lastTarget){
    //	return false;
    //}

}


// Global variables
var isCSS, isW3C, isIE4, isNN4, isIE6CSS;

// Initialize upon load to let all browsers establish content objects

window.onload = initAll;

function initAll() {
    // Create our helper object that will show the item while dragging
    if (document.getElementById('dragcontainer')) {


        document.onmousemove = mouseMove;
        document.onmousedown = mouseDown;
        document.onmouseup = mouseUp;
        dragHelper = document.createElement('DIV');
        dragHelper.style.cssText = 'position:absolute;display:none;';


        CreateDragContainer(
	        document.getElementById('dragcontainer')
        );

        document.body.appendChild(dragHelper);

        if (document.images) {
            isCSS = (document.body && document.body.style) ? true : false;
            isW3C = (isCSS && document.getElementById) ? true : false;
            isIE4 = (isCSS && document.all) ? true : false;
            isNN4 = (document.layers) ? true : false;
            isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
        }

        scrollBars[0] = new scrollBar("scrollmain", "scrollcontent", "lineup0",
            "linedown0", "dragcontainer");
        scrollBars[0].initScroll();
    }
}
/* ***** KATEGORIMENY ***** */
var last;
var lastlevel;
var lasttop;
var lastlevel2;
var lastlevel3
function setVisibility(id, level) {

    var panel = document.getElementById(id);
    var lastpanel = document.getElementById(last);
    if (panel != null) {
        var sjekk = panel.style.visibility;
        if (sjekk == "" || sjekk == "hidden") {
            panel.style.display = "block";
            panel.style.visibility = "visible";

            if ((level == 1 && lasttop != id) || (level == 1 && lasttop == undefined)) {
                lastpanel = document.getElementById(lastlevel3);
                if (lastpanel != null) {
                    lastpanel.style.display = "none";
                    lastpanel.style.visibility = "hidden";
                }
                lastpanel = document.getElementById(lastlevel2);
                if (lastpanel != null) {
                    lastpanel.style.display = "none";
                    lastpanel.style.visibility = "hidden";
                }
                lastpanel = document.getElementById(lasttop);
                if (lastpanel != null) {
                    lastpanel.style.display = "none";
                    lastpanel.style.visibility = "hidden";
                }
            }
            else if (id == lasttop) {
                if (lastlevel2 != undefined)
                    if (id.toString().indexOf(lastlevel2.toString().replace("pnlWrapper", "")) == -1) {
                    lastpanel = document.getElementById(lastlevel2);
                    if (lastpanel != null) {
                        lastpanel.style.display = "none";
                        lastpanel.style.visibility = "hidden";
                    }
                }
                if (lastlevel3 != undefined)
                    if (id.toString().indexOf(lastlevel3.toString().replace("pnlWrapper", "")) == -1) {
                    lastpanel = document.getElementById(lastlevel3);
                    if (lastpanel != null) {
                        lastpanel.style.display = "none";
                        lastpanel.style.visibility = "hidden";
                    }
                }
            }
            if (level == 2 && lastlevel2 != id) {
                lastpanel = document.getElementById(lastlevel3);
                if (lastpanel != null) {
                    lastpanel.style.display = "none";
                    lastpanel.style.visibility = "hidden";
                }
                lastpanel = document.getElementById(lastlevel2);
                if (lastpanel != null) {
                    lastpanel.style.display = "none";
                    lastpanel.style.visibility = "hidden";
                }
                if (lasttop != undefined) {
                    if (id.toString().indexOf(lasttop.toString().replace("pnlWrapper", "")) == -1) {
                        lastpanel = document.getElementById(lasttop);
                        if (lastpanel != null) {
                            lastpanel.style.display = "none";
                            lastpanel.style.visibility = "hidden";
                        }
                    }
                }
            }
            else if (lastlevel2 == id) {
                if (lasttop != undefined) {
                    if (id.toString().indexOf(lasttop.toString().replace("pnlWrapper", "")) == -1) {
                        lastpanel = document.getElementById(lasttop);
                        if (lastpanel != null) {
                            lastpanel.style.display = "none";
                            lastpanel.style.visibility = "hidden";
                        }
                    }
                }
            }
            if (level == 3 && lastlevel3 != id) {
                lastpanel = document.getElementById(lastlevel3);
                if (lastpanel != null) {
                    lastpanel.style.display = "none";
                    lastpanel.style.visibility = "hidden";
                }
            }
        }
        else {
            panel.style.display = "none";
            panel.style.visibility = "hidden";
        }
        last = id;
        lastlevel = level;
        if (level == 1) {
            lasttop = id;
        }
        if (level == 2) {
            lastlevel2 = id;
        }
        if (level == 3) {
            lastlevel3 = id;
        }
    }
}

