
var promotionNavObj;

var promotionNav = Class.create();

promotionNav.prototype = {
	timeout : null,
	initialize : function(element) {
		this.element = $(element);
		
		this.promotionInserts = $$('.promotion-insert');
		this.promotionLinks = $$('.promotion-link');
		this.observe();
		},
		
	observe : function() {
		this.promotionLinks.each(function(item) {
			Event.observe(item.firstChild, 'click', this.activate.bindAsEventListener(this) );
			}.bind(this));

		},
		
	activate : function(evt) {
		var elm = Event.findElement(evt, "a");
		var selectedInsert = $(elm.hash.gsub(/#/,''));

		this.promotionInserts.each(function(item) {
			if (item == selectedInsert) { item.addClassName('selected'); }
			else { item.removeClassName('selected'); }
			}.bind(this));

		this.promotionLinks.each(function(item) {
			if (item == elm.parentNode) { item.addClassName('selected'); }
			else { item.removeClassName('selected'); }
			}.bind(this));

		Event.stop(evt);
		}
}


function setClickable() {
		var allClickable = $$('.clickable');
		var allClickableHref = $$('.clickable a');
		allClickable.each(function(element) {
			var childAnchor = $(element).getElementsByTagName('a').item(0);
			if (childAnchor) {
  				Event.observe($(element), 'click', function() { document.location = childAnchor.href }, false);
  				}			
			}.bind(this));
		}




var promotion = new domFunction(function() {
	setClickable();
	
	}, { 'container' : 'id' } );


var promotion = new domFunction(function() {
		if ($('promotions') ) {
			promotionNavObj = new promotionNav('promotions');
		}
	}, { 'container' : 'id' } );