if (!JS_COMMUNITY) { var JS_COMMUNITY = new Object(); }

JS_COMMUNITY.general = {
	// datamembers
 	debug: false,
 	
	init: function() {
		JS_COMMUNITY.general.hookModalBoxes();
	},
	
	hookOverlay : function(show) {
		if($('#overlay').length == 0) $('body').prepend('<div id="overlay"></div>');
		$('#overlay').height($(document).height());
		$('#overlay').css("filter", "alpha(opacity=40)");
		if(show) $('#overlay').show();
		else $('#overlay').hide();
	},

	hookModalBoxes: function() {
		$('.modal-box-close').bind('click', function(evt) {
			evt.preventDefault();
			var id = $(this).attr('href');
			$(id).hide();
			JS_COMMUNITY.general.hookOverlay(false);
		});

		$('.modal-box-toggle').bind('click', function(evt) {
			var id = $(this).attr('href');
			var dataChunks = Array;
			if ($(this).attr('rel') != '') {
				var dataChunks = $(this).attr('rel').split(':');
			}
			JS_COMMUNITY.general.hookOverlay(true);

			for(i in dataChunks) { $('#'+ dataChunks[i].split('=')[0]).val(dataChunks[i].split('=')[1]); }
			
			$(id).show();
			evt.stopPropagation();
			evt.preventDefault();
			$(id + ' .modal-box-inner').bind('click', function(evt) { evt.stopPropagation(); });
			$(document.body).bind('click', function(evt) {
				$(id).hide();
				JS_COMMUNITY.general.hookOverlay(false);
			});
			$(document.body).bind('keypress', function(evt) {
				if (evt.keyCode == 27) {
					$(id).hide();
					JS_COMMUNITY.general.hookOverlay(false);
				}
			});
		});
	},
	
	hookHumanizedBoxes: function() {
		$(document).bind('mousemove keypress', function(evt) {
			$('.humanizedBox').hide();
			$(document).unbind('mousemove keypress');
		});
	},

 	setExternalFavicons	: function() {
 		$('#externalLinksList a[href^="http://"]').each(function() {
			var faviconIMG = $('<img width="16" height="16" alt="' + $(this).attr('title') + '" title="' + $(this).attr('title') + '" class="externalLinkImage" />').prependTo($(this));
			var extImg = new Image();
			extImg.src = $(this).attr('href').replace(/^(http:\/\/[^\/]+).*$/, '$1') +'/favicon.ico';
			extImg.onload = function() { faviconIMG.attr('src', extImg.src); }
			extImg.onerror = function() { faviconIMG.attr('src', '/modules/core/layout/images/externalLink.gif'); }
			extImg.onabort = function() { faviconIMG.attr('src', '/modules/core/layout/images/externalLink.gif'); }
 		});
	},

	// end of object
	_eoo: true		
}

$(document).ready(function() { JS_COMMUNITY.general.init(); });
