﻿

var SandJensen = {
    visBil: function(bilNr, visEuro, erTysk) {
        window.location.href = bilNr;
        return;

        var url = "";

        if (erTysk) url = "/visbil_de.htm";
        else url = "/visbil.htm";

        url += "?bilnr=" + bilNr;

        if (visEuro) {
            window.location.href = url + "&euro=" + visEuro;
        } else {
            window.location.href = url;
        }
    },

    visInteressekort: function(bilNr) {
        //this.popup("/Interessekort.aspx?bilnr=" + bilNr, 775, 730);
        this.popup("/Interessekort.aspx?bilnr=" + bilNr, 595, 440);
    },

    vis360Billeder: function(url) {
        this.popup(url, 825, 550);
    },

    popup: function(url, bredde, hojde) {
        var window_width = bredde;
        var window_height = hojde;
        var window_top = (screen.height - window_height) / 2;
        var window_left = (screen.width - window_width) / 2;

        var win = window.open(url, null, 'width=' + window_width + ',height=' + window_height + ',top=' + window_top + ',left=' + window_left);
        win.focus();
    },





    BilInfo: {
        valgteBillede: null,

        initialize: function() {
            var visBilBoks = $("vis-bil-boks");

            if (!visBilBoks)
                return;

            var storeBilleder = $$(".bil-store-billeder div");

            var thumbBilleder = $$("div#slider-box div.billeder img");

            thumbBilleder.each(function(element, index) {

                var billede = storeBilleder[index];

                billede.fx = new Fx.Style(billede, 'opacity', { duration: 400 });

                if (index == 0) {
                    SandJensen.BilInfo.valgteBillede = billede;
                }

                element.addEvent("click", function(evt) {
                    new Event(evt).stop();

                    valgteBillede = SandJensen.BilInfo.valgteBillede;

                    valgteBillede.fx.start(1, 0).chain(function() {
                        valgteBillede.style.display = "none";
                        billede.style.display = "block";
                        billede.fx.set(0);
                        billede.fx.start(0, 1);
                        SandJensen.BilInfo.valgteBillede = billede;
                    });
                });
            });

            var array = new Array();

            var udstyr = $$(".bil-udstyr p")[0].innerHTML;

            var offset = $$(".bil-store-billeder a.special-360-picture").length;

            if (offset == 1) {
                SandJensen.BilInfo.valgteBillede = storeBilleder[1];
            }

            $$(".bil-store-billeder a").each(function(element, index) {
                if (element.className != 'special-360-picture') {
                    array.push([element.href, udstyr]);

                    element.addEvent("click", function(evt) {
                        new Event(evt).stop();

                        Lightbox.open(array, index - offset);
                    });
                }
            });
        }
    },

    NyhedRotator: {
        nuvaerendeNyhedBoks: null,
        nyhedsBokse: null,

        naeste: function() {
            var nuBoks = SandJensen.NyhedRotator.nuvaerendeNyhedBoks;
            var naesteBoks = nuBoks.naesteBoks;

            nuBoks.fx.start(1, 0).chain(function() {
                nuBoks.style.display = "none";
                naesteBoks.style.display = "block";
                naesteBoks.fx.set(0);
                naesteBoks.fx.start(0, 1);
                SandJensen.NyhedRotator.nuvaerendeNyhedBoks = naesteBoks;
            });
        },

        initialize: function() {
            var nyhedBoks = $("nyhedsrotator");
            if (nyhedBoks) {
                var forrigeNyhedBoks = null;
                var startBoks = null;

                this.nyhedsBokse = $$("div#nyhedsrotator div");

                this.nyhedsBokse.each(function(nyhedBoks, index) {
                    nyhedBoks.fx = new Fx.Style(nyhedBoks, 'opacity', { duration: 400 });

                    if (startBoks == null) {
                        startBoks = nyhedBoks;
                    } else {
                        forrigeNyhedBoks.naesteBoks = nyhedBoks;
                    }

                    forrigeNyhedBoks = nyhedBoks;
                });

                forrigeNyhedBoks.naesteBoks = startBoks;

                this.nuvaerendeNyhedBoks = startBoks;
                this.naeste.periodical(5000);
            }
        }
    },

    Galleri: {
        nuvaerendeBilledeIndex: 0,
        thumbBilleder: null,

        initialize: function() {
            var visGalleriBoks = $("vis-galleri");
            if (!visGalleriBoks)
                return;

            var naesteKnap = $$("div#vis-galleri-top div.naeste a")[0];
            naesteKnap.addEvent("click", function(evt) {
                new Event(evt).stop();
                SandJensen.Galleri.visNaesteBillede();
            });

            var forrigeKnap = $$("div#vis-galleri-top div.forrige a")[0];
            forrigeKnap.addEvent("click", function(evt) {
                new Event(evt).stop();
                SandJensen.Galleri.visForrigeBillede();
            });

            var thumbBilleder = $$("div#slider-box div.billeder img");
            thumbBilleder.each(function(element, index) {
                element.addEvent("click", function() {
                    SandJensen.Galleri.visMellemBillede(index);
                });
            });

            SandJensen.Galleri.thumbBilleder = thumbBilleder;
            var array = new Array();

            $$("div#vis-galleri-billede div").each(function(element, indeks) {

                var img = element.getElement("img");
                var p = element.getElement("p");

                array.push([img.src.replace("alm", "stor"), p.innerHTML]);

                img.addEvent("click", function() {
                    Lightbox.open(array, indeks);
                });
            });

            var galleriKategorier = $("galleri-kategorier");
            if (galleriKategorier) {
                var kategoriBoks = $$("div#galleri-kategorier div.kategori");

                var overlayBoks = new Element("div", {
                    "styles": {
                        "position": "absolute",
                        "width": "20px",
                        "height": "7px",
                        "border": "2px solid white",
                        "top": "1px",
                        "left": "1px",
                        "opacity": "0"
                    }
                });

                document.body.appendChild(overlayBoks);

                var fx = new Fx.Styles(overlayBoks, { duration: 900, transition: Fx.Transitions.Circ.easeOut });

                kategoriBoks.each(function(boks, indeks) {
                    var billedeLink = boks.getFirst();
                    billedeLink.korEffekt = true;

                    billedeLink.addEvent("mouseenter", function(evt) {
                        if (!billedeLink.korEffekt) return;
                        billedeLink.korEffekt = false;


                        var pos = billedeLink.getPosition();

                        var hojde = billedeLink.getStyle("height").toInt();
                        var bredde = billedeLink.getStyle("width").toInt();

                        var startTop = pos.y + (hojde / 2) - 15;
                        var startLeft = pos.x + (bredde / 2) - 20;
                        var endTop = startTop - 25;
                        var endLeft = startLeft - 50;

                        fx.stop();
                        overlayBoks.setStyle("display", "block");
                        fx.set({ "border-width": 2 + "px", "width": 25 + "px", "height": 15 + "px", "top": startTop + "px", "left": startLeft + "px", "opacity": 0.5 })

                        fx.start({ "border-width": 10 + "px", "width": 112 + "px", "height": 59 + "px", "top": endTop + "px", "left": endLeft + "px", "opacity": 0 }).chain(function() {
                            overlayBoks.setStyle("display", "none");
                        });


                        (function() { billedeLink.korEffekt = true; }).delay(900);
                    });
                });
            }
        },

        visMellemBillede: function(indeks) {
            var nuvaerendeBilledeBoks = $("galleri-mellem-billede-" + SandJensen.Galleri.nuvaerendeBilledeIndex);
            var effekt = nuvaerendeBilledeBoks.effect("opacity", { duration: 400 });
            effekt.start(1, 0).chain(function() {
                nuvaerendeBilledeBoks.style.display = "none";

                var src = SandJensen.Galleri.thumbBilleder[indeks].src;

                var billedeBoks = $("galleri-mellem-billede-" + indeks);

                if (billedeBoks == null) {
                    var img = new Element("img", {
                        "src": src.replace("thumbnail", "alm")
                    });

                    billedeBoks = new Element("div", {
                        "id": "galleri-mellem-billede-" + indeks,
                        "class": "galleri-mellem-billede"
                    });

                    img.injectInside(billedeBoks);
                    billedeBoks.injectAfter(nuvaerendeBilledeBoks);
                }

                billedeBoks.style.display = "block";
                var billedeEffekt = billedeBoks.effect("opacity", { duration: 400 });
                billedeEffekt.set(0);
                billedeEffekt.start(0, 1);
                SandJensen.Galleri.nuvaerendeBilledeIndex = indeks;
            });
        },

        visNaesteBillede: function() {
            var nyIndeks = SandJensen.Galleri.nuvaerendeBilledeIndex + 1;
            if (nyIndeks < SandJensen.Galleri.thumbBilleder.length) {
                SandJensen.Galleri.visMellemBillede(nyIndeks);
            }
        },

        visForrigeBillede: function() {
            var nyIndeks = SandJensen.Galleri.nuvaerendeBilledeIndex - 1;
            if (nyIndeks >= 0) {
                SandJensen.Galleri.visMellemBillede(nyIndeks);
            }
        }
    },

    Slider: {
        marginSide: 555,
        marginMin: 0,
        marginMax: 0,
        effekt: null,
        billedeSlider: null,

        initialize: function() {
            var sliderBox = $("slider-box");
            if (!sliderBox)
                return;



            var naesteKnap = $$("div#slider-box div.naeste")[0];
            var forrigeKnap = $$("div#slider-box div.forrige")[0];

            SandJensen.Slider.billedeSlider = $$("div#slider-box div.billeder")[0];

            var bredde = SandJensen.Slider.billedeSlider.getStyle("width").toInt();

            SandJensen.Slider.marginMax = (bredde - SandJensen.Slider.marginSide) * -1;
            SandJensen.Slider.effekt = new Fx.Style(SandJensen.Slider.billedeSlider, "margin-left", { duration: 2000 });

            naesteKnap.addEvent("click", function() {
                SandJensen.Slider.effekt.stop();

                var start = SandJensen.Slider.billedeSlider.getStyle("margin-left").toInt();
                var slut = start - SandJensen.Slider.marginSide;

                if (slut < SandJensen.Slider.marginMax) {
                    slut = SandJensen.Slider.marginMax;
                }

                SandJensen.Slider.effekt.start(start, slut);
            });

            forrigeKnap.addEvent("click", function() {
                SandJensen.Slider.effekt.stop();

                var start = SandJensen.Slider.billedeSlider.getStyle("margin-left").toInt();
                var slut = start + SandJensen.Slider.marginSide;

                if (slut > SandJensen.Slider.marginMin) {
                    slut = SandJensen.Slider.marginMin;
                }

                SandJensen.Slider.effekt.start(start, slut);
            });
        }
    },

    TextBoxes: {
        initialize: function() {
            var selects = $$("#avancerede-sogeform select");
            for (var i = 0; i < selects.length; i++) {
                var select = selects[i];
                select.options[0].selected = true;
            }

            var inputs = $$("input.autorename");
            var form = null;

            if (inputs.length > 0) {
                for (var i = 0; i < inputs.length; i++) {
                    var input = inputs[i];

                    input.defaultValue = input.getAttribute("defaultval");
                    input.value = input.defaultValue;

                    $(input).addEvent("focus", function(e) {
                        var element = e.target || e.srcElement;
                        if (element.value == element.defaultValue) {
                            element.value = "";
                        }
                    });

                    $(input).addEvent("blur", function(e) {
                        var element = e.target || e.srcElement;
                        if (element.value == "") {
                            element.value = element.defaultValue;
                        }
                    });
                }

                form = inputs[0].form;
                form.trysubmit = function() {
                    var inputs = $$("input.autorename");
                    for (var i = 0; i < inputs.length; i++) {
                        var input = inputs[i];
                        if (input.value == input.defaultValue) {
                            input.value = "";
                        }
                    }

                    form.submit();
                };

            }
        }
    },

    SmoothDropDown: {
        openedDropDown: null,

        initialize: function() {
            //return;

            var selects = $$("select");

            // cycle trough the select fields
            for (var i = 0; i < selects.length; i++) {
                var select = selects[i];

                SandJensen.SmoothDropDown.buildStructure(select);
            }
        },

        buildStructure: function(select) {

            var id = "";
            if (select.id.length > 0) {
                id = select.id;
            } else if (select.name.length > 0) {
                id = select.name;
            } else {
                id = "nice-select-" + i;
            }

            select.id = id;

            var selectBox = document.createElement("div");
            selectBox.className = "select-container";
            selectBox.id = "select-for-" + id;

            //create and build div structure
            var selectBox = document.createElement("div");
            selectBox.className = "select-container";
            selectBox.id = "select-for-" + id;

            var selectedBox = document.createElement("div");
            selectedBox.className = "selected";

            var optionsBox = document.createElement("div");
            optionsBox.className = "options";

            optionsBox.id = "select-options-for-select-" + id;

            var optionsBoxUnderDiv = document.createElement("div");

            optionsBoxUnderDiv.style.position = "absolute";
            optionsBoxUnderDiv.style.overflow = "hidden";
            optionsBoxUnderDiv.style.height = "0px";
            optionsBoxUnderDiv.style.left = SandJensen.SmoothDropDown.findPosY(select) + 'px';
            optionsBoxUnderDiv.style.top = SandJensen.SmoothDropDown.findPosY(select) + 17 + 'px';
            optionsBoxUnderDiv.appendChild(optionsBox);

            var clearBox = document.createElement("div");
            clearBox.style.clear = "both";

            var optionsList = document.createElement("ul");

            selectBox.appendChild(selectedBox);
            selectBox.appendChild(optionsBoxUnderDiv);
            selectBox.appendChild(clearBox);


            optionsBox.selectObj = select;
            select.optionsBox = optionsBox;


            optionsBox.appendChild(optionsList);




            var selectedText = document.createElement("a");
            selectedText.className = "selected-text";
            selectedText.href = "#l";

            $(selectedText).addEvent("click", function(e) {
                var link = e.target || e.srcElement;

                selectBox.toggleOptions();

                if (e.preventDefault) e.preventDefault();
                e.returnValue = false;

            });
            //NiceForms._addEvent(selectedText, "click", NiceForms._onSelectedTextClick);

            var selectedString = select.options[select.selectedIndex].text;

            selectedText.appendChild(document.createTextNode(selectedString));
            selectedBox.appendChild(selectedText);

            //hide the select field
            select.style.display = "none";

            //insert select div
            select.parentNode.insertBefore(selectBox, select);

            //get select's options and add to options div
            for (var j = 0; j < select.options.length; j++) {
                var option = select.options[j];

                var optionLinkId = id + "-option-" + j;

                var optionLink = document.createElement("a");
                optionLink.href = "#";


                optionLink.appendChild(document.createTextNode(option.text));
                optionLink.optionObj = option;
                optionLink.id = optionLinkId;

                var optionListItem = document.createElement("li");
                optionListItem.appendChild(optionLink);

                if (option.selected) {
                    optionListItem.className = "selected";
                }

                optionsList.appendChild(optionListItem);

                $(optionLink).addEvent("click", SandJensen.SmoothDropDown.onListItemClick);
            }


            selectBox.fx = new Fx.Style(optionsBoxUnderDiv, 'height', { duration: 400 });
            selectBox.toggleOptions = function() {

                if (SandJensen.SmoothDropDown.openedDropDown != null && SandJensen.SmoothDropDown.openedDropDown != selectBox) {
                    SandJensen.SmoothDropDown.openedDropDown.toggleOptions();
                    return;
                }

                var height = optionsBoxUnderDiv.childNodes[0].offsetHeight;

                if (selectBox.fx.__state == "open") {
                    selectBox.fx.start(height + 10, 0).chain(function() {
                        selectBox.fx.__state = "closed";
                        SandJensen.SmoothDropDown.openedDropDown = null;
                    });
                } else {
                    SandJensen.SmoothDropDown.openedDropDown = selectBox;

                    var left = SandJensen.SmoothDropDown.findPosX(selectBox);
                    var top = SandJensen.SmoothDropDown.findPosY(selectBox) + 19;

                    if (document.all) {
                        if (selectBox.id.indexOf("advanced") != -1) {
                            //left += 1;
                            top += 1;
                        } else {
                            left += 0;
                            top += 1;
                        }
                    }

                    optionsBoxUnderDiv.style.left = left + 'px';
                    optionsBoxUnderDiv.style.top = top + 'px';

                    selectBox.fx.start(0, height + 10).chain(function() {
                        selectBox.fx.__state = "open";
                    });
                }
            };


        },

        findPosY: function(obj) {
            var posTop = 0;
            while (obj.offsetParent) {
                posTop += obj.offsetTop;
                obj = obj.offsetParent;
            }
            return posTop;
        },

        findPosX: function(obj) {
            var posLeft = 0;
            while (obj.offsetParent) {
                posLeft += obj.offsetLeft;
                obj = obj.offsetParent;
            }
            return posLeft;
        },

        onListItemClick: function(e) {
            var link = e.target || e.srcElement;
            var option = link.optionObj;
            var li = link.parentNode;
            var ul = li.parentNode;
            var optionsBox = ul.parentNode;
            var select = option.parentNode;
            var selectContainer = optionsBox.parentNode.parentNode;
            var selectedTextLink = selectContainer.childNodes[0].childNodes[0];


            for (var i = 0; i < ul.childNodes.length; i++) {
                ul.childNodes[i].className = "";
            }

            li.className = "selected";
            select.selectedIndex = option.index;
            selectContainer.toggleOptions();
            selectedTextLink.innerHTML = option.text;

            if (select.id == "advanced-search-make") {
                SandJensen.SmoothDropDown._ajaxUpdate(select);
            }

            if (e.preventDefault) e.preventDefault();
            e.returnValue = false;
        },

        _ajaxUpdate: function(select) {
            var req = XMLHttpRequest ? new XMLHttpRequest : new window.ActiveXObject('Microsoft.XMLHTTP');

            req.onreadystatechange = function() {

                if (req.readyState == 4) {

                    var splitArr = req.responseText.split(";");

                    var modelSelect = $("advanced-search-model");
                    var numberOfOptions = modelSelect.options.length - 1;
                    for (i = 0; i < numberOfOptions; i++) {
                        modelSelect.removeChild(modelSelect.options[1]);
                    }

                    for (var i = 0; i < splitArr.length; i++) {
                        modelSelect.options.add(new Option(splitArr[i], splitArr[i]));
                    }


                    var smoothContainer = $("select-for-advanced-search-model");
                    smoothContainer.parentNode.removeChild(smoothContainer);

                    SandJensen.SmoothDropDown.buildStructure(modelSelect);
                }
            };

            var selectedValue = select.options[select.selectedIndex].text;
            var url = "/BilModeller.ashx?maerke=" + encodeURIComponent(selectedValue);

            if ($("advanced-search-model").className.indexOf("tysk") != -1) {
                url += "&Tysk=true";
            }

            req.open("get", url, true);
            req.send(null);

        },

        _addEvent: function(obj, type, callbackFunction) {
            if (obj.addEvent) {
                obj.addEvent(type, callbackFunction);
            } else if (obj.attachEvent) {
                obj.attachEvent("on" + type, callbackFunction);
            } else {
                alert("NiceForms._addEvent failed.");
            }
        }


    },

    Picture360: {
        initialize: function() {

            var div = $("new-360-pictures");
            if (div) {
                var list = $$("#new-360-pictures p");
                var p1 = list[0];
                var p2 = list[1];
                var fx1 = p1.effect("opacity", { duration: 700 });
                var fx2 = p2.effect("opacity", { duration: 700 });

                fx1.set(0);
                fx2.set(0);

                var f = function() {

                    p1.style.display = "block";
                    p2.style.display = "none";
                    fx1.start(0, 1);
                    setTimeout(function() {
                        fx1.start(1, 0).chain(function() {
                            p2.style.display = "block";
                            p1.style.display = "none";
                            fx2.start(0, 1);
                            setTimeout(function() {
                                fx2.start(1, 0).chain(function() {
                                    f();
                                });
                            }, 5000);
                        });
                    }, 5000);
                };

                f();
            }

            var link = $('picture-in-360-link');
            if (link) {



                var fx = new Fx.Style('picture-in-360-link', 'color', { duration: 500 });


                var myFunc = function() {
                    fx.set('#000');
                    fx.start('#000', '#E40001').chain(function() {
                        fx.start('#E40001', '#000');
                    });
                };

                setInterval(myFunc, 1500);
            }
        }
    }


}




