var zones = new Array();
var allads = new Array();
var offset = 0;
var active_zones = new Array();


//First add all the zones

add_ad_zone("ta");

add_ad_zone("tb");

add_ad_zone("tc");

add_ad_zone("bf");

add_ad_zone("fe");

add_ad_zone("afa");



//Next add all the ads

add_ad("ta","/images/event/photos/advertise_here_150x90.png","advertise","Advertise Here - Site Sponsor Tier A","Advertise Here","/site_information/advertise/");

add_ad("tb","/images/event/photos/advertise_here_150x90_.png","advertise","Advertise Here - Site Sponsor Tier B","Advertise Here","/site_information/advertise/");

add_ad("tc","/images/event/photos/advertise_here_150x90__.png","advertise","Advertise Here - Site Sponsor Tier C","Advertise Here","/site_information/advertise/");

add_ad("bf","/images/event/photos/advertise_here_468x60.png","advertise","Advertise Here - Bottom Fold Banner","Advertise Here","/site_information/advertise/");

add_ad("afa","/images/event/photos/10372484.gif","buycostumes_kids_125","BuyCostumes.com","BuyCostumes.com: Kids Costumes","http://www.dpbolvw.net/click-3434485-10368003");

add_ad("afa","/images/event/photos/10598877.gif","invitationbox_125","Invitation Box","Invitation Box: A huge selection of Halloween Invitations","http://www.tkqlhce.com/click-3434485-10585685");

add_ad("fe","/images/event/photos/marsbanner150x90.gif","mars_fe","Mars Haunted House - Milwaukee","Mars Haunted House - Milwaukee","http://www.marshauntedhouse.com");

add_ad("fe","/images/event/photos/bcbanner150x90.gif","bc_fe","Burial Chamber - Neenah","Burial Chamber - Neenah","http://www.burialchamber.com");

add_ad("fe","/images/event/photos/150x90_banner.gif","wisconsin_feargrounds_fe","Wisconsin Feargrounds - Waukesha","Wisconsin Feargrounds - Waukesha","http://www.wisconsinfeargrounds.com");

add_ad("afa","/images/event/photos/10681623.gif","costume_express_halloween_125","Costume Express","Costume Express - Halloween","http://www.jdoqocy.com/click-3434485-10646981");

add_ad("fe","/images/event/photos/Shawano_Manor_150x90_banner.gif","shawano_manor_fe","Shawano Manor - Green Bay","Shawano Manor - Green Bay","http://www.shawanomanor.com");

add_ad("afa","/images/event/photos/10756481.gif","costume_express_men","Costume Express","Men&#39;s costumes from Costume Express","http://www.kqzyfj.com/click-3434485-10684095");

add_ad("afa","/images/event/photos/10756473.gif","costume_express_boys125","Costume Express","Boy&#39;s costumes from Costume Express","http://www.jdoqocy.com/click-3434485-10684091");

add_ad("afa","/images/event/photos/10471344.gif","costume_craze_all_ages","Costume Craze","Costume Craze - Costumes for All Ages!","http://www.jdoqocy.com/click-3434485-10464539");

add_ad("afa","/images/event/photos/piratebanner.jpg","tudor_125","TudorDressing.com - Renaissance Clothing &amp; Costumes","TudorDressing.com- Renaissance Clothing &amp; Costumes","http://www.linkconnector.com/traffic_affiliate.php?lc=021257028792003956");

add_ad("afa","/images/event/photos/buycostumes10404803.gif","buycostumes_2009_party_125","BuyCostumes.com 2009","BuyCostumes.com - Halloween Props and Decorations","http://www.dpbolvw.net/click-3434485-10399490");

add_ad("afa","/images/event/photos/buycostumes10424004.gif","buycostumes_2009_party2_125","BuyCostumes.com 2009","BuyCostumes.com - Halloween Party Supplies","http://www.kqzyfj.com/click-3434485-10418246");

add_ad("afa","/images/event/photos/buycostumes4003061.gif","buycostumes_2009_petcostumes","BuyCostumes.com 2009","Buy Costumes: Pet Costumes","http://www.anrdoezrs.net/click-3434485-4003061");

add_ad("afa","/images/event/photos/buycostumes10372483.gif","buycostumes_sexycostumes_125","BuyCostumes.com 2009","Buy Costumes: Sexy Costumes","http://www.anrdoezrs.net/click-3434485-10368002");

add_ad("afa","/images/event/photos/buycostumes.gif","bc_under30","BuyCostumes.com","BuyCostumes.com - Costumes under $30","http://www.dpbolvw.net/click-3434485-10700428");

add_ad("afa","/images/event/photos/buycostumes.jpg","bc_costumes","BuyCostumes.com","BuyCostumes.com - Halloween Costumes","http://www.jdoqocy.com/click-3434485-10698039");

add_ad("afa","/images/event/photos/buycostumes_.gif","spirit_costumesall","Spirit.com","Spirit.com - Costumes for all occasions","http://www.jdoqocy.com/click-3434485-10590009");

