// $Id: ads.js 5955 2011-02-10 12:02:55Z lalund $

// OAS Setup

OAS_url ='http://ads.vg.no/RealMedia/ads/';

OAS_rn = '001234567890'; OAS_rns = '1234567890';

OAS_rn = new String (Math.random()); OAS_rns = OAS_rn.substring (2, 11);

OAS_req = OAS_sitepage+'/1'+OAS_rns+'@'+OAS_listpos;

OAS_target = '_top';

// The following lines will insert code allowing calling of OAS_RICH as defined using the
// Open Adstream MJX call. This will always happen since this is true for all browsers from > 2000.
OAS_version = 11;
if (navigator.userAgent.indexOf('Mozilla/3') != -1) {
    OAS_version = 10;
}

if (OAS_version >= 11 && showAds) {
    document.write('<script language="JavaScript1.1" type="text/javascript" src="' + OAS_url + 'adstream_mjx.ads/' + OAS_req + '?' + OAS_query + '"></script>');
}
document.write('');

// End OAS setup

// This function will never be called (see above) and is not tested.
function OAS_NORMAL(pos) {
    document.write('<a href="'+OAS_url+'click_nx.ads/'+OAS_req+'!'+pos + '?' + OAS_query+'" target="' + OAS_target + '" >');
    document.write('<img src="'+OAS_url+'adstream_nx.ads/'+OAS_req+'!'+pos + '?' +OAS_query+'" border=0></a>');
}

// Avoid displaying the 'annonse' text if no ad was found
function no_OAS_AD(pos) {
    var container = jQuery('#ad_'+pos+'_content');
    if( !container) {
        return;
    }
    if(container.hasClass('adOas') ) {
    	container.css('display','none');
    }
}

// Render the ad
function OAS_AD_inner(pos) {
    if (!showAds) {
        return false;
    }
    
    split_pos = OAS_listpos.split(',');
    
    var found = false;
    for (key in split_pos) {
        if (split_pos[key] == pos) {
            found = true;
            break;
        }
    }
    if(!found ) {
        return false;
    }

    if (OAS_version >= 11) {
        OAS_RICH(pos);
    } else {
        OAS_NORMAL(pos);
    }
    return true;
}

// Test if the full width top ad i rendered, needed to avoid rendering
// the smaller top ads in this case.
function isTopWideShown() {
    var wideTop = jQuery('#ad_' + adTopWideName + '_content');
    if (wideTop.css('display') != 'none') {
        return true;
    }
    return false;
}

// This prints the div for an ad if certain criteria are fulfilled
function OAS_AD(pos, stripped) {
    var doRender = true;
    if(stripped === undefined) {
        stripped = false;
    }
    // special test to render top ads correctly
    if ((pos == adTopLeftName || pos == adTopRightName) && isTopWideShown()) {
        doRender = false;
    }
    if (doRender) {
        if (!stripped) {document.write('<div class="adOas" id="ad_'+pos+'_content">');}
        document.write('<h3 class="adLabel">');
        document.write('<span>ANNONSE</span></h3>');
        var success = OAS_AD_inner(pos);
        if (!stripped) {document.write('</div>');}
        
	//Check if the ad is not sold: if so, we must hide the text 'ANNONSE' 
        if(!success) {
            no_OAS_AD(pos);
	} else {
            var innerHtml = jQuery('#ad_'+pos+'_content').html();
            if(innerHtml == '&nbsp;' || innerHtml.indexOf('empty.gif') != -1) {
                no_OAS_AD(pos);
            }
        }    
    }
}


