/*
*	Author:		Jelle van der Coelen
*				jelle@jellevandercoelen.com
*
*	Version: 	1.0.0.0
*/
coolbox = null
function triggerCoolBox(title, msg, options)
{
	if(coolbox == null)
	{
		coolbox = new CoolBox(title, msg, options);
		
		coolbox.trigger();
	}
	else
		coolbox.shake();
};

/*
*
*/
function CoolBox(title, msg, options)
{
	/**/
	var defaults =
	{
		/**/
		'title'		: title,
		'msg'		: msg,
		
		/**/
		'tempDir'	: 'http://server/_util/js/CoolBox/templates/',
		'type'		: 'default.html',
		
		/**/
		'width'		: '350',
		'height'	: '150'
	}
	
	/**/
	defaults.left	= (((screen.width - defaults.width) / 2) + $(document).scrollLeft());
	defaults.top	= ((((screen.height - defaults.height) / 2) / 2) + $(document).scrollTop());
	
	/**/
	var options = $.extend(defaults, options);

	/*
	*
	*/
	this.trigger = function()
	{
		$('body').append('<div class="cb_container" id="w9999"></div>');
		
		$('.cb_container').css(
		{
			'height' 	: defaults.height+'px',
			'width' 	: defaults.width+'px',
			'zIndex'	: '2000'
		});
		
		$.post(defaults.tempDir+defaults.type, {}, function(data)
		{
			$('.cb_container').html(data);
		});
		
		this.CurrentHeight = (defaults.Height - 28);
		
		$('body').append('<div id="cb_overlay"></div>');
		$('#cb_overlay').css(
		{
			'height' 		: (parseInt(defaults.height) + 20)+'px',
			'width' 		: (parseInt(defaults.width) + 20)+'px',
			'opacity' 		: 0.4,
			'position' 		: 'absolute',
			'background' 	: '#000000',
			'top' 			: (defaults.top-10)+'px',
			'left' 			: (defaults.left-10)+'px'
		});
		
		$('.cb_container').css({'left': defaults.left, 'top': defaults.top}).fadeIn(150);
	};
	
	/*
	*
	*/
	this.setVars = function()
	{
		$('.cb_title').html(defaults.title);
		$('#cb_msg').html(defaults.msg);
		
		$('#cb_img').attr('src', 'httplink'+defaults.msg);
		
		$('.cb').css({'width': defaults.width+'px'});
	}
	
	/*
	*
	*/
	this.shake = function()
	{
		var o = $('#cb_window').parent();
		
		d = 30;
		
		o.animate({'marginLeft' : '-=20px', 'marginTop' : '-=10px'}, d)
		.animate({'marginLeft' : '+=20px', 'marginTop' : '+=10px'}, d)
		.animate({'marginLeft' : '+=20px', 'marginTop' : '+=10px'}, d)
		.animate({'marginLeft' : '-=20px', 'marginTop' : '-=10px'}, d)
		.animate({'marginLeft' : '-=20px', 'marginTop' : '-=10px'}, d)
		.animate({'marginLeft' : '+=20px', 'marginTop' : '+=10px'}, d)
		.animate({'marginLeft' : '+=20px', 'marginTop' : '+=10px'}, d)
		.animate({'marginLeft' : '-=20px', 'marginTop' : '-=10px'}, d);
	}
	
	/*
	*
	*/
	this.kill = function()
	{
		$('#w9999').remove();
		$('#cb_overlay').remove();
	}
}
