function Pinmap(id,imagearray) {
  this.element = document.getElementById(id);  if (!this.element) return false;
  this.image = this.element.getElementsByTagName("img")[0];
  this.links = this.element.getElementsByTagName("area");
  this.items = this.element.getElementsByTagName("li");
  this.imagearray = imagearray;
  this.bind();
}
Pinmap.prototype.bind = function() {
  var o = this;
  for(var i = 0; i < this.links.length; i++) {
    this.links[i].onmouseover = function() { o.show(this); return false; }
  }
  var x = 0;
  var y = 0;
  for(var i = 0; i < this.items.length; i++) {
    if (this.items[i].innerHTML.length > x) {
      y = i;
      x = this.items[i].innerHTML.length;
    }
  }
  this.items[y].style.display = "block";
  this.image.src = this.imagearray[y]  
}
Pinmap.prototype.show = function(caller) {
  for(var i = 0; i < this.links.length; i++) {
    var link = this.links[i];
    if (link == caller) {
      this.items[i].style.display = "block";
      this.image.src = this.imagearray[i] 
    }else {
      this.items[i].style.display = "none";
    }
  }
}

//for sidebar interior func, see /page/elements
function afns_placeOnionStoreAd(){
	var featured_products = new Array();

	featured_products.push( new StoreProduct(
		'', 
		'HP_145x199Calendar.png',
		'',
		'http://store.theonion.com/?utm_source=onhp') );

	featured_products.push( new StoreProduct(
		'', 
		'HP_145x199HolidayCards.png',
		'',
		'http://store.theonion.com/?utm_source=onhp') );

	featured_products.push( new StoreProduct(
		'', 
		'HP_145x199Tees.png',
		'',
		'http://store.theonion.com/?utm_source=onhp') );
	
	featured_products.push( new StoreProduct(
		'', 
		'HP_Callout_145x199Obama.png',
		'',
		'http://store.theonion.com/obama-commemorative-cover-black-man-given-nations-worst-job-2008-p-372.html?utm_source=onhp') );
	

	var prodNum = Math.round((featured_products.length-1)*Math.random());
	//var prodNum = 0;
	afns_writeProduct( featured_products[prodNum], 'onion_store_1' );
}
function afns_writeProduct( product, target ){
	var text = '<a target="_blank" href="'+product.link+'">'+
	'<img src="http://www.theonion.com/content/themes/onion/assets/store/home/'+product.image+'?k=2" /></a>';
	document.getElementById( target ).innerHTML = text;
}
