var currentImg;
var theRules = {
/*
	'img.publicPhoto' : function(el) {
		el.onmouseover = function() {
			var contextMenu = $('photoContextMenuBtn');
			var showMenuLink = $('showPhotoContextMenuLink');
			
			showMenuLink.onclick = function() {
				var contextMenu = $('photoContextMenu');
				contextMenu.style.top = findPosY(el) + el.height +'px';
				contextMenu.style.left = findPosX(el) + el.width +'px';
				contextMenu.show();
			};

			contextMenu.style.top = findPosY(el) + el.height - 20 +'px';
			contextMenu.style.left = findPosX(el) +'px';
			contextMenu.style.width = el.width +'px';
			contextMenu.show();
			if (currentImg != this) {
				Element.hide('photoContextMenu');
			}
			
			currentImg = this;
		},
		el.onmouseout = function() {
			var contextMenu = $('photoContextMenuBtn');
			contextMenu.hide();
		}
	},
	'#photoContextMenuBtn' : function(el) {
		el.onmouseover = function() {
			this.show();
		}
		el.onmouseout = function() {
			this.hide();
		}
	},
	'#photoContextMenu' : function(el) {
	//	Element.visible('
	}
*/
//	,
//	
};

//Behaviour.register(theRules);
//Behaviour.addLoadEvent(do_onload);

function do_onload() {

	removeImageLinkBorders();
	
	// Id names of all the "boxes"
	//boxIds = $('categories','elsewhere','recent','blogroll','flickr', 'music');

	var boxIds = document.getElementsByClassName("sidebox");	


	for (i = 0; i < boxIds.length; i++) {
		if (boxIds[i]) {
			cookieValue = readCookie(boxIds[i].id);
			if (cookieValue == 'invisible') {
				var h3 = boxIds[i].getElementsByTagName('h3');
				Element.addClassName(h3[0], 'invisible');
				var kids = boxIds[i].childNodes;
				for (j = 1; j < kids.length; j++) {
					if (kids[j].id) {
						Element.hide(kids[j]);
					}
				}
			}
		}		
	}	
}

function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

function setCookie(name,value,days) {
 if (days) {
   var date = new Date();
   date.setTime(date.getTime()+(days*24*60*60*1000));
   var expires = ";expires="+date.toGMTString();
 } else {
   expires = "";
 }
 document.cookie = name+"="+value+expires+";path=/";
}


function readCookie(name) {
 var needle = name + "=";
 var cookieArray = document.cookie.split(';');
 for(var i=0;i < cookieArray.length;i++) {
   var pair = cookieArray[i];
   while (pair.charAt(0)==' ') {
     pair = pair.substring(1, pair.length);
   }
   if (pair.indexOf(needle) == 0) {
     return pair.substring(needle.length, pair.length);
   }
 }
 return null;
}

function removeImageLinkBorders() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName('a');
	for (var i=0; i<anchors.length; i++) {
   		anchor = anchors[i];
		var images = anchor.getElementsByTagName('img');
		if (images[0] != null) {
			anchor.className = "image";
		}
 	}
	return;
}

function viewProfile(memberName){
	var actionUrl = _woRootURL + 'wa/Profile/display?member='+memberName;
	location=actionUrl;
}





Behaviour.addLoadEvent(delayedLoad);
//Behaviour.addLoadEvent(loadPhotostrip);

//delayedLoad();

function delayedLoad() {
	
	var delayedElements = document.getElementsByClassName("delayedLoader");
	
	for (i = 0; i < delayedElements.length; i++) {
		registerDelayedLoad( delayedElements[i] );
	}	

}

function registerDelayedLoad(loaderid){
      // Determine what to show if the panel takes a while to  load
      var busyContent = 'Loading, please wait...';
    //  if (busyDivID != '') {
    //      busyContent = $('busydiv').innerHTML;
    //  }
   	  var loader = $(loaderid);
	  var updateUrl = loader.getAttribute('updateUrl');
	  if (!updateUrl){
	  	updateUrl = loader.getAttribute('updateDA');
	  	updateUrl = _woRootURL + 'wa/' + updateUrl;
	  }
	  
	 loader.update( busyContent );
	 //onLoading:function(request){loader.update(busyContent);})
      
      if (loader.innerHTML=='' || loader.innerHTML==busyContent) {
         new Ajax.Updater(loader, updateUrl, {method: 'get', asynchronous:true, evalScripts:true})
      }
}



//Behaviour.addLoadEvent(initJavaScript);

function initLifebeat() {
//	setTimeout( 'sendLifebeat();', 15000 );
}

function sendLifebeat() {

	new Ajax.Request( _woRootURL + 'wa/xlifebeat', {
		method: 'get',
 	 	onSuccess: function(transport) {
     		 setTimeout( 'sendLifebeat();', 10000 );
  		}
	});

}


//	var myGlobalHandlers = {
//		onCreate: function(){
//			Element.show('systemWorking');
//		},
//
//		onComplete: function() {
//			if(Ajax.activeRequestCount == 0){
//				Element.hide('systemWorking');
//			}
//		}
//	};
//
//	Ajax.Responders.register(myGlobalHandlers);

/*	
function addPhotoToFavourites( imageID, el ){

	new Ajax.Request( _woRootURL + 'wa/Nav/xaddPhotoToFavourites', {
		method: 'get',
		onSuccess: function(transport){
		
		}
		onFailure: function(transport){
		
		}
	}

}	
	*/
var memberProfileUrl = "wa/Profile/display?member=";	