
function makeLinksExternal(){
	$("a[href*='http://']:not([href*='"+location.hostname+"'])").attr("target","_blank"); 
}

function overlay(){
	var screenH = $(document).height();
	var screenW = $(document).width();
	$("body").append('<div id="overlay" class="overlay"></div>');
	$.get("inc/adofthemonth.inc.php",function(data){
		$("#overlay_content").append(data);										  
	});
	/*
	$.get("includes/view/common/categories.windowmanager.php?module="+module+"&id="+id+"&category="+category,function(data){
		$("#overlay_content").append(data);														 
		$("#overlay_content").bind("onload",function(){
			$(this).css("background-image","none");									 
			$(this).fadeIn("slow");				
		});
	});	
	*/
	$("body").append('<div id="overlay_content" class="overlay_content"></div>');
	$("#overlay").css("width",screenW);
	$("#overlay").css("height",screenH);
	$(document).bind("keypress",function(e){
		if(e.keyCode == 27 && $("#overlay").length > 0){
			close_widget();
		}					 
	});	
}

function close_widget(){
	$("#overlay").remove();
	$("#overlay_content").remove();
}

(function($){ $.fn.rotator = function(options){

    var defaults = {
		ms: 2000,
		n: 1,
		autoHeight: false
	};
  
    var options = $.extend(defaults, options);
	
	return this.each(function(index) {
		
		var $this = $(this);
		
		var initialHeight = 0;
		$this.children().filter(":lt("+options.n+")").each(function(index,item){
		    initialHeight += $(item).height();
		});
		
		$this.height(initialHeight);
		
		setInterval(function(){
		    
			var childHeight = $this.children().filter(":first-child").height();
		    var animParams = {scrollTop: (childHeight) + "px"};
			var autoHeight = 0;
		    $this.children().filter(":lt("+(options.n+1)+")").each(function(index,item){
		        if(index>0)autoHeight += $(item).height();
		    });
			if(options.autoHeight)animParams = $.extend({height:(autoHeight) + "px"}, animParams);
		
			
		    $this.animate(animParams, 1000, function(){
		        $this.scrollTop(0);
			    $this.append($this.children().filter(":first-child"));
				$this.css("overflow","hidden"); //Chrome hack
		    });

			
	    }, options.ms);
		

	});

  
}})(jQuery);

function forgot_pwd(){	
	$("a[rel=activation]").click(function(){
		$("#login_content").load('process.php?action=reqpwdchange',function(){			
			$("#passwordreset").submit(function(){
				var req_address = $(this).attr("action");
				req_address += "&ac=true";			
				var serial = $(this).serialize();	
				
				$.post(req_address,serial,function(data){					
					if(data == "ok"){
						$("#passwordreset").fadeOut(200,function(){
							$("#login_content").html("<p>Please check your email, we have sent you a confirmation mail to reset your password</p>");
							$("#login_content").fadeIn(200);
						});
					} else {
						$("#passwordreset").fadeOut(200,function(){
							$("#login_content").html('<p>That email address isn\'t valid, <a href="#" onclick="back_to_forgotpwd_form();return false;"><strong>please try again</strong></a> or <a href="#" onclick="back_to_login_form();return false;"><strong>log in</strong></a></p>');
							$("#login_content").fadeIn(200);
						});
					}//end if
					//$("#signin_bar").remove();	
				});
				return false;
			});
		}).fadeIn("slow");
		return false;
	});
}

function back_to_forgotpwd_form(){
	$("#login_content").load('process.php?action=reqpwdchange',function(){			
		$("#passwordreset").submit(function(){
			var req_address = $(this).attr("action");
			req_address += "&ac=true";			
			var serial = $(this).serialize();	
			
			$.post(req_address,serial,function(data){			
				if(data == "ok"){
					$("#passwordreset").fadeOut(200,function(){
						$("#login_content").html("<p>Please check your email, we have sent you a confirmation mail to reset your password</p>");
						$("#login_content").fadeIn(200);
					});
				} else {
					$("#passwordreset").fadeOut(200,function(){
						$("#login_content").html('<p>That email address isn\'t valid, <a href="#" onclick="back_to_forgotpwd_form();return false;"><strong>please try again</strong></a> or <a href="#" onclick="back_to_login_form();return false;"><strong>log in</strong></a></p>');
						$("#login_content").fadeIn(200);
					});
				}//end if
				//$("#signin_bar").remove();	
			});
			return false;
		});
	}).fadeIn("slow");
}

function back_to_login_form(){	
	$("#login_content").html('<span id="login_content"><form action="login.php" method="post" name="log_in" id="log_in">Username <input name="username" id="username" type="text" class="half" />Password <input name="password" id="password" type="password" class="half" /><input name="Log In" type="submit" value="Log In" id="loginbt" /><a href="activation.php" rel="activation">Forgot your password?</a></form></span>');
	$("a[rel=activation]").click(function(){
		$("#login_content").load('process.php?action=reqpwdchange',function(){			
			$("#passwordreset").submit(function(){
				var req_address = $(this).attr("action");
				req_address += "&ac=true";			
				var serial = $(this).serialize();	
				
				$.post(req_address,serial,function(data){					
					if(data == "ok"){
						$("#passwordreset").fadeOut(200,function(){
							$("#login_content").html("Please check your email, we have sent you a confirmation mail to reset your password");
							$("#login_content").fadeIn(200);
						});
					} else {
						$("#passwordreset").fadeOut(200,function(){
							$("#login_content").html('That email address isn\'t valid, <a href="#" onclick="back_to_forgotpwd_form();return false;">please try again</a> or <a href="#" onclick="back_to_login_form();return false;">log in</a>');
							$("#login_content").fadeIn(200);
						});
					}//end if
					//$("#signin_bar").remove();	
				});
				return false;
			});
		}).fadeIn("slow");
		return false;
	});
}

