$(document).ready(function() {

	//Initiate previous issue scroller
	$("div.scrollable").scrollable(); 
	 
	 //Initiate Overlays
	$("a[rel]").overlay({
		expose: {
			color: '#000',
			loadSpeed: 500,
			opacity: 0.5
		},
		closeOnClick: true,
		api: true
	});
	
	function showRequest(){
		$('#formresponse').html("<img src=\"images/loading.gif\"");
	}
	
	function showResponse(){
		$('#formresponse').html("<span class=\"postsuccess\">We've e-mailed your friends to tell them about our magazine. <span class=\"bold\">Thanks!</span></span>");
		setTimeout(function() { 
			$("a[rel]").each(function() { 
				$(this).overlay().close(); 
			}); 
		},4000);
	}
	
	//Validate tell a friend form
	$("#tellfriendform").validate({
		submitHandler: function(form) {
				$('#tellfriendform').ajaxSubmit({
					target: "#formresponse",
					beforeSubmit: showRequest,
					success: showResponse
				});
			},
		rules: {
			name: {
				required: true,
				minlength: 2
			},
			email1: {
				required: true,
				email: true
			},
			email2: {
				email: true
			},
			email3: {
				email: true
			},
			email4: {
				email: true
			},
			email5: {
				email: true
			},
			email6: {
				email: true
			}
			
		}
	});
	
	$("#loginform").validate({
	
		rules: {
			username: {
				required: true,
				minlength: 3
			},
			password: {
				required: true,
				minlength: 3
			}
		}
	});
	
	//Initiate registration form validation
	$("#register").validate({
	
		rules: {
			username: {
				required: true,
				minlength: 3
			},
			emailreg: {
				required: true,
				minlength: 5,
				email: true
			},
			email_confirm: {
				required: true,
				equalTo: "#emailreg"
			},
			new_password: {
				required: true,
				minlength: 6
			},
			password_confirm: {
				required: true,
				equalTo: "#new_password",
				minlength: 6
			},
			pf_nospam: {
				required: true,
				minlength: 2,
				digits: true,
				range: [12, 12]
			}
		}
		


	});
});
	
	//Function to open issues
	function MM_openBrWindow(theURL,winName,w,h,scrollbars) 
	{ 
	  LeftPosition=(screen.width)?(screen.width-w)/2:100;
	  TopPosition=(screen.height)?(screen.height-h)/2:100;
	  
	  settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scrollbars+',location=no,directories=no,status=0,menubar=no,toolbar=no,resizable=no';
	  URL = theURL;
	  window.open(URL,winName,settings);
	}