var messageStack = stdClass.extend({
	//constructor
	constructor: function(el, settings) {
		this.base();
		// initialize settings
		Object.extend(this.s, {
			timer: null,
			waitTime: 4000,
			effectTime: 2000,
			closeSelector: ".close"
			/* put extensions to collections here */
		});
		
		// initialize nodes
		Object.extend(this.n, {
			el: el,
			childEl: [],
			tempContainer: document.createElement('div')
			/* put extensions to nodes here */
		});
		
		// initialize collections
		Object.extend(this.c, {
			messageFunctions: {
				success: this.successMessage.bind(this),
				error: this.errorMessage.bind(this)
			}
			/* put extensions to collections here */
		});
		var eles = this.n.el.getElementsBySelector('ul');
		
		for(var x=0; x<eles.length; x++){
			var childEl = {
				el: eles[x],
				timer: null
			}
			this.startTimer(childEl);
			this._attachEvents(childEl);
		}
	},
	closeClicked: function(childEl){
		this.removeMessage(childEl);
	},
	addMessage: function(message, type){
		if(!this.n.el){
			return;
		}
		if(typeof(this.c.messageFunctions[type]) == "function"){
			var html = this.c.messageFunctions[type](message);
		}else{
			return;
		}
		
		this.n.tempContainer.innerHTML = html;
		var childEl = {
			el:this.n.tempContainer.firstChild,
			timer:null
		}
		this.n.el.appendChild(childEl.el);
		this._attachEvents(childEl);
		Element.show(this.n.el);
		if(window.Effect){
			Effect.BlindDown(childEl.el,{
				duration: (this.s.effectTime/1000),
				afterFinishInternal: function(effect) {
					effect.element.undoClipping();
					effect.element.style.height = '';
				}
			});
		}else{
			Element.show(childEl.el);
		}
		this.startTimer(childEl);
	},
	removeMessage: function(childEl) {
		this.endTimer(childEl);
		if(window.Effect){
			Effect.Fade(childEl.el, {
				duration: (this.s.effectTime/1000)
			});
			/*Effect.BlindUp(childEl.el,{
				duration: (this.s.effectTime/1000),
				afterFinishInternal: function(effect) {
					effect.element.undoClipping();
					effect.element.style.height = '';
					Element.hide(effect.element);
				}
			});*/
		}else{
			Element.hide(this.n.el);
		}
	},
	startTimer: function(childEl) {
		this.endTimer(childEl);
		this.s.timer = setTimeout(this.removeMessage.bind(this, childEl), this.s.waitTime);
	},
	endTimer: function(childEl) {
		if(childEl.timer != null){
			clearTimeout(childEl.timer);
			childEl.timer = null;
		}
	},
	successMessage: function(message){
		var html = '<ul class="success">';
		html += '<li class="title">Success</li>';
		html += '<li>' + message + '</li>';
		html += '</ul>';
		return html;
	},
	errorMessage: function(message){
		var html = '<ul class="error">';
		html += '<li class="title">Error</li>';
		html += '<li>' + message + '</li>';
		html += '<li class="close">Close me</li>';
		html += '</ul>';
		return html;
	},
	_attachEvents: function(childEl) {
		var eles = document.getElementsBySelector(this.s.closeSelector, (childEl.el||this.n.el));
		for(var x=0; x<eles.length; x++){
			this.eObserve(eles[x], 'click', this.closeClicked.bind(this, childEl));
		}
	}
});
Behaviour.register({
	'div#messagestack' : function(el){
		new messageStack (el);
	}
});var Favorites = stdClass.extend({
	//constructor
	constructor: function(el, settings) {
		this.base();
		// initialize settings
		Object.extend(this.s, {
			//moduleName: 'AdminModules__AddFavorites',
			favoritesSelector: '.favorites',
			moduleName: 'AddBookmark',
			json: {
				ver: '0.1',
				meta: {},
				data: {
					requests: []
				}
			},
			uniqueID: null,
			type: null
			/* put extensions to collections here */
		});
		
		// initialize nodes
		Object.extend(this.n, {
			el: el,
			link: null
			/* put extensions to nodes here */
		});
		
		// initialize collections
		Object.extend(this.c, {
			requests: []
			/* put extensions to collections here */
		});
		
		if(this.n.el.id != ""){
			this.s.moduleName = this.n.el.id;
		}
		//alert('ran');
		this._findLinks();
		this._addEvents();
		var args = String(this.n.link).getUrlArgument();
		args = args.split(",");
		for(var x=0; x<args.length; x++){
			args[x] = args[x].replace(/^[\s'"]+|[\s'"]+$/g,"");
		}
		
		this.s.uniqueID = args[0];
		this.s.type = args[1];
	},
	linkOnClick: function(e){
		if(Element.hasClassName(this.n.link, 'loggedin_false')){
			this.showLoginBox();
			Event.stop(e);
		}else if(Element.hasClassName(this.n.link, 'bookmark_add')){
			this.addRequest("addFavorites", {
				uniqueID: this.s.uniqueID,
				type: this.s.type
			});
			this.JsonOut();
			Event.stop(e);
		}else if(Element.hasClassName(this.n.link, 'bookmark_remove')){
			this.addRequest("removeFavorites", {
				uniqueID: this.s.uniqueID,
				type: this.s.type
			});
			this.JsonOut();
			Event.stop(e);
		}
	},
	showLoginBox: function() {
		new FormDialog({
			'+zones': {
				heading: 'Loading...',
				text: 'Loading...'
			},
			position: {  
				exemplarAnchor: 'bottom right',
				selfAnchor: 'top right',
				exemplar: this.n.el,
				offsetY: 0,
				offsetX: 0
			},
			groupId: 'AuthLogin',
			groupLimit: 1,
			startHidden: true,
			moduleName: 'AuthLogin',
			parentThis: this,
			classNames: ['kDialog2', 'authLogin']
		});
	},
	addRequest: function(requestName, dataObject) {
		this.c.requests.push({
			id: this.c.requests.length,
			type: requestName,
			data: dataObject
		});
	},
	//json methods
	JsonOut: function() {
		//construct the post
		this.s.json.data.requests = this.c.requests;
		//this.setMeta('columns', '');
		var data = '__json=' + this.s.moduleName + '&data=' + Object.toJSON(this.s.json);
		this.c.requests = [];
		//alert(data);
		//send out the request
		var myAjax = new Ajax.Request(window.location,
		{
			method: 'post',
			parameters: data,
			onSuccess: this.JsonIn.bind(this)
		});
		
		//var returnData = '{"meta":{},"data":{"html":"<a href=\'javascript:void(51820)\' class=\'bookmark_remove\'>Remove from Favorites</a><br /> <a href=\'/favorites/\'>View Favorites</a>"},"responses":[{"id":1,"type":"addFavorites","data":{"success":"true"}}]}';
		//this.JsonIn({responseText:returnData});
	},
	
	JsonIn: function(t) {
		//alert(t.responseText);
		var result = t.responseText.evalJSON();
		(result.responses.length).times(function(i) {
			if(result.responses[i].type == 'addFavorites'){
				if(result.responses[i].data.success == "false"){
					this.showLoginBox();
				}else{
					//this.n.jsonNode.innerHTML = result.data.html;
					var eles = document.getElementsBySelector(this.s.favoritesSelector);
					for(var x=0; x<eles.length; x++){
						eles[x].parentThis.n.el.innerHTML = result.data.html;
						eles[x].parentThis._startScripts(eles[x].parentThis.n.el);
						eles[x].parentThis._findLinks();
						eles[x].parentThis._addEvents();
					}
					this.n.el.innerHTML = result.data.html;
					this._startScripts(this.n.el);
					this._findLinks();
					this._addEvents();
				}
			}
		}.bind(this));
	},
	_startScripts: function(el) {
		//put initializing scripts here
	},
	_findLinks: function() {
		this.n.link = document.getElementsBySelector('a', this.n.el)[0]
	},
	_addEvents: function() {
		this.eObserve(this.n.link, 'click', this.linkOnClick.bind(this));
	}
});
EventSelectors.register({
	'.favorites': function(el, index) {
		el.parentThis = new Favorites(el);
	}
}, true);
var aStarRatings = stdClass.extend({
	//constructor
	constructor: function(el, settings) {
		this.base();
		// initialize settings
		Object.extend(this.s, {
			moduleName: null,
			json: {
				ver: '0.1',
				meta: {},
				data: {
					requests: []
				}
			},
			ulSelector: 'ul.rateable',
			starSelector: 'a',
			ratingTextSelector: '.rating_text',
			currentRatingSelector: '.current-rating'
			/* put extensions to collections here */
		});
		Object.extend(this.s, settings);
		// initialize nodes
		Object.extend(this.n, {
			container: el,
			ul: null,
			stars: [],
			ratingText: null,
			currentRating: null,
			jsonNode: document.createElement('div')
			/* put extensions to nodes here */
		});
		
		// initialize collections
		Object.extend(this.c, {
			requests: []
			/* put extensions to collections here */
		});
		this.parseClasses(this.n.container, true);
		/*if(!this.n.container.vars){
			alert('You need to add the class of "vars:{moduleName:theNameOfModule}" to your container!');
			return;
		}*/
		if(this.n.container.vars && this.n.container.vars.moduleName != ""){
			this.s.moduleName = this.n.container.vars.moduleName;
		}
		
		this._findElements();
	},
	starClicked: function(el){
		if(Element.hasClassName(this.n.ul, 'longText')){
			this.addRequest("changeRating", {
				newRating: el.vars.stars,
				uniqueID: this.n.ul.vars.uniqueID,
				type: this.n.ul.vars.type,
				longText: 'true'
			});
		}else{
			this.addRequest("changeRating", {
				newRating: el.vars.stars,
				uniqueID: this.n.ul.vars.uniqueID,
				type: this.n.ul.vars.type
			});
		}
		this.JsonOut();
		//el.blur();
	},
	parseClasses: function(el, parseChildren){
		var classes = String(el.className).split(" ");
		var keepClasses = [];
		for(var x=0; x<classes.length; x++){
			if(classes[x].indexOf(':') != -1){
				var matches = classes[x].match(/^(\w*):{1,2}\{(.*)\}$/);
				var ob = {};
				var vars = matches[2].split(",");
				for(var y=0; y<vars.length; y++){
					vars[y] = vars[y].split(/::?/);
					if(!vars[y][1]) vars[y][1] = '';
					ob[vars[y][0]] = vars[y][1];
				}
				el[matches[1]] = ob;
			}else{
				keepClasses.push(classes[x]);
			}
		}
		el.className = keepClasses.join(" ");
		if(parseChildren){
			var eles = el.getElementsByTagName('*');
			for(var x=0; x<eles.length; x++){
				this.parseClasses(eles[x]);
			}
		}
	},
	addRequest: function(requestName, dataObject) {
		this.c.requests.push({
			id: this.c.requests.length,
			type: requestName,
			data: dataObject
		});
	},
	//json methods
	JsonOut: function() {
		//construct the post
		this.s.json.data.requests = this.c.requests;
		//this.setMeta('columns', '');
		var data = '__json=' + this.s.moduleName + '&data=' + Object.toJSON(this.s.json);
		this.c.requests = [];
		//alert(data);
		//send out the request
		if(this.s.moduleName == ''){
			var returnData = '{"meta":{},"data":{"html":"<div class=\'rating vars:{moduleName:AdminModule__rating}\'><ul class=\'rateable floatleft vars:{uniqueID=51820}\'><li class=\'current-rating\' style=\'width: ' + (this.s.json.data.requests[0].data.newRating*12) + 'px;\'> </li><li><a href=\'javascript:void(0)\' title=\'1 star\' class=\'one-star vars:{stars:1}\'>1</a></li><li><a href=\'javascript:void(0)\' title=\'2 stars\' class=\'two-stars vars:{stars:2}\'>2</a></li><li><a href=\'javascript:void(0)\' title=\'3 stars\' class=\'three-stars vars:{stars:3}\'>3</a></li><li><a href=\'javascript:void(0)\' title=\'4 stars\' class=\'four-stars vars:{stars:4}\'>4</a></li><li><a href=\'javascript:void(0)\' title=\'5 stars\' class=\'five-stars vars:{stars:5}\'>5</a></li></ul><span class=\'rating_text\'>' + this.s.json.data.requests[0].data.newRating + '/5</span></div>"},"responses":[{"id":1,"type":"changeRating","data":{"success":"true"}}]}';
			this.JsonIn({responseText:returnData});
		}else{
			var myAjax = new Ajax.Request(window.location,
			{
				method: 'post',
				parameters: data,
				onSuccess: this.JsonIn.bind(this)
			});
		}
	},
	
	JsonIn: function(t) {
		//alert(t.responseText);
		var result = t.responseText.evalJSON();
		(result.responses.length).times(function(i) {
			if(result.responses[i].type == 'changeRating'){
				var container = this.n.container;
				while(container != document.body && !Element.hasClassName(container, "box")){
					container = container.parentNode;
				}
				this.n.jsonNode.innerHTML = result.data.html;
				var eles = document.getElementsBySelector(this.s.ratingTextSelector, container);
				var ratingHTML = document.getElementsBySelector(this.s.ratingTextSelector, this.n.jsonNode)[0].innerHTML
				for(var x=0; x<eles.length; x++){
					eles[x].innerHTML = ratingHTML;
				}
				var width = document.getElementsBySelector(this.s.currentRatingSelector, this.n.jsonNode)[0].style.width;
				var eles = document.getElementsBySelector(this.s.currentRatingSelector, container);
				for(var x=0; x<eles.length; x++){
					eles[x].style.width = width;
				}
				this._startScripts(this.n.container);
			}else if(result.responses[i].type == 'showLogin'){
				new FormDialog({
					'+zones': {
						heading: 'Loading...',
						text: 'Loading...'
					},
					position: {  
						exemplarAnchor: 'bottom right',
						selfAnchor: 'top right',
						exemplar: this.n.container,
						offsetY: 0,
						offsetX: 0
					},
					groupId: 'AuthLogin',
					groupLimit: 1,
					startHidden: true,
					moduleName: 'AuthLogin',
					parentThis: this,
					classNames: ['kDialog2', 'authLogin']
				});
				this.n.container.blur();
			}
		}.bind(this));
	},
	_startScripts: function(el) {
		//empty for now...
	},
	_findElements: function(){
		this.n.ul = document.getElementsBySelector(this.s.ulSelector, this.n.container)[0];
		if(!this.n.ul){
			return;
		}
		this.n.currentRating = document.getElementsBySelector(this.s.currentRatingSelector, this.n.container)[0];
		var stars = document.getElementsBySelector(this.s.starSelector, this.n.ul);
		this.n.stars = [];
		for(var x=0; x<stars.length; x++){
			this.eObserve(stars[x], 'click', this.starClicked.bind(this, stars[x]));
			this.n.stars.push(stars[x]);
		}
		this.n.ratingText = document.getElementsBySelector(this.s.ratingTextSelector, this.n.container)[0];
	}
});
EventSelectors.register({
	'.rating': function(el, index) {
		new aStarRatings(el, {
			moduleName: 'AddRating'
		});
	}
}, true);/*
* @author Adam Brill
* edited by Damien Filiatrault on 2/2/2007
*/

var Tags = stdClass.extend({
	//constructor
	constructor: function(el, settings) {
		this.base();
		// initialize settings
		Object.extend(this.s, {
			moduleName: '',
			json: {
				ver: '0.1',
				meta: {},
				data: {},
				requests: []
			},
			highlightSelector: '.new'
			/* put extensions to collections here */
		});
		
		//get ContentEntryInfoId
		//this.s.ceid = document.getElementsBySelector('.addtags p input.image')[0].getAttribute('id');
		
		// initialize nodes
		Object.extend(this.n, {
			el: el,
			p: el.getElementsBySelector('p#tagscontainer')[0],
			form: el.getElementsByTagName('form')[0],
			jsonNode: document.createElement('div')
			/* put extensions to nodes here */
		});
		// initialize collections
		Object.extend(this.c, {
			requests: []
			/* put extensions to collections here */
		});
		
		if (!this.n.form) {
			return;	// Abort the script if the form doesn't exist
		}
		if(this.n.el.id != ''){
			this.s.moduleName = this.n.el.id;
		}
		
		this._addEvents();
	},
	formOnSubmit: function(e){
		Event.stop(e);
		var serializedForm = Form.serialize(this.n.form);
		
		this.addRequest("submitForm", {
			postData: escape(serializedForm)
		});
		this.JsonOut();
	},
	addRequest: function(requestName, dataObject) {
		this.c.requests.push({
			id: this.c.requests.length,
			type: requestName,
			data: dataObject
		});
	},
	//json methods
	JsonOut: function() {
		//construct the post
		this.s.json.requests = this.c.requests;
		//this.setMeta('columns', '');
		var data = '__json=' + this.s.moduleName + '&data=' + Object.toJSON(this.s.json);
		this.c.requests = [];
		//send out the request
		var myAjax = new Ajax.Request(window.location,
		{
			method: 'post',
			parameters: data,
			onSuccess: this.JsonIn.bind(this)
		});
	},
	
	JsonIn: function(t) {
		var result = t.responseText.evalJSON();
		(result.responses.length).times(function(i) {
			if(result.responses[i].type == 'submitForm'){
				this.n.jsonNode.innerHTML = result.data.html;
				var ptags = this.n.jsonNode.getElementsByTagName('p');
				var p = null;
				for(var x=0; x<ptags.length; x++){
					if(ptags[x].id == 'tagscontainer'){
						p = ptags[x];
						break;
					}
				}
				if(p != null){
					this.n.p.innerHTML = p.innerHTML;
					this._startScripts(this.n.p);
				}
				this.n.form.reset();
			}
		}.bind(this));
	},
	_startScripts: function(el) {
		var highlights = document.getElementsBySelector(this.s.highlightSelector, el);
		for(var x=0; x<highlights.length; x++){
			new Effect.Highlight(highlights[x], {duration: 5, startcolor:'#D3EC9E'});
		}
	},
	_addEvents: function() {
		this.eObserve(this.n.form, 'submit', this.formOnSubmit.bind(this));
	}
});
EventSelectors.register({
	'div.tags': function(el, index) {
		new Tags(el);
	}
}, true);
ShareDialog = {
	interval: null,
	opacity: 0,
	open: false,
	eventsSet: false,
	html: false,
	cache: true,
	show: function() {
		if(!this.el){
			this.buildEl();
		}
		this.opacity = 1;
		this.updateOpacity(this.opacity);
		clearInterval(this.interval);
		this.interval = setInterval("ShareDialog.updateRelativeOpacity(20)", 10);
		this.el.style.display = "block";
		
		this.position();
		if(document.all && !this.iframe){
			this.iframe = document.createElement('iframe');
			this.iframe.style.height = this.el.offsetHeight;
			this.iframe.style.width = "100%";
			this.iframe.style.position = "absolute";
			this.iframe.style.top = "0";
			this.iframe.style.left = "20px";
			this.iframe.style.zIndex = "-1";
			this.iframe.style.filter = "alpha(opacity=0)";
			this.iframe.style.padding = "20px";
			this.iframe.style.marginLeft = "-20px";
			this.iframe.style.marginTop = "-20px";
			this.el.appendChild(this.iframe);
		}
	},
	position: function() {
		var vpHeight = self.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight);
		var scrollTop = self.pageYOffset || (document.documentElement.scrollTop || document.body.scrollTop);
		var top = (vpHeight - this.el.offsetHeight)/2 + scrollTop;
		this.el.style.top = top+"px";
	},
	hide: function() {
		this.interval = setInterval("ShareDialog.updateRelativeOpacity(-20)", 10);
	},
	updateRelativeOpacity: function(opacity) {
		var newOpacity = parseInt(this.opacity) + parseInt(opacity);
		this.updateOpacity(newOpacity);
	},
	updateOpacity: function(opacity) {
		if(opacity >= 100){
			opacity = 100;
			clearInterval(this.interval);
			this.open = true;
			this.makeEvents();
		}
		if(opacity <= 0){
			opacity = 0;
			clearInterval(this.interval);
			this.el.style.display = "none";
			this.open = false;
			this.unMakeEvents();
		}
		this.el.style.opacity = opacity/100;
		this.el.style.filter = "alpha(opacity="+opacity+")";
		this.opacity = opacity;
		if(opacity <= 0 && !this.cache){
			this.el = false;
			this.html = false;
		}
	},
	updateSelected: function() {
		var recs = [];
		var sp = ShareDialog.share_recipients.value.split(/[,\s]/);
		var found = false;
		for(var x=0; x<sp.length; x++){
			if(!/^\s*$/.test(sp[x]) && recs.indexOf(sp[x]) == -1){
				recs.push(sp[x]);
			}
		}
		var eles = ShareDialog.contactContainer.getElementsByTagName('a');
		for(var x=0; x<eles.length; x++){
			if(recs.indexOf(eles[x].innerHTML) != -1){
				eles[x].className = "selected";
			}else{
				eles[x].className = "";
			}
		}
	},
	onBodyClick: function(e) {
		if(!ShareDialog.open){
			return;
		}
		var ele = (e != undefined && e.target != undefined)? e.target : e.srcElement;
		var found = false;
		while(ele && ele != document.body){
			if(ele == ShareDialog.el){
				found = true;
				break;
			}
			ele = ele.parentNode;
		}
		if(!found){
			ShareDialog.hide();
		}
	},
	onBodyScroll: function(e) {
		ShareDialog.position();
	},
	onContactClick: function(e) {
		var ele = (e != undefined && e.target != undefined)? e.target : e.srcElement;
		if(String(ele.tagName).toLowerCase() == "a"){
			var recs = [];
			var sp = ShareDialog.share_recipients.value.split(/[,\s]/);
			var found = false;
			for(var x=0; x<sp.length; x++){
				if(sp[x] == ele.innerHTML){
					found = true;
				}else if(!/^\s*$/.test(sp[x]) && recs.indexOf(sp[x]) == -1){
					recs.push(sp[x]);
				}
			}
			if(!found){
				recs.push(ele.innerHTML);
			}
			ShareDialog.share_recipients.value = recs.join(",");
			ShareDialog.updateSelected();
		}
		return false;
	},
	makeEvents: function() {
		if(ShareDialog.eventsSet){
			return;
		}
		if(document.body.addEventListener){
			ShareDialog.share_recipients.addEventListener("blur", ShareDialog.updateSelected, false);
			ShareDialog.contactContainer.addEventListener("click", ShareDialog.onContactClick, false);
			document.body.addEventListener("click", ShareDialog.onBodyClick, false);
			window.addEventListener("scroll", ShareDialog.onBodyScroll, false);
		}else if(document.body.attachEvent){
			ShareDialog.share_recipients.attachEvent("onblur", ShareDialog.updateSelected);
			ShareDialog.contactContainer.attachEvent("onclick", ShareDialog.onContactClick);
			document.body.attachEvent("onclick", ShareDialog.onBodyClick);
			window.attachEvent("onscroll", ShareDialog.onBodyScroll);
		}
		ShareDialog.eventsSet = true;
	},
	unMakeEvents: function() {
		if(!ShareDialog.eventsSet){
			return;
		}
		if(document.body.addEventListener){
			ShareDialog.share_recipients.removeEventListener("blur", ShareDialog.updateSelected, false);
			ShareDialog.contactContainer.removeEventListener("click", ShareDialog.onContactClick, false);
			document.body.removeEventListener("click", ShareDialog.onBodyClick, false);
			window.removeEventListener("scroll", ShareDialog.onBodyScroll, false);
		}else if(document.body.attachEvent){
			ShareDialog.share_recipients.detachEvent("onblur", ShareDialog.updateSelected);
			ShareDialog.contactContainer.detachEvent("onclick", ShareDialog.onContactClick);
			document.body.detachEvent("onclick", ShareDialog.onBodyClick);
			window.detachEvent("onscroll", ShareDialog.onBodyScroll);
		}
		ShareDialog.eventsSet = false;
	},
	buildEl: function() {
		Array.prototype.indexOf = function(needle) {
			for(var x=0; x<this.length; x++){
				if(needle == this[x]){
					return x;
				}
			}
			return -1;
		}
		var div = document.createElement('div');
		div.innerHTML = this.html;
		this.el = div.firstChild;
		this.hide();
		document.body.appendChild(this.el);
		
		this.share_recipients = document.getElementById('share_recipients');
		this.contactContainer = document.getElementById('share_contacts');
	}
};

var sharePopup = stdClass.extend({
	//constructor
	constructor: function(el, e) {
		this.base();
		// initialize settings
		Object.extend(this.s, {
			moduleName: 'RecommendPage',
			json: {
				ver: '0.1',
				meta: {},
				data: {
					requests: []
				}
			}
			/* put extensions to collections here */
		});
		
		// initialize nodes
		Object.extend(this.n, {
			el:el
			/* put extensions to nodes here */
		});
		
		// initialize collections
		Object.extend(this.c, {
			requests: []
			/* put extensions to collections here */
		});
		
		Element.parseClasses(this.n.el);
		if(this.n.el.vars){
			if(e){
				Event.stop(e);
			}
			this.show();
		}
	},
	show: function() {
		if(ShareDialog.html){
			ShareDialog.show();
		}else{
			Element.parseClasses(this.n.el);
			if(this.n.el.vars.cache == "false"){
				ShareDialog.cache = false;
			}
			this.addRequest('getShareDialog', {
				title: escape(this.n.el.vars.title.replace(/\+/g, " ")),
				referer: this.n.el.vars.url
			});
			this.JsonOut();
		}
		//person_send var:{title:test6%20&More,url:journals%2Fentry%2Fview%2F84368%2F}
	},
	addRequest: function(requestName, dataObject) {
		this.c.requests.push({
			id: this.c.requests.length,
			type: requestName,
			data: dataObject
		});
	},
	//json methods
	JsonOut: function() {
		//construct the post
		this.s.json.data.requests = this.c.requests;
		//this.setMeta('columns', '');
		var data = '__json=' + this.s.moduleName + '&data=' + Object.toJSON(this.s.json);
		this.c.requests = [];
		//send out the request
		var myAjax = new Ajax.Request(window.location,
		{
			method: 'post',
			parameters: data,
			onSuccess: this.JsonIn.bind(this)
		});
	},
	
	JsonIn: function(t) {
		var result = t.responseText.evalJSON();
		(result.responses.length).times(function(i) {
			if(result.responses[i].type == 'getShareDialog'){
				ShareDialog.html = result.responses[i].data.html;
				this.show();
			}
		}.bind(this));
	}
});
EventSelectors.register({
	'a.person_send': function(el) {
		if(!Element.hasClassName(el, 'loginBox') && !el.onclick){
			Event.observe(el, 'click', function(e){
				new sharePopup(this, e);
			}.bind(el));
		}
	}
}, true);/**
 * ConfirmDialog
 * @requires kDialog2 
 */
var ConfirmDialog = kDialog2.extend({
	// Static properties
	settings: function(settings) {
		if (typeof(this.s) == 'undefined') {
			this.base();

			Object.extendProperties(this.s, {
				'+innerTriggers': [
					{node: '.ok', event: 'click', action: 'onClickOK'},
					{node: '.cancel', event: 'click', action: 'onClickCancel'},
					{node: '.close', event: 'click', action: 'hide'}
				],
				'+innerZones': [{node: '.buttons', name: 'buttons'}],
				'+zones': {
					heading: 'Confirm',
					content: '		<p class="text">Please click OK or Cancel.</p>' +
					'		<form class="buttons">' +
					'			<input type="image" src="'+Config.templatePath+'i/button_ok.gif" alt = "OK" class="ok">' +
					'			<input type="image" src="'+Config.templatePath+'i/button_cancel.gif" alt = "Cancel" class="cancel">' +
					'		</form>'
				},
				onClickOK: function() { return true; },
				onClickCancel: function() { return true; }
			});
			this.s.innerZones.push({node: '.buttons', name: 'buttons'});
			Object.extendProperties(this.s, settings);
		}
	},

	constructor: function(settings) {
		this.settings(settings);
		this.create();
	},

	// Convenience functions
	setButtons: function(html) {
		this.setZone('buttons', html);
	},

	onClickOK: function(ele, e) {
		Event.stop(e);
		if (this.s.onClickOK(this)) this.hide();
	},

	onClickCancel: function(ele, e) {
		Event.stop(e);
		if (this.s.onClickCancel(this)) this.hide();
	}
});

alertDialog = function(text, header) {
	if(!header){
		header = "Alert";
	}
	var confirmDialog = new ConfirmDialog({
		'+zones': {
			heading: header,
			content: '		<p class="text">' + text + '</p>' +
			'		<form class="buttons">' +
			'			<input type="image" src="'+Config.templatePath+'i/button_ok.gif" alt = "OK" class="ok">' +
			'		</form>'
		}
	});
}

mouseoverDialog = function(text, header, ele) {
	if(ele.confirmDialog && ele.confirmDialog.timeout){
		clearTimeout(ele.confirmDialog.timeout);
		ele.confirmDialog.timeout = null;
		return;
	}
	if(!header){
		header = "Alert";
	}
	var confirmDialog = new ConfirmDialog({
		'+zones': {
			heading: header,
			content: '		<p class="text">' + text + '</p>' +
			'		<form class="buttons">' +
			'			<input type="image" src="'+Config.templatePath+'i/button_ok.gif" alt = "OK" class="ok">' +
			'		</form>'
		},
		'position': {
			exemplarAnchor: 'bottom left',
			selfAnchor: 'top left',
			exemplar: ele,
			offsetY: 0,
			offsetX: 0
		},
		'lightBox': {
			visible: false,
			opacity: 40,
			color: '#000',
			className: 'lightbox'
		}
	});
	confirmDialog.n.superNode.onmouseover = function() {
		clearTimeout(this.timeout);
		this.timeout = null;
	}.bind(confirmDialog);
	confirmDialog.n.superNode.onmouseout = function(confirmDialog) {
		this.timeout = setTimeout(function() { this.hide(); confirmDialog.timeout=null; }.bind(this), 500);
	}.bind(confirmDialog, confirmDialog);
	ele.onmouseout = function(confirmDialog) {
		this.timeout = setTimeout(function() { this.hide(); confirmDialog.timeout=null; }.bind(this), 500);
	}.bind(confirmDialog, confirmDialog);
	ele.confirmDialog = confirmDialog;
}

var confirmRemovePost = function(el, e) {
	Event.stop(e);
	var confirmDialog = new ConfirmDialog({
		onClickOK: function() {
			window.location = this.href;
			return true;
		}.bind(el),
		startHidden: true,
		position: {
			exemplarAnchor: 'bottom left',
			selfAnchor: 'top left',
			exemplar: el,
			offsetY: 0,
			offsetX: 0
		}
	});
	confirmDialog.setText('Are you sure that you would like to delete this entry and all comments?');
	confirmDialog.show();
}

var confirmRemoveComment = function(el, e) {
	Event.stop(e);
	var confirmDialog = new ConfirmDialog({
		onClickOK: function() {
			window.location = this.href;
			return true;
		}.bind(el),
		startHidden: true,
		position: {
			exemplarAnchor: 'bottom right',
			selfAnchor: 'top right',
			exemplar: el,
			offsetY: 0,
			offsetX: 0
		}
	});
	confirmDialog.setText('Are you sure that you would like to delete this comment and all children comments?');
	confirmDialog.show();
}

//instantiate and use the object
EventSelectors.register({
	'a.answered:click' : function(el, e) {
		Event.stop(e);
		var confirmDialog = new ConfirmDialog({
			onClickOK: function() {
				window.location = this.href;
				return true;
			}.bind(el),
			startHidden: true,
			position: {
				exemplarAnchor: 'bottom right',
				selfAnchor: 'top right',
				exemplar: el,
				offsetY: 0,
				offsetX: 0
			}
		});
		confirmDialog.setText('Are you sure that you would like to close this question?');
		confirmDialog.show();
	},
	'a.group_remove:click' : function(el, e) {
		Event.stop(e);
		var confirmDialog = new ConfirmDialog({
			onClickOK: function() {
				window.location = this.href;
				return true;
			}.bind(el),
			startHidden: true,
			position: {
				exemplarAnchor: 'bottom left',
				selfAnchor: 'top left',
				exemplar: el,
				offsetY: 0,
				offsetX: 0
			}
		});
		confirmDialog.setText('Are you sure that you would like to delete this group?');
		confirmDialog.show();
	},
	'a.group_leave:click' : function(el, e) {
		Event.stop(e);
		var confirmDialog = new ConfirmDialog({
			onClickOK: function() {
				window.location = this.href;
				return true;
			}.bind(el),
			startHidden: true,
			position: {
				exemplarAnchor: 'bottom left',
				selfAnchor: 'top left',
				exemplar: el,
				offsetY: 0,
				offsetX: 0
			}
		});
		confirmDialog.setText('Are you sure that you would like to leave this group?');
		confirmDialog.show();
	}/*,
	'a.post_remove:click' : function(el, e) {
		Event.stop(e);
		var confirmDialog = new ConfirmDialog({
			onClickOK: function() {
				window.location = this.href;
				return true;
			}.bind(el),
			startHidden: true,
			position: {
				exemplarAnchor: 'bottom left',
				selfAnchor: 'top left',
				exemplar: el,
				offsetY: 0,
				offsetX: 0
			}
		});
		confirmDialog.setText('Are you sure that you would like to delete this post and all comments?');
		confirmDialog.show();
	},
	'a.comment_remove:click' : function(el, e) {
		Event.stop(e);
		var confirmDialog = new ConfirmDialog({
			onClickOK: function() {
				window.location = this.href;
				return true;
			}.bind(el),
			startHidden: true,
			position: {
				exemplarAnchor: 'bottom right',
				selfAnchor: 'top right',
				exemplar: el,
				offsetY: 0,
				offsetX: 0
			}
		});
		confirmDialog.setText('Are you sure that you would like to delete this comment and all children comments?');
		confirmDialog.show();
	}*/
}, true);var makeLoginBox = function(node, e) {
	new FormDialog({
		'+zones': {
			heading: 'Loading...',
			text: 'Loading...'
		},
		position: {  
			exemplarAnchor: 'bottom right',
			selfAnchor: 'top right',
			exemplar: node,
			offsetY: 0,
			offsetX: 0
		},
		groupId: 'AuthLogin',
		groupLimit: 1,
		startHidden: true,
		moduleName: 'AuthLogin',
		parentThis: this,
		classNames: ['kDialog2', 'authLogin']
	}, node);
	if(e){
		Event.stop(e);
	}
	return false;
}
EventSelectors.register({
    'a.loginBox:click': function(node, e) {
		if(String(node.onclick).indexOf('makeLoginBox') == -1){
			makeLoginBox(node,e);
		}
	}
});