function resizeSWF(id, nHeight) 
{
	nHeight += "px";
    document.getElementById(id).style.height = nHeight;
}

var inputHolder = Class.create({
    
    default_value: '',
    input_id: '',
    
    initialize: function(input_id, submit_id) 
    {
        this.default_value = $(input_id).value;
        this.input_id = input_id;
        
        Event.observe($(input_id),  'focus', this.onFocusChange.bindAsEventListener(this));
        Event.observe($(input_id),  'blur',  this.onFocusChange.bindAsEventListener(this));
        Event.observe($(submit_id), 'click', this.onFormSubmit.bindAsEventListener(this));
    },
    
    onFormSubmit: function(event)
    {
        if (this.default_value!=$(this.input_id).value)
        {
            $(this.input_id).up('form').submit();
        }
    },
    
    onFocusChange: function(event)
    {
        if (event.type=='focus')
        {
            if ( this.default_value==Event.element(event).value ) Event.element(event).value = '';
        }
        if (event.type=='blur')
        {
            if ( Event.element(event).value=='' ) Event.element(event).value = this.default_value;
        }
    }
});


Event.observe(window,'load',function(){

    // track poll answers
    var uls = $$('ul.answers');
    if (uls.length)
    {
        for (var i=0; i<uls.length; i++)
        {
            var lis = uls[i].childElements();
            if (lis.length)
            {
                for (var j=0; j<lis.length; j++)
                {
                    Event.observe(lis[j].down('a'), 'mouseover', function(event) {
                        if (Event.element(event).previous('span'))
                        {
	                        Event.element(event).previous('span').setStyle({
	                            "visibility" : "hidden"
	                        });
	                    }
                    });
                    Event.observe(lis[j].down('a'), 'mouseout', function(event) {
                        if (Event.element(event).previous('span'))
                        {
	                        Event.element(event).previous('span').setStyle({
	                            "visibility" : "visible"
	                        });
	                    }
                    });
                }
            }
        }
    }
        

    /* Replace content H1 tags with flash titles */
    
    if ($('rich_dc_content'))
    {
        var h1 = $$('#rich_dc_content h1');
        
        for (var i=0; i<h1.length; i++)
        {
            // format header
            var h1_content = h1[i].innerHTML;
            h1_content = h1_content.replace(/\&amp\;/, '&');
            h1_content = h1_content.replace(/\&nbsp\;/, ' ');
            h1_content = h1_content.replace(/\&mdash\;/, '-');
            h1_content = h1_content.replace(/\&ndash\;/, '-');
            h1_content = h1_content.replace(/\%/, '%25');
            h1_content = h1_content.replace(/\&/, '%26');
            
            var title_ID = 'js_title_' + (Math.random()*10000);
            var span = new Element('span',{'id':title_ID});
            h1[i].update();
            h1[i].insert({'top':span});
	        swfobject.embedSWF( 
	            "/media/title.swf",
	            title_ID,
	            "100%",
	            "30",
	            "9.0.0",
	            "",
	            {"t":h1_content,
	             "titleID":title_ID},
	            {"wmode":"transparent"});        
        }
    }
});