

/**
main function to decide whether ads should be shown or not, pass the layers to determine which one should be shown
**/

function tb_to_do_or_to_not(postTime, layer, postid) {
  var showAds = false;
  var typeOfUser = -1;
  if(tb_show_ads_to_social_users(postTime) == true) {
    //tb_write_ads_for_users(2);
    showAds = false;
  }
  else if(tb_show_ads_to_search_engines(postTime) == true) {
    showAds = true;
    typeOfUser = 1;
  }
  else if(tb_show_regular_ads(postTime) == true) {
    showAds = true;
    typeOfUser = 3;
  }
  //showAds = false;
  if(showAds && (typeOfUser != -1 && typeOfUser <= 3)) {
    if(layer == "top") {
      tb_top_ad_variables(typeOfUser);
    }
    else if(layer == "middle") {
      tb_middle_ad_variables(typeOfUser)
    }
    else if(layer == "bottom") {
      tb_bottom_ad_variables(typeOfUser);
    }
    else if(layer == "toplinks") {
      tb_top_links_ad_variables(typeOfUser);
    }
    else if(layer == "bottomlinks") {
      tb_bottom_links_ad_variables(typeOfUser);
    }
    
    //insertGoogleJS(layer, postid);
    displayTheSittingDuck(layer, postid);
    
  }
  
}

var displayedFun = 0;
var maxDisplay = 2;


function tb_show_ads_to_search_engines(postTime) {
  var referrerArray = new Array(12);
	referrerArray[0] = "google";
	referrerArray[1] = "msn";
	referrerArray[2] = "live";
	referrerArray[3] = "yahoo";
	referrerArray[4] = "search";
	referrerArray[5] = "aol";
	referrerArray[6] = "ask";
	referrerArray[7] = "altavista";
	referrerArray[8] = "netscape";
	referrerArray[9] = "alltheweb";
	referrerArray[10] = "lycos";
	referrerArray[11] = "cuil";
	
	for(i = 0; i < referrerArray.length; i++ ) {
		if(document.referrer.indexOf(referrerArray[i]) != -1) {
			return true;	
		}
	}
	
	return false;
	
}

function tb_show_ads_to_social_users(postTime) {
	return false;
}

function tb_show_regular_ads(postTime) {
	var secstohours = tb_calculate_hours_into_secs(8);
  var tbDate = new Date();
  var theTime = tbDate.getTime();
  var strTime = theTime.toString();
  strTime = strTime.substring(0,10);
  theTime = parseInt(strTime);
	if((theTime - postTime) >= secstohours) {
		return true;	
	}
}

function tb_calculate_hours_into_secs(hours) {
  return 60 * 60 * hours; 
}

function insertGoogleJS(layer, postid) {
  var srcJS = "http://pagead2.googlesyndication.com/pagead/show_ads.js";
  var script = document.createElement("script"); //create a script element
  script.setAttribute("type","text/javascript"); //set its type
  script.setAttribute("src", srcJS); //set its src
  document.getElementById('tb-'+ layer +'-sitting-duck-' + postid).appendChild(script); //append it to head tagname
}

function displayTheSittingDuck(layer, postid) {
  var sittingDuckStyle = tb_return_layer('tb-'+ layer +'-sitting-duck-' + postid);
  sittingDuckStyle.visibility = 'visible';
  sittingDuckStyle.display = 'inline';
}

function displayTheStandingDuck(layer) {
  var sittingDuckStyle = tb_return_layer(layer);
  sittingDuckStyle.visibility = 'visible';
  sittingDuckStyle.display = 'inline';
}

function tb_return_layer(divLayer) {
  var getElemID = 0;
  var useGraphics = 0;
  var allDocs = 0;
  var allLayers = 0;

  if (document.getElementById) {
  	getElemID = 1; 
  	useGraphics = 1;
  }
  else {
  	if (document.all) {
  		allDocs = 1; 
  		useGraphics = 1;
  	}
  	else {
  		navigator_version = parseInt(navigator.appVersion);
  		if ((navigator.appName.indexOf('Netscape') != -1) && (navigator_version == 4)) {
  			allLayers = 1; 
  			useGraphics = 1;
  		}
  	}
  }

	var layerStyle;

	if (getElemID) { 
		if (layerStyle = document.getElementById(divLayer)) { return layerStyle.style; }
		else { return false; }
	}
	else { 
		if (allDocs) { return (document.all[divLayer].style); }
		else {
			if (allLayers) { return (document.layers[divLayer]); }
		}
	}
}



