/*
Class: Land Detail Box
Used for displaying the Land Details for My Selection.
Thankyou Slimbox for the inspiraion for this little Diddy - http://www.digitalia.be/software/slimbox
Note:
The Detail Box requires an XHTML doctype.
Arguments:
element 	- the knob container
options 	- see Options below
data		- Contains the content to be displayed in the detail box
Options:
mode 		- either 'browse' or 'detail'. Defaults to "detail"
id			- The Holders ID name. Default is "detailHolder"
width		- Modal Box Width
height		- Modal Box Height
className	- Class name.
dataType	- 'Json'.
*/
var landDetail = new Class({
    options: {
        mode: 'details',
        id: 'detailHolder',
        width: 250,
        height: 250,
        className: null,
        dataType: Object,
        container: null,
        google: false,
        fixed: false,
        fixTop: 0,
        fixLeft: 0
    },
    initialize: function(el, options, data) {

        this.eventKeyDown = this.keyboardListener.bindAsEventListener(this);
        this.eventPosition = this.positions.bind(this);

        this.setOptions(options);

        this.options.container = $(el);

		
		
        if (!this.options.fixed) marginLeft = -(this.options.width / 2);
        else marginLeft = this.options.fixLeft;

        this.browseStyle = { 'width': this.options.width, 'height': this.options.height, 'marginLeft': marginLeft };

        if ($(this.options.id + '_content')) $(this.options.id).empty();
        //Holder for the
        if (this.options['google']) {
            this.mapView = new Element('div', { 'id': 'mapView' }).injectInside($(el));
            this.fullView = new Element('div', { 'id': 'fullMap' }).injectInside(this.mapView);
            this.mapFX = this.mapView.effect('height', { duration: 500, transition: Fx.Transitions.quartInOut });
            //this.mapFX = new Fx.Slide(this.mapView);
            if (this.options.mode != 'map') {
                if (window.ie) this.mapView.addClass('none');
                //if (window.ie) this.mapView.removeClass('none');
                this.mapFX.hide();
            }
        }

        // this.holder 	= new Element('div', {'id': this.options.id+'_content'}).setHTML(data).addClass(this.options.mode + ' none').injectAfter(this.mapView);

        this.holder = new Element('div', { 'id': this.options.id + '_content' }).setHTML(data).injectInside($(el));

        this.header = new Element('div', { 'id': 'header' }).injectInside(this.holder);
        this.closeButt = new Element('a', { 'class': 'closeButton' }).setHTML('close').injectInside(this.header);
        this.header_ul = new Element('ul').injectInside(this.header);
        this.header_li1 = new Element('li').injectInside(this.header_ul);
        this.lotName = new Element('h4').injectInside(this.header_li1);
        this.price = new Element('li').addClass('price').injectInside(this.header_ul);
        this.header_li3 = new Element('li').addClass('controls').injectInside(this.header_ul);
        this.interest = new Element('a', { 'id': 'regInterest' }).addClass('interest').setHTML('Register Interest').injectInside(this.header_li3)
        // this.share		= new Element('a', {'title':'Share with a friend'}).addClass('share').setHTML('Share Details').injectInside(this.header_li3);
        this.Save = new Element('a', { 'id': 'actionButton' }).setHTML('Save to MyList').injectInside(this.header_li3);

        this.middle = new Element('div', { 'id': 'middle' }).injectInside(this.holder);
        this.middleHold = new Element('div', { 'id': 'middleHolder' }).injectInside(this.middle);

        this.extras = new Element('p').addClass('extras').injectInside(this.middleHold);
        this.Status = new Element('span').addClass('status').setHTML('Property Status:&nbsp;&nbsp;').injectInside(this.extras);
        this.statMark = new Element('img', { 'width': 12, 'height': 12 }).injectInside(this.Status)
        this.StatusText = new Element('span').injectInside(this.Status);
        this.Size = new Element('span').addClass('size').injectInside(this.extras);
        this.envelope = new Element('span').addClass('envelope').injectInside(this.extras);

        this.detailMenu = new Element('div', { 'id': 'detailMenu' }).injectInside(this.middleHold);
        this.menu = new Element('ul').injectInside(this.detailMenu);
        this.menu1 = new Element('li', { 'id': 'menu_overview' }).addClass('current').injectInside(this.menu);
        this.menu1_link = new Element('a', { 'href': 'javascript:;' }).setHTML('Overview').injectInside(this.menu1);
        this.menu1_link.onclick = this.viewChange.bind(this, [this.menu1, 'overview']);
        this.link_marker = new Element('img', { 'src': config['baseURI'] + 'SiteAssets/images/content/g-detailMenu_marker.gif' }).injectInside(this.menu1_link);
        this.menu2 = new Element('li', { 'id': 'menu_gallery' }).injectInside(this.menu);
        this.menu2_link = new Element('a', { 'href': 'javascript:;' }).setHTML('Gallery').injectInside(this.menu2);
        this.menu2_link.onclick = this.viewChange.bind(this, [this.menu2, 'gallery']);
        this.marker2 = this.link_marker.clone().injectInside(this.menu2_link);
        // this.menu3		= new Element('li').injectInside(this.menu);
        // this.menu3_link	= new Element('a').setHTML('Show on Map').injectInside(this.menu3);
        this.menu4 = new Element('li', { 'id': 'menu_specifications' }).injectInside(this.menu);
        this.menu4_link = new Element('a', { 'href': 'javascript:;' }).setHTML('Specifications').injectInside(this.menu4);
        this.menu4_link.onclick = this.viewChange.bind(this, [this.menu4, 'specifications']);
        this.marker3 = this.link_marker.clone().injectInside(this.menu4_link);

        this.detailCont = new Element('div', { 'id': 'detailContent' }).injectAfter(this.detailMenu);
        this.contentHold = new Element('div').addClass('contentPanel').injectInside(this.detailCont);

        this.lotTitle = new Element('h4').injectInside(this.contentHold);
        this.descript = new Element('p', { 'id': 'descript' }).injectInside(this.contentHold);
        // this.pdf		= new Element('span').addClass('downloadPDF').injectInside(this.extras);

        this.imgPanel = new Element('div', { 'id': 'imagePanel' }).injectBefore(this.contentHold);
        this.map = new Element('div', { 'id': 'map' }).injectInside(this.imgPanel);
        this.loadTxt = new Element('span', { 'id': 'maploading' }).setHTML('Loading the Map for here').injectInside(this.map);
        this.image = new Element('img').injectInside(this.imgPanel);


        //actions Panel
        this.actions = new Element('div').addClass('actionsPanel').injectAfter(this.middleHold);
        this.actPan1 = new Element('div').addClass('actPan1').setHTML('&nbsp;').injectInside(this.actions);
        this.actPan3 = new Element('div').addClass('actPan3').injectInside(this.actions);
        this.actPan2 = new Element('div').addClass('actPan2').setHTML('&nbsp;').injectInside(this.actions);
        this.pdf_file = new Element('a', { 'href': '#' }).addClass('downloadPDF').setHTML('Download PDF').injectInside(this.actPan2);
        this.control = new Element('span').setHTML('Images:&nbsp;&nbsp;').injectInside(this.actPan3);
        this.viewMap = new Element('a', { 'href': 'javascript:void(0);' }).addClass('viewMap').setHTML('Google Map').injectInside(this.actPan3);
        this.viewMap.onclick = this.viewChange.bind(this, [this.menu1, 'overview']);
        this.viewPic = new Element('a', { 'href': 'javascript:void(0);' }).addClass('viewImage').setHTML('Land Size').injectInside(this.actPan3);
        this.viewPic.onclick = this.viewChange.bind(this, [this.menu1, 'overview']);

        //Detail Panel Footer
        this.footer = new Element('div', { 'id': 'footer' }).injectAfter(this.middle);
        //Commented out refer to bug 167		
        //this.fits		= new Element('p').addClass('fits').setHTML('Saved Homes Fit: <a href="#">The Aldinga</a> <a href="#">Glenferrie</a>').injectInside(this.footer);
        this.fits		= new Element('p').addClass('fits').setHTML('&nbsp;').injectInside(this.footer);
         if (this.options.lookedAt) {
            this.looked = new Element('p').addClass('looked').setHTML('People that looked at the this Home also looked at').injectInside(this.footer);
        }
        //Overlay used in browse mode
        this.overlay = new Element('div', { 'id': this.options.id + '_overlay' }).injectInside(document.body);


        this.fx = {
            overlay: this.overlay.effect('opacity', { duration: 500 }).hide(),
            holder: this.holder.effect('opacity', { duration: 500 }).hide(),
            control: this.imgPanel.effect('opacity', { duration: 500 }).set(0)
        };

        if (this.options.mode == 'detail' || this.options.mode == 'browse') {
            // this.map.setStyle('display', 'block');
            if (this.options.mode == 'detail') $('itemNav').removeClass('none');
            this.fx.control.set(1);
        }
        if (this.options.mode == 'browse') {
            this.holder.setStyles(this.browseStyle);
            // this.fx.holder.hide();
        }
        if (this.options.mode == 'map') {
            // this.mapView.removeClass('none');
            // this.mapFX.start(300);
            // 
            this.fx.control.set(1);
        }

    },
    updateDetail: function(obj, key) {
        // $(this.options.id).empty();

        //bind Event to Links
        this.menu1_link.removeEvents('click').addEvent('click', function() {
            this.switchContent('overview', obj);
        } .bind(this));
        if (obj.ALOT_nGalleryCount > 0) {
            this.menu2.setStyle('display', 'block');
            this.menu2_link.removeEvents('click').addEvent('click', function() { this.switchContent('gallery', obj) } .bind(this));
        } else {
            this.menu2.setStyle('display', 'none');
        }
        this.menu4_link.removeEvents('click').addEvent('click', function() { this.switchContent('specifications', obj) } .bind(this));
        this.viewMap.removeEvents('click').addEvent('click', function() {
            this.switchContent('viewMap', obj);
        } .bind(this));
        if (config.AssetVersion == 2) {
            if (obj.location) {
                this.viewPic.removeEvents('click').addEvent('click', function() {
                    this.switchContent('viewImage', obj);
                } .bind(this));
                this.viewPic.setStyle("display", "inline");
            } else {
                this.viewPic.setStyle("display", "none");
            }
        }

        this.lotName.setHTML(obj.LOT_strName);
        this.price.setHTML(obj.LOT_mPrice);
        this.Size.setHTML('Size: ' + obj.lot_darea + 'm&sup2;');
        this.statMark.setProperty('src', config['baseURI'] + 'SiteAssets/images/content/list/bkgd-' + utils.cleanString(' ', obj.SLST_strName.toLowerCase()) + 'Marker.png')
        this.StatusText.addClass(obj.SLST_strName.toLowerCase()).setHTML('&nbsp;&nbsp;' + obj.SLST_strName);

        //this.lotTitle = new Element('h4').injectInside(this.contentHold);
        if ('LOT_strOverviewTitle' in obj) { this.lotTitle.setText(obj.LOT_strOverviewTitle); this.lotTitle.removeClass('none'); }
        else {
            this.lotTitle.addClass('none');
        }


        this.descript.setHTML(obj.Lot_strOverviewTrimmed);

        // -------- Update menu links ---------
        // ------------- By Ross --------------
        // -----------  24.06.2008 ------------
        //this.menu4_link.setProperty('href', '../pdf/createpdf.aspx?param=3,'+  obj.LOT_nId);
        // ------------------------------------
        if (obj.SLST_strName.toLowerCase() == 'sold') {
            this.header_li3.addClass('inactive').setOpacity(0.5);

            $$('#header li.controls a').each(function(el) {
                el.setProperty('title', '').removeClass('registered').removeClass('saved');
            });
            this.Save.onclick = function() { };
            this.interest.onclick = function() { };
        } else {
            this.header_li3.removeClass('inactive').setOpacity(1);
            if (myList.list != null && myList.list.LandIds.contains(obj.LOT_nId.toInt()) == true) {
                this.Save.setHTML('Saved').addClass('saved').setProperty('title', obj.LOT_strName + ' has been Saved').onclick = function() { }; //.setProperty('onclick', 'mySelection.Delete(\'LotIds\', '+obj.LOT_nId+', \''+obj.LOT_strName+'\')');
            } else {
                // this.Save.empty();
                this.Save.setHTML('Save').removeClass('saved').setProperty('title', 'Save ' + obj.LOT_strName).onclick = function() {
                    mySelection.save(obj.LOT_nId, obj.LOT_strName);
                };
            }
            if (Site.sUser.uDetails()) {
                if (obj.iRegistered.toInt() == 1) {
                    this.interest.addClass('registered').setProperty('title', 'You have registered interest in ' + obj.LOT_strName).onclick = this.actionRegister.bind(this, true);
                } else {
                    this.interest.removeClass('registered').setProperty('title', 'Register your interest in ' + obj.LOT_strName).onclick = this.actionRegister.bind(this, false);
                }
                $$('.detailLabel-tip').each(function(el) { el.remove(); });
            } else {
                this.interest.removeClass('registered').setProperty('title', 'Sign up or Sign In::to Register Interest');
                //Setting the toolTip for Register Interest.
                $$('.detailLabel-tip').each(function(el) { el.remove(); });
                var Tips1 = new Tips($$(this.interest), {
                    offsets: { 'x': -27, 'y': -68 },
                    className: 'detailLabel',
                    fixed: true
                });
            }
        }
        //this.pdf_file.setProperty('href', 'createPDF.aspx?uid='+obj.LOT_nId);
        //this.pdf_file.setProperty('href', '../pdf/createpdf.aspx?param=3,' + obj.LOT_nId);
        //Initialize pdf links
        downloadPDFRecover();
        this.pdf_file.removeEvents('click').addEvent('click', function() {
            if (this.hasClass('downloadPDF')) {
                window.location.href = '../pdf/createpdf.aspx?param=3,' + obj.LOT_nId;
                timeout = setTimeout("downloadPDFRecover()", 10000);
                //disable link here:
                this.removeClass('downloadPDF').addClass("downloadPDFdisabled").setText('Downloading PDF ...');
            }
        });
        if (config.AssetVersion == '1') {
            this.image.setProperty('src', config['baseURI'] + 'Utilities/GenerateImage.aspx?path=../Assets/LOTs/' + obj.LOT_nId + '/' + obj.ALOT_strFileName + '&w=300&h=240&mode=resizefit');
            this.image.removeEvents('click').addEvent('click', function() { Lightbox.show(config['baseURI'] + 'Assets/LOTs/' + obj.LOT_nId + '/' + obj.ALOT_strFileName, obj.LOT_strName); })
        } else {
            this.image.setProperty('src', config['baseURI'] + 'Utilities/GenerateImage.aspx?path=' + obj.location + '&w=300&h=240&mode=resizefit');
            this.image.removeEvents('click').addEvent('click', function() { Lightbox.show(obj.location, obj.LOT_strName); })
        }
        //this.getExtras(obj.LOT_nId, 'looked');

        //Similar Lots (Related lots)
        if (this.options.lookedAt) {
            this.looked.setHTML('Popular land: <a href="#">' + obj.tblHits[0].HIT_LOT_strName + '</a> and <a href="#">' + obj.tblHits[1].HIT_LOT_strName) + '</a>';
        }
        //Commented out refer to bug 167
        this.getExtras(obj.LOT_nId, 'fits');

        var registered = false;

        if (obj.iRegistered.toInt() == 1 || obj.SLST_strName.toLowerCase() == 'sold') {
            registered = true;
        }
        //sending View Data to the database for Viewed History
        this.addView(3, obj.LOT_nId.toInt(), obj.LOT_strName, registered);

        if (this.options.mode == 'browse') {
            this.setup(true);
            this.positions();
            this.fx.overlay.start(0.15);
            this.closeButt.onclick = this.close.bind(this);
            this.overlay.onclick = this.close.bind(this);
        }
        if (this.options.mode == 'map') this.map.addClass('none');

        if (Land.currentItem != undefined) Land.currentItem = key;

        this.holder.removeClass('none')
        this.fx.holder.start(1);

        //Set default view to overview
        this.switchContent('overview', obj);
        this._currentSection = 'overview';
        this.viewChange(this.menu1, 'overview');
    },
    nullEvent: function() {

    },
    changeMode: function(mode) {

        // this.holder.removeClass(this.options.mode).addClass(mode);

        this.options.mode = mode;

        switch (mode) {
            case 'browse':
                // if($('pageNav_top').getStyle('display') == 'none') $('pageNav_top').setStyle('display','block');
                this.holder.setStyles(this.browseStyle)//.addClass('none');
                this.mapView.addClass('none');
                this.map.setStyle('display', 'block');
                this.fx.holder.hide();
                break;

            case 'detail': case 'map':
                // this.holder.setProperty('style', ' ');
                this.holder.setStyles({ 'width': 'auto', 'marginLeft': 0, 'height': 'auto' });

                this.mapView.removeClass('none');

                this.map.setStyle('display', 'block');
                // this.mapView.setStyle('display', 'block');

                if (mode == 'map') {
                    this.map.setStyle('display', 'none');
                    if (window.ie) this.mapView.removeClass('none');
                    this.mapFX.start(300);
                    Land.mainMap.moveMap([Land.lotData[Land.currentItem]['posn'][0], Land.lotData[Land.currentItem]['posn'][1]], 17);
                } else {
                    if (window.ie) this.mapView.addClass('none');
                    this.mapFX.start(0);
                }

                if (mode == 'detail' && Land.detailMap) {
                    Land.detailMap.createMarker(Land.lotData[Land.currentItem]);
                    Land.detailMap.moveMap([Land.lotData[Land.currentItem]['posn'][0], Land.lotData[Land.currentItem]['posn'][1]], 17);
                }

                break;
        }
    },
    getExtras: function(key, type) {
        switch (type) {
            case 'looked':
                var url = config['baseURI'] + config['viewedLots'] + '?ObjectId=3&PrimaryKey=' + key;
                var toFill = this.looked;
                break;
            case 'fits':
                var url = config['baseURI'] + config['ViewLotHomes'] + '?LotId=' + key;
                var toFill = this.fits;
                break;
        }

        new Ajax(url, {
            method: 'post',
            update: toFill
			// onComplete: function() { 
				// var Links = toFill.getElements('a');
				
				// alert(Links)
				
				// Links.each(function(link){
					// alert(link.href);
				// })
			// }
        }).request();
    },
    addView: function(object, key, strName, registered) {
        //Sending home information to the SOXC panel
        if (Site.sUser) {
            if (!registered && Site.sUser.regProcess != 2) Site.sUser.updateRegister(object, key, strName, { estateName: EstateName });
            Site.sUser.showAgent(object, key);
        }
        var URI = config['baseURI'] + config['addHit'];
        var query = 'ObjectId=' + object + '&PrimaryKey=' + key;
        var myXHR = new XHR({ method: 'get' }).send(URI, query);
    },
    actionRegister: function(stopAction) {
        if (stopAction == true) {
            return;
        } else {
            if (Site.sUser.uDetails() && Site.sUser.regProcess == 1) {
                Site.sUser.actionRegInterest(1);
                if (this.options.mode == 'browse') this.close();
            }
        }
    },
    positions: function() {
        this.overlay.setStyles({ 'top': window.getScrollTop(), 'height': window.getHeight() });
        if (!this.options.fixed || window.getScrollTop() > this.options.fixTop) {
            this.top = (window.getHeight() / 2) - (this.options.height / 2) + window.getScrollTop();
        } else {
            this.top = this.options.fixTop;
        }
        this.holder.setStyles({ top: this.top });
    },
    setup: function(open) {
        var fn = open ? 'addEvent' : 'removeEvent';
        window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);
        document[fn]('keydown', this.eventKeyDown);
    },
    keyboardListener: function(event) {
        switch (event.keyCode) {
            case 27: this.close(); break;
        }
    },
    close: function(args) {
        this.holder.addClass('none');
        this.fx.holder.start(0);
        this.fx.overlay.start(0);
        this.setup(false);
    },
    closeOverlay: function() {
        this.fx.overlay.start(0);
        return;
    },
    viewChange: function(el, view) {
        $$('#detailMenu li').removeClass('current');
        el.addClass('current');
    },
    switchContent: function(sec, obj) {

        if (this._currentSection == sec) return;

        //Clear
        this.detailCont.firstChild.setStyle("display", "block");
        //this.contentHold.empty();
        this.descript.empty();

        this._currentSection = sec;

		this.contentHold.addClass('noBackground');

        //Dispaly
        switch (sec) {
            case 'overview':
                this.setOverview(obj);
				this.contentHold.removeClass('noBackground');
                this.actPan3.setStyle("display", "block");
                break;
            case 'viewMap':
                if ($('map').getStyle('display') == 'none') $('map').setStyle('display', 'block');
                //                this.descript.empty();
                //                if (!$('descript')) this.descript = new Element('p', { 'id': 'descript' }).injectInside(this.contentHold);
                //                this.descript.setHTML(obj.Lot_strOverviewTrimmed);
                //                this.viewChange.bind(this, [this.menu1, 'overview']);
                this.setOverview(obj);
                this.actPan3.setStyle("display", "block");
                break;
            case 'viewImage':
                $('map').setStyle('display', 'none');
                //                if (!$('descript')) this.descript = new Element('p', { 'id': 'descript' }).injectInside(this.contentHold);
                //                this.descript.setHTML(obj.Lot_strOverviewTrimmed);
                //                this.viewChange.bind(this, [this.menu1, 'overview']);
                this.setOverview(obj);
                this.actPan3.setStyle("display", "block");
                break;
            case 'specifications':
                this.detailCont.firstChild.setStyle("display", "none");
                //this._specHeader = new Element('h4').setHTML('Specifications').injectInside(this.contentHold);
                this.contentHold.setHTML('Specifications');
                var SpecificationsHtml = 'Please click the link below to download specifications: ';
                if (!$('descript')) this.descript = new Element('p', { 'id': 'descript' });
                this.descript.setHTML(SpecificationsHtml);
                this.descript.injectInside(this.contentHold);
                var specificationsLink = new Element('a', { 'href': 'javascript:void(0)' }).setText('Download').injectInside(this.descript);
                //Initialize pdf links
                downloadPDFRecover2();
                specificationsLink.removeEvents('click').addEvent('click', function() {
                    if (this.getText() == "Download") {
                        window.location.href = '../pdf/createpdf.aspx?param=3,' + obj.LOT_nId;
                    }
                    timeout = setTimeout("downloadPDFRecover2()", 10000);
                    //disable link here:
                    this.setText('Downloading...').setStyle('color', '#aaa');
                });
                this.viewChange.bind(this, [this.menu4, 'specifications']);
                this.actPan3.setStyle("display", "none");
                break;
            case 'gallery':
                this.detailCont.firstChild.setStyle("display", "none");
                this.contentHold.setHTML('<img src="../SiteAssets/images/myListloader.gif" width="16" height="16" alt="" /> Loading Gallery');

                var URI = config['baseURI'] + config['LandGalleryReturn'] + '?LotId=' + obj.LOT_nId;
                var galleryObj = new Json.Remote(URI, {
                    method: 'get',
                    onComplete: this.buildGallery.bind(this)
                }).send();
                this.actPan3.setStyle("display", "none");
                break;
            default:
                break;
        }
    },
    buildGallery: function(obj) {
        this.viewChange.bind(this.menu2, 'gallery');
        this.contentHold.empty();
        this._gallHolder = new Element('div', { 'id': 'gallHolder' }).injectInside(this.contentHold);
        if (obj.root.NewDataSet.tblGallery.length > 0) {
            obj.root.NewDataSet.tblGallery.each(function(item, index) {
                this.imageDiv = new Element('div').setStyles({ 'width': 160, 'float': 'left', 'margin-bottom': 10 }).injectInside(this._gallHolder);
                if (config.AssetVersion == 1 && item.ALOT_strFilename.substr(0, 4).toLowerCase() != 'http') {
                    this.galleryImage = new Element('img').setProperty('src', '../Utilities/GenerateImage.aspx?path=../' + item.ALOT_strFilename + '&w=150&h=120&mode=resizefit').injectInside(this.imageDiv);
                    this.galleryImage.removeEvents('click').addEvent('click', function() { Lightbox.show('../' + item.ALOT_strFilename, ' ' + item.ALOT_strTitle); })
                    new Element('br').injectInside(this.imageDiv);
                    this.galleryTitle = new Element('a').setProperty('a', 'javascript:void(0);').setText(item.ALOT_strTitle).injectInside(this.imageDiv);
                    this.galleryTitle.removeEvents('click').addEvent('click', function() { Lightbox.show('../' + item.ALOT_strFilename, ' ' + item.ALOT_strTitle); })
                } else {
                    this.galleryImage = new Element('img').setProperty('src', '../Utilities/GenerateImage.aspx?path=' + item.ALOT_strFilename + '&w=150&h=120&mode=resizefit').injectInside(this.imageDiv);
                    this.galleryImage.removeEvents('click').addEvent('click', function() { Lightbox.show(item.ALOT_strFilename, ' ' + item.ALOT_strTitle); })
                    new Element('br').injectInside(this.imageDiv);
                    this.galleryTitle = new Element('a').setProperty('a', 'javascript:void(0);').setText(item.ALOT_strTitle).injectInside(this.imageDiv);
                    this.galleryTitle.removeEvents('click').addEvent('click', function() { Lightbox.show(item.ALOT_strFilename, ' ' + item.ALOT_strTitle); })
                }
            }, this);
        } else {
            this.imageDiv = new Element('div').setStyles({ 'width': 160, 'float': 'left', 'margin-bottom': 10 }).injectInside(this._gallHolder);
            if (config.AssetVersion == 1 && obj.root.NewDataSet.tblGallery.ALOT_strFilename.substr(0, 4).toLowerCase() != 'http') {
                this.galleryImage = new Element('img').setProperty('src', '../Utilities/GenerateImage.aspx?path=../' + obj.root.NewDataSet.tblGallery.ALOT_strFilename + '&w=150&h=120&mode=resizefit').injectInside(this.imageDiv);
                this.galleryImage.removeEvents('click').addEvent('click', function() { Lightbox.show('../' + obj.root.NewDataSet.tblGallery.ALOT_strFilename, obj.LOT_strName + ': ' + obj.root.NewDataSet.tblGallery.ALOT_strTitle); })
                new Element('br').injectInside(this.imageDiv);
                this.galleryTitle = new Element('a').setProperty('a', 'javascript:void(0);').setText(obj.root.NewDataSet.tblGallery.ALOT_strTitle).injectInside(this.imageDiv);
                this.galleryTitle.removeEvents('click').addEvent('click', function() { Lightbox.show('../' + obj.root.NewDataSet.tblGallery.ALOT_strFilename, obj.LOT_strName + ': ' + obj.root.NewDataSet.tblGallery.ALOT_strTitle); })
            } else {
                this.galleryImage = new Element('img').setProperty('src', '../Utilities/GenerateImage.aspx?path=' + obj.root.NewDataSet.tblGallery.ALOT_strFilename + '&w=150&h=120&mode=resizefit').injectInside(this.imageDiv);
                this.galleryImage.removeEvents('click').addEvent('click', function() { Lightbox.show(obj.root.NewDataSet.tblGallery.ALOT_strFilename, obj.LOT_strName + ': ' + obj.root.NewDataSet.tblGallery.ALOT_strTitle); })
                new Element('br').injectInside(this.imageDiv);
                this.galleryTitle = new Element('a').setProperty('a', 'javascript:void(0);').setText(obj.root.NewDataSet.tblGallery.ALOT_strTitle).injectInside(this.imageDiv);
                this.galleryTitle.removeEvents('click').addEvent('click', function() { Lightbox.show(obj.root.NewDataSet.tblGallery.ALOT_strFilename, obj.LOT_strName + ': ' + obj.root.NewDataSet.tblGallery.ALOT_strTitle); })
            }
        }
    },
    setOverview: function(obj) {
        this.contentHold.setText('');
        if ($('gallHolder')) $('gallHolder').remove();
        this.detailCont.firstChild.setStyle("display", "block");
        this.lotTitle = new Element('h4').injectInside(this.contentHold);
        this.descript = new Element('p', { 'id': 'descript' }).injectInside(this.contentHold);
        if ('LOT_strOverviewTitle' in obj) { this.lotTitle.setText(obj.LOT_strOverviewTitle); this.lotTitle.removeClass('none'); }
        else {
            this.lotTitle.addClass('none');
        }
        this.descript.setHTML(obj.Lot_strOverviewTrimmed);
        this.viewChange.bind(this, [this.menu1, 'overview']);
    }
});
landDetail.implement(new Events);
landDetail.implement(new Options);

function downloadPDFRecover() {
    var link = $('middle').childNodes[1].childNodes[2].childNodes[1];

    if(link) link.removeClass('downloadPDFdisabled').addClass("downloadPDF").setText('Download PDF');
}

function downloadPDFRecover2() {
    var des = $('descript').childNodes[1];

    if (des) des.setText('Download').setStyle('color', '#008BDD');
}
