function resetMenu(){
    var menuList = $("menu").getElementsByTagName("li");
    for(i = 0; i < menuList.length; i++){
        menuList[i].className = "";
    }
}

function stylePage(){
    var menuUl = $("menu");
    var menuList = menuUl.getElementsByTagName("a");
    for(i = 0; i < menuList.length; i++){
	menuList[i].onclick = function(){
	    for(j = 0; j < menuList.length; j++){
		menuList[j].parentNode.className = "";
	    }
	    this.parentNode.className = "selected";
	}
    }
};

function buildTooltip(e){
    var newToolTip = new Element('div');
    newToolTip.addClassName('tooltip');
    newToolTip.setStyle({
	position: 'absolute',
	top: e.pointerY() + "px",
	left: e.pointerX() + "px"});
    return newToolTip;
}

function addTooltipToElement( ele, message ){
    var element = Element.extend( ele );
    var tt;
    Event.observe( element, 'mouseover', 
		   function(e){
		       tt = buildTooltip(e);
		       tt.update( message );
		       $('main').appendChild( tt );
		   } );
    Event.observe( element, 'mouseout',
		   function(e){
		       tt.remove();
		   } );
}

function buildPopup(divid,divclass,divinnerHTML,_x,_y){
    var newDiv = new Element("div");
    if(divid != null || divid != ""){
	newDiv.setAttribute("id",divid);
    }
    if(divclass != null || divclass != ""){
	newDiv.setAttribute("class",divclass);
	newDiv.setAttribute("className",divclass);
    }
    newDiv.update( divinnerHTML );
    newDiv.setStyle({
 	position: 'absolute',
 	top: _y+"px",
 	left: _x+"px"
    });
    $("main").appendChild(newDiv);
}

function encode(txt){
    var returnString = txt;
    returnString = returnString.replace(/&/g,"_and_;");
    returnString = returnString.replace(/\+/g,"_plus_;");
    returnString = returnString.replace(/#/g,"%23");
    returnString = returnString.replace(/</g,"_lb_;");
    returnString = returnString.replace(/>/g,"_rb_;");
    returnString = returnString.replace(/\n/g,"_nlc_;");
    return returnString;
};

function decode(txt){
    var returnString = txt;
    returnString = returnString.replace(/%5C/g,"\\");
    returnString = returnString.replace(/%27/g,"'");
    returnString = returnString.replace(/_plus_;/g,"+");
    returnString = returnString.replace(/_and_;/g,"&");
    returnString = returnString.replace(/%23/g,"#");
    returnString = returnString.replace(/_lb_;/g,"&#60;");
    returnString = returnString.replace(/_rb_;/g,"&#62;");
    returnString = returnString.replace(/_nlc_;/g,"<br>");
    return returnString;
};

function countdown( y, m, d ){
    var montharray = new Array( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" );
    
    var today = new Date();
    var todayyear = today.getYear()
    if( todayyear < 1000 ){
        todayyear += 1900;
    }
    var todaystring = montharray[ today.getMonth() ] + " " + today.getDate() + ", " + todayyear;
    var futurestring = montharray[ m - 1 ] + " " + d + ", " + y;
    var dd = Date.parse( futurestring ) - Date.parse( todaystring );
    dd = Math.floor( dd / ( 60*60*1000*24 ) );
    $( "counter" ).innerHTML = dd;
    setTimeout( "countdown( 2010, 5, 1 )", 60000 );
};

Event.observe( window, 'load',
	       function() {
		   var thumb_id = "thumb_fullview_unique";
		   var thumbs = $$('img.thumb');
		   
		   thumbs.each( function(i) {
		       Element.observe(i, 'click', function(e) {
			   if( i.hasClassName('thumb') ){
			       i.removeClassName('thumb');
			   }else{
			       i.addClassName('thumb');
			   }	       
		       });
		   });

		   var needsTooltip = $$('.tooltipped');
		   needsTooltip.each( function(i){
		       addTooltipToElement( i, i.readAttribute('tooltiptitle') );
		   });
	       });
