(function($){
	
	$.humjay = $.humjay || {};
	$.humjay.squaredi = {
		overlay: false,
		conf: {
			icon: false
		}
	};

	function Squaredi(el, conf) {
		el = $(el);
		
		if(conf.icon) {
			el.append('<span class="icon"/>');
		}
	
		el.click(function(e){
			if(!$.humjay.squaredi.overlay) {
				$("<div/>").attr("id", "humjay-overlay").text("Click Anywhere to Close").prepend('<div class="magnified-content"/>').appendTo(document.body);
				$.humjay.squaredi.overlay = $("#humjay-overlay").overlay({
					mask: {
						color: '#000000',
						loadSpeed: 200,
						opacity: 0.9
					},
					top: '25%'
				}).data("overlay");
			}
			$('#humjay-overlay').children('.magnified-content').text((conf.attr) ? el.attr(conf.attr) : el.text());
			$.humjay.squaredi.overlay.load();
			e.preventDefault();
		});

	}
	
	// jQuery plugin implementation
	$.fn.squaredi = function(conf) { 
		this.each(function(i) {		

			var config = $.extend({}, $.humjay.squaredi.conf, conf); 
			if($(this).hasClass('icon')) config.icon = true;
			var el = new Squaredi($(this), config);
			$(this).data("squaredi", el);	
		});
		
		return this;
		
	};
	
})(jQuery);
