(function ($) {
    $.floatbox = function (options, callback) {		
        var settings = $.extend({
            content : '',
            fade : false,
            bgConfig : {
                position: $.InSightCN.IECheck.IE6 ? 'absolute': 'fixed',
                zIndex: 9999,
                width: $.InSightCN.getPageWidth() + $.InSightCN.getPageScroll()[0] + 'px',
                height: $.InSightCN.getPageHeight() + $.InSightCN.getPageScroll()[1] + 'px',
                top:  '0px',
                left: '0px',
                backgroundColor: '#000',
                opacity: '0',
                display: 'none'
            },
            boxConfig : {
                position: 'absolute',
                zIndex: 10000,
                width: '500px',
                marginLeft: '-250px',
                height: 'auto',
                top: '200px',
                left: '50%',
                backgroundColor: '#fff',
                display: 'none',
				opacity: '0.95',
				border: '5px solid #777',
			    '-moz-border-radius': '5px',
			    '-webkit-border-radius': '5px'
            }
        }, options);
		
		var $floatbox_bg = $('<div id = "floatbox-bg"></div>');
		var $floatbox = $('<div id = "floatbox"></div>');
		
        var closeBox = function () {
            if (settings.fade) {
                $floatbox.fadeOut(200, function () {
                     $floatbox_bg.fadeOut(200, function () {
						$floatbox_bg.remove();
						$floatbox.remove();
                    });
                });
            } else {
				$floatbox_bg.remove();
				$floatbox.remove();
            }
        };
		
		(function () {
			var content = typeof settings.content === 'string' ? settings.content : settings.content.clone();
			
            $floatbox_bg.css(settings.bgConfig).appendTo('body');
            $floatbox.html(content).css(settings.boxConfig).appendTo('body');
            $floatbox.prepend('<h3><span></span><a href="#close" class="close-floatbox">Close</a></h3>')
                .find('.close-floatbox').bind('click', function () {
                    closeBox();
					return false;
                });
            if (settings.fade) {
               $floatbox_bg.fadeIn(200, function () {
					$.InSightCN.IECheck.IE6 ? $.InSightCN.boxScroll($floatbox_bg) : '';
                    $floatbox.fadeIn(200, callback);
                });
            } else {
               $floatbox_bg.show();
			   $floatbox.show();
            };
        })();
    };
})(jQuery);


function tooltips(con) {
	jQuery.floatbox({
		content: con,
		fade: true
	});
	jQuery('#floatbox').css({
		   'padding': '20px 0',
		   'opacity': '0.8',
		   'font-size': '14px',
		   'top': '200px',
		   'width': '400px',
		   'background': '#000',
		   'color': '#fff',
		   'opacity': '0.7',
		   '-moz-border-radius': '5px',
		   '-webkit-border-radius': '5px'
		}).find('h3').remove();
	
	closeFloatBox(2000);
};

function popup(title, con) {
	jQuery.floatbox({
		content: con,
		fade: true
	});
	jQuery('#floatbox').css({
	   //'padding': '20px 0',
	   'opacity': '0.8',
	   'top': '40%',
	   'width': '400px',
	   'background': '#fff',
	   'color': '#666',
	   'opacity': '0.95',
	   'margin-left': '-200px',
	   '-moz-border-radius': '5px',
	   '-webkit-border-radius': '5px'
	}).find('h3 span').html(title);
	
	
	//closeFloatBox(2000);
};

function closeFloatBox(timer) {
	if(!timer) {
		timer = 500;
	};
	jQuery('#floatbox').fadeOut(timer, function () {
		 jQuery('#floatbox-bg').fadeOut(timer, function () {
			jQuery('#floatbox').remove();
			jQuery('#floatbox-bg').remove();
		});
	});
};

function floatbox(title, con, callback) {
	jQuery.floatbox({
		content: con,
		fade: true
	}, callback);
	
	jQuery('#floatbox').css({
		'text-align': 'left',
		'opacity': '0.9'
	}).find('h3 span').html(title).end().find('div').show();
};
