if(typeof adclip=="undefined" && !adclip) {

        
        var adclip = {'tmp':{}, 'client': {}, 'url': {}, 'clips': {}, 'element': {}, 'events': {}, 'vars': {}, 'ajax':{}, 'utils':{}, 'fajax':{}, 'time':{}, 'asset':{}, 'array':{}, 'color':{}, 'string':{}};
        adclip.defLang = '';
        
        // goPage
        adclip.vars.goPage = {
                
                'search':'004.aspx',
                'advancedsearch':'102.aspx',
                'detail':'/ads/{Source}/css{CustomCss}/cat{CustomCat}/r_{Region}/l_{RegionLevel}/{Language}/pk_{PubKey}/Ad/detail/{AdPubKey}.htm',
                'login':'UserArea/006.aspx',
                'addad':'Ads/002.aspx',
                'addclip':'Clips/064.aspx',
                'adclipresult':'core2.aspx',
                'highlightcredits':'116.aspx',
                
                'goto': 'Clips/goto.aspx',
                
                'clipchannel': 'scripts/clips/pages/channel/c@tlp_channel@/Default.aspx',
                'cliphome': 'scripts/clips/pages/home/h@tlp_home@/Default.aspx'
                
        };
        
        //define vars
        adclip.vars.baseURL = 'http://www.adclip.com/';
        adclip.vars.baseClipsScripts = adclip.vars.baseURL + 'scripts/clips/base.ashx';
        adclip.vars.baseImagePath = adclip.vars.baseURL + 'scripts/clips/img/';
        adclip.vars.hitSource = {
                    'SEARCH_PAGE' : '1',
                    'HIGHLIGHT': '2',
                    'EXTERNAL_LINK' : '3'
        };
        
        

        
        (function() {

            //initialization, browser, os detection
            var d, n, nav, dom, nu='', brow='', ie, ie4, ie5, ie5x, ie6, ie7;
            var ns4, moz, moz_rv_sub, release_date='', moz_brow, moz_brow_nu='', moz_brow_nu_sub='', rv_full=''; 
            var mac, win, old, lin, ie5mac, ie5xwin, konq, saf, op, op4, op5, op6, op7;

            d=document;
            n=navigator;
            nav=n.appVersion;
            
            nan=n.appName;
            nua=n.userAgent;
            old=(nav.substring(0,1)<4);
            mac=(nav.indexOf('Mac')!=-1);
            win=( ( (nav.indexOf('Win')!=-1) || (nav.indexOf('NT')!=-1) ) && !mac)?true:false;
            lin=(nua.indexOf('Linux')!=-1);
            // begin primary dom/ns4 test
            // this is the most important test on the page
            if ( !document.layers )
            {
                dom = ( d.getElementById ) ? d.getElementById : false;
            }
            else { 
                dom = false; 
                ns4 = true;// only netscape 4 supports document layers
            }
            // end main dom/ns4 test

            op=(nua.indexOf('Opera')!=-1);
            saf=(nua.indexOf('Safari')!=-1);
            konq=(!saf && (nua.indexOf('Konqueror')!=-1) ) ? true : false;
            moz=( (!saf && !konq ) && ( nua.indexOf('Gecko')!=-1 ) ) ? true : false;
            ie=((nua.indexOf('MSIE')!=-1)&&!op);
            if (op)
            {
                str_pos=nua.indexOf('Opera');
                nu=nua.substr((str_pos+6),4);
                brow = 'Opera';
            }
            else if (saf)
            {
                str_pos=nua.indexOf('Safari');
                nu=nua.substr((str_pos+7),5);
                brow = 'Safari';
            }
            else if (konq)
            {
                str_pos=nua.indexOf('Konqueror');
                nu=nua.substr((str_pos+10),3);
                brow = 'Konqueror';
            }
            // this part is complicated a bit, don't mess with it unless you understand regular expressions
            // note, for most comparisons that are practical, compare the 3 digit rv nubmer, that is the output
            // placed into 'nu'.
            else if (moz)
            {
                // regular expression pattern that will be used to extract main version/rv numbers
                pattern = /[(); \n]/;
                // moz type array, add to this if you need to
                moz_types = new Array( 'Firebird', 'Phoenix', 'Firefox', 'Iceweasel', 'Galeon', 'K-Meleon', 'Camino', 'Epiphany', 'Netscape6', 'Netscape', 'MultiZilla', 'Gecko Debian', 'rv' );
                rv_pos = nua.indexOf( 'rv' );// find 'rv' position in nua string
                rv_full = nua.substr( rv_pos + 3, 6 );// cut out maximum size it can be, eg: 1.8a2, 1.0.0 etc
                // search for occurance of any of characters in pattern, if found get position of that character
                rv_slice = ( rv_full.search( pattern ) != -1 ) ? rv_full.search( pattern ) : '';
                //check to make sure there was a result, if not do  nothing
                // otherwise slice out the part that you want if there is a slice position
                ( rv_slice ) ? rv_full = rv_full.substr( 0, rv_slice ) : '';
                // this is the working id number, 3 digits, you'd use this for 
                // number comparison, like if nu >= 1.3 do something
                nu = rv_full.substr( 0, 3 );
                for (i=0; i < moz_types.length; i++)
                {
                    if ( nua.indexOf( moz_types[i]) !=-1 )
                    {
                        moz_brow = moz_types[i];
                        break;
                    }
                }
                if ( moz_brow )// if it was found in the array
                {
                    str_pos=nua.indexOf(moz_brow);// extract string position
                    moz_brow_nu = nua.substr( (str_pos + moz_brow.length + 1 ) ,3);// slice out working number, 3 digit
                    // if you got it, use it, else use nu
                    moz_brow_nu = ( isNaN( moz_brow_nu ) ) ? moz_brow_nu = nu: moz_brow_nu;
                    moz_brow_nu_sub = nua.substr( (str_pos + moz_brow.length + 1 ), 8);
                    // this makes sure that it's only the id number
                    sub_nu_slice = ( moz_brow_nu_sub.search( pattern ) != -1 ) ? moz_brow_nu_sub.search( pattern ) : '';
                    //check to make sure there was a result, if not do  nothing
                    ( sub_nu_slice ) ? moz_brow_nu_sub = moz_brow_nu_sub.substr( 0, sub_nu_slice ) : '';
                }
                if ( moz_brow == 'Netscape6' )
                {
                    moz_brow = 'Netscape';
                }
                else if ( moz_brow == 'rv' || moz_brow == '' )// default value if no other gecko name fit
                {
                    moz_brow = 'Mozilla';
                } 
                if ( !moz_brow_nu )// use rv number if nothing else is available
                {
                    moz_brow_nu = nu;
                    moz_brow_nu_sub = nu;
                }
                if (n.productSub)
                {
                    release_date = n.productSub;
                }
            }
            else if (ie)
            {
                str_pos=nua.indexOf('MSIE');
                nu=nua.substr((str_pos+5),3);
                brow = 'Microsoft Internet Explorer';
            }
            // default to navigator app name
            else 
            {
                brow = nan;
            }
            op5=(op&&(nu.substring(0,1)==5));
            op6=(op&&(nu.substring(0,1)==6));
            op7=(op&&(nu.substring(0,1)==7));
            op8=(op&&(nu.substring(0,1)==8));
            op9=(op&&(nu.substring(0,1)==9));
            ie4=(ie&&!dom);
            ie5=(ie&&(nu.substring(0,1)==5));
            ie6=(ie&&(nu.substring(0,1)==6));
            ie7=(ie&&(nu.substring(0,1)==7));
            // default to get number from navigator app version.
            if(!nu) 
            {
                nu = nav.substring(0,1);
            }
            /*ie5x tests only for functionavlity. dom or ie5x would be default settings. 
            Opera will register true in this test if set to identify as IE 5*/
            ie5x=(d.all&&dom);
            ie5mac=(mac&&ie5);
            ie5xwin=(win&&ie5x);
            
            
        
            adclip.client = {
                'nu':              nu,
                'brow':            brow,
                'ie':              ie,
                'ie4':             ie4,
                'ie5':             ie5,
                'ie5x':            ie5x,
                'ie6':             ie6,
                'ie7':             ie7,
                'ns4':             ns4,
                'moz':             moz,
                'moz_rv_sub':      moz_rv_sub,
                'release_date':    release_date,
                'moz_brow':        moz_brow,
                'moz_brow_nu':     moz_brow_nu,
                'moz_brow_nu_sub': moz_brow_nu_sub,
                'rv_full':         rv_full,
                'mac':             mac,
                'win':             win,
                'old':             old,
                'lin':             lin,
                'ie5mac':          ie5mac,
                'ie5xwin':         ie5xwin,
                'konq':            konq,
                'saf':             saf,
                'op':              op,
                'op4':             op4,
                'op5':             op5,
                'op6':             op6,
                'op7':             op7
            }
        

        } ());

        

        
        
        adclip.vars.categoriesDependentOnCountry = {
            // countryID: [catID1, ..., catIDn-1]
            /*
            '1': [1,2,3], //Portugal
            '2': [1,3], //Inglaterra
            //'3': [1,2]  // Brasil
            */

            
            
        };
        
        
        // translations
        
        adclip.translations = {
        
            

            /*        
            'pt_pt':{
                    'LANG': 'pt-PT',
                    'CATEGORIES_BY_ID': {'1': 'Imobiliário', '2': 'Automóveis', '3': 'Emprego'},
                    'REGIONS_BY_ID': {'1': {
                                            '1': 'Portugal',
                                            '2': 'Inglaterra',
                                            //'3': 'Brasil'
                                            }
                    }
                    
            },
            'en_us':{
                    'LANG': 'en-US',
                    'CATEGORIES_BY_ID': {'1': 'Real Estate', '2': 'Cars', '3': 'Jobs'},
                    'REGIONS_BY_ID': {'1': {
                                            '1': 'Portugal',
                                            '2': 'England',
                                            //'3': 'Brazil'
                                            }
                    }
            
            },
            */
            
            
            'global': {
                    'LANGUAGES': {
                        'pt-PT': 'Português',
                        'en-US': 'English'
                    },
                    'REGION1_BY_LANGUAGE': {
                        'pt-PT': 1,
                        'en-US': 2
                    }
                    
                    
            }
        };
        
        adclip.addTranslations = function(lang, translations){
            var mix = {};
            lang = lang.toLowerCase().replace("-", '_');
            
            for(var x in adclip.translations[lang]){
                mix[x] = adclip.translations[lang][x];
            }
            
            for(var x in translations){
                mix[x] = translations[x];
            }
            
            adclip.translations[lang] = mix;
        }
        
        
        adclip.t = function(sentence, lang){
            if(typeof lang == 'undefined' || !lang) lang = adclip.lang();
            lang = lang.toLowerCase().replace("-", '_');
            return adclip.translations[lang][sentence];
            
        }

        adclip.url.clear = function(str) {
            return str.replace(/&&/gi, '&')
                      .replace(/\?&/gi, '?')
                      .replace(/&$/gi, '');
        }

        adclip.url.encode = function(str) {
              str = encodeURIComponent(str);
              return str;
        }
        
        adclip.url.decode = function(str) {
            str = str.replace(/\+/gi, ' ');
            str = decodeURIComponent(str);
            return str;
        }

        adclip.lang = function(lang){
            if(adclip.isTrue(lang)){
                 adclip.defLang = lang;
             } else {
                if(adclip.defLang == ''){
                    return 'en-US';
                } else {
                    return adclip.defLang;
                }
            }
        }
       
       
        adclip.getLanguage = function(lang){
            if(typeof lang == 'undefined' || !lang) lang = adclip.lang();
            return adclip.translations['global']['LANGUAGES'][lang];   
        }
               
       
        adclip.getCategory = function(id, lang){
            if(typeof lang == 'undefined' || !lang) lang = adclip.lang();
            lang = lang.toLowerCase().replace("-", '_');
            return adclip.url.decode(adclip.translations[lang]['CATEGORIES_BY_ID'][id]);   
        }
        
        
        adclip.getRegion = function(level, id, lang){
            if(typeof lang == 'undefined' || !lang) lang = adclip.lang();
            lang = lang.toLowerCase().replace("-", '_');
            return adclip.url.decode(adclip.translations[lang]['REGIONS_BY_ID'][level][id]);
        }
        
        
        adclip.isTrue = function(varTest){
            if(typeof varTest != 'undefined' && (varTest == true || varTest || varTest != '' || varTest != 0 )){
                return true;
            } else {
                return false;
            }
        }
        
        
        /**
         * Retruns the x position of the given object in the window / screen.
         */
        adclip.element.findPosX = function(obj) {
            var curleft = 0;
            if(obj.offsetParent)
                while(1) 
                {
                  if(obj.style.position.toLowerCase() != 'relative' && obj.style.position.toLowerCase() != 'absolute')
                    curleft += obj.offsetLeft;
                    
                  if(!obj.offsetParent)
                    break;
                  obj = obj.offsetParent;
                }
            else if(obj.x)
                if(obj.style.position.toLowerCase() != 'relative' && obj.style.position.toLowerCase() != 'absolute')
                    curleft += obj.x;
            return curleft;
        }

        /**
         * Retruns the x position of the given object in the window / screen.
         */
        adclip.element.findPosY = function(obj) {
            var curtop = 0;
            if(obj.offsetParent)
                while(1)
                {
                  if(obj.style.position.toLowerCase() != 'relative' && obj.style.position.toLowerCase() != 'absolute')
                    curtop += obj.offsetTop;
                    
                  if(!obj.offsetParent)
                    break;
                  obj = obj.offsetParent;
                }
            else if(obj.y)
                if(obj.style.position.toLowerCase() != 'relative' && obj.style.position.toLowerCase() != 'absolute')
                    curtop += obj.y;
            return curtop;
        }
        
        adclip.events.onChangeLanguage = function(opts){
            adclip.lang(opts.language);
            
            // change language on SearchBox
            if(typeof adclip.clips.searchBox.prototype.instance != "undefined" && adclip.clips.searchBox.prototype.instance.length > 0){
                for(var x in adclip.clips.searchBox.prototype.instance){
                    adclip.clips.searchBox.prototype.instance[x].draw();
                }
            
            }
            
            
            
            // callBack
            if(typeof adclip_onChangeLanguage == "function") adclip_onChangeLanguage(opts);
        }
        
        
        
        
        /** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
         ** Code licensed under Creative Commons Attribution-ShareAlike License      **
         ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
        adclip.ajax.XHConn = function()
        {
          var xmlhttp, bComplete = false;
          try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
          catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
          catch (e) { try { xmlhttp = new XMLHttpRequest(); }
          catch (e) { xmlhttp = false; }}}
          if (!xmlhttp) return null;
          this.connect = function(sURL, sMethod, sVars, fnDone, async)
          {
            if (!xmlhttp) return false;
            bComplete = false;
            sMethod = sMethod.toUpperCase();

            try {
              if (sMethod == "GET")
              {
                xmlhttp.open(sMethod, sURL+"?"+sVars, async);
                sVars = "";
              }
              else
              {
                xmlhttp.open(sMethod, sURL, async);
                xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
                xmlhttp.setRequestHeader("Content-Type",
                  "application/x-www-form-urlencoded");
              }
              xmlhttp.onreadystatechange = function(){
                if (xmlhttp.readyState == 4 && !bComplete)
                {
                  bComplete = true;
                  fnDone(xmlhttp);
                }};
              xmlhttp.send(sVars);
            }
            catch(z) { return false; }
            return true;
          };
          return this;
        }
        
        
        adclip.url.maker = function(type, config, values, locationOn){
            var url = '';
            if (type=='detail')
            {       
                  var curlang = "en-US";
                  var editorUrl = "";
                  var token ="?";
                  if (typeof config.resultPage=='undefined')
                  {
                   editorUrl=config.opt_urlTarget
                  }
                  else
                  { 
                    editorUrl=config.resultPage;
                  }
                  if (editorUrl.indexOf("?")>0)
                  {
                    token="&";
                  }
                 var ClipRegion1 = "194";
                 if (typeof config.idRegion1 == "undefined") {
                        ClipRegion1 = IdRegion;
                    }
                else {
                    
                        ClipRegion1 = config.idRegion1;
                }
                 if (typeof CustomLanguage != "undefined") {
                        curlang = CustomLanguage;
                }
                  var link = adclip.vars.goPage[type.toLowerCase()];
                  link = link.replace("{CustomCat}", catCustom).replace(
                            "{CustomCss}", cssCustom).replace(
                            "{Region}", ClipRegion1).replace(
                            "{RegionLevel}", "1").replace(
                            "{Language}", curlang).replace(
                            "{PubKey}", config.publicKey).replace("{AdPubKey}",values.public).replace(
                            "{Source}", adclip.vars.hitSource['HIGHLIGHT']);
                 return  editorUrl + token +"t="+  Math.random() +"#adclip/" +  link;
            }
            else{
            var page = adclip.vars.goPage[type.toLowerCase()];
            if(adclip.isTrue(config.opt_target)){
                // Outside of my site
                url = adclip.vars.baseURL + adclip.vars.goPage.adclipresult + '?';
                
            } else {
                //On my site                
                if(config.opt_urlTarget.split('?').length > 1){
                    url += config.opt_urlTarget; // + '&';
                    // para browser normais poderia ser config.opt_urlTarget.substr(-1,1) mas em IE assim retorna sempre "h" independente do final, vai-se lá entender.
                    if(config.opt_urlTarget.substr(config.opt_urlTarget.length-1,1) != '?' && config.opt_urlTarget.substr(config.opt_urlTarget.length-1,1) != '&') url += '&';
                } else {
                    url += config.opt_urlTarget + '?';
                }
            }
                
            vaulesParams = '';
            for(var c in values){
                var val = (typeof(values[c]) == "string") ? values[c].replace(/#/gi, '') : values[c];
                vaulesParams += '&' + c + '=' + val;
            }
            
            
            var tmp = '';
            tmp =  vaulesParams +
                    (!adclip.isTrue(values.language) ? '&language=' + config.language : '') +
                    (config.ownerOnly ? '&ow=1' : '') +
                    (config.characterSet ? '&charSet=' + config.characterSet : '');
                    
            
            url += "bcparameters=" + adclip.url.encode(page + '?' + tmp);
            url += (config.publicKey ? '&clip=' + config.publicKey : '');
            


            if(adclip.isTrue(locationOn)){
                parent.location = url;
            } else {
                return url;
            }
            }
            
        };
        

        
        adclip.utils.colorHexStrip = function(color){
            return (typeof(color) == "string") ? color.replace(/#|\s/gi, '') : color;
        };
       
       // emula ajax por JS Tag
        adclip.fajax.getObj = function(src, objReturn){
           if(!adclip.isTrue(objReturn)) objReturn = 'bc_fajaxObj';
           var head = document.getElementsByTagName("head")[0];
           var script = document.createElement('script');
           
           script.type = 'text/javascript';
           script.src = src + (src.indexOf('?')>0 ? '&' : '?') + "objReturn=" + objReturn + '&' + adclip.time.mktime();
           head.appendChild(script);
        }
        
        
        adclip.time.mktime = function() {
            // http://kevin.vanzonneveld.net
            // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
            // +   improved by: baris ozdil
            // +      input by: gabriel paderni 
            // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
            // *     example 1: mktime( 14, 10, 2, 2, 1, 2008 );
            // *     returns 1: 1201871402
            
            var no, i = 0, d = new Date(), argv = arguments, argc = argv.length;
         
            var dateManip = {
                0: function(tt){ return d.setHours(tt); },
                1: function(tt){ return d.setMinutes(tt); },
                2: function(tt){ return d.setSeconds(tt); },
                3: function(tt){ return d.setMonth(parseInt(tt)-1); },
                4: function(tt){ return d.setDate(tt); },
                5: function(tt){ return d.setYear(tt); }
            };
         
            for( i = 0; i < argc; i++ ){
                no = parseInt(argv[i]);
                if(no && isNaN(no)){
                    return false;
                } else if(no){
                    // arg is number, let's manipulate date object
                    if(!dateManip[i](no)){
                        // failed
                        return false;
                    }
                }
            }
         
            return Math.floor(d.getTime()/1000);
        }
        
        
        
        adclip.asset.css = function(href, id){
            var head = document.getElementsByTagName("head")[0];
            var link = document.createElement('link');
            if(adclip.isTrue(id)){
                link.id = id;
            }
            link.type = 'text/css';
            link.href = href;
            link.rel = 'stylesheet';
            head.appendChild(link);
        }
        

        adclip.array.existValue = function(needle, haystack, strict){
            // *     example 1: adclip.array.existValue(2, [1,2,3]);
            // *     returns 1: true

            var found = false, key, strict = !!strict;
         
            for (key in haystack) {
                if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
                    found = true;
                    break;
                }
            }
         
            return found;
        }

        
        adclip.array.implode = function( glue, pieces ) {
            return ( ( pieces instanceof Array ) ? pieces.join ( glue ) : pieces );
        }
        
        // Color Tools
        
        adclip.color.hex2rgb = function(hex){

              var o=hex.toLowerCase().replace(/#/gi, '');
              var c=o.length;
              
              if(c == 3){
                o = o + o;
              }
              else if(c < 6){
                return [64, 127, 127];
              }
              
	            return {  r: parseInt(o.slice(0,2),16),
                        g: parseInt(o.slice(2,4),16),
                        b: parseInt(o.slice(4),16)
                     }

        }
        
        
        adclip.color.rgb2hsl = function(r, g, b){
            r /= 255, g /= 255, b /= 255;
            var max = Math.max(r, g, b), min = Math.min(r, g, b);
            var h, s, l = (max + min) / 2;

            if(max == min){
                h = s = 0; // achromatic
            }else{
                var d = max - min;
                s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
                switch(max){
                    case r: h = (g - b) / d + (g < b ? 6 : 0); break;
                    case g: h = (b - r) / d + 2; break;
                    case b: h = (r - g) / d + 4; break;
                }
                h /= 6;
            }

            //return [h, s, l];
            return {'h': h, 's': s, 'l': l};
        }
        
        adclip.color.colorWhiteOrBlack = function(hex){

            var rgb = adclip.color.hex2rgb(hex);
            var hsl = adclip.color.rgb2hsl(rgb.r, rgb.g, rgb.b);
            return hsl.l > 0.5 ? '#000000' : '#ffffff';
            
        }
        
        
       adclip.string.trim =  function(str, charlist) {
            var whitespace, l = 0, i = 0;
            str += '';
            
            if (!charlist) {
                // default list
                whitespace = " \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000";
            } else {
                // preg_quote custom list
                charlist += '';
                whitespace = charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
            }
            
            l = str.length;
            for (i = 0; i < l; i++) {
                if (whitespace.indexOf(str.charAt(i)) === -1) {
                    str = str.substring(i);
                    break;
                }
            }
            
            l = str.length;
            for (i = l - 1; i >= 0; i--) {
                if (whitespace.indexOf(str.charAt(i)) === -1) {
                    str = str.substring(0, i + 1);
                    break;
                }
            }
            
            return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
        }
        
}

/*custom*/
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() {


        var loc = document.location.href;
        //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;
/*
        if (loc.indexOf("#adclip//") > 0 && loc.indexOf(this.config.publicKey) > 0) {

            if (loc.indexOf('#adclip/') > 0) {
                HPC = adclip.vars.baseURL + loc.substring(loc.indexOf('#adclip/') + 8);
            }
            if (loc.indexOf('#adclips/') > 0) {
                HPC = adclip.vars.baseURL + loc.substring(loc.indexOf('#adclips/') + 9);
            }
            if (HPC != "") {
                HPC = HPC.replace(";", "#").replace("|", "?");
                var frag = "<iframe style='bgcolor:#000;' height='350' frameborder='0' border='0' width='100%' scrolling='no' id='f_" + this.config.publicKey + "' src='" + HPC + "'></iframe>";
                //document.getElementById(this.config.publicKey).innerHTML = frag;
                document.write(frag);

            }
        }
*/
        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);

    }





}