(function($){
	$.fn.extend({
		modalLogin: function(){
			//create overlay
			var overlay = $("<div id='modal-overlay'></div>");
			var loginw  = $("<div id='modal-window'></div>");
			
			loginw.html($("#logincode").html());
			
			return this.each(function(){
				$(this).click(function(e){
					
					$(this).blur();
					
					if (typeof document.body.style.maxHeight === "undefined") { //if IE 6
						$("body","html").css({height: "100%", width: "100%"});
						$("html").css("overflow","hidden");
					}
					
					$("body").append(overlay.click(function(){ modalHide();}));
					overlay.css("opacity",0.5);
					overlay.fadeIn(150);
					e.preventDefault();
					$(document).keydown(handleEscape);
					
					$("body").append(loginw);
					loginw.fadeIn(150);
					$("#modal-window .modalclose").click(function(e){e.preventDefault(); modalHide(); return false;});					
				});
			});
			
			function modalHide(){
				$(document).unbind("keydown",handleEscape);
				var remove = function(){ $(this).remove(); };
				overlay.fadeOut(remove);
				loginw.fadeOut(remove);
			}
			
			function handleEscape(e){
				if (e.keyCode == 27){
					modalHide();
				}
			}
			
		}
	});
})(jQuery);

$(document).ready(function(){              
	$('a[rel*=modalLogin]').modalLogin();
	for(var i=0; i < runWhenReady.length; i++){
		eval(runWhenReady[i] + '();');
	}
}); 

$(document).ready(function(){
	$("#form_user").focus(function(){
		if ($("#form_user").val() == 'email')
			$("#form_user").val("");  
	});  
	$("#form_password").focus(function(){
	  	if ($("#form_password").val() == '******')
	  		$("#form_password").val("");
	});
	$(".login_btn a").click(function(e){
		e.preventDefault();
		$("#form-login").submit();  
	});
	
	$(".button").mouseover(function(e){
		$(e.currentTarget).addClass("button_on");
	});
	
	$(".button").mouseout(function(e){
	  	$(e.currentTarget).removeClass("button_on");
	});
});
