/*
	2009 by David Aerne / Bluesystem Sarl
	
	usage:
	$.dialme(con, opt)
	
	example:
	$.dialme('<p> some html you wanna show </p>', {objtype: 'div', cusid: 'mybox'})

*/

/* dialme windows engine jquery plugin */
(function($){

$.dialme = function (con, opt) {

	if (con) { /* checking if params are valid */
	
		if (typeof con === 'object'){
			throw 'you need to specify a content to display'
		}
	
		var opts = $.extend({}, $.dialme.defaults, opt) /* extend the default options with the given options */
	
		/* constructing the msg box */
		
		var box = '<' + opts.objtype + ' '
		
		if ( opts.cusid == $.dialme.defaults.cusid ) {
			var id = opts.cusid + $.dialme.actualid
	 		$.dialme.actualid += 1 
		}else{
			var id = opts.cusid
		}
		
		box += 'id="' + id + '"'
		
		if (opts.cusclass) {
			box += ' class="' + opts.cusclass + '"'
		}
		if (opts.style) {
			box += ' style="' + opts.style + '"'
		}

		box += '>' + con + '</' + opts.objtype + '>'
		
		/* end constructing box */
		/* box styleing */
		
		var css = {
		}
		
		/* end box styleing */
		/* render the box */
		
		if (opts.lightbox == true) {
			$('body').append('<div class="dial_shadow"></div>').find("div.dial_shadow:last").click(function(){ $(this).remove(); $('#' +id).remove() })
		}
		if ($('#' + opts.cusid).attr('id')) {
			$('#' + opts.cusid).html(con)	
		}else{
			$('body').append(box)
		}
		
		$('#'+id).css(css)
		
	} else {
		throw 'you need give options for dialme()'
	}
	
}

$.dialme.defaults = {

		target: 'blank',
		lightbox: false,
		size: 'auto',
		pos: {
			x: false,
			y: false
		},
		cusid: 'dialme_',
		cusclass: 'jqDialme',
		boutons: {
			confirm: 'ok',
			onconfirm: false,
			cancel: 'cancel'
		},
		size: {
			x: false,
			y: false
		},
		style: '',
		winbar: {
			close: true,
			min: true,
			max: true
		},
		objtype: 'div'
}

$.dialme.actualid = 0

})(jQuery);