window.addEvent('domready', SandJensen.BilInfo.initialize.bind(SandJensen.BilInfo));
window.addEvent('domready', SandJensen.NyhedRotator.initialize.bind(SandJensen.NyhedRotator));
window.addEvent('domready', SandJensen.Galleri.initialize.bind(SandJensen.Galleri));
window.addEvent('domready', SandJensen.Slider.initialize.bind(SandJensen.Slider));
window.addEvent('domready', SandJensen.TextBoxes.initialize.bind(SandJensen.TextBoxes));
window.addEvent('domready', SandJensen.SmoothDropDown.initialize.bind(SandJensen.SmoothDropDown));
window.addEvent('domready', SandJensen.Picture360.initialize.bind(SandJensen.Picture360));












// JScript File

function placeFlash(fil, width, height)
{
	    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="' + width + '" height="' + height + '" >\n');
	    document.write('<param name="movie" value="/media/' + fil + '">\n');
	    document.write('<param name="quality" value="high">\n');	
	    document.write('<param name="wmode" value="transparent">\n');	
	    document.write('<embed src="/media/'+ fil + '" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" wmode="transparent" width="' + width + '" height="' + height + '">\n');
	    document.write('</embed>\n');	
	    document.write('</object>\n');
}
// JScript File

function placeFlashRaw(fil, width, height) {
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="' + width + '" height="' + height + '" >\n');
    document.write('<param name="movie" value="/media/' + fil + '">\n');
    document.write('<param name="quality" value="high">\n');
    document.write('<param name="wmode" value="transparent">\n');
    document.write('<embed src="' + fil + '" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" wmode="transparent" width="' + width + '" height="' + height + '">\n');
    document.write('</embed>\n');
    document.write('</object>\n');
}


