/**
 * This file the login dialog for the playground area
 * @author: Charles Russell
 */



//This is a blank object that will later contain a refrence to a PlaygroundConnect Object
var PageManager ={};

//Name space for this page
var RCC ={};

/**
 * This object is the page management code for the RCC Contact page
 * 
 */
RCC.PlaygroundConnect = function(manager){
	var dragKey;
	var targetLock;
	var dialogElement;
	

	/**
	 * This makes the call to the playground login management system
	 * The security is not meant to be high, just provide a roadbump;
	 */
	function verify_4_playground(){
		this.callback.success = function(o){
			var returnValue = YAHOO.lang.JSON.parse(o.responseText );
			if (returnValue.verfied === "true") {
				window.location = "http://www.russellcomputerconsulting.com/rccPlayground/RCCplaygroundBase.php";
			}
			else {
				alert("You must be verified to enter this area. \nCheck your user name and password");
			}
		};
		this.callback.failure = function(o){
			alert("Currently unable to connect to server.  You may cancel or try again");
		};
		this.submit();
	}
	
	/**
	 * Close the dialog window
	 */
	function closeDialog(){
		
		this.cancel();
	}
	return{
		
		//drag and drop implimentation
		ddKey:new YAHOO.util.DD("key","playGroup"),
		lockTarget:new YAHOO.util.DDTarget("lock","playGroup"),
		//dialog definition
		playdialog:new YAHOO.widget.Dialog("playgroundLogin",{
			constraintoviewport:true,
			width:"300px",
			modal:true,
			fixedcenter:true,
			buttons:[
				{text:"Verify Credentials",handler:verify_4_playground},
				{text:"Cancel",handler:closeDialog}
			]
		}),
		/**
		 * Initialize the page elements
		 */
		init:function(){
			/*
var keyAnimation = new YAHOO.util.Motion(this.ddKey.id,{
				points:{ 
					to: YAHOO.util.Dom.getXY(this.ddKey.getEl()) }
				}
			);
*/
			this.ddKey.onDragDrop = function(e,id){
				if (id == "lock") {
					PageManager.playdialog.show();
					YAHOO.util.DDM.moveToEl(this.getEl(),YAHOO.util.Dom.get("keyhook"));

				}
			};
		}

	};
};



YAHOO.util.Event.onDOMReady(function(){
	PageManager = new RCC.PlaygroundConnect();
	PageManager.init();
	PageManager.playdialog.render(document.body);
	PageManager.playdialog.hide();
});