/** the core variables **/
function tb_sidebar_se_links_ad_variables() {
  google_ad_client = "pub-2703385610225771";
  /* Sidebar SE Links */
  google_ad_slot = "3401868667";
  google_ad_width = 200;
  google_ad_height = 90;
}

function tb_top_all_links_ad_variables() {
  google_ad_client = "pub-2703385610225771";
  /* Header Links For ALL */
  google_ad_slot = "4706228381";
  google_ad_width = 468;
  google_ad_height = 15;
}
function tb_top_links_ad_variables(id) {
  if(id == 1) { 
    google_ad_client = "pub-2703385610225771";
    /* Top TB Links SE Users */
    google_ad_slot = "8570772727";
    google_ad_width = 468;
    google_ad_height = 15;
	}
	else if(id == 2) { 
    //nada no ads they dont click on it
	}
	else {
    google_ad_client = "pub-2703385610225771";
    /* Top Regular User Links */
    google_ad_slot = "7830593160";
    google_ad_width = 468;
    google_ad_height = 15;
	}
}

function tb_bottom_links_ad_variables(id) {
  if(id == 1) { 
    google_ad_client = "pub-2703385610225771";
    /* Bottom SE Users Links */
    google_ad_slot = "7400907280";
    google_ad_width = 468;
    google_ad_height = 15;
	}
	else if(id == 2) { 
    //nada no ads they dont click on it
	}
	else {
    google_ad_client = "pub-2703385610225771";
    /* Bottom Regular User Links */
    google_ad_slot = "4139311484";
    google_ad_width = 468;
    google_ad_height = 15;
	}
}



function tb_top_ad_variables(id) {
  if(id == 1) { 
    google_ad_client = "pub-2703385610225771";
    /* Top New Search Engine Ads */
    google_ad_slot = "2890636466";
    google_ad_width = 336;
    google_ad_height = 280;
	}
	else if(id == 2) { 
    //nada no ads they dont click on it
	}
	else {
    google_ad_client = "pub-2703385610225771";
    /* Top New Regular Users Ads */
    google_ad_slot = "3009088807";
    google_ad_width = 468;
    google_ad_height = 60;
	}
}

function tb_middle_ad_variables(id) {
  var howMuchIsLess = 6;
  var useLinks = false;
  if(numpara <= howMuchIsLess) {
    useLinks = true;
  }

  if(id == 1) { 
    if(tb_middle_chotusa) {
      google_ad_client = "pub-2703385610225771";
      /* Middle SE USERS Small */
      google_ad_slot = "2688513836";
      google_ad_width = 234;
      google_ad_height = 60;
    }
    else if(useLinks) {
      google_ad_client = "pub-2703385610225771";
      /* Middle TB Regular Users Links */
      google_ad_slot = "8847188889";
      google_ad_width = 468;
      google_ad_height = 15;
    }
    else {
      google_ad_client = "pub-2703385610225771";
      /* Middle SE USERS */
      google_ad_slot = "7737208133";
      google_ad_width = 468;
      google_ad_height = 60;    
    }
	}
	else if(id == 2) { 
    //nada
	}
	else {
    if(tb_middle_chotusa) {
      google_ad_client = "pub-2703385610225771";
      /* Middle New Regular Users Ads Small */
      google_ad_slot = "9937712998";
      google_ad_width = 234;
      google_ad_height = 60;
    }
    else if(useLinks) {
      google_ad_client = "pub-2703385610225771";
      /* Middle TB Regular Users Links */
      google_ad_slot = "8847188889";
      google_ad_width = 468;
      google_ad_height = 15;
    }
    else {
      google_ad_client = "pub-2703385610225771";
      /* Middle New Regular Users Ads */
      google_ad_slot = "7848417929";
      google_ad_width = 468;
      google_ad_height = 60;
    }
	}
}

function tb_bottom_ad_variables(id) {
  if(id == 1) { 
    google_ad_client = "pub-2703385610225771";
    /* Bottom SE USERS */
    google_ad_slot = "3951600122";
    google_ad_width = 336;
    google_ad_height = 280;
	}
	else if(id == 2) { 
    //nada no ads they dont click on it
	}
	else {
    google_ad_client = "pub-2703385610225771";
    /* Bottom TB Regular Users */
    google_ad_slot = "1893888682";
    google_ad_width = 468;
    google_ad_height = 60;
	}
}