Event.observe(window,'load',initTabs);
Event.observe(window,'load',initExtLinks);
Event.observe(window,'load',initSearchField);
Event.observe(window,'load',initInfo);
Event.observe(window,'load',initIE6HeaderFigure);


//init product featured tabs
function initTabs() {
  if( $("promotions") != null ) {	
	  var tabsLinks = $$('#promotions ul li a');
	  var tabsPanels = $$('#promotions div.product');
	  
	  for(i=0;i<tabsLinks.length;i++) {
		tabsLinks[i].href="#tab"+i;
	  }
	  for(i=0;i<tabsPanels.length;i++) {
		tabsPanels[i].setAttribute('id', 'tab'+i);
	  }

	  thumbnailTabs=$$('#promotions ul').first();
	  if(thumbnailTabs) { new Fabtabs(thumbnailTabs);}
  }
}

//init open in new wnd for external links
function initExtLinks() {
  var extLinks = $$('a[rel="external"]');
  extLinks.each(function(el){
	Event.observe(el,'click',function(){
      window.open(el.href);
	},false);
	el.onclick = function(){return false;}
	
  });
}

// clear search form
function initSearchField() {
  var searchField = $$('#nav form input').first();
  
  Event.observe(searchField,'focus', function() {
	  if(this.value!=this.defaultValue) {
	    this.defaultValue = this.value;
	  }
	  this.value='';
  });
  
  Event.observe(searchField,'blur', function() {
    if(!this.value.length) {
	  this.value = this.defaultValue;
	}
  });
}

// behavior for info popup 
function initInfo() {
	var infoLinks = $$('.price-info');	
	$(infoLinks).each(function(el){
		var infoLink = $(el).down();
		var infoBox = $(infoLink).nextSiblings().first();
		
		$(infoBox).hide();
		
		Event.observe(infoLink,'click',function(){
			$(infoBox).show();
		});

		var closeInfoBox = $(infoBox).childElements().last();	
		
		Event.observe(closeInfoBox,'click',function(){
			$(infoBox).hide();
		});

		closeInfoBox.onclick = function(){ return false; };

	});
}

// load header figure
function initIE6HeaderFigure() {
  if(Prototype.Browser.IE) {
	$('header').update('<div class="figure"></div>'+$('header').innerHTML);
  }
}

