
(function($) {
	$.fn.maxZIndex = function(opt) {
	    /// <summary>
	    /// Returns the max zOrder in the document (no parameter)
	    /// Sets max zOrder by passing a non-zero number
	    /// which gets added to the highest zOrder.
	    /// </summary>    
	    /// <param name="opt" type="object">
	    /// inc: increment value, 
	    /// group: selector for zIndex elements to find max for
	    /// </param>
	    /// <returns type="jQuery" />
	    var def = { inc: 10, group: "*" };
	    $.extend(def, opt);
	    var zmax = 0;
	    $(def.group).each(function() {
	        var cur = parseInt($(this).css('z-index'));
	        zmax = cur > zmax ? cur : zmax;
	    });
	    if (!this.jquery)
	        return zmax;
	
	    return this.each(function() {
	        zmax += def.inc;
	        $(this).css("z-index", zmax);
	    });
	}
})(jQuery);

(function($) {
  $.fn.easyOverlay = function(props){
	var closeit = "closeit";
	var closeit_text = "X";
	var mask = null;
	
	if(props)
	{
		closeit = props.closeit != undefined ? props.closeit : "closeit";
		closeit_text = props.closeit_text != undefined ? props.closeit_text : "X";
		mask = props.mask != undefined ? props.mask : null;
	}
	
    $(this).click(function(e) {
        var wide = ($(window).width() / 2) - ($(this.rel).width() / 2);
        var high = ($(window).height() / 2) - ($(this.rel).height() / 2);
        
        if(mask != null && this.mask_dom == undefined)
        {
        	var color = mask.color != undefined ? mask.color : "#333"; 
        	var opacity =  mask.opacity != undefined ? mask.opacity : 0.8;
        	var dom_html = "<div id='exposeMask' style='position: fixed; top: 0px; left: 0px; width: " + $(window).width() + "px; height: " + ($(window).height()) + "px; display: block; opacity: " + opacity + "; z-index: "+ ($(this.rel).css["z-index"] - 2)+"; background-color: "+ color +";'></div>";
        	this.mask_dom = $(dom_html).appendTo("body");
        }
        
        if(this.mask_dom)
        	this.mask_dom.fadeIn();
        
        if($(this.rel + " > ." + closeit).length == 0)
        {
        	var close = $("<div class='" + closeit + "'>" + closeit_text + "</div>").appendTo(this.rel);
        	var self = this;
        	
            close.click(function(e) {
    	      $(self.rel).fadeOut();
    	      self.mask_dom.fadeOut();
    	    });
        }
        
        $(this.rel).css({
          top: high + "px",
          left: wide + "px",
		  display: 'none',
          visibility: "visible"
        }).fadeIn();
    });
    
    
  };
})(jQuery)
