
var MyFancyHTML = false;

(function($) {
	
	
	jQuery.fn.MyFancy = function(title, footer) {
		$(this).each(function(){
			var obj = $(this);
			var url = $(this).attr('href');
			var title = ((title == undefined || title == "") ? $(this).attr('title') : title);
			var footer = ((footer == undefined || footer == "") ? $(this).attr('footer') : footer);
			$(this).click(function(){ $.MyFancy(url, null, title, null, footer); return false; });
		});
	};
	
	$.MyFancy = function(url, str, title, afterLoadFunc, footer) {
		
		var content = '';
		
		if (!MyFancyHTML)
		{
			htmlPop =	'<div class="myFancy_dark"></div>' +
						'<div class="myFancy">' +
						'	<div class="close"></div>' +
						'	<h1></h1>' +
						'	<div class="inner"></div>' +
						'	<div class="footer"></div>' +
						'</div>';
				
			$('#center').append(htmlPop);
			
			$('.myFancy_dark, .myFancy > .close').click(function() { $.MyFancy.close(); });
			MyFancyHTML = true;
		}
		
		
		if (url == null) $.MyFancy.open(str, title, null, footer);
		else
		{
			$.get(url + '&pmode=empg',function(msg){ $.MyFancy.open(msg, title, afterLoadFunc, footer); });
		}
	}
	
	$.MyFancy.close = function() {
		
		$('.myFancy').removeClass('opened');
		$('.myFancy_dark').hide();
		$('.myFancy').hide();
		
		setTimeout(function(){
			$('.myFancy .inner').html('');
			$('.myFancy > h1').html('');
		}, 500);
	}
	
	$.MyFancy.open = function(msg, title, afterLoadFunc, footer) {

		$('.myFancy > h1').show();
		$('.myFancy > .footer').show();
		$('.myFancy .inner').css('padding-right', '');
		if (title == undefined || title == "" || title == "title")
		{
			title = "";
			$('.myFancy > h1').hide();
			$('.myFancy .inner').css('padding-right', 35);
		}
		if (footer == undefined || footer == "" || footer == "title")
		{
			footer = "";
			$('.myFancy > .footer').hide();
		}
		
		$('.myFancy > h1').html(title);
		$('.myFancy > .footer').html(footer);
		
		$('.myFancy').addClass('opened');
		$('.myFancy .inner').html(msg);
		$('.myFancy').center();
		$('.myFancy_dark').show();
		$('.myFancy').show();
		
		if (afterLoadFunc != undefined && afterLoadFunc != "") afterLoadFunc();
		
		// For inner fancy boxes
		$('.myFancy .fancy').MyFancy();
	}
	
	$.MyFancy.IsOpen = function() {
		
		return $('.myFancy').hasClass('opened');
	}
	
})(jQuery);
