var DeepLinkPopup;
var DeepLink = stdClass.extend({
	//constructor
	constructor: function(el, settings) {
		this.base();
		// initialize settings
		Object.extend(this.s, {
			moduleName: 'DeepLink',
			ceid: null,
			json: {
				ver: '0.1',
				meta: {},
				data: {},
				requests: []
			}
			/* put extensions to collections here */
		});
		
		// initialize nodes
		Object.extend(this.n, {
			el: el,
			form: null,
			submitButton: null,
			dialog: null
			/* put extensions to nodes here */
		});
		
		// initialize collections
		Object.extend(this.c, {
			requests: []
			/* put extensions to collections here */
		});
		this._attachEvents();

	},
	
	elOnClick: function(e) {
		Event.stop(e);
		DeepLinkPopup = new NodeBase({

			position: {  
				exemplarAnchor: 'top right',
				selfAnchor: 'top left',
				exemplar: this.n.el,
				offsetY: 0,
				offsetX: 5
			},
			groupId: 'InviteDialogs',
			groupLimit: 1,
			startHidden: true,
			moduleName: this.s.moduleName,
			parentThis: this,
			ceID: this.s.ceid,
			params: {
				url: this.n.el.href.substr(this.n.el.href.indexOf('url=')+4)
			}
		});
		DeepLinkPopup.create();
		DeepLinkPopup.setContent(document.getElementById("deeplink_"+this.n.el.getAttribute("deeplinkid")).innerHTML);
		DeepLinkPopup.show();

		//send out the request
		/*
		var myAjaj = new Ajax.Request(window.location,
		{
			method: 'post',
			parameters: '__ajax='+ this.s.moduleName+'&deeplinkid='+this.n.el.getAttribute("deeplinkid"),
			onSuccess: function(response) 
			{ 
				updateDeepLink(response, DeepLinkPopup);
			}
		});
		*/
	},
	_attachEvents: function() {
		this.eObserve(this.n.el, 'click', this.elOnClick.bind(this));
	}


});

function updateDeepLink(response, popup) {
	popup.setContent(response.responseText);
	popup.show();
}
	
/*
EventSelectors.addLoadEvent(addDeepLinks);
function addAdminDateSelectors()
{
	document.getElementsByClassName("deeplink").each(function(el)
	{
		alert("here2");
		picker=new DeepLink(el);
	});
}*/

EventSelectors.register({
	'a.deeplink': function(el, index) 
	{
		new DeepLink(el);
	}
}, true);