(function ()
{

	var _extend = function (source, destination)
	{
		var d = destination || {};
		
		for (var i in source)
		{
			if (typeof(d[i]) == 'undefined')
				d[i] = source[i];
		}
		
		return d;
	};

	var Bronxx = window.Bronxx = function ()
	{
		this.page = undefined;
		
		return this;
	};
	
	Bronxx.prototype =
	{
		DOM:
		{
			get: function (selector, context)
			{
				var mode = (selector.indexOf('#') == 0 ? 'id' : 'tag');
				var elements;
				
				if (mode == 'id')
				{
					selector = selector.substr(1, selector.length);
					elements = document.getElementById(selector);
				}
				
				return elements;
			}
		},
		
		Event:
		{
			add: function (element, type, method, bubble)
			{
				if (window.addEventListener)
				{// w3c
					element.addEventListener(type, method, bubble || false);
				}
				 else if (window.attachEvent)
				 {// IE (sucks)
				 	element.attachEvent('on' + type, function ()
					{
						method.call(this, window.event, this)
					});
				 }
				  else
				  {// old & lame (netscape);
				  	element['on' + type] = method;
				  }
			}
		},

		extend: function (source, destination)
		{
			var d = destination || {};
			for (var i in source)
			{
				if (typeof(d[i]) == 'undefined')
				  d[i] = source[i];
			}
			return d;
		},

		setPage: function ()
		{
			var page = window.location.href.split('/');
				page = page[page.length-1].split('.')[0];

			this.page = page;

			return this;
		},
		
		PopUp: function (content, name, settings)
		{
			var defaults =
			{
				menubar: 'no',
				location: 'no',
				resizable: 'no',
				
				width: '300',
				height: '300'
			};
			var options = _extend(defaults, settings);
			
			var buildSettingString = function (obj)
			{
				var str = '';
				
				for (var i in obj)
				{
					str += i + '=' + obj[i] + ',';
				}
				
				return str.substr(0, str.length-1);
			}
			
			var settingString = buildSettingString(options);
			
			//console.log(settingString);
			
			window.open(name, content, settingString	);
		}
	}
	
	window.onload = function ()
	{
		var site = new Bronxx();
		var popUpLink = site.DOM.get('#popuplink');
		
		site.setPage();
		site.Event.add(popUpLink, 'click', function (e, link)
		{
			if (e.preventDefault)
			  e.preventDefault();

			var top = this.offsetTop - 20;
			var left = (screen.left - this.offsetLeft);
			var url = link.href;
			
			
			site.PopUp('video', this.href,
			{
				left: left,
				screenY: top,
				width: 320,
				height: 277
			});

			return false;
		});
	};
})();