function ValiderTilmeldingTilNyhedsmail(form, sprog) {
    var email1 = form.elements["email"].value;
    var email2 = form.elements["email2"].value;

    if (email1 != email2) {
        if (sprog == "de") alert("E-mails matcher ikke hinanden.");
        else alert("E-mails matcher ikke hinanden.");
        
        form.elements["email2"].focus();
        return false;
    }

    return true;
}





























var LightboxFrame = {

    init: function(options) {
        this.options = $extend({
            resizeDuration: 400,
            resizeTransition: false, // default transition
            initialWidth: 825,
            initialHeight: 640
        }, options || {});


        this.anchors = [];
        $each(document.links, function(el) {
            if (el.rel && el.rel.test(/^lightboxframe/i)) {
                el.onclick = this.click.pass(el, this);
                this.anchors.push(el);
            }
        }, this);


        this.eventKeyDown = this.keyboardListener.bindAsEventListener(this);
        this.eventPosition = this.position.bind(this);

        this.overlay = new Element('div', { 'id': 'lbOverlay' }).injectInside(document.body);

        this.center = new Element('div', { 'id': 'lbCenter', 'styles': { 'width': this.options.initialWidth, 'height': this.options.initialHeight, 'marginLeft': -(this.options.initialWidth / 2), 'display': 'none'} }).injectInside(document.body);
        this.image = new Element('iframe', {
            'id': 'lbFrame',
            'frameborder': 0,
            'src': '',
            'width': 818,
            'height': 590,
            'scrolling': 'no',
            'style': 'border:0;'

        }).injectInside(this.center);

        this.bottomContainer = new Element('div', { 'id': 'BottomContainer' }).injectInside(this.center);
        this.bottom = new Element('div', { 'id': 'lbBottom' }).injectInside(this.bottomContainer);
        new Element('a', { 'id': 'lbCloseLink', 'href': '#' }).injectInside(this.bottom).onclick = this.overlay.onclick = this.close.bind(this);
        new Element('div', { 'styles': { 'clear': 'both'} }).injectInside(this.bottom);

        this.fx = {
            overlay: this.overlay.effect('opacity', { duration: 500 }).hide(),
            bottom: this.bottom.effect('margin-top', { duration: 400 })
        };
    },

    click: function(link) {

        this.position();
        this.fx.overlay.start(0.8);
        this.setup(true);
        this.top = window.getScrollTop() + (window.getHeight() / 15);
        this.center.setStyles({ top: this.top, display: '' });
        var url = link.href;
        window.setTimeout(function() {
            var f = document.getElementById('lbFrame');
            if (f.src != url) f.src = url;
        },
        700);


try {
    var pageTracker = _gat._getTracker("UA-16323065-1");
    var carName = $$("#vis-bil-boks h1")[0].innerText;
    pageTracker._trackEvent("3D Billeder", "Klik", carName);
  }catch(err){}


        return false;
    },

    position: function() {
        this.overlay.setStyles({ 'top': window.getScrollTop(), 'height': window.getHeight() });
    },

    setup: function(open) {
        var elements = $A(document.getElementsByTagName('object'));
        elements.extend(document.getElementsByTagName(window.ie ? 'select' : 'embed'));
        elements.each(function(el) {
            if (open) el.lbBackupStyle = el.style.visibility;
            el.style.visibility = open ? 'hidden' : el.lbBackupStyle;
        });
        var fn = open ? 'addEvent' : 'removeEvent';
        window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);
        document[fn]('keydown', this.eventKeyDown);
        this.step = 0;
    },

    keyboardListener: function(event) {
        switch (event.keyCode) {
            case 27: case 88: case 67: this.close(); break;
        }
    },

    close: function() {
        for (var f in this.fx) this.fx[f].stop();
        this.center.style.display = 'none';
        this.fx.overlay.chain(this.setup.pass(false, this)).start(0);
        return false;
    }
};

window.addEvent('domready', LightboxFrame.init.bind(LightboxFrame));




