﻿Event.observe(window, 'load', function() {
    
	//Grab all of our news blocks
    var newsBlocks = $$('.contentArea1-callout DIV.news');
	
	//Go through the news blocks, and if they have an ID on them, hide it.
    newsBlocks.each(function(element){
        if (element.id){
            element.setStyle({display:'none'});
        }
    });
    
	//Grab all of the elements that will run a toggle
    var togglers = $$('.lbtoggle SPAN');
	
	//Fire off the toggleMe function on click
    togglers.each(function(element){
        Event.observe(element, 'click', toggleMe)				   
    });
    
    
 });

//toggle news elements on click
//argument "e" is the mouseEvent passed by the Event.observe.
function toggleMe(e){
	
	//target is the element that actually fired the event.
    var target = $(e.findElement('span'));
	
	//targetBlock is the block of news we're looking for.
	//	We're basing this from the target's id and stripping out "-listen"
    var targetBlock = $(target.id.replace("-listen",""));
    
	//Toggle it up!
    if (!targetBlock.visible()){
        target.update('<a name="">Collapse</a>')
        Effect.SlideDown(targetBlock)
    }else{
        target.update('<a name="">Expand</a>')
        Effect.SlideUp(targetBlock)	
    }
}


     
     //hides news articles on page load
     loadEvent = function()
     {
        var strReturn = "";
        var strHref = window.location.href;
        if ( strHref.indexOf("?") > -1 ){
            var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
                    if (strQueryString.indexOf("event=") > -1 ){
                        var aParam = strQueryString.split("=");
                        strReturn = aParam[1];
                    }
        }
        
        if(strReturn != "")
        {
            $(strReturn).toggle();
        }
     }

     window.onload=loadEvent;