// Preload Images
img1 = new Image(16, 16);  
img1.src="images/spinner.gif";

img2 = new Image(220, 19);  
img2.src="images/ajax-loader.gif";

// When DOM is ready
$(document).ready(function(){
	// Launch MODAL BOX if the Login Link is clicked
	$(".listLogin").click(
		function(){
			file = $(this).attr("name");
			$("#loginFormPopUp").modal({onOpen: function (dialog) {
				dialog.overlay.fadeIn('slow', function () {
					dialog.container.slideDown('slow', function () {
							dialog.data.fadeIn('slow');
						});
					});
				}
			});
		}
	);
	
	// When the form is submitted
	$("#status > form").submit(function(){  
	
		// Hide 'Submit' Button
		$('#submit').hide();
		
		// 'this' refers to the current submitted form  
		var str = $(this).serialize();  
		
		// -- Start AJAX Call --
		$.ajax({  
		    type: "POST",
		    url: "login.php?popup=1",  // Send the login info to this page
		    data: str,  
		    success: function(msg){  
				$("#status").ajaxComplete(function(event, request, settings){  
					 // Show 'Submit' Button
					$('#submit').show();
					if( msg.indexOf('OK') > -1) // LOGIN OK?
					{  
						var login_response = '<div id="logged_in">' +
							 '<div style="width: 350px; float: left; margin-left: 70px;">' + 
							 '<div style="width: 40px; float: left;">' +
							 '<img style="margin: 10px 0px 10px 0px;" align="absmiddle" src="images/ajax-loader.gif">' +
							 '</div>' +
							 '<span class="b"><strong>'+ 
							 msg.substring(2) +"</<strong></span></div>";  
					
						$('a.modalCloseImg').hide();  
					
						$('#simplemodal-container').css("width","500px");
						$('#simplemodal-container').css("height","120px");
					 
						$(this).html(login_response); // Refers to 'status'
						
						setTimeout('go_to_private_page()', 600); 
						$('#simplemodal-container').fadeOut(3000);
						$('#simplemodal-overlay').fadeOut(3000);
					//ERROR?
					}else{  
						var login_response = msg;
						$('#login_response').show();
						$('#login_response').html(login_response);
					}  
				});  
			}  
		});  
	  
		// -- End AJAX Call --
		return false;
		
	}); // end submit event
});

function go_to_private_page(){
	//alert(file);
	window.location = 'file.php?id='+file; // Members Area
	//window.location = 'index.php'; // Members Area
	
}
