var ord = Math.floor(Math.random() * 100000000);
/* GLOBAL VARIABLES! Caution some of these have pretty common names */ 
var ad_debug = false; /*global */ 

// DOUBLECLICK (DART) VARIABLES
var site = "";
var zone = "";
var passed_hash = "";
var all_hash = "";
var all_hash_set = false;
// END DOUBLECLICK (DART) VARIABLES

// GOOGLE VARIABLES -- DEFAULTS
var google_ad_client = "pub-7893828636899382";
var google_alternate_ad_url_template = "http://ad.doubleclick.net/adi/eons.google/google;sz=widthxheight;ord=" + ord + "?";
var google_ad_width = 728;
var google_ad_height = 90;
var google_ad_format = "728x90_as";
var google_ad_type = "text";
var google_ad_channel = "8674095514";

// END GOOGLE VARIABLES


function init_dart(_zone, _hash, _provider) {
	site = "eons.obits";
    zone = _zone;
    all_hash = _hash;	
}

function render_dart_js(site, zone, hash, size, ptile, ord){
    var protocol = 'http';
    if (location.href.match(/^https/)) {
        protocol = 'https';
    }
    
	if (hash) {
	    if (hash.match(/;$/) === null) {
	        hash = hash + ";";// make sure the hash ends with a ;
	    }
	}
    var js = '<script src="' + protocol + '://ad.doubleclick.net/adj/' + site + '/' + zone + ';' + hash + 'sz=' + size + ';tile=' + ptile + ';ord=' + ord + '?"><\/script>';
    if (ad_debug == true) {
        alert(js);
    }
    document.write(js);
}

function render_google_adsense_js(channel, width, height){
    return render_google_js(channel, "as", width, height);
}

function alert_google_variables(){
    var s = "google_ad_channel:\t" + google_ad_channel + "\n";
    s += "google_ad_width:\t" + google_ad_width + "\n";
    s += "google_ad_height:\t" + google_ad_height + "\n";
    s += "google_ad_format:\t" + google_ad_format + "\n";
    s += "google_alternate_ad_url_template:\t" + google_alternate_ad_url_template + "\n";
    alert(s);
}

function render_google_js(channel, format, width, height){
    if (channel.match(/^[0-9]+$/) == null) // if the channel is a name (not all numbers), look it up in the hash to get the right channel id
    {
		// the obits channel
        channel = "9590164840";
    }
    google_ad_channel = channel;
    google_ad_width = width;
    google_ad_height = height;
    google_ad_format = width + "x" + height + "_" + format;
    tmp = google_alternate_ad_url_template.replace(/width/, width);
    google_alternate_ad_url = tmp.replace(/height/, height);
    if (ad_debug == true) {
        alert_google_variables();
    }
    var protocol = 'http';
    if (location.href.match(/^https/)) {
        protocol = 'https';
    }
    var js = '<script src="' + protocol + '://pagead2.googlesyndication.com/pagead/show_ads.js"><\/script>';
    document.write(js);
}

function adjust_size(size){
    new_size = size;
    if (size == "120x60") {
        new_size = "125x125";
    }
    return new_size;
}

function dart(_site, _zone, _hash, _provider, size, ptile){
    site = "eons.obits";
    zone = _zone;
    size = adjust_size(size);
    render_dart_js(site, zone, _hash, size, ptile, ord);
}

function dart1(site, zone, hash, _provider, size){
    passed_hash = hash;
    dart(site, zone, "dcopt=ist;" + hash, "", size, 1);
}

function dart2(size){
    dart(site, zone, passed_hash, "", size, 2);
}

function dart3(size){
    dart(site, zone, passed_hash, "", size, 3);
}

function dart4(size){
    dart(site, zone, passed_hash, "", size, 4);
}

function dart5(size){
    dart(site, zone, passed_hash, "", size, 5);
}

function dart6(size){
    dart(site, zone, passed_hash, "", size, 6);
}

function dart7(size){
    dart(site, zone, passed_hash, "", size, 7);
}

function dart10(size){
    dart(site, zone, "loc=1;" + passed_hash, "", size, 10);
}

function dart11(size){
    dart(site, zone, "loc=2;" + passed_hash, "", size, 11);
}

function dart12(size){
    dart(site, zone, "loc=3;" + passed_hash, "", size, 12);
}

function google_mu(channel){
    zone = "bottom";
    dart(site, zone, passed_hash, "", "300x250", 6);
}

function google_lb(channel){
    zone = "bottom";
    dart(site, zone, passed_hash, "", "728x90", 7);
}
