/**
//Webges : Website Management Software
//It enables you to simply manage your website from the 
//smallest to the biggest. It's architecture allow you
//to build new plugin to fit your requirement.
//For more informations and update see <http://www.webges.fr>
//Copyright (C) 2008  <Adrien Cusinberche (adrien@webges.fr)>

//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program.  If not, see <http://www.gnu.org/licenses/>.

Very simple Box plugin for Webges
**/
jQuery.fn.box = function(settings) {
	settings = jQuery.extend({
		url:false,
		width: 600,
		fade_bg:false,
		img_url: "/images/backend/box/closelabel.gif"
	}, settings);
  return this.each(function(){
    var close_html = "<div id=\"box_close\"><a href=\"#0\" onclick=\"javascript:jQuery('#"+ jQuery(this).attr('id') +"').fadeOut();jQuery('#box_overlay').remove();\"><img src=\"" + site_url + settings.img_url + "\" alt=\"close\" /></a></div>";
	// Add the close button
	jQuery("#box_close").remove();
	if(settings.url){
		var html = $.ajax({
		url: settings.url,
		async: false
		}).responseText;
		jQuery(this).html(close_html + html);
	}else{
		jQuery(close_html).prependTo(this);
	}
	jQuery(this).addClass('box');
	jQuery(this).draggable();
	if(settings.fade_bg){
		// Add a layer class
		jQuery("<div id='box_overlay' class='box_overlayBG'></div>").prependTo('body');
		//jQuery('body').append("<div id='box_overlay' class='box_overlayBG'></div>");
	}
	// Specify position and show box :
	var PosX = ( screen.availWidth - settings.width ) / 2; 
	var PosY = ( (screen.availHeight-250) - jQuery(this).height() ) / 2; 
	jQuery(this).css({
        top:	PosY,
        left:	PosX,
		width: settings.width
      }).show();
  });
};