﻿if(typeof adclip.clips.highlightBoxCustom=="undefined" && !adclip.clips.highlightBoxCustom){


        // translations 
        adclip.addTranslations('pt-PT',
                {
                    'SEE_AD': 'Ver an&uacute;ncio',
                    'CLASSIFIEDS_ADCLIP': 'Classificados AdClip'
                });

        adclip.addTranslations('en-US',
                {
                    'SEE_AD': 'See ad',
                    'CLASSIFIEDS_ADCLIP': 'AdClip Classified Ads'
                });


                adclip.clips.highlightBoxCustom = function(objName, config) {
                    this.objName = objName;
                    this.config = config;
                    this.id = adclip.clips.highlightBoxCustom.prototype.idCount++;
                    this.elementID = 'bc_HighlightBoxCustom' + this.id;
                    this.UI = {};
                    this.values = {};

                    this.publicValues = {
                        'elementID': this.elementID
                    };

                    this.initialize();
                }

        adclip.clips.highlightBoxCustom.prototype.idCount = 0;
        adclip.clips.highlightBoxCustom.prototype.instance = [];
        adclip.clips.highlightBoxCustom.prototype.imgPath = adclip.vars.baseImagePath;
        adclip.clips.highlightBoxCustom.prototype.styles = {};



        adclip.clips.newHighlightBoxCustom = function(config) {
            var c = adclip.clips.highlightBoxCustom.prototype.idCount;
            adclip.clips.highlightBoxCustom.prototype.instance[c] = new adclip.clips.highlightBoxCustom("adclip.clips.highlightBoxCustom.prototype.instance[" + c + "]", config);
            adclip.clips.highlightBoxCustom.prototype.instance[c].setAds();

            return adclip.clips.highlightBoxCustom.prototype.instance[c].publicValues;

        };


        adclip.clips.highlightBoxCustom.prototype.initialize = function(){


            //START: compatibility
            if (adclip.isTrue(this.config.resultPage)) this.config.opt_urlTarget = this.config.resultPage
            //END: compatibility


            if (adclip.isTrue(this.config.titleDetail)) {
                this.config.titleDetail = this.config.titleDetail.toLowerCase();
            }

            var cssClass = adclip.isTrue(this.config.cssClass) ? this.config.cssClass : ''
            
            if (adclip.isTrue(this.config.resultPage)) {
                this.config.opt_target = false;
            } else {
                this.config.opt_target = true;
                this.config.opt_urlTarget = "";
            }
            
            
            if (adclip.defLang == '') adclip.defLang = this.config.language;
            
        
            // add in doom
            document.write('<div id="' + this.elementID + '" class="bc_HighlightBoxCustom ' + cssClass + '"></div>');

            this.UI.app = document.getElementById(this.elementID);
        
        };

        adclip.clips.highlightBoxCustom.prototype.pubShow = function(opt){
            if(opt == 1){
                this.UI.pub.style.display = "block";
            } else {
                this.UI.pub.style.display = "none"
            }
        }

        adclip.clips.highlightBoxCustom.prototype.getElementsByClass = function(searchClass, node, tag) {
            var classElements = new Array();
            if (node == null)
                node = document;
            if (tag == null)
                tag = '*';
            var els = node.getElementsByTagName(tag);
            var elsLen = els.length;
            var pattern = new RegExp('(^|\\\\s)' + searchClass + '(\\\\s|$)');
            for (i = 0, j = 0; i < elsLen; i++) {
                if (pattern.test(els[i].className)) {
                    classElements[j] = els[i];
                    j++;
                }
            }
            return classElements;
        }

        adclip.clips.highlightBoxCustom.prototype.draw = function() {
            var tlp = document.getElementById(this.config.elementIDtemplate);
            tlp.style.display = 'none';
            var tItem = this.getElementsByClass('items', tlp)[0].innerHTML;
            var tMaster = tlp.innerHTML;


            this.UI.app.innerHTML = tMaster;
            var rItems = this.getElementsByClass('items', this.UI.app)[0];
            rItems.innerHTML = '';

            var data = this.values.ads.data;

            var items = '';

            for (c = 0; c < data.length; c++) {
                var item = tItem;
                var showAd = '';
                var shortTitle = adclip.url.decode(data[c].shortTitle);
                var description = adclip.url.decode(data[c].description);
                var price = adclip.url.decode(data[c].price);
                var title = adclip.url.decode(data[c].title);
                var openNewWindowHTMLtarget = adclip.isTrue(this.config.openNewWindow) ? '_blank' : '_self';


                switch (this.config.titleDetail) {
                    case 'long': showAd = adclip.t("SEE_AD") + ': ' + shortTitle + ' - ' + description; break;
                    case 'short': showAd = adclip.t("SEE_AD") + ': ' + description; break;
                    default: showAd = adclip.t("SEE_AD"); break;
                }

                if (adclip.client.ie) showAd = '"' + showAd + '"';

                item = item.replace(/@SHORT_TITLE@/gi, shortTitle);
                item = item.replace(/@SHOW_AD@/gi, showAd);
                item = item.replace(/@IMAGE_PATH@/gi, adclip.vars.baseURL + data[c].imagePath);
                item = item.replace(/@DESCRIPTION@/gi, description);
                item = item.replace(/@PRICE@/gi, price);
                item = item.replace(/@TITLE@/gi, title);
                item = item.replace(/@URL@/gi, this.makeURL(data[c].publickey));
                var classCSS = ('item' + (c + 1) + ' ') + ((c + 1) % 2 == 0 ? 'even' : 'odd');
                item = item.replace(/@ODD_OR_EVEN@/gi, (adclip.client.ie ? '"' + classCSS + '"' : classCSS));
                items += item;
            }

            var textType = false;

            items = items.replace(/@TARGET@/gi, openNewWindowHTMLtarget);

            var rItems = this.getElementsByClass('items', this.UI.app)[0];
            rItems.innerHTML = items;

        };
        
        
        adclip.clips.highlightBoxCustom.prototype.makeURL = function(publicKey){
            
            
           return adclip.url.maker('detail',
                               this.config,
                               {
                               'public': publicKey,
                               'hlb': 1,
                               'hitsrc': adclip.vars.hitSource['HIGHLIGHT']
                               },
                               false);
        }
        
        
        adclip.clips.highlightBoxCustom.prototype.setAds = function(){
            var params = "?code=highlightboxcustom&task=get&language=" + this.config.language + "&region1=" + this.config.idRegion1 + "&category=" + this.config.idCategory + "&idSize=" + this.config.idSize + "&instance=" + this.id + "&clip=" + this.config.publicKey + (adclip.isTrue(this.config.searchExpression) ? '&expression=' + adclip.url.encode(this.config.searchExpression) : '') + "&noi=" + this.config.numberOfAds + ((adclip.isTrue(this.config.geo)) ? "&geo=1" : '') + "&time=" + adclip.time.mktime();
            
            adclip.fajax.getObj(adclip.vars.baseClipsScripts + params);
            
        }
        
        


        
}