add_ad("afa","/images/event/photos/CelebrateExpressClearance.jpg","costume_express_clearance","Costume Express","Clearance from Costume Express","http://www.tkqlhce.com/click-3434485-10693352");

add_ad("afa","/images/event/photos/Invitation Consultants.jpg","invitation_consultants_a","Invitation Consultants","Invitation Consultants - Unique invitations for any event","http://www.dpbolvw.net/click-3434485-10488679");

add_ad("afa","/images/event/photos/Old Time Candy.jpg","otcandy","Old Time Candy","Old Time Candy - Candy you ate as a kid®","http://www.anrdoezrs.net/click-3434485-10707481");

add_ad("afa","/images/event/photos/peggle.jpg","popcap_peggle","PopCap Games","PopCap Games - Peggle","http://www.kqzyfj.com/click-3434485-10511839");

add_ad("afa","/images/event/photos/Think Geek.gif","thinkgeek_shirts","Think Geek","Think Geek - New Shirts for Geeks","http://www.jdoqocy.com/click-3434485-10731906");

add_ad("afa","/images/event/photos/ThnkGeek Candy.gif","thinkgeek_candy","Think Geek","Think Geek - Geek Candies","http://www.dpbolvw.net/click-3434485-10737418");

add_ad("afa","/images/event/photos/wristband.gif","wristband_express","Wristband Express","Wristband Express","http://www.jdoqocy.com/click-3434485-10703601");

add_ad("fe","/images/event/photos/House_of_Bathory 150x90.jpg","fe_hob","House of Bathory","House of Bathory - Manitowoc","http://www.deadbydawn.com");

add_ad("afa","/images/event/photos/10758009.gif","costume_express_free_shipping","Costume Express - Free Shipping","Costume Express - Free shipping on order of $75 or more","http://www.anrdoezrs.net/click-3434485-10684849");

add_ad("afa","/images/event/photos/10774275.gif","costume_express_halloween_decor","Halloween Decor from Costume Express","Halloween Decor from Costume Express","http://www.dpbolvw.net/click-3434485-10692941");

add_ad("afa","/images/event/photos/10775103.gif.jpg","costume_express_clearance","Clearance from Costume Express","Clearance from Costume Express","http://www.kqzyfj.com/click-3434485-10693352");

add_ad("afa","/images/event/photos/10512395.gif.jpg","anytime_costumes_generic","Anytime Costumes - Halloween Costumes &amp; More Since 1954","Anytime Costumes - Halloween Costumes &amp; More Since 1954","http://www.kqzyfj.com/click-3434485-10505240");

add_ad("afa","/images/event/photos/lillian vernon.htm","lillian_vernon","Lillian Vernon Online","Lillian Vernon Online","http://click.linksynergy.com/fs-bin/click?id=pU2bEnvfum0&amp;offerid=37989.10001497&amp;subid=0&amp;type=4");



//Add a zone array to the zones array
function add_ad_zone(slug){
  zones[slug]           = new Array();
  zones[slug]["ads"]    = new Array();
  zones[slug]["slug"]   = slug;
}


//Add an ad array to a zone
function add_ad(zone,image,slug,adname,alt,url){
  var ad = Array();
  ad["id"]     = zone+"-"+slug;
  ad["zone"]   = zone;
  ad["image"]  = image;
  ad["slug"]   = slug;
  ad["name"]   = adname;
  ad["alt"]    = alt;
  ad["url"]    = url;
  ad["rurl"]   = "/ads/r/"+zone+"/"+slug+"/";
  zones[zone]["ads"][zones[zone]["ads"].length] = ad;
  allads[ad["id"]] = ad;
  offset += 1;
}


//Activate a Zone
function ad_show(slug){
  active_zones[active_zones.length] = slug;
}


function ad_rotate(){
    var zone;
    var adlink;
    var image;
    var ad;
    var i;
    var numads = active_zones.length;
    if(numads){
      for(i=0; i<numads; i++)    {
        zone  = zones[active_zones[i]];
        if(zone["ads"].length){
          //jQuery("#console").text(active_zones[i]);
          ad    = zone["ads"][Math.floor(Math.random()*zone["ads"].length)];
          adlink = jQuery("#az"+zone["slug"]);
          adlink.attr("href",ad["rurl"]);
          adlink.attr("name",zone["slug"]+"-"+ad["slug"]);
          image = jQuery("#az"+zone["slug"]+" > img");
          image.attr("src", ad["image"]);
          image.attr("alt", ad["alt"]);
          image.attr("title", ad["name"]);
        }
      }
    }
}


jQuery(document).ready(function() {
  var refreshAdId = setInterval(ad_rotate, 12000);
  jQuery("[id^=az]").bind("mouseenter", function(e) {
    var ad = allads[this.name];
    this.href=ad["url"];
    this.onmousedown = function() { jQuery.get(ad["rurl"]) } ;
  });
  jQuery("[id^=az]").bind("mouseleave", function(e) {
    var ad = allads[this.name];
    this.href=ad["rurl"];
  });
});
