// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

var _googleInterval;


function addGoogleTracking()	
{
	var sc = document.createElement('script');
	sc.type = 'text/javascript';
	sc.src = 'http://www.google-analytics.com/ga.js';
	document.getElementsByTagName("head").item(0).appendChild(sc);
	_googleInterval = setInterval(activateGoogle,250);
}

function activateGoogle()
{
	if(typeof _gat != 'undefined') 
	{
		clearInterval(_googleInterval);
		var pageTracker = _gat._getTracker("UA-4009444-1");
		pageTracker._initData();
		pageTracker._trackPageview();
	}
}


measureSelect=Behavior.create({
 initialize: function(obj) {
   // Adjusts the lentgh of the select element  
   // in ie7 to allow for all text to be displayed
     isIE = (navigator.appVersion.search(/MSIE\s7.0/) != -1) ? true : false
 },
 onmousedown: function(){
   el =this.element.id+'_sel';
   el_width = this.element.getWidth();
   if(!$(el)){this.storeEl(el_width)}
   this.clickEvent(this.setWidth())
 },
 onblur: function(){
   this.clickEvent($(el).readAttribute('curwidth'));
 },
 onchange: function(){
   this.clickEvent($(el).readAttribute('curwidth'));
 },
 clickEvent: function(optWidth){
   if(isIE && this.optLen()){$(this.element.id).setStyle({width: optWidth })}
 },
 optTextLen: function(){
   opts = this.element.childElements();
   strLen = opts.collect(function(s){ return s.text.length })
   return strLen.max();
 },
 setWidth: function(){
   selWidth = this.optTextLen();
   return (selWidth * 7);
 },
 optLen: function(e){
   if(this.optTextLen() > 25){ return true } else {return false}
 },
 storeEl: function(ew){
   if(!this.element.getWidth()==0){
     $('wrap').insert({after: new Element("span",{'curwidth':ew,'id':this.element.id + '_sel'})  })
   }
 }
 
});

Event.addBehavior({
  'select': measureSelect()
});





document.observe("dom:loaded", function() {
    //insert google tracking
	addGoogleTracking();
});
