/**
//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: 400
	}, settings);
  return this.each(function(){
    var close_html = "<div id=\"box_close\"><a href=\"#0\" onclick=\"javascript:jQuery('#"+ jQuery(this).attr('id') +"').fadeOut();jQuery('#jquery-overlay').fadeOut();\"><img src=\"" + site_url + "/images/backend/box/closelabel.gif\" 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();
	// Masque sur le main div
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	$('#jquery-overlay').css({
		backgroundColor:	"#D400F7",
		opacity:			0.65,
		height:				jQuery('body').height()+130
	}).fadeIn();
	// Specify position and show box :
	var PosX = ( (screen.availWidth)- settings.width ) / 2; 
	var PosY = ( (screen.availHeight-400) - jQuery(this).height() ) / 2; 
	jQuery(this).css({
        top:	PosY,
        left:	PosX,
        backgroundColor: "#FFF",
		width: settings.width
      }).show();
  });
};