/*
 * jQuery WG OverlayBoxCookied
 * Copyright (c) 2009 Roberto Lee (webgenerator.nl)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * Date: 2009-09-02
 * Rev: 1
 */
/*
REQUIREMENTS
jquery ui dialogbox
*/
(function($){
     $.fn.extend({
         OverlayBoxCookied: function(options) {
				var defaults = {
					name_of_cookie_prefix: 'show_box_',
					name_of_cookie_id: '',
					expiration_cookie: 7,
					tbox_height: 660,
					tbox_width: 865,
					show_box_type: '', //'','once','always'
					url:'',
					title:''
				};
				var options = $.extend(defaults, options);

			  	return this.each(function() {
					if(options.url != '')
					{
						var show_type = jQuery.trim(options.show_box_type.toLowerCase());
						var show_box_name = (options.name_of_cookie_prefix + options.name_of_cookie_id).toLowerCase(); //name of cookie

						if(options.show_box_type == '')
						{
							jQuery.cookie(show_box_name, null); //Delete cookie when if never to show
						}
						else
						{
							var show_box = jQuery.cookie(show_box_name);
				        	if((show_box != 'no') || (show_type == 'always'))
				        	{
				        		var iframeobj = $("<iframe src =\""+options.url+"\" frameborder=\"auto\" id=\"iframe\"><p>Your browser does not support iframes.</p></iframe>");
								iframeobj.dialog({
									bgiframe: true,
									height: options.tbox_height,
									width: options.tbox_width,
									modal: true,
									draggable: false,
									title: options.title,
									open: function(event, ui) {
										$(this).css("width","110%");
									}
								});
				        	}
							if((show_type == 'once') && (show_box != 'no'))
							{
								jQuery.cookie(show_box_name, 'no', {expires: options.expiration_cookie}); //set cookie not to show next time
							}
						}
					}
			  	});
         }
    });
})(jQuery);
