/* Change to make jQuery play alongside Prototype */
$j = jQuery.noConflict();

  /**************************************
  * MNO Ad Specials
  *************************************/

 (function($j){

     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 **/
         toppknappContainer: '#adTopLeft', /** The class or unique id of the main "toppknapp" adpos div **/
         toppbannerContainer: '#adTopRight', /** The class or unique id of the main "toppbanner" adpos div **/
         toppStripeContainer: '#adTopStripe',
         tickerContainer: '#adOuterBottomFixed'

        }, tickerOptions :  {

        /*************************
         *  Sticky Ticker Banner *
         * **********************/

            /** Statics **/
                appendToDiv: '#Ticker_container',
                setMarker: false, /* Use admarker tag */
                adMarkerClass: 'adMarker f-666 f-75 s-01 tickerMarker', /** Classname of admarker **/
                adText: 'annonse',
                callBackFunc: false, /** Additional function to be executed at the end. Set to false or empty to skip **/
                ie6fixPageWidth: 1030, /* Width of page to center ad */
                ie6fixTopOffset: 120, /* Offset to align to bottom on load */

            /** Defaults **/
                width: 1280,
                height: 30,
                zIndex: 1100,
                align: 'center'

         }, tAdOptions : {

         /********
         *  T-AD *
         * *******/

            /** Statics **/
                insertAfterWhere: '.adInnerBarLeft', /** 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: '#Toppknapp_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 **/

         }, localHorseshoeOptions : {

         /*************
         *  Local Horseshoe *
         * ************/

             /** Statics **/
             appendTopBannerTo: '#Hestesko_topp_container', /** Needs to be a unique ID. Shouldn't need to change. Is in display_ad **/
             closeBtn: true, /** Html close button? **/
             closeBtnText: 'X',
             callBackFunc: false /** Additional function to be executed at the end. Set to false or empty to skip **/

         }, localHorseshoePosOptions : {

         /**************************************************************
         *  Local 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: 0, /** How many pixels to shift right. Uses negative margin-right **/ // 0, by Roar
                 appendToDiv: '#Toppbanner_container',  /** same identifier as Pagecurl topbannerID **/
                 alterViewport: false, /** Alter "viewport" div width" to center page properly? **/ //False by Roar
                 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 **/
        }};

        /*******************************
        * Updating settings *
        * ****************************/

        $j.updateAdtechOptions = function(updateSettings) {
            adtechSettings = $j.extend(true, adtechSettings, updateSettings);
        };

         /*********************
        *  adTech functions *
        * *******************/

        $j.groupId = Math.round(Math.random() * 1000000000);

        $j.getTimeStamp =  new Date().getTime();

        /***************************************
        *  Add flash function, using swfObject *
        * *************************************/

       var swfobject_version = (window.swfobject) ? 2 : (window.SWFObject) ? 1 : false;

       $j.loadWithSwfObject = function (file, clicktagFormat, clicktags, insertFlashToDiv, flashWidth, flashHeight, flashVersion, wmode, flashVars, altImg) {

            if (swfobject_version >= 2) {
              /** Check to see if flash plugin installed **/
              if (swfobject.hasFlashPlayerVersion(flashVersion)) {
                  var flashvars_string = '';
                  if (typeof(flashVars) != 'undefined') {
                      $j.each(flashVars, function(key, value) {
                         if (key != '') { flashvars_string += key + "=" + value + "&"; };
                      });
                  }
                  var clicktags_string = '';
                  if (typeof(clicktags) != 'undefined' && typeof(clicktags) != 'string') {
                      $j.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 != '') {  $j.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 *
        * *****************************/

        $j.loadImageObject = function(imgId,imgfile,insertImgToDiv,clicktag) {

            /** insertImgToDiv points to id - # ? **/
            insertImgToDiv = insertImgToDiv.search(/\#/) == -1 ? '#' + insertImgToDiv : insertImgToDiv;

            $j('<img />')
                .attr({
                    src: imgfile,
                    id: imgId
                })
                .appendTo(insertImgToDiv);

            /** IF objekt **/
            if (typeof(clicktag) != 'string') {

                $j.getAttributeByIndex = function(obj, index) {
                  var i = 0;
                  for (var attr in obj){
                    if (index === i){
                      return obj[attr];
                    }
                    i++;
                  }
                  return null;
                 };

                clicktag = $j.getAttributeByIndex(clicktag, 0);

            }

            if (clicktag != '') {
                 $j('#' + imgId).wrap('<a href="'+ unescape(clicktag) +'" target="_blank" />');
             }

        };

         /*************************************
        *  Add external code banners function *
        * ************************************/

        $j.addExternalCode = function(code,clicktag,where) {

           code = code.replace(/(\[rand\])/, $j.groupId);
           code = code.replace(/(\[timestamp\])/, $j.getTimeStamp);
           code = code.replace(/(\[click\])/, clicktag);

           $j(code).appendTo(where);

        };

        /******************
        *  Sticky Ticker *
        * ****************/

       $j.ticker = function(tickerOptions) {

         var defaults = {
             flashUrl: adtechSettings.globalOptions.flashurl,
			 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.width,
             wmode: adtechSettings.globalOptions.wmode,
             clickTagFormat: adtechSettings.globalOptions.clickTagFormat,
             clicktags: adtechSettings.globalOptions.clicktags
         },

         settings = $j.extend({}, defaults, tickerOptions);

            /* Optional ticker marker */
            if(settings.setMarker == true) {
              $j(adtechSettings.tickerOptions.appendToDiv)
                .append('<span class="'+ adtechSettings.tickerOptions.adMarkerClass +'"><span>V</span> '+ adtechSettings.tickerOptions.adText +'</span>');
            }

            /* Align div */
            $j(adtechSettings.tickerOptions.appendToDiv).css({
                   width: settings.width,
                   height: settings.height,
                   margin: settings.align == 'center' ? '0 auto' : '0'
            });

            /* Add ad target for flash and external code */
            if (settings.flashUrl != '' || settings.extCode != '') {
                $j('<div id="tickerAd" />').appendTo(adtechSettings.tickerOptions.appendToDiv);
            }

            /** Use flash */
            if (settings.flashUrl != '' && settings.extCode == '') {
                $j.loadWithSwfObject(settings.flashUrl, settings.clickTagFormat, settings.clicktags , "tickerAd", settings.width, settings.height, settings.flashVersion.toString(), settings.wmode, false, settings.altImg);
            }

            /* Use image */
            if (settings.imgUrl != '' && settings.extCode == '' && settings.flashUrl == '') {
                $j.loadImageObject("tickerAd", settings.imgUrl, adtechSettings.tickerOptions.appendToDiv, settings.clicktags);
            }

            /* Use external code */
            if (settings.extCode != '' && settings.flashUrl == '') {
                $j.addExternalCode(settings.extCode,settings.clicktags, "#tickerAd");
            }

            /** IE 6 fix - JS belongs here NOT in css! **/
            if($j.browser.msie == true && $j.browser.version == 6.0) {

                /* Set position on load */
                var posTop = (((document.documentElement ? document.documentElement.clientHeight : document.body.clientHeight) - adtechSettings.tickerOptions.ie6fixTopOffset) + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop));
                $j(adtechSettings.globalOptions.tickerContainer).css({
                    position: 'absolute',
                    top: posTop + 'px',
                    left: -(settings.width - adtechSettings.tickerOptions.ie6fixPageWidth)/2 + 'px',
                    width: settings.width + 'px'
                });

                /* Update top position on scroll */
                $j(window).scroll( function() {
                    var posTop = (((document.documentElement ? document.documentElement.clientHeight : document.body.clientHeight) - adtechSettings.tickerOptions.ie6fixTopOffset) + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop));
                    $j(adtechSettings.globalOptions.tickerContainer).css({
                        top: posTop + 'px'
                    });
                });
            }

            /** Fade in **/
            $j(adtechSettings.globalOptions.tickerContainer).fadeIn(500);

            if (adtechSettings.tickerOptions.callBackFunc != '') {
                try {
                    var callBackFunc = new Function(adtechSettings.tickerOptions.callBackFunc);
                    callBackFunc();
                } catch(err) {};
            }
         };

         /*********
          *  T-Ad *
          * ******/

         $j.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,
             insertAfterWhere: adtechSettings.tAdOptions.insertAfterWhere
         },

         settings = $j.extend({}, defaults, tAdOptions);

         $j('.adInnerBarLeft').css('display', 'block');
         $j('#adInnerBarLeft').css('display', 'block');

         /* Place into left horse wrapper */
         $j(adtechSettings.globalOptions.leftHorseShoeContainer).append('<div id="Stolpe1_container" />');

         /* Add vertical flash */
         if (settings.tbarVertSwf != '') {
             $j('#Stolpe1_container').append('<div id="tAdLeft" />');
             $j.loadWithSwfObject(settings.tbarVertSwf, settings.clickTagFormatVert, settings.clicktagsVert , "tAdLeft", settings.tbarVertWidth, settings.tbarVertHeight, settings.flashVersion.toString(), settings.wmode, false, settings.vertAlt);
         }

         /** Or image **/
         if (settings.tbarVertSwf == '' && settings.tbarVertImg != '') {
             if(settings.tbarExpandedUrl.indexOf('null') == -1) {
                 settings.clicktagsVert = null;
             }
             $j.loadImageObject('tAdLeft', settings.tbarVertImg, '#Stolpe1_container', settings.clicktagsVert);
         }

         /* Insert T-bar ad */
         $j('#TStripe_container').append('<div id="TBarTop" />');

         /* Add horizontal flash */
         if (settings.tbarSmallSwf != '') {
             $j('#TBarTop').append('<div id="tAdInnerBar" />');
             $j.loadWithSwfObject(settings.tbarSmallSwf, settings.clickTagFormatHorz, settings.clicktagsHorz , "tAdInnerBar", settings.tbarSmallWidth, settings.tbarSmallHeight, settings.flashVersion.toString(), settings.wmode, false, settings.horzAlt);
         }

         /* Or image */
         if (settings.tbarSmallSwf == '' && settings.tbarSmallImg != '') {
             $j.loadImageObject('tAdInnerBar', settings.tbarSmallImg, '#TStripe_container', settings.clicktagsHorz);
         }

         /** Add class to pageBody or other element **/
         //$j(adtechSettings.tAdOptions.addClassToContainer).addClass(adtechSettings.tAdOptions.addThisClass);

         /* Explandable option */
         if(settings.tbarExpandedUrl.indexOf('null') == -1) {

             var TBarExpandedLoaded = false;

             /* Insert Expandable container */
             $j('<div id="TBarContent" />').appendTo("#TStripe_container").css('display', 'none')
               .append('<div id="LoadingTBarMain">&nbsp;</div><div id="TBarMainContainer"><div id="TBarMain">&nbsp;</div></div>');

             if (adtechSettings.tAdOptions.appendCloseBtn) {
                $j('#TBarContent').append('<div class="closeTBarContent" id="TBarX"> X </div>');
             }

             $j('#TBarTop, #Stolpe1_container, #TBarX').mousedown( function(e) {
                  if($j('#TBarContent').is(':hidden')) {
                      $j('#TBarContent').show();
                      if(!TBarExpandedLoaded) {
                        $j.loadWithSwfObject(settings.tbarExpandedUrl, settings.clickTagFormat, settings.clicktagsLarge , "TBarMain", settings.tbarExpandedWidth, settings.tbarExpandedHeight, settings.flashVersion.toString(), settings.wmode, false);
                        TBarExpandedLoaded = true;
                      }
                   } else {
                     $j('#TBarContent').hide();
                   }
               });
         }

           /** Create callback function **/
           if (adtechSettings.tAdOptions.callBackFunc != '') {
                try {
                    var callBackFunc = new Function(adtechSettings.tAdOptions.callBackFunc);
                    callBackFunc();
                } catch(err) {};
            }

          };

         /*****************************************************
          *  Interstitial. Simple offset version with timeout *
          * **************************************************/

         $j.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,
             clickTagFormat: adtechSettings.globalOptions.clickTagFormat,
             clicktags: adtechSettings.globalOptions.clicktags
         },

         settings = $j.extend({}, defaults, interstitialOptions);

         $j('<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
            });

          $j('<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 == '') {
                $j.loadWithSwfObject(settings.flashurl, settings.clickTagFormat, settings.clicktags , "interstitialSwf", settings.width, settings.height, settings.flashVersion.toString(), settings.wmode, false, settings.altImg);
           }

           if (settings.extCode != '') {
                $j.addExternalCode(settings.extCode, settings.clicktags, "#interstitialSwf");
           }

           /** Fade in **/
           $j('#interstitial')
            .show();

           /** Delay removal **/
           jQuery.fn.delayRemoval = function() {
              $j("#interstitial").animate({opacity: 1.0}, settings.timeOut*1000, function () {
                 $j("#interstitial").remove();
              });
           };

           /** Remove event **/
           jQuery.fn.removeThis = function(el) {
              if(el == "closeInterstitial") {
                  $j("#interstitial").remove();
              }  else {
                  $j(this).delayRemoval();
              }
           };

           /** Set initial timeout **/
           $j("#interstitial")
              .delayRemoval();

           /** Set "timeout" events **/
           $j('#interstitial')
             .hover( function () {
               $j(this).stop();
             }, function () {
               $j(this).removeThis();
            });

           /** Set onclick remove event **/
            $j(".closeInterstitial")
             .click( function (el) {
                $j(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 *
          * *******************************/

        $j.questback = function (qbStandardOptions) {

            var defaults = {
             qb_url: '',
             img_url: '',
             width: 468,
             target: '_blank',
             height: 400,
             timeOut: 5
            },

            settings = $j.extend({}, defaults, qbStandardOptions);

            /* Align popup to center of screen */
            var posTop = ($j(window).height()/2) - (settings.height/2);
            var posLeft = ($j(window).width()/2) - (settings.width/2);

            var QB_Window = window.open('','QuestBack','top=' + posTop + ',left=' + posLeft + ',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 *
        * ********************************************************************************/

         $j.horseshoePos = function (horseShoePosOptions) {

            var defaults = {
                width: 1030
            },

            settings = $j.extend({}, defaults, horseShoePosOptions);

            if (settings.width == 1030) { $j(adtechSettings.globalOptions.toppknappContainer).addClass("w1030"); }

            $j(adtechSettings.globalOptions.toppbannerContainer).hide();

            $j(document).ready(function () {
               if (settings.width == 1006) {
                   $j(adtechSettings.globalOptions.leftHorseShoeContainer).addClass("w1006");
                   $j(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 *
        * *****************************************************************************/

         $j.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,
                 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 = $j.extend({}, defaults, horseShoeOptions);

            /** Add left swf/alt img container **/
            if ((settings.leftAltImg != '' || settings.leftSwf != '') && settings.topImg == '') {
                $j('<div id="leftHorseShoeSwf" />').appendTo(adtechSettings.globalOptions.leftHorseShoeContainer);
            }

            /** Add left banner flash **/
            if (settings.leftSwf != '') {
                    $j.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 == '') {
                  $j.loadImageObject('leftHorseShoeImg', settings.leftImg, adtechSettings.globalOptions.leftHorseShoeContainer, settings.clicktagsLeft);
             }

             /** External code **/
             if (settings.extCodeLeft != '') {
                 $j.addExternalCode(settings.extCodeLeft, settings.clicktagsLeft, adtechSettings.globalOptions.leftHorseShoeContainer);
             }

             /** Add top banner flash  **/
             if (settings.topSwf != '') {
                $j(adtechSettings.horseshoeOptions.appendTopBannerTo).html(''); /* Added by Roar to remove unused ad-code*/
                $j('<div id="topHorseShoeSwf" />').appendTo(adtechSettings.horseshoeOptions.appendTopBannerTo);
                $j.loadWithSwfObject(settings.topSwf, settings.clickTagFormatTop, settings.clicktagsTop, 'topHorseShoeSwf', settings.topWidth, settings.topHeight, settings.flashVersion.toString(), settings.wmode, false, settings.topAltImg);
             }

             /** Or top image **/
             if (settings.topImg != '' && settings.extCodeTop == '') {
                  $j.loadImageObject('topHorseShoeImg', settings.topImg, settings.appendTopBannerTo, settings.clicktagsTop);
             }

             /** External code **/
             if (settings.extCodeTop != '') {
                 $j.addExternalCode(settings.extCodeTop, settings.clicktagsTop, settings.appendTopBannerTo);
             }

             /** Show top banner wrapper. Add 1030 class, hide top banner **/
             $j(adtechSettings.globalOptions.toppknappContainer).addClass('w'+settings.topWidth);
             $j(adtechSettings.globalOptions.toppbannerContainer).hide();
             /*$j(adtechSettings.globalOptions.toppknappContainer).remove();
             $j(adtechSettings.globalOptions.toppbannerContainer).addClass('w'+settings.topWidth);*/


             /** Add right swf/alt img container **/
             if ((settings.rightAltImg != '' || settings.rightSwf != '') && settings.rightImg == '') {
                $j('<div id="rightHorseShoeSwf" />').appendTo(adtechSettings.globalOptions.rightHorseShoeContainer);
             }

             /** Add right banner flash  **/
             if (settings.rightSwf != '') {
                    $j.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 == '') {
                  $j.loadImageObject('rightHorseShoeImg', settings.rightImg, adtechSettings.globalOptions.rightHorseShoeContainer, settings.clicktagsTop);
             }

             /** External code **/
             if (settings.extCodeRight != '') {
                 $j.addExternalCode(settings.extCodeRight, settings.clicktagsRight, adtechSettings.globalOptions.rightHorseShoeContainer);
             }

             /** Show horseshoe banners **/
             //$j(adtechSettings.horseshoeOptions.appendTopBannerTo).add(adtechSettings.globalOptions.rightHorseShoeContainer).add(adtechSettings.globalOptions.leftHorseShoeContainer).show();
             //$j(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) {};
            }

         };


        /****************************************
        * Local horseshoe using banner template *
        *****************************************/

         $j.localhorseshoe = function (localHorseShoeOptions) {

            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,
                 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.localHorseshoeOptions.appendTopBannerTo
            },

            settings = $j.extend({}, defaults, localHorseShoeOptions);

            $j('#adOuterTop').css('display', 'block');
            $j('.adOuterTop').css('display', 'block');
            $j(adtechSettings.globalOptions.leftHorseShoeContainer).append('<div id="Stolpe1_container" />');
            $j(adtechSettings.globalOptions.rightHorseShoeContainer).append('<div id="Stolpe2_container" />');

            /** Add left swf/alt img container **/
            if ((settings.leftAltImg != '' || settings.leftSwf != '') && settings.leftImg == '') {
                $j('<div id="leftHorseShoeSwf" />').appendTo('#Stolpe1_container');
            }

            /** Add left banner flash **/
            if (settings.leftSwf != '') {
                    $j.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 == '') {
                 if(settings.expandableSwf && settings.expandableSwf.indexOf('null') == -1) {
                     settings.clicktagsLeft = '';
                 }
                  $j.loadImageObject('leftHorseShoeImg', settings.leftImg, '#Stolpe1_container', settings.clicktagsLeft);
             }

             /** External code **/
             if (settings.extCodeLeft != '') {
                 $j.addExternalCode(settings.extCodeLeft, settings.clicktagsLeft, '#Stolpe1_container');
             }

             /** Add top banner flash  **/
             if (settings.topSwf != '') {
                //$j('#Hestesko_container').html(''); /* Added by Roar to remove unused ad-code*/
                $j('<div id="topHorseShoeSwf" />').appendTo(settings.appendTopBannerTo); /* changed from adtechSettings.globalOptions.toppbannerContainer to adcontainer, to replace content in the ad div */
                $j.loadWithSwfObject(settings.topSwf, settings.clickTagFormatTop, settings.clicktagsTop, 'topHorseShoeSwf', settings.topWidth, settings.topHeight, settings.flashVersion.toString(), settings.wmode, false, settings.topAltImg);
             }

             /** Or top image **/
             if (settings.topImg != '' && settings.extCodeTop == '') {
                 if(settings.expandableSwf && settings.expandableSwf.indexOf('null') == -1) {
                     settings.clicktagsTop = '';
                 }
                  $j.loadImageObject('topHorseShoeImg', settings.topImg, settings.appendTopBannerTo, settings.clicktagsTop);
             }

             /** External code **/
             if (settings.extCodeTop != '') {
                 $j.addExternalCode(settings.extCodeTop, settings.clicktagsTop, settings.appendTopBannerTo);
             }

             /** Add right swf/alt img container **/
             if ((settings.rightAltImg != '' || settings.rightSwf != '') && settings.rightImg == '') {
                $j('<div id="rightHorseShoeSwf" />').appendTo('#Stolpe2_container');
             }

             /** Add right banner flash  **/
             if (settings.rightSwf != '') {
                    $j.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 == '') {
                 if(settings.expandableSwf && settings.expandableSwf.indexOf('null') == -1) {
                     settings.clicktagsRight = '';
                 }
                  $j.loadImageObject('rightHorseShoeImg', settings.rightImg, '#Stolpe2_container', settings.clicktagsRight);
             }

             /** External code **/
             if (settings.extCodeRight != '') {
                 $j.addExternalCode(settings.extCodeRight, settings.clicktagsRight, '#Stolpe2_container');
             }

             /** Explandable option **/
             if(settings.expandableSwf && settings.expandableSwf.indexOf('null') == -1) {
                 var expandableLoaded = false;

                 /* Insert Expandable container */
                 $j('<div id="expandable" />').appendTo('#adOuterTop').css({
                        display: 'none',
                        width: '1030px',
                        height: settings.expandableHeight + 'px'
                     })
                     .append('<div id="expandableAd">&nbsp;</div>');

                 if (adtechSettings.localHorseshoeOptions.closeBtn) {
                    $j('#expandable').prepend('<div id="closeBtn"> ' + adtechSettings.localHorseshoeOptions.closeBtnText + ' </div>');
                    $j('#closeBtn').css({
                        font: 'bold 24px times, serif',
                        color: '#fff',
                        background: '#000',
                        padding: '0 5px 2px 5px',
                        position: 'absolute',
                        left: '1004px',
                        zIndex: 9999,
                        cursor: 'pointer'
                    });
                 }

                 $j('#Hestesko_topp_container, #Stolpe2_container, #Stolpe1_container, #rightHorseShoeSwf, #leftHorseShoeSwf, #closeBtn').mousedown( function(e) {
                      if($j('#expandable').is(':hidden')) {
                          $j('#Hestesko_topp_container').hide();
                          $j('#expandable').show();
                          $j('#page object, #adTopLeft, #adTopRight, #adTopStripe').hide();
                          //if(!expandableLoaded) {
                            $j.loadWithSwfObject(settings.expandableSwf, settings.clickTagFormat, settings.clicktagsExpandable , "expandableAd", settings.expandableWidth, settings.expandableHeight, settings.flashVersion.toString(), settings.wmode, false);
                            expandableLoaded = true;
                          //}
                       } else {
                         $j('#expandable').hide();
                         $j('#page object, #adTopLeft, #adTopRight, #adTopStripe').hide();
                         $j('#expandableAd').remove();
                         $j('#expandable').append('<div id="expandableAd">&nbsp;</div>');
                         $j('#Hestesko_topp_container').show();
                       }
                 });
             }

             /** Create callback function **/
             if (adtechSettings.localHorseshoeOptions.callBackFunc != '') {
                try {
                    var callBackFunc = new Function(adtechSettings.localHorseshoeOptions.callBackFunc);
                    callBackFunc();
                } catch(err) {};
            }

         };



         /********************************************
        *  Pagecurl, topbanner only (TODO: Netboard) *
        * *******************************************/

         $j.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',
                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 = $j.extend({}, defaults, pCurlOptions);

            var appendToThis = settings.appendToWhere == 'toppbanner' ? adtechSettings.pagecurlOptions.topbannerID : adtechSettings.pagecurlOptions.netboardID;

            $j('<div id="pagecurl_banner_swf" />')
               .appendTo(appendToThis);

            /** Add flash using swfObject **/
            $j.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 **/
            $j(appendToThis)
               .addClass('pagecurl_container')
               .show();

            /** Add pagecurl flashes **/
            $j(document).ready(function () {

                 $j('<div id="pagecurl_small_container" class="pagecurl_visible" />')
                    .append('<div id="pagecurl_small_swf" />')
                    .appendTo(appendToThis);

                 $j('<div id="pagecurl_big_container" />')
                    .append('<div id="pagecurl_big_swf" />')
                    .appendTo(appendToThis);

                 /** Add flash using swfObject **/
                 $j.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);
                 $j.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 **/
                 $j('#pagecurl_small_container').mouseover(function () {
                    $j('#pagecurl_small_container, #pagecurl_big_container').toggleClass('pagecurl_visible');
                });

                $j('#pagecurl_big_container').mouseout(function () {
                    setTimeout(function () {
                       $j('#pagecurl_small_container, #pagecurl_big_container').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 *
          * ************************************/

         $j.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,
             shiftRight: adtechSettings.lAdOptions.shiftRight,
             appendToDiv: adtechSettings.lAdOptions.appendToDiv
         },

         settings = $j.extend({}, defaults, LOptions);

         /** Add top banner flash  **/
         if (settings.topBannerSwf != '' && settings.extCodeTop == '') {
              $j(settings.appendToDiv).append('<div id="leftL" />');
              $j.loadWithSwfObject(settings.topBannerSwf, settings.clickTagFormatTop, settings.clicktagsTop , "leftL", 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 : '';
              $j.loadImageObject('leftL', settings.topBannerImg, settings.appendToDiv, include_tophref);
         }

         /** External code **/
         if (settings.extCodeTop != '') {
             $j.addExternalCode(settings.extCodeTop, settings.clicktagsTop, adtechSettings.globalOptions.toppbannerContainer);
         }

         /** Shift right accordingly, show div **/
         $j(adtechSettings.globalOptions.toppbannerContainer).css('margin-right', '-'+ settings.shiftRight + 'px');
         //$j(settings.appendToDiv).show();

         /** Add right banner flash **/
         if (settings.rightBannerSwf != '' && settings.extCodeRight == '') {
                $j(adtechSettings.globalOptions.rightHorseShoeContainer).append('<div id="rightL" />');
                $j.loadWithSwfObject(settings.rightBannerSwf, settings.clickTagFormatRight, settings.clicktagsRight , "rightL", 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 : '';
              $j.loadImageObject('rightL', settings.rightBannerImg, adtechSettings.globalOptions.rightHorseShoeContainer, include_righthref);
         }

         /** External code **/
         if (settings.extCodeRight != '') {
             $j.addExternalCode(settings.extCodeRight, settings.clicktagsRight, adtechSettings.globalOptions.rightHorseShoeContainer);
         }

         /** Alter "viewport width" **/
         if (adtechSettings.lAdOptions.alterViewport) { $j(adtechSettings.lAdOptions.alterViewportID).css({width: adtechSettings.lAdOptions.alterViewportWidth}); }

         /** If expandable banner template **/
         if (settings.isExpandable) {

             /** Set up divs for big banner **/
             $j('<div id="bigLBanner" />')
                 .hide()
                 .append('<span id="LBarX"> '+ adtechSettings.lAdOptions.closeBtnText +' </span>')
                 .append('<div id="bigLSwf" />')
                 .appendTo(settings.appendToDiv);

            /** Close button? **/
            if (adtechSettings.lAdOptions.closeBtn) {
                $j('<div id="bigLBanner" />')
                    .append('<span id="LBarX"> '+ adtechSettings.lAdOptions.closeBtnText +' </span>');
            }

             /** Expandable not loaded yet **/
             var bigLExpandedLoaded = false;

             /** Onclick events **/
             $j('#leftL,#rightL,#LBarX').mousedown( function(e) {
                  if($j('#bigLBanner').is(':hidden')) {
                      /** Z-index of top banner and viewportads. ie7 bug **/
                      $j(settings.appendToDiv + ', #viewportAds').css({ zIndex: 9900 });
                      $j('#bigLBanner').show();
                      if(!bigLExpandedLoaded) {
                        /** Set width and height of container **/
                        $j('#bigLBanner').css({width: settings.expandableWidth, height: settings.expandableHeight});
                        /** Load large flash **/
                        $j.loadWithSwfObject(settings.expandableSwf, settings.clickTagFormatExpandable, settings.clicktagsExpandable , "bigLSwf", settings.expandableWidth, settings.expandableHeight, settings.flashVersion.toString(), settings.wmode, false);
                        bigLExpandedLoaded = true;
                      }
                   } else {
                     $j('#bigLBanner').hide();
                     $j('#viewportAds').css({ zIndex: 0 });
                   }
               });

              };

             /** Create callback function **/
            if (adtechSettings.lAdOptions.callBackFunc != '') {
                try {
                    var callBackFunc = new Function(adtechSettings.lAdOptions.callBackFunc);
                    callBackFunc();
                } catch(err) {};
            }

         };

 })(jQuery);