  /**************************************
  * MNO Ad Specials
  *************************************/

 function addTAdClass() {
     $('.ad-marker:last')
        .clone()
        .appendTo('#hd');
 };

 function addLBodyClass() {
    jQuery('body')
      .addClass('LAd');
 }

 var iframeAdArray = new Array();
 var itrArray = 0;
 iframeAdArray[0] = "";
 function getAdUrl() {
    itrArray++;
    return iframeAdArray[itrArray];
 }

 function expandThis(obj) {
     $.expandThis(obj);
 }

 function collapseThis(obj) {
    $.collapseThis(obj);
 }

 (function($){

     var adtechSettings = {

         /***********************************************************
         * Contains Static and Default variables.                  *
         * Defaults can be overridden by banner templates/traffic. *
         * *********************************************************/

         globalOptions: {

        /********************
         * Global Defaults.  *
         * ******************/

         flashVersion: 8,
         wmode: 'opaque',
         clickTagFormat: 'clickTAG',
         clicktags: '', flashurl: '', imgurl: '', extCode: '', /** Better leave empty **/
         leftHorseShoeContainer: '.adOuterLeft',   /** The class or unique id of the main left horseshoe div **/
         rightHorseShoeContainer: '.adOuterRight', /** The class or unique id of the main right horseshoe div **/
         toppbannerContainer: '.adTopBanner', /** The class or unique id of the main "toppbanner" adpos div **/
         documentDomain: 'aftenposten.no' /** In cases where it should be used, the top level domain **/

        }, tickerOptions :  {

        /*************************
         *  Sticky Ticker Banner *
         * **********************/

            /** Statics **/
                 adMarkerClass: 'adMarker f-666 f-75 s-01 tickerMarker', /** Classname of admarker **/
                 appendTickerTo: 'body',
                 adText: 'annonse',
                 callBackFunc: false, /** Additional function to be executed at the end. Set to false or empty to skip **/

            /** Defaults **/
                width: 1280,
                height: 30,
                zIndex: 1100,
                align: 'center'

         }, tAdOptions : {

         /********
         *  T-AD *
         * *******/

            /** Statics **/
                insertAfterWhere: '#hd' , /** Where to insert the horizontal stripe of the T-ad in the html structure. Id or class. Must be unique **/
                appendCloseBtn: true, /** Append close X ? **/
                addClassToContainer: '#pageBody', /** Referring to non-existing element will fail silently. Used to add e.g. padding to body element after inserting horizontal T **/
                addThisClass: 'padTop8', /** The class to add **/
                callBackFunc: false /** Additional function to be executed at the end. Set to false or empty to skip **/

        }, interstitialOptions : {

         /****************
         *  Interstitial *
         * **************/

             /** Statics **/
                bgColor: '#f4f4f4',
                zIndex: 11000,
                adText: 'Lukk annonse',
                appendInterstitialTo: 'body',
                callBackFunc: false, /** Additional function to be executed at the end. Set to false or empty to skip **/

             /** Defaults **/
                paddingTopBtm: 30, /** Top and bottom padding around flash **/
                topOffset: 300,  /** Top offset from window **/
                timeOut: 3,     /** Default timeout before close **/
                align: 'center',  /** Center, left or right. Text-align/margin auto **/
                interstitialWidth: '100%',
                interstitialHeight: '700' /** Pixels **/

        }, horseshoeOptions : {

         /*************
         *  Horseshoe *
         * ************/

             /** Statics **/
             appendTopBannerTo: '#Toppbanner_container', /** Needs to be a unique ID. Shouldn't need to change. Is in display_ad **/
             callBackFunc: false /** Additional function to be executed at the end. Set to false or empty to skip **/

         }, horseshoePosOptions : {

         /**************************************************************
         *  Horseshoe using three banners, add classes (backup only..) *
         * ************************************************************/

            /** Statics **/
            callBackFunc: false /** Additional function to be executed at the end. Set to false or empty to skip **/

        }, pagecurlOptions : {

         /************
         *  Pagecurl *
         * ***********/

             /** Statics **/
                topbannerID: '#Toppbanner_container',  /** Shouldn't need to change if using same display_ad. Usually this container is set to display:none; **/
                netboardID: '#Netboard1_container',  /** Not in use yet, but identifies the netboard **/
                flashurl_pagecurl_small: 'http://ap.oasfile.aftenposten.no/pagecurl/pageflip_oop_small.swf',
                flashurl_pagecurl_big: 'http://ap.oasfile.aftenposten.no/pagecurl/pageflip_oop.swf',
                flashvars_small_animate: 'true', /** Animate the small flip? **/
                timeout: 1500, /** Timemout on large flip before moving back to small **/
                callBackFunc: false /** Additional function to be executed at the end. Set to false or empty to skip **/

         }, lAdOptions : {

         /*********
         *  L-Ad *
         * *******/

             /** Statics **/
                 shiftRight: 12, /** How many pixels to shift right. Uses negative margin-right **/
                 appendToDiv: '#Toppbanner_container',  /** same identifier as Pagecurl topbannerID **/
                 alterViewport: true, /** Alter "viewport" div width" to center page properly? **/
                 alterViewportWidth: '1202px',
                 alterViewportID: '#viewport', /** Viewport identifier **/
                 closeBtn: true, /** Html close button? **/
                 closeBtnText: 'X',
                 callBackFunc: false /** Additional function to be executed at the end. Set to false or empty to skip **/

        }, stickySkyscraperOptions :  {

         /*********************
         *  Sticky skyscraper *
         * *******************/

            /** Statics **/
                 adMarkerClass: 'adMarker f-666 f-75 s-01 tickerMarker', /** Classname of admarker **/
                 insertAfter: '#sticky_sky_container',  /** Insert after where **/
                 adText: 'annonse',
                 btmMaxPosContainer: '.adBottomBoard', /* At which container should you stop scrolling?  */
                 btmPadding: 98, /** Pixels. Whitespace below where ad should stop **/
                 relativeParent: '#pageBody', /** Relative parent of sticky skyscraper. Because uses position:absolute for bottom placement.  **/
                 callBackFunc: false, /** Additional function to be executed at the end. Set to false or empty to skip **/

            /** Defaults **/
                width: 180,
                height: 500

         }, standardExpandableOptions :  {

         /*********************
         *  Expandable click  *
         * *******************/

            /** Statics **/
                callBackFunc: false, /** Additional function to be executed at the end. Set to false or empty to skip **/
                expContainerEnding: "_container",
                iframeWrapperUrl: 'http://ap.oasfile.aftenposten.no/iframe/iframe_ext.htm', /** Must be within same domain or subdomain **/

            /** Defaults **/
                width: 180,
                height: 500

         }};

        /*******************************
        * Updating settings *
        * ****************************/

        $.updateAdtechOptions = function(updateSettings) {
            adtechSettings = $.extend(true, adtechSettings, updateSettings);
        };

         /*********************
        *  adTech functions *
        * *******************/

        $.groupId = Math.round(Math.random() * 1000000000);

        $.getTimeStamp = function() {
           return new Date().getTime();
        };

        /***************************************
        *  Add flash function, using swfObject *
        * *************************************/

       var swfobject_version = (window.swfobject) ? 2 : (window.SWFObject) ? 1 : false;

       $.loadWithSwfObject = function (file, clicktagFormat, clicktags, insertFlashToDiv, flashWidth, flashHeight, flashVersion, wmode, flashVars, altImg) {
                var flashvars_string = '';
                if (swfobject_version >= 2) {
                  /** Check to see if flash plugin installed **/
                  if (swfobject.hasFlashPlayerVersion(flashVersion)) {
                      if (typeof(flashVars) != 'undefined') {
                          $.each(flashVars, function(key, value) {
                             if (key != '') { flashvars_string += key + "=" + value + "&"; }
                          });
                      }
                      var clicktags_string = '';
                      if (typeof(clicktags) != 'undefined' && typeof(clicktags) != 'string') {
                          $.each(clicktags, function(key, value) {
                             if (key != '') { clicktags_string += key + "=" + value + "&"; }
                          });
                      } else {
                         clicktags_string = clicktagFormat + "=" + clicktags + "&";
                      }
                      var params = {
                         wmode: wmode,
                         allowscriptaccess: 'always',
                         flashvars : flashvars_string + clicktags_string
                      };
                      var att = { data: file + '?' + clicktags_string, width: flashWidth, height: flashHeight};
                      /** using createSWF instead of embedSWF lets us control embedding to when we want. onLoad or not **/
                      swfobject.createSWF( att, params, insertFlashToDiv);
                  }  else {
                     /** ALT image **/
                     var altImgID = insertFlashToDiv + 'AltImg';
                     if (altImg != '') {  $.loadImageObject(altImgID, altImg, insertFlashToDiv, clicktags); }
                  }
                }
                else {
                    var content = new SWFObject (file+ '?' + clicktagFormat + '=' + clicktags, insertFlashToDiv, flashWidth, flashHeight, flashVersion);
                    content.addParam("wmode", wmode);
                    content.addParam("FlashVars", flashvars_string + clicktagFormat + "=" + clicktags);
                    content.write(insertFlashToDiv);
               }
       };

        /******************************
        *  Add image banners function *
        * *****************************/

        $.loadImageObject = function(imgId,imgfile,insertImgToDiv,clicktag) {

            /** insertImgToDiv points to id - # ? **/
            insertImgToDiv = insertImgToDiv.search(/\#/) == -1 ? ( insertImgToDiv.search(/\./) != -1 ? insertImgToDiv  : '#' + insertImgToDiv ) : insertImgToDiv;

            $('<img />')
                .attr({
                    src: imgfile,
                    id: imgId
                })
                .appendTo(insertImgToDiv);

            /** IF objekt **/
            if (typeof(clicktag) != 'string') {

                $.getAttributeByIndex = function(obj, index) {
                  var i = 0;
                  for (var attr in obj){
                    if (index === i){
                      return obj[attr];
                    }
                    i++;
                  }
                  return null;
                 };

                clicktag = $.getAttributeByIndex(clicktag, 0);

            }

            if (clicktag != '') {
                 $('#' + imgId).wrap('<a href="'+ unescape(clicktag) +'" target="_blank" />');
             }

        };

         /*************************************
        *  Add external code banners function *
        * ************************************/

        $.addExternalCode = function(code,clicktag,where) {

           code = code.replace(/(\[rand\])/, $.groupId);
           code = code.replace(/(\[timestamp\])/, $.groupId);
           code = code.replace(/(\[click\])/, clicktag);

            $(code)
              .appendTo(where);

        };

        /******************
        *  Sticky Ticker *
        * ****************/

       $.ticker = function(tickerOptions) {

         var defaults = {
             flashurl: adtechSettings.globalOptions.flashurl,
             imgurl: adtechSettings.globalOptions.imgurl,
             altImg: adtechSettings.globalOptions.imgurl,
             extCode: adtechSettings.globalOptions.extCode,
             width: adtechSettings.tickerOptions.width,
             height: adtechSettings.tickerOptions.height,
             zIndex: adtechSettings.tickerOptions.zIndex,
             align: adtechSettings.tickerOptions.align,
             flashVersion: adtechSettings.globalOptions.flashVersion,
             wmode: adtechSettings.globalOptions.wmode,
             clickTagFormat: adtechSettings.globalOptions.clickTagFormat,
             clicktags: adtechSettings.globalOptions.clicktags,
             pixelCounter: adtechSettings.globalOptions.imgurl
         },

         settings = $.extend({}, defaults, tickerOptions);

         var ticker = $('<div id="tickerAd" />')
            .appendTo(adtechSettings.tickerOptions.appendTickerTo)
            .hide()
            .css({
               width: '100%',
               height: settings.height,
               zIndex: settings.zIndex
          });

          var tickerInner = $('<div id="tickerAdInner" />')
            .appendTo(ticker)
            .append('<span class="'+ adtechSettings.tickerOptions.adMarkerClass +'"><span>V</span> '+ adtechSettings.tickerOptions.adText +'</span>')
            .css({
               width: settings.width,
               height: settings.height,
               margin: settings.align == 'center' ? '0 auto' : '0'
            });

           $('<div id="tickerAdSwf" />')
                .appendTo(tickerInner);

           /** Add flash using swfObject **/
           if (settings.flashurl != '' && settings.extCode == '') {
                $.loadWithSwfObject(settings.flashurl, settings.clickTagFormat, settings.clicktags , "tickerAdSwf", settings.width, settings.height, settings.flashVersion.toString(), settings.wmode, false, settings.altImg);
           }

           /** Or image **/
           if (settings.imgurl != '' && settings.extCode == '') {
                $.loadImageObject('tickerImg', settings.imgurl, "#tickerAdSwf", settings.clicktags);
           }

           if (settings.extCode != '') {
                $.addExternalCode(settings.extCode,settings.clicktags, "#tickerAdSwf");
           }

           if (settings.pixelCounter != '') {
               var img = '<img src="'+  settings.pixelCounter +'" style="display: none;" />';
               $.addExternalCode(img,'',ticker);
           }

           /** Fade in **/
           ticker
             .fadeIn(500);

           if (adtechSettings.tickerOptions.callBackFunc != '') {
                try {
                    var callBackFunc = new Function(adtechSettings.tickerOptions.callBackFunc);
                    callBackFunc();
                } catch(err) {};
            }

         };

         /*********
          *  T-Ad *
          * ******/

         $.tAd = function(tAdOptions) {

         var defaults = {
             tbarSmallSwf: adtechSettings.globalOptions.flashurl,
             tbarSmallImg: adtechSettings.globalOptions.flashurl,
             horzAlt: adtechSettings.globalOptions.flashurl,
             tbarSmallWidth: 1030,
             tbarSmallHeight: 90,
             tbarExpandedUrl: adtechSettings.globalOptions.flashurl,
             tbarExpandedWidth: 1030,
             tbarExpandedHeight: 598,
             tbarVertSwf: adtechSettings.globalOptions.flashurl,
             tbarVertImg: adtechSettings.globalOptions.flashurl,
             vertAlt: adtechSettings.globalOptions.flashurl,
             tbarVertWidth: 90,
             tbarVertHeight: 1000,
             flashVersion: 8,
             wmode: adtechSettings.globalOptions.wmode,
             clickTagFormatHorz: adtechSettings.globalOptions.clickTagFormat,
             clickTagFormatVert: adtechSettings.globalOptions.clickTagFormat,
             clickTagFormatLarge: adtechSettings.globalOptions.clickTagFormat,
             clicktagsHorz: adtechSettings.globalOptions.clicktags,
             clicktagsVert: adtechSettings.globalOptions.clicktags,
             clicktagsLarge: adtechSettings.globalOptions.clicktags,
             pixelCounter: adtechSettings.globalOptions.imgurl,
             pixelCounterExpanded: adtechSettings.globalOptions.imgurl,
             insertAfterWhere: adtechSettings.tAdOptions.insertAfterWhere
         },

         settings = $.extend({}, defaults, tAdOptions);

         var tBarAdWrapper = $('<div id="TBarAdWrapper" class="innstikk" />')
            .insertAfter(settings.insertAfterWhere)
            .hide();

         $('<div id="TBarTop" />')
           .appendTo(tBarAdWrapper)
           .append('<div id="TBarSmallHors" />');

         var tBarContent = $('<div id="TBarContent" />')
           .appendTo(tBarAdWrapper)
           .hide()
           .append('<div id="LoadingTBarMain">&nbsp;</div><div id="TBarMainContainer"><div id="TBarMain">&nbsp;</div></div>');

         if (adtechSettings.tAdOptions.appendCloseBtn) {
            tBarContent
              .append('<div class="closeTBarContent" id="TBarX"> X </div>');
         }

         /** Place into left horse wrapper **/
         $(adtechSettings.globalOptions.leftHorseShoeContainer)
             .empty()
             .append('<div id="TBarLeft" />');

        if (settings.pixelCounter != '') {
               var img = '<img src="'+  settings.pixelCounter +'" style="display: none;" />';
               $.addExternalCode(img,'',"#TBarLeft");
         }

         tBarAdWrapper
            .insertAfter(settings.insertAfterWhere)
            .fadeIn(500);

         /** Add vertical flash **/
         if (settings.tbarVertSwf != '') {
              $('#TBarLeft')
                 .append('<div id="TBarLeftSwf" />');
                 $.loadWithSwfObject(settings.tbarVertSwf, settings.clickTagFormatVert, settings.clicktagsVert , "TBarLeftSwf", settings.tbarVertWidth, settings.tbarVertHeight, settings.flashVersion.toString(), settings.wmode, false, settings.vertAlt);
         }

         /** Or image **/
         if (settings.tbarVertImg != '') {
             $('#TBarLeft')
                .css({background: 'url("'+ settings.tbarVertImg +'") no-repeat left top'});
         }

         /** Add horizontal flash **/
         if (settings.tbarSmallSwf != '') {
             $.loadWithSwfObject(settings.tbarSmallSwf, settings.clickTagFormatHorz, settings.clicktagsHorz , "TBarSmallHors", settings.tbarSmallWidth, settings.tbarSmallHeight, settings.flashVersion.toString(), settings.wmode, false, settings.horzAlt);
         }

         /** Or image **/
         if (settings.tbarSmallImg != '') {
             $('#TBarSmallHors')
                .css({background: 'url("'+ settings.tbarSmallImg +'") no-repeat left top'});
         }

         /** Add class to pageBody or other element **/
         $(adtechSettings.tAdOptions.addClassToContainer).addClass(adtechSettings.tAdOptions.addThisClass);

         var TBarExpandedLoaded = false;

         if (settings.tbarExpandedUrl != '') {
             $('#TBarTop, #TBarLeft, #TBarX').mousedown( function(e) {
                  if(tBarContent.is(':hidden')) {
                      if (settings.pixelCounterExpanded != '') {
                            var img = '<img src="'+  settings.pixelCounterExpanded +'" style="display: none;" />';
                            $.addExternalCode(img,'',tBarAdWrapper);
                      }
                      tBarContent.show();
                      tBarAdWrapper.addClass('innstikkOpen');
                      if(!TBarExpandedLoaded) {
                        /**Load large flash **/
                        $.loadWithSwfObject(settings.tbarExpandedUrl, settings.clickTagFormat, settings.clicktagsLarge , "TBarMain", settings.tbarExpandedWidth, settings.tbarExpandedHeight, settings.flashVersion.toString(), settings.wmode, false);
                        TBarExpandedLoaded = true;
                      }
                   } else {
                     tBarContent.hide();
                     tBarAdWrapper.removeClass('innstikkOpen');
                   }
               });
           }

          /** Create callback function **/
          if (adtechSettings.tAdOptions.callBackFunc != '') {
                try {
                    var callBackFunc = new Function(adtechSettings.tAdOptions.callBackFunc);
                    callBackFunc();
                } catch(err) {};
            }

          };

         /*****************************************************
          *  Interstitial. Simple offset version with timeout *
          * **************************************************/

         $.interstitial = function(interstitialOptions) {

         var defaults = {
             flashurl: adtechSettings.globalOptions.flashurl,
             altImg: adtechSettings.globalOptions.flashurl,
             extCode: adtechSettings.globalOptions.extCode,
             width: 1004,
             height: 650,
             interstitialWidth: adtechSettings.interstitialOptions.interstitialWidth,
             interstitialHeight: adtechSettings.interstitialOptions.interstitialHeight,
             paddingTopBtm: adtechSettings.interstitialOptions.paddingTopBtm,
             zIndex: adtechSettings.interstitialOptions.zIndex,
             topOffset: adtechSettings.interstitialOptions.topOffset,
             timeOut: adtechSettings.interstitialOptions.timeOut,
             bgColor: adtechSettings.interstitialOptions.bgColor,
             align: adtechSettings.interstitialOptions.align,
             flashVersion: adtechSettings.globalOptions.flashVersion,
             wmode: adtechSettings.globalOptions.wmode,
             pixelCounter: adtechSettings.globalOptions.imgurl,
             clickTagFormat: adtechSettings.globalOptions.clickTagFormat,
             clicktags: adtechSettings.globalOptions.clicktags
         },

         settings = $.extend({}, defaults, interstitialOptions);

         var interstitial = $('<div id="interstitial" />')
            .appendTo(adtechSettings.interstitialOptions.appendInterstitialTo)
            .hide()
            .append('<span class="closeInterstitial">' + adtechSettings.interstitialOptions.adText + '</span>')
            .css({
               top: settings.topOffset,
               height: settings.interstitialHeight,
               zIndex: settings.zIndex
          });

          $('<div id="interstitialInner" />')
            .appendTo(interstitial)
            .append('<div id="interstitialSwf />')
            .css({
               width: settings.interstitialWidth,
               height: settings.interstitialHeight,
               margin: settings.align == 'center' ? '0 auto' : '0',
               cssFloat: settings.align == 'center' ? 'none' : settings.align,
               backgroundColor: settings.bgColor,
               padding: settings.paddingTopBtm + 'px 0 ' + settings.paddingTopBtm + 'px 0'
           });

           /** Add flash using swfObject **/
           if (settings.flashurl != "" && settings.extCode == '') {
                $.loadWithSwfObject(settings.flashurl, settings.clickTagFormat, settings.clicktags , "interstitialSwf", settings.width, settings.height, settings.flashVersion.toString(), settings.wmode, false, settings.altImg);
           }

           if (settings.extCode != '') {
                $.addExternalCode(settings.extCode, settings.clicktags, "#interstitialSwf");
           }

           if (settings.pixelCounter != '') {
                var img = '<img src="'+  settings.pixelCounter +'" style="display: none;" />';
                $.addExternalCode(img,'',interstitial);
           }

           /** Fade in **/
           interstitial
            .show();

           /** Delay removal **/
           jQuery.fn.delayRemoval = function() {
              interstitial.animate({opacity: 1.0}, settings.timeOut*1000, function () {
                 interstitial.remove();
              });
           };

           /** Remove event **/
           jQuery.fn.removeThis = function(el) {
              if(el == "closeInterstitial") {
                  interstitial.remove();
              }  else {
                  $(this).delayRemoval();
              }
           };

           /** Set initial timeout **/
           interstitial
              .delayRemoval();

           /** Set "timeout" events **/
           interstitial
             .hover( function () {
               $(this).stop();
             }, function () {
               $(this).removeThis();
            });

           /** Set onclick remove event **/
            $(".closeInterstitial")
             .click( function (el) {
                $(this).removeThis(el.target.className);
            });

           /** Create callback function **/
           if (adtechSettings.interstitialOptions.callBackFunc != '') {
                try {
                    var callBackFunc = new Function(adtechSettings.interstitialOptions.callBackFunc);
                    callBackFunc();
                } catch(err) {};
            }

         };

         /**********************************
          *  Standard questback popup *
          * *******************************/

        $.questback = function (qbStandardOptions) {

            var defaults = {
             qb_url: '',
             img_url: '',
             width: 468,
             target: '_blank',
             height: 400,
             timeOut: 5
            },

            settings = $.extend({}, defaults, qbStandardOptions);

            var QB_Window = window.open('','QuestBack','location=No,scrollbars=No,toolbar=No,directories=No,status=No,menubar=No,width='+ settings.width +',height='+ settings.height);
            var QB = QB_Window.document;
            /** QB.open(); **/
            QB.write('\n');
            QB.write('<HTML>\n');
            QB.write('<HEAD>\n');
            QB.write('<TITLE></TITLE>\n');
            QB.write('</HEAD>\n');
            QB.write('<BODY bgcolor=white marginwidth=0 marginheight=0 leftmargin=0 topmargin=0>\n');
            QB.write('<script type="text/javascript">\n');
            QB.write('<!--\n');
            QB.write('setTimeout("window.blur();opener.focus()",'+ settings.timeOut*1000 +');//-'+'->\n');
            QB.write('</scr'+'ipt>\n');
            QB.write('<TABLE width=100% height=100% border=0 cellpadding=0 cellspacing=0><TR valign=middle><td align=center><a href="'+ settings.qb_url +'" target="'+ settings.target +'">\n');
            QB.write('<img src="'+ settings.img_url +'" border=0 alt="Img"></a></TD></TR></TABLE>\n');
            QB.write('</BODY>\n');
            QB.write('</HTML>');
            QB.close();

        };

         /*********************************************************************************
        *  Control horseshoe positioning only, standard helios code using three positions *
        * ********************************************************************************/

         $.horseshoePos = function (horseShoePosOptions) {

            var defaults = {
                width: 1030
            },

            settings = $.extend({}, defaults, horseShoePosOptions);

            if (settings.width == 1030) { $(adtechSettings.globalOptions.toppbannerContainer).addClass("w1030"); }

            $(adtechSettings.globalOptions.toppbannerContainer).hide();

            $(document).ready(function () {
               if (settings.width == 1006) {
                   $(adtechSettings.globalOptions.leftHorseShoeContainer).addClass("w1006");
                   $(adtechSettings.globalOptions.rightHorseShoeContainer).addClass("w1006");
               }
            });

           /** Create callback function **/
           if (adtechSettings.horseshoePosOptions.callBackFunc != '') {
                try {
                    var callBackFunc = new Function(adtechSettings.horseshoePosOptions.callBackFunc);
                    callBackFunc();
                } catch(err) {};
            }

         };

         /******************************************************************************
        *  Control horseshoe completely using banner template. Requires only one adPos *
        * *****************************************************************************/

         $.horseshoe = function (horseShoeOptions) {

            var defaults = {
                 leftSwf: adtechSettings.globalOptions.flashurl,
                 leftImg: adtechSettings.globalOptions.imgurl,
                 leftAltImg: adtechSettings.globalOptions.imgurl,
                 extCodeLeft: adtechSettings.globalOptions.extCode,
                 leftWidth: 90,
                 leftHeight: 1000,
                 topSwf: adtechSettings.globalOptions.flashurl,
                 topImg: adtechSettings.globalOptions.imgurl,
                 topAltImg: adtechSettings.globalOptions.imgurl,
                 extCodeTop: adtechSettings.globalOptions.extCode,
                 topWidth: 1030,
                 topHeight: 150,
                 rightSwf: adtechSettings.globalOptions.flashurl,
                 rightImg: adtechSettings.globalOptions.imgurl,
                 rightAltImg: adtechSettings.globalOptions.imgurl,
                 extCodeRight: adtechSettings.globalOptions.extCode,
                 rightWidth: 90,
                 rightHeight: 1000,
                 flashVersion: adtechSettings.globalOptions.flashVersion,
                 wmode: adtechSettings.globalOptions.wmode,
                 pixelCounter: adtechSettings.globalOptions.imgurl,
                 clickTagFormatLeft: adtechSettings.globalOptions.clickTagFormat,
                 clickTagFormatTop: adtechSettings.globalOptions.clickTagFormat,
                 clickTagFormatRight: adtechSettings.globalOptions.clickTagFormat,
                 clicktagsLeft: adtechSettings.globalOptions.clicktags,
                 clicktagsTop: adtechSettings.globalOptions.clicktags,
                 clicktagsRight: adtechSettings.globalOptions.clicktags,
                 appendTopBannerTo: adtechSettings.horseshoeOptions.appendTopBannerTo
            },

            settings = $.extend({}, defaults, horseShoeOptions);

            /** Add left swf/alt img container **/
            if ((settings.leftAltImg != '' || settings.leftSwf != '') && settings.topImg == '') {
                var leftHorseDiv = $('<div id="leftHorseShoeSwf" />')
                        .appendTo(adtechSettings.globalOptions.leftHorseShoeContainer);
            }

            /** Add left banner flash **/
            if (settings.leftSwf != '') {
                    $.loadWithSwfObject(settings.leftSwf, settings.clickTagFormatLeft, settings.clicktagsLeft , 'leftHorseShoeSwf', settings.leftWidth, settings.leftHeight, settings.flashVersion.toString(), settings.wmode, false, settings.leftAltImg);
            }

             /** Or left image  **/
             if (settings.leftImg != '' && settings.extCodeLeft == '') {
                  $.loadImageObject('leftHorseShoeImg', settings.leftImg, adtechSettings.globalOptions.leftHorseShoeContainer, settings.clicktagsLeft);
             }

             /** External code **/
             if (settings.extCodeLeft != '') {
                 $.addExternalCode(settings.extCodeLeft, settings.clicktagsLeft, adtechSettings.globalOptions.leftHorseShoeContainer);
             }

             /** Add top banner flash  **/
             if (settings.topSwf != '') {
                    $.loadWithSwfObject(settings.topSwf, settings.clickTagFormatTop, settings.clicktagsTop, settings.appendTopBannerTo.slice(1), settings.topWidth, settings.topHeight, settings.flashVersion.toString(), settings.wmode, false, settings.topAltImg);
             }

             /** Or top image **/
             if (settings.topImg != '' && settings.extCodeTop == '') {
                  $.loadImageObject('topHorseShoeImg', settings.topImg, settings.appendTopBannerTo, settings.clicktagsTop);
             }

             /** External code **/
             if (settings.extCodeTop != '') {
                 $.addExternalCode(settings.extCodeTop, settings.clicktagsTop, settings.appendTopBannerTo);
             }

             /** Show top banner wrapper. Add 1030 class, hide top banner **/
             $(adtechSettings.globalOptions.toppbannerContainer).show().addClass('w'+settings.topWidth);

             /** Add right swf/alt img container **/
             if ((settings.rightAltImg != '' || settings.rightSwf != '') && settings.rightImg == '') {
                $('<div id="rightHorseShoeSwf" />')
                        .appendTo(adtechSettings.globalOptions.rightHorseShoeContainer);
             }

             /** Add right banner flash  **/
             if (settings.rightSwf != '') {
                    $.loadWithSwfObject(settings.rightSwf, settings.clickTagFormatRight, settings.clicktagsRight , 'rightHorseShoeSwf', settings.rightWidth, settings.rightHeight, settings.flashVersion.toString(), settings.wmode, false, settings.rightAltImg);
             }

             /** Or right image **/
             if (settings.rightImg != '' && settings.extCodeRight == '') {
                  $.loadImageObject('rightHorseShoeImg', settings.rightImg, adtechSettings.globalOptions.rightHorseShoeContainer, settings.clicktagsTop);
             }

             /** External code **/
             if (settings.extCodeRight != '') {
                 $.addExternalCode(settings.extCodeRight, settings.clicktagsRight, adtechSettings.globalOptions.rightHorseShoeContainer);
             }

             if (settings.pixelCounter != '') {
                var img = '<img src="'+  settings.pixelCounter +'" style="display: none;" />';
                $.addExternalCode(img,'',adtechSettings.globalOptions.leftHorseShoeContainer);
             }

             /** Show horseshoe banners **/
             $(adtechSettings.horseshoeOptions.appendTopBannerTo).add(adtechSettings.globalOptions.rightHorseShoeContainer).add(adtechSettings.globalOptions.leftHorseShoeContainer).show();
             $(adtechSettings.globalOptions.leftHorseShoeContainer).add(adtechSettings.globalOptions.rightHorseShoeContainer).addClass('w'+settings.topWidth);

             /** Create callback function **/
             if (adtechSettings.horseshoeOptions.callBackFunc != '') {
                try {
                    var callBackFunc = new Function(adtechSettings.horseshoeOptions.callBackFunc);
                    callBackFunc();
                } catch(err) {};
            }

         };

         /********************************************
        *  Pagecurl, topbanner only (TODO: Netboard) *
        * *******************************************/

         $.pagecurl = function (pCurlOptions) {

            var defaults = {
                appendToWhere: adtechSettings.pagecurlOptions.appendToWhere,
                flashurl: adtechSettings.globalOptions.flashurl,
                topAltImg: adtechSettings.globalOptions.imgurl,
                flashurl_pagecurl_small: adtechSettings.pagecurlOptions.flashurl_pagecurl_small,
                flashurl_pagecurl_big: adtechSettings.pagecurlOptions.flashurl_pagecurl_big,
                width: 768,
                height: 150,
                width_small: 240,
                height_small: 150,
                width_big: 868,
                height_big: 630,
                flashVersion: 9,
                wmode: 'transparent',
                pixelCounter: adtechSettings.globalOptions.imgurl,
                clickTagFormat: adtechSettings.globalOptions.clickTagFormat,
                clicktags: adtechSettings.globalOptions.clicktags,
                flashvars_small: {
                    topCornerFile: adtechSettings.globalOptions.flashurl,
                    flashBgColor: '000000',
                    animate: adtechSettings.pagecurlOptions.flashvars_small_animate
                },
                flashvars_big: {
                    topCornerFile: adtechSettings.globalOptions.flashurl,
                    flashBgColor: '000000',
                    animate: 'false',
                    mainFlashFile: adtechSettings.globalOptions.flashurl,
                    clicktags_big: adtechSettings.globalOptions.flashurl,
                    clickTagFormat_big: adtechSettings.globalOptions.clickTagFormat
                }
            },

            settings = $.extend({}, defaults, pCurlOptions);

            var appendToThis = settings.appendToWhere == 'toppbanner' ? adtechSettings.pagecurlOptions.topbannerID : adtechSettings.pagecurlOptions.netboardID;

            $('<div id="pagecurl_banner_swf" />')
               .appendTo(appendToThis);

            /** Add flash using swfObject **/
            $.loadWithSwfObject(settings.flashurl, settings.clickTagFormat, settings.clicktags , "pagecurl_banner_swf", settings.width, settings.height, settings.flashVersion.toString(), settings.wmode, false, settings.leftAltImg, false, settings.topAltImg);

            /** Set z-indexes and such **/
            $(appendToThis)
               .addClass('pagecurl_container')
               .show();

            /** Add pagecurl flashes **/
            $(document).ready(function () {

                 var smallContainer = $('<div id="pagecurl_small_container" class="pagecurl_visible" />')
                    .append('<div id="pagecurl_small_swf" />')
                    .appendTo(appendToThis);

                 if (settings.pixelCounter != '') {
                    var img = '<img src="'+  settings.pixelCounter +'" style="display: none;" />';
                    $.addExternalCode(img,'',smallContainer);
                 }

                 var bigContainer = $('<div id="pagecurl_big_container" />')
                    .append('<div id="pagecurl_big_swf" />')
                    .appendTo(appendToThis);

                 /** Add flash using swfObject **/
                 $.loadWithSwfObject(settings.flashurl_pagecurl_small, settings.clickTagFormat, settings.clicktags , "pagecurl_small_swf", settings.width_small, settings.height_small, settings.flashVersion.toString(), settings.wmode, settings.flashvars_small, false);
                 $.loadWithSwfObject(settings.flashurl_pagecurl_big, settings.clickTagFormat_big, settings.clicktags_big , "pagecurl_big_swf", settings.width_big, settings.height_big, settings.flashVersion.toString(), settings.wmode, settings.flashvars_big, false);

                 /** Mouseover events, control opening and closing of flash/curl **/
                 smallContainer.mouseover(function () {
                     $(this).add(bigContainer).toggleClass('pagecurl_visible');
                });

                bigContainer.mouseout(function () {
                    setTimeout(function () {
                       $(this).add(smallContainer).toggleClass('pagecurl_visible');
                    }, adtechSettings.pagecurlOptions.timeout);
                });

            });

            /** Create callback function **/
             if (adtechSettings.pagecurlOptions.callBackFunc != '') {
                try {
                    var callBackFunc = new Function(adtechSettings.pagecurlOptions.callBackFunc);
                    callBackFunc();
                } catch(err) {};
            }

         };

          /**************************************
          *  Reverse L - with expandable option *
          * ************************************/

         $.LAd = function(LOptions) {

         var defaults = {
             isExpandable: false,
             topBannerSwf: adtechSettings.globalOptions.flashurl,
             topBannerImg: adtechSettings.globalOptions.imgurl,
             topAltImg: adtechSettings.globalOptions.imgurl,
             extCodeTop: adtechSettings.globalOptions.extCode,
             rightBannerSwf: adtechSettings.globalOptions.flashurl,
             rightBannerImg: adtechSettings.globalOptions.imgurl,
             rightAltImg: adtechSettings.globalOptions.imgurl,
             extCodeRight: adtechSettings.globalOptions.extCode,
             expandableSwf: adtechSettings.globalOptions.flashurl,
             topBannerWidth: 768,
             topBannerHeight: 150,
             rightBannerWidth: 180,
             rightBannerHeight: 1000,
             expandableWidth: 948,
             expandableHeight: 1000,
             clickTagFormatTop: adtechSettings.globalOptions.clickTagFormat,
             clickTagFormatRight:  adtechSettings.globalOptions.clickTagFormat,
             clickTagFormatExpandable:  adtechSettings.globalOptions.clickTagFormat,
             clicktagsTop:  adtechSettings.globalOptions.clicktags,
             clicktagsRight: adtechSettings.globalOptions.clicktags,
             clicktagsExpandable: adtechSettings.globalOptions.clicktags,
             flashVersion: adtechSettings.globalOptions.flashVersion,
             wmode: adtechSettings.globalOptions.wmode,
             pixelCounter: adtechSettings.globalOptions.imgurl,
             pixelCounterExpanded: adtechSettings.globalOptions.imgurl,
             shiftRight: adtechSettings.lAdOptions.shiftRight,
             appendToDiv: adtechSettings.lAdOptions.appendToDiv
         },

         settings = $.extend({}, defaults, LOptions);

         var rightBar = $('<div id="Stolpe2_container" />')
            .append('<div id="rightLSwf" />')
            .appendTo(adtechSettings.globalOptions.rightHorseShoeContainer);

         /** Add top ALT image/swf container **/
         if (settings.topAltImg != '' || settings.topBannerSwf != '') {
             var topBar = $('<div id="leftTopL" />')
                     .appendTo(settings.appendToDiv);
             $('<div id="leftTopSwf" />')
                     .appendTo(topBar);
         }

         /** Add top banner flash  **/
         if (settings.topBannerSwf != '' && settings.extCodeTop == '') {
                 $.loadWithSwfObject(settings.topBannerSwf, settings.clickTagFormatTop, settings.clicktagsTop , "leftTopSwf", settings.topBannerWidth, settings.topBannerHeight, settings.flashVersion.toString(), settings.wmode, false, settings.topAltImg);
         }

         /** Or top image **/
         if (settings.topBannerImg != '' && settings.extCodeTop == '') {
              /** Only pass clictags/href if not expandable **/
              var include_tophref = !settings.isExpandable ? settings.clicktagsTop : '';
              $.loadImageObject('topBannerImg', settings.topBannerImg, settings.appendToDiv, include_tophref);
         }

         /** External code **/
         if (settings.extCodeTop != '') {
             $.addExternalCode(settings.extCodeTop, settings.clicktagsTop, adtechSettings.globalOptions.toppbannerContainer);
         }

         /** Shift right, align right accordingly, show div **/
         $(settings.appendToDiv)
                 .css('right', '-'+ settings.shiftRight + 'px')
                 .show();

         /** Add right banner flash **/
         if (settings.rightBannerSwf != '' && settings.extCodeRight == '' ) {
                $.loadWithSwfObject(settings.rightBannerSwf, settings.clickTagFormatRight, settings.clicktagsRight , "rightLSwf", settings.rightBannerWidth, settings.rightBannerHeight, settings.flashVersion.toString(), settings.wmode, false, settings.rightAltImg);
         }

         /** Or right image **/
         if (settings.rightBannerImg != '' && settings.extCodeRight == '') {
              /** Only pass clictags/href if not expandable **/
              var include_righthref = !settings.isExpandable ? settings.clicktagsRight : '';
              $.loadImageObject('rightBannerImg', settings.rightBannerImg, '#Stolpe2_container', include_righthref);
         }

         /** External code **/
         if (settings.extCodeRight != '') {
             $.addExternalCode(settings.extCodeRight, settings.clicktagsRight, adtechSettings.globalOptions.rightHorseShoeContainer);
         }

         if (settings.pixelCounter != '') {
              var img = '<img src="'+  settings.pixelCounter +'" style="display: none;" />';
              $.addExternalCode(img,'',rightBar);
         }

         /** Alter "viewport width" **/
         if (adtechSettings.lAdOptions.alterViewport) { $(adtechSettings.lAdOptions.alterViewportID).css({width: adtechSettings.lAdOptions.alterViewportWidth}); }

         /** If expandable banner template **/
         if (settings.isExpandable) {

             /** Set up divs for big banner **/
             var bigBanner = $('<div id="bigLBanner" />')
                 .hide()
                 .append('<span id="LBarX"> '+ adtechSettings.lAdOptions.closeBtnText +' </span>')
                 .append('<div id="bigLSwf" />')
                 .appendTo(settings.appendToDiv);

            if (settings.pixelCounterExpanded != '') {
                var img = '<img src="'+  settings.pixelCounterExpanded +'" style="display: none;" />';
                $.addExternalCode(img,'',bigBanner);
            }

            /** Close button? **/
            if (adtechSettings.lAdOptions.closeBtn) {
                var lBarX = $('<span id="LBarX"> '+ adtechSettings.lAdOptions.closeBtnText +' </span>');
                bigBanner
                    .append(lBarX);
            }

             /** Expandable not loaded yet **/
             var bigLExpandedLoaded = false;

             /** Onclick events **/
             topBar.add(rightBar).add(lBarX).mousedown( function(e) {
                  if(bigBanner.is(':hidden')) {
                      /** Z-index of top banner and viewportads. ie7 bug **/
                      $(settings.appendToDiv).add('#viewportAds').css({ zIndex: 9900 });
                      bigBanner.show();
                      if(!bigLExpandedLoaded) {
                        /** Set width and height of container **/
                        bigBanner.css({width: settings.expandableWidth, height: settings.expandableHeight});
                        /** Load large flash **/
                        $.loadWithSwfObject(settings.expandableSwf, settings.clickTagFormatExpandable, settings.clicktagsExpandable , "bigLSwf", settings.expandableWidth, settings.expandableHeight, settings.flashVersion.toString(), settings.wmode, false);
                        bigLExpandedLoaded = true;
                      }
                   } else {
                     bigBanner.hide();
                     $('#viewportAds').css({ zIndex: 0 });
                   }
               });

              };

             /** Create callback function **/
            if (adtechSettings.lAdOptions.callBackFunc != '') {
                try {
                    var callBackFunc = new Function(adtechSettings.lAdOptions.callBackFunc);
                    callBackFunc();
                } catch(err) {};
            }

         };

         /****************************
        *  Sticky skyscraper banner *
        * **************************/

        $.stickySkyscraper = function(stickySkyscraperOptions) {

         var defaults = {

             flashurl: adtechSettings.globalOptions.flashurl,
             imgurl: adtechSettings.globalOptions.imgurl,
             altImg: adtechSettings.globalOptions.imgurl,
             extCode: adtechSettings.globalOptions.extCode,
             width: adtechSettings.stickySkyscraperOptions.width,
             height: adtechSettings.stickySkyscraperOptions.height,
             flashVersion: adtechSettings.globalOptions.flashVersion,
             wmode: adtechSettings.globalOptions.wmode,
             pixelCounter: adtechSettings.globalOptions.imgurl,
             clickTagFormat: adtechSettings.globalOptions.clickTagFormat,
             clicktags: adtechSettings.globalOptions.clicktags
         },

         settings = $.extend({}, defaults, stickySkyscraperOptions);

         var stickySkySkraper = $('<div id="stickySkyscraper" />')
            .insertAfter(adtechSettings.stickySkyscraperOptions.insertAfter)
            .hide()
            .css({
               width: settings.width,
               zIndex: settings.zIndex
            });

          var stickySkySkraperInner = $('<div id="stickySkyscraperInner" />')
            .appendTo(stickySkySkraper)
            .append('<span class="'+ adtechSettings.stickySkyscraperOptions.adMarkerClass +'"><span>V</span> '+ adtechSettings.stickySkyscraperOptions.adText +'</span>')
            .css({
               width: settings.width,
               height: settings.height + 15
            });

           $('<div id="stickySkyscraperSwf" />')
                .appendTo(stickySkySkraperInner);

           /** Add flash using swfObject **/
           if (settings.flashurl != '' && settings.extCode == '') {
                $.loadWithSwfObject(settings.flashurl, settings.clickTagFormat, settings.clicktags , "stickySkyscraperSwf", settings.width, settings.height, settings.flashVersion.toString(), settings.wmode, false, settings.altImg);
           }

           /** Or image **/
           if (settings.imgurl != '' && settings.extCode == '') {
              $.loadImageObject('stickySkyscraperImg', settings.imgurl, "#stickySkyscraperSwf", settings.clicktags);
           }

           /** Or external code **/
           if (settings.extCode != '') {
                 $.addExternalCode(unescape(settings.extCode),settings.clicktags, "#stickySkyscraperSwf");
           }

           if (settings.pixelCounter != '') {
                var img = '<img src="'+  settings.pixelCounter +'" style="display: none;" />';
                $.addExternalCode(img,'',stickySkySkraper);
           }

           $sticky_btm_pos_max = $(adtechSettings.stickySkyscraperOptions.btmMaxPosContainer).offset().top - adtechSettings.stickySkyscraperOptions.btmPadding;
           $body_offset = $(adtechSettings.stickySkyscraperOptions.relativeParent).offset().top;

           /** Skip IE6 **/
           if (window.XMLHttpRequest) {
              $(window).scroll(function () {
                    if ($(window).scrollTop() + settings.height >= $sticky_btm_pos_max) {
                        stickySkySkraper.css({ position: 'absolute', top: $sticky_btm_pos_max - settings.height - $body_offset});
                    } else if ($(window).scrollTop() >= $(adtechSettings.stickySkyscraperOptions.insertAfter).offset().top) {
                        stickySkySkraper.css({ position: 'fixed', top: '0' });
                    } else {
                        stickySkySkraper.css({ position: 'static', top: 'auto' });
                    }
               });
           }

           /** Fade in **/
           stickySkySkraper
            .fadeIn(500);

           if (adtechSettings.stickySkyscraperOptions.callBackFunc != '') {
                try {
                    var callBackFunc = new Function(adtechSettings.stickySkyscraperOptions.callBackFunc);
                    callBackFunc();
                } catch(err) {};
            }

         };


        /****************************
        *  Expandable click banner  *
        * **************************/

       var itr_expandable = 1;

       $.standardExpandable = function(expandableOptions) {

       var defaults = {
             expandableAlias: '_container',
             pushContent: false,
             pushContentWhere: 'below',
             animate: false,
             duration: 500,
             closeButton: false,
             closeButtonTxt: 'X',
             collapsedSwf: adtechSettings.globalOptions.flashurl,
             collapsedImg: adtechSettings.globalOptions.imgurl,
             collapsedAltImg: adtechSettings.globalOptions.imgurl,
             collapsedExtCode: adtechSettings.globalOptions.extCode,
             collapsedWidth: adtechSettings.standardExpandableOptions.width,
             collapsedHeight: adtechSettings.standardExpandableOptions.height,
             expandedSwf: adtechSettings.globalOptions.flashurl,
             expandedAltImg: adtechSettings.globalOptions.imgurl,
             expandedImg: adtechSettings.globalOptions.imgurl,
             expandedExtCode: adtechSettings.globalOptions.extCode,
             expandedWidth: adtechSettings.standardExpandableOptions.width,
             expandedHeight: adtechSettings.standardExpandableOptions.height,
             flashVersion: 9,
             wmode: "opaque",
             pixelCounter: adtechSettings.globalOptions.imgurl,
             pixelCounterExpanded: adtechSettings.globalOptions.imgurl,
             clickTagFormatCollapsed: adtechSettings.globalOptions.clickTagFormat,
             clickTagFormatExpanded: adtechSettings.globalOptions.clickTagFormat,
             clicktagsCollapsed: adtechSettings.globalOptions.clicktags,
             clicktagsExpanded: adtechSettings.globalOptions.clicktags
       },

       settings = $.extend({}, defaults, expandableOptions);

       /** Function for appending closebutton **/
       jQuery.fn.appendCloseButton = function (settings) {
          if ($(this).find("span.expandableCloseX").length == 0) {
            $('<span class="expandableCloseX '+ settings.direction +'"> '+ settings.closeButtonTxt +' </span>')
                .appendTo(this);
            $(".expandableCloseX").click(function () {
               $(this).parents("div:first").animateCollapse(settings);
                return false;
            });
          } else {
              $(this).find("span.expandableCloseX").show();
          }
       };

      /** Function for animating the collapse of a container **/
      jQuery.fn.animateCollapse = function (settings) {
         $(this).animate({
             width: settings.collapsedWidth,
             height: settings.collapsedHeight
          }, settings.duration, function() {
             if ($(this).hasClass('exp_large_flash_container')) {
                $(this).hide();
             }
             $(this).find("span").hide();
             $(this).parents(".expandableBanner:first").removeClass("open");
         });
       };

       /** Call from actionscript **/
       $.expandThis = function(obj) {

            /** Img or flash calling? **/
           $smallContainer = $(obj).is("a") ? $(obj).parents(".exp_small_flash_container:first") : $(obj).find(".exp_small_flash_container:first");

           settings =  $smallContainer.parents(".expandableBanner:first").data('setting');

           /** One or two flash files ?? */

           var isOneFile = (settings.expandedSwf == "" && settings.expandedImg == "") || (settings.collapsedSwf != "" && settings.expandedSwf == "");
           var isOneImg = settings.collapsedImg != '' && settings.expandedImg == "";

           $expLargeContainer = $smallContainer.next(".exp_large_flash_container");
           var $expContainer = $smallContainer.parents(".expandableBanner:first");

           $whichContainer = isOneFile ? $smallContainer : $expLargeContainer ;

           var isExpanded =  $smallContainer.height() == settings.expandedHeight;
           var largeFileHidden = !isOneFile && $expLargeContainer.is(":hidden");
           var largeFileVisible = !isOneFile && $expLargeContainer.is(":visible");

           if (largeFileHidden || (isOneFile && !isExpanded) || (isOneImg && !isExpanded)) {
               $expContainer.addClass("open");
               if (settings.animate) {
                $whichContainer.css({width: settings.collapsedWidth + "px", height: settings.collapsedHeight + "px", overflow: 'hidden'});
                $whichContainer.animate({
                     width: settings.expandedWidth,
                     height: settings.expandedHeight
                  }, settings.duration);
               } else {
                  $whichContainer.css({width: settings.expandedWidth + "px", height: settings.expandedHeight + "px", overflow: 'hidden'});
                  $whichContainer.show();
               }
           } else if (largeFileVisible || (isOneFile && isExpanded)) {
               if (settings.animate) {
                 $whichContainer.animateCollapse(settings);
               } else {
                 if (isOneFile) {
                  $whichContainer.css({width: settings.collapsedWidth + "px", height: settings.collapsedHeight + "px", overflow: 'hidden'});
                  $expContainer.removeClass("open");
                } else {
                  $whichContainer.hide();
                  $expContainer.removeClass("open");
                }
               }
           } else {
              $expContainer.addClass("open");
              /** Over, above, or below original flash file? **/
              var largeFlashContainer = $('<div class="exp_large_flash_container none" />');
              if (settings.pushContent && settings.pushContentWhere == 'above') {
                  largeFlashContainer
                    .insertBefore($smallContainer);
              } else if (settings.pushContent && settings.pushContentWhere == 'below') {
                 largeFlashContainer
                    .insertAfter($smallContainer);
              } else {
                  largeFlashContainer
                    .css({position: 'absolute'})
                    .insertAfter($smallContainer);
              }

              $expLargeContainer = $smallContainer.next(".exp_large_flash_container");

              $('<div id="exp_large_flash'+ itr_expandable +'" />')
                   .appendTo($expLargeContainer);

              /** Set relative/absolute positioning **/
               var relPos = settings.direction == 'down-right' ? $expLargeContainer.css({top: 0, left: 0}) : (settings.direction == 'down-left' ? $expLargeContainer.css({top: 0, right: 0}) : (settings.direction == 'up-right' ? $expLargeContainer.css({bottom: 0, left: 0}) : $whichContainer.css({bottom: 0, right: 0})));

              /** Add flash using swfObject **/
              if (settings.expandedSwf != '' && settings.expandedExtCode == '') {
                    /** Placement var to send to flash file **/
                    var flashvars = {
                       placement: obj
                   };
                   $.loadWithSwfObject(settings.expandedSwf, settings.clickTagFormatExpanded, settings.clicktagsExpanded , "exp_large_flash" + itr_expandable, settings.expandedWidth, settings.expandedHeight, settings.flashVersion.toString(), settings.wmode, flashvars, settings.expandedAltImg);
                   itr_expandable++;
              }

              /** Or image **/
              if (settings.expandedImg != '' && settings.expandedExtCode == '') {
                 $.loadImageObject('exp_large_flash_img' + itr_expandable, settings.expandedImg, "#exp_large_flash" + itr_expandable, settings.clicktagsExpanded);
                 itr_expandable++;
                 $($expLargeContainer).toggle(function() {
                     window.open($(this).find("a").attr("href"));
                  }, function () {
                     return $.collapseThis($expContainer);
                  });
              }

              if (settings.pixelCounterExpanded != '') {
                    var img = '<img src="'+  settings.pixelCounterExpanded +'" style="display: none;" />';
                    $.addExternalCode(img,'',$expLargeContainer);
              }

              if (settings.animate) {
                $expLargeContainer.css({width: "300px", height: "200px", overflow: 'hidden'});
                $expLargeContainer.animate({
                     width: settings.expandedWidth,
                     height: settings.expandedHeight
                  }, settings.duration);
              } else {
                  $expLargeContainer.show();
              }
           }
           if (settings.closeButton) {
             $expLargeContainer.appendCloseButton(settings);
           }

           return false;

       };

       $.collapseThis = function(obj) {
            settings =  $(obj).data('setting');
            $expContainer = $("#"+ settings.expandableAlias + "_container");
            $expContainerLarge = $expContainer.find(".exp_large_flash_container");
            $expContainerSmall = $expContainer.find(".exp_small_flash_container");
            if ($expContainerLarge.length > 0) {
               if (settings.animate) {
                  $expContainerLarge.animateCollapse(settings);
                } else {
                  $expContainerLarge.hide();
                  $expContainer.removeClass("open");
                }
            } else {
                if (settings.animate) {
                  $expContainerSmall.animateCollapse(settings);
                } else {
                  $expContainerSmall.css({width: settings.collapsedWidth + "px", height: settings.collapsedHeight + "px", overflow: 'hidden'});
                  $expContainer.removeClass("open");
                }
            }
       };

       /** Which container? **/
       $expContainer = $("#" + settings.expandableAlias + adtechSettings.standardExpandableOptions.expContainerEnding);

       /** Placement var to send to flash file **/
       var flashvars = {
           placement: "#" + settings.expandableAlias + adtechSettings.standardExpandableOptions.expContainerEnding
       };

       $expSmallContainer = $('<div class="exp_small_flash_container" />')
            .appendTo($expContainer);

       $thisSmallContainer = $('<div id="exp_small_flash'+ itr_expandable +'" />')
                .appendTo($expSmallContainer);

       /** Add flash using swfObject **/
       if (settings.collapsedSwf != '' && settings.collapsedExtCode == '') {
            var w = settings.expandedSwf == "" ? settings.expandedWidth  : settings.collapsedWidth;
            var h = settings.expandedSwf == "" ? settings.expandedHeight  : settings.collapsedHeight;
            $.loadWithSwfObject(settings.collapsedSwf, settings.clickTagFormatCollapsed, settings.clicktagsCollapsed , "exp_small_flash" + itr_expandable, w, h, settings.flashVersion.toString(), settings.wmode, flashvars, settings.collapsedAltImg);
            itr_expandable++;
            if (settings.closeButton && settings.expandedSwf == "") {
               $expSmallContainer.click(function (e) {
                     $(e.currentTarget).appendCloseButton(settings);
                });
           }
       }

       /** Or image **/
       if (settings.collapsedImg != '' && settings.collapsedExtCode == '') {
          $.loadImageObject('exp_small_flash_img' +itr_expandable, settings.collapsedImg, "#exp_small_flash" +itr_expandable, settings.clicktagsExpanded);
          itr_expandable++;
          $expSmallContainer.find("a").click(function (e) {
             if (settings.closeButton && settings.expandedImg == "") {
                $(e.currentTarget).parents(".exp_small_flash_container:first").appendCloseButton(settings);
             }
             var isExpanded =  $(e.currentTarget).parents(".exp_small_flash_container:first").height() == settings.expandedHeight;
             if (isExpanded && $(this).data('clicked') != true) {
                $(this).data('clicked', true);
             } else {
                $(this).data('clicked', false);
                return $.expandThis(e.currentTarget);
             }
          });
       }

       /** Or external code **/
       if (settings.collapsedExtCode != '') {
           /** Check if we should add a friendly iframe **/
           if (settings.collapsedExtCode.toLowerCase().indexOf("iframe") == -1) {
               if (window.location.href.indexOf("aftenposten.no") != -1) {
                  document.domain = adtechSettings.globalOptions.documentDomain;
               }
               iframeAdArray.push(settings.collapsedExtCode);
               $('<iframe width="'+ settings.expandedWidth +'" height="'+ settings.expandedHeight +'" frameborder="0" marginwidth="0" marginheight="0" class="extIframe" name="extIframe" scrolling="no" src="'+ adtechSettings.standardExpandableOptions.iframeWrapperUrl +'?placement='+ $expContainer +'" id="'+ settings.expandableAlias +'_iframe"></iframe>')
                    .appendTo($thisSmallContainer);
           } else {
               $.addExternalCode(settings.collapsedExtCode, settings.clicktagsCollapsed, "#exp_small_flash" +itr_expandable );
           }
           itr_expandable++;
       }

       if (settings.pixelCounter != '') {
             var img = '<img src="'+  settings.pixelCounter +'" style="display: none;" />';
             $.addExternalCode(img,'',$expContainer);
       }

       /** Set relative/absolute positioning **/
       $expContainer.addClass("expandableBanner")
               .css({width: settings.collapsedWidth + "px", height: settings.collapsedHeight + "px"});
       $expSmallContainer
               .css({width: settings.collapsedWidth + "px", height: settings.collapsedHeight + "px", overflow: 'hidden'});

       /** One or two flash files ?? */
       var isOneFile = settings.expandedSwf == "";
       $whichContainer = isOneFile ? $expSmallContainer : $expContainer.find(".exp_large_flash_container") ;
       if (isOneFile) {
           /** Set relative/absolute positioning, if one file **/
           $whichContainer.css({position: 'absolute'});
           var relPos = settings.direction == 'down-right' ? $whichContainer.css({top: 0, left: 0}) : (settings.direction == 'down-left' ? $whichContainer.css({top: 0, right: 0}) : (settings.direction == 'up-right' ? $whichContainer.css({bottom: 0, left: 0}) : $whichContainer.css({bottom: 0, right: 0})));
       }

       /** Attach data to element **/
       $expContainer.data(
           'setting', settings
       );

       if (adtechSettings.standardExpandableOptions.callBackFunc != '') {
            try {
                var callBackFunc = new Function(adtechSettings.standardExpandableOptions.callBackFunc);
                callBackFunc();
            } catch(err) {};
        }

       /** Fade in **/
       $expContainer
             .fadeIn(500);

       };

 })(jQuery);

var adtechSettings = {
    tAdOptions : { callBackFunc: 'addTAdClass()' },
    lAdOptions : { callBackFunc: 'addLBodyClass()' }
};

jQuery.updateAdtechOptions(adtechSettings);

jQuery(document).ready(function () {
    /*iframe Firefox Fix */
    if(jQuery.browser.mozilla){
        jQuery("iframe").each(function () {
           jQuery(this).attr("src", jQuery(this).attr("src"));
        });
    }
});
