/**
 * 
 * @author marco 
 * Crescent Design Lite
 *  
**/

var login = function(){
	function openPopUp( tier ){	
		var stageHeight, tierNum;
		
		if( $( 'html' ).height() < $( window ).height() ){
			stageHeight = $( window ).height();
		}else{
			stageHeight = $( 'html' ).height();
		}
		
		if( tier == 1) { tierNum = "script/login.php"; }
		else{ tierNum = "../script/login.php" }
		 		
		$( '#loginBackground' ).css({ 'width' : '100%', 'height' : stageHeight, 'display' : 'block' });		
		$( '#message' ).css({ 'border' : '10px solid #666666', 'margin' : '-50px 0 0 -250px', 'background' : '#fff' });		
		$( '#message' ).html( '<div id="loginForm"><div id="loginLogo"></div><form method="post" action="' + tierNum + '" onsubmit="login.validate()"> <table> <tr><td>Username: </td> <td><input type="text" name="username" value="" id="username" /></td></tr> <tr><td>Password: </td> <td><input type="password" name="password" value="" id="password" /></td></tr> <tr><td colspan="2"><input type="submit" value="login" /><button title="cancel" onclick="login.closePopup()">Cancel</button></td></tr> </table> </form></div>' );	
		$( '#message' ).css({ 'width' : '500px', 'height' : '100px' });
		$( '#message' ).fadeIn( 'slow' );
	};
	function close() {
		$( "#message" ).hide();
		$( "#loginBackground" ).hide();
	};
	
	// Validate login
	function validateLogin(){		
		var username = $( '#username' ).val();
		var password = $( '#password' ).val();
		
		if( username == "" || username == " " ){
			return false;
		}else if( password == "" || password == " "  ){
			return false;
		}else{
			return true;
		}
		
		return false;
	};
	
	return {
		popUp:openPopUp,
		validate:validateLogin,
		closePopup:close
	}
}();

function enlargeImage( url ){	
	var stageHeight
	if( $( 'html' ).height() < $( window ).height() ){
		stageHeight = $( window ).height();
	}else{
		stageHeight = $( 'html' ).height();
	}
	
	$( '#loginBackground' ).css({ 'width' : '100%', 'height' : stageHeight, 'display' : 'block'  });
	$( '#message' ).html( "<img src='' width='10' height='10' alt='Image enlarge' />" );
	$( '#message' ).fadeIn( 'slow' );
	$( '#message img' ).load(
		function(){					
			$(this).hide(); 
			$( '#message' ).css({ 'background' : 'images/loader.gif', 'top' : '50%', 'left' : '50%', 'margin' : '-50px 0 0 -50px', 'border' : 'none', 'background' : 'none' });
			$(this).css({ 'border' : '10px solid #666666' });
			$(this).animate({
				opacity: 100,
				height: 400,
				width: 400,
				marginLeft: -150,
				marginTop: -150,
			}, 'default');
		}
	).attr( 'src', url );
}

function viewText( id ){
	if ($(id).parent().parent().children('.hiddenContent').css("display") == "none") {
		$('p.hiddenContent').css('display: none');
		$(id).parent().parent().children('.hiddenContent').slideDown("default");
		$(id).html('Close');
	}else{
		$(id).parent().css("margin", "0 0 30px 0");
		$(id).parent().parent().children('.hiddenContent').slideUp("default");
		$(id).html('View');
	}
}


