﻿var ActiveNetwork = window.ActiveNetwork || {};

(function() {

ActiveNetwork.CasSession = function(siteUrl, redirectUrl) {
	this.initialize(siteUrl, redirectUrl);
};

(function() {
	
	ActiveNetwork.CasSession.prototype = (function() {
		
		return {
			
			siteUrl: null,
			redirectUrl: null,
			loginData: null,

			initialize: function(siteUrl, redirectUrl) {
				this.siteUrl = siteUrl;
				this.redirectUrl = redirectUrl;
			},

			updateLoginStatus: function(data) {
				this.loginData = data;
				Event.fire(document, "cas:loaded");
			},

			logIn: function() {
			    var url = "http://www.active.com/ihoops/login/?referrerUrl=" + window.location.href;
			    window.location = url;
			},

			logOut: function() {
				Event.fire(document, "cas:logout");
			    if(typeof __logoutToHomePage != "undefined" && __logoutToHomePage == true) {
			        new Ajax.Request('/CM/WebUI/PageTypes/LoginStatus/CasValidate.aspx');
			        window.location = "http://community.active.com/logout.jspa?referrerUrl=" + this.siteUrl;
			    } else {
			        var url = "http://community.active.com/logout.jspa";
			        var theBody = $$("body")[0];
			        var iframe = document.createElement("iframe");
			        iframe.src = url;
			        iframe.height = iframe.width = 0;
			        iframe.style.display = "none";
			        theBody.appendChild(iframe);
			    }
			},

			signUp: function() {
				var url = "http://www.active.com/ihoops/login/?show=create&referrerUrl=" + this.redirectUrl;
				window.location = url;
			},

			myActive: function() {
				var url = "http://community.active.com/people/" + this.loginData.DisplayName;
				window.location = url;
			},

			getAvatarUrl: function() {
				return "http://community.active.com/people/" + this.loginData.DisplayName + "/avatar?version=" + this.loginData.AvatarVersion;
			}

		};
	}());
	
}());

}());

