
var postAuth = function postAuth(){}
var userDialog = new Object();
var userEditAction = new Object();

//var lightbox;

function logType(evt){
	if(evt.keyCode == dojo.keys.ENTER){
		login();
	}
}

function login(){
  var p = {
    url: '/rpc/login.php',
    timeout: 5000,
	content: {'e':dijit.byId('le').attr('value'),'p':dijit.byId('lp').attr('value')},
	preventCache:true,
	load: function (data) {
		if( isset(data.error) ){
			dojo.byId('lMessage').innerHTML = '<h3>'+data.error+'. <a href="#forgotPassword" onClick="forgotPassowrd();">Click here to reset your password.</a></h3>';
		}else{
			stg = 'page/profile';
			//postAuth = function(){ console.log('login'); loader(stg); }
			testFire('topLogin','topUserInfo');
			window.location = "/myprofile";
		}
	},
	error: function (error) { console.log(error); },
    handleAs: "json"
  };
dojo.xhrPost(p);
}

function logout(){
  var p = {
    url: '/rpc/logout.php',
    timeout: 5000,
	//content: {'e':dijit.byId('le').attr('value'),'p':dijit.byId('lp').attr('value')},
	preventCache:true,
	load: function (data) {
		stg = 'page/home';
		postAuth = function(){ loader(stg); }
		testFire('topUserInfo','topLogin');
		window.location = "http://lyfe.net/";
	},
	error: function (error) { console.log(error); },
    handleAs: "json"
  };
dojo.xhrPost(p);
}

function loader(stg){
	dijit.byId('stage').setHref(stg+'.php');
	dojo.xhrGet({ url: '/js/'+stg+'.php', handleAs:"javascript", error:function(){console.log('nogood');} });
	//dojo.xhrGet({ url: '/js/'+stg+'.js', handleAs:"javascript", error:function(){console.log('nogood');} });
}

function testFire(s,h){
  dojo.fadeOut({ node: dojo.byId(s), duration:300}).play();
  dojo.fx.wipeOut({ node: dojo.byId(s),
                    duration:250,
                    onEnd:function(){ dojo.fx.wipeIn({ node: dojo.byId(h), duration:250}).play();
                                      dojo.fadeIn({ node: dojo.byId(h), duration:300, onEnd:function(){postAuth();}}).play();
                                    }
                  }).play();
}

dojo.addOnLoad(
	function(){
		//lightbox = new dojox.image.LightboxDialog().startup();
	}
);

function isset(v){
	if( (typeof v) == 'undefined' ){
		return false;
	}else{
		return true;
	}
}

function userSettingsBar(){
	if(dojo.byId('identBar').style.opacity == 0){
		dojo.fx.wipeIn({ node: dojo.byId('identBar'), easing: dojo.fx.easing.backOut, duration:250}).play();
		dojo.fadeIn({ node: dojo.byId('identBar'), duration:300 }).play();
	}else{
		dojo.fx.wipeOut({ node: dojo.byId('identBar'), easing: dojo.fx.easing.backIn, duration:250}).play();
		dojo.fadeOut({ node: dojo.byId('identBar'), duration:300 }).play();
	}
}

function imgLoc(img){
	if( img.filename != null ){
		var theDate = new Date(img.dt * 1000);
		return 'http://i2.lyfe.net'+'/media/images/'+theDate.getFullYear()+'/'+(theDate.getMonth()+1)+'/'+img.filename+'_t.jpg';
	}else{
		return 'http://lyfe.net/imgs/avatar.jpg';	
	}
}

function iSmallFade(id, inout){
	if( inout == 1 ){
		//dojo.query(id).fadeTo({ end: 0.5 }).play();
		dojox.fx.fadeTo({ node: dojo.byId(id), end:0.2, duration:300}).play();
	}else{
		dojo.fadeIn({ node: dojo.byId(id), duration:300}).play();
	}
}

function showMiniProfile(id){
	dijit.byId('dialog_miniprofile').setHref('/page/miniprofile.php?id='+id);
	dijit.byId('dialog_miniprofile').show();	
}