// JavaScript Document
var JamesNetworks = {
	
	init : function()
	{
		$$('a[rel^=overlaybox]').each(function(atag)
		{
			 atag.onclick = function()
			  {
				  //alert(this);
				  var box = this.rel.split("_")[1];
				
					// fade in the overlay (re)used by lightbox
					var arrayPageSize = Lightbox.prototype.getPageSize();
					$('overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
					new Effect.Appear('overlay', { duration: .3, from: 0.0, to: 0.5 });
					
					// position and show the contact form
					var arrayPageScroll = document.viewport.getScrollOffsets();
					var lightboxTop = arrayPageScroll[1] + Math.round(document.viewport.getHeight()-$(box).getHeight())/2;
					var lightboxLeft = Math.round((arrayPageSize[0]-$(box).getWidth())/2);
					
					// alert(lightboxTop);
					// alert(lightboxLeft);
					$(box).setStyle({ top:lightboxTop+'px', left:lightboxLeft+'px' }).show();
					
					// close box action
					$('close_'+box).onclick = function()
					{
						$('close_'+box).parentNode.hide();
						new Effect.Fade('overlay', { duration: 0.3 });
						return false;
					}
					
					// overlay action
					var overlay;
					if( overlay = $('overlay'))
					{
						overlay.onclick = function()
						{
							if($(box)) $(box).hide();
						}
					}
					return false;
			  }
		});
		
		/*var sbmt = $('submit_emailsupportbox');
		sbmt.onclick = function()
		{
			new Ajax.Request('/includes/ajax/sendHelp.php',
			{
				method: 'get',
				parameters: $('form_helpcenter').serialize(true),
				onSuccess: function(transport)
				{
					var response = transport.responseText || "no response text";
					//alert(response);
					$('emailsupportbox_errormsg').update(response);
					$('form_helpcenter').hide();
					//new Effect.Appear(box, { duration: 3.0, from: 1.0, to: 1.0 });
					//new Effect.Fade(box, { duration: 0.3, from:1.0, to:1.0, queue: 'end' });
					//new Effect.Fade('overlay', { duration: 0.3, from:0.5, to:0.0 });
				},
				onFailure: function(){ alert('Something went wrong...') }
			});
		}*/
	}
}

Event.observe( window, "load", JamesNetworks.init );