/*

	jQuery notify plugin
	Copyright (c) 2010 Gael Jaunin

	For support and tutorials visit
	http://www.xuserver.net/

	License: GNU Lesser General Public License (LGPL) 
	at http://opensource.org/licenses/lgpl-2.1.php

	This plugin is free software;  you can redistribute it  and/or  modify  it 
	under the terms of the GNU Lesser General Public License as  published  by 
	the Free Software Foundation;  either version 2.1 of the License,  or  (at 
	your option) any later version.
	This software 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 Lesser  General  Public 
	License for more details.
	You should have received a copy of  the  GNU Lesser General Public License 
	along with this library;  if not,  write to the  Free Software Foundation, 
	Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

	THIS COMMENT AND COPYRIGHT NOTICE MUST BE RETAINED IN THE CODE AS IS FOR LEGAL USE

*/


jxNotifyId = 0; 
jxNotifyArray = new Array();
  
jQuery.extend({
  jxNotify:function(content, options){
    var defaults = {
      title:'',
      state : 'highlight',
      sticky:false,
      blink:false,
      life:1500,
      width:275
    };
    var options = $.extend(defaults, options);
    if( $('#jxnotify').width() ==null ){
      $container = $('<div id="jxnotify" ></div>');
      $container.css('position','fixed')
        .css('z-index','9999')
        .css('float','left')
        .css('top','35px')
        .css('left','5px')
        .prependTo('body');
    }else{
      $container = $('#jxnotify'); 
    };
    jxNotifyId++;
    jxNotifyArray[jxNotifyId] = $('<div id="jxNotify-'+jxNotifyId+'" class="ui-widget ui-widget-content ui-corner-all ui-state-'+options.state+'" />');
    $container.append(jxNotifyArray[jxNotifyId]);    
    
    if (options.blink){ jxNotifyArray[jxNotifyId].jxBlink({sticky:options.sticky}); }
    if (options.title ==''){var t = '';}else{var t = '<b>'+options.title+'</b><br />';}
    jxNotifyArray[jxNotifyId].html(t+content)
      .css('width',options.width+'px')
      .css('padding','5px')
      .css('cursor','pointer')
      .css('float','left')
      .css('margin-top','7px')
      .css('min-height','60px')
    ;
    $container.append('<div style="clear:both;height:0px" />');    
    
    
    if(options.sticky){      
      jxNotifyArray[jxNotifyId].prepend( $('<span style="float:right" class="ui-icon ui-icon-close" />') );
      jxNotifyArray[jxNotifyId].click(function(){
        $(this).fadeOut('slow',function(){$(this).remove();} );
      });        
    }else{
      var timer = options.life;    
      jxNotifyArray[jxNotifyId]
      .delay(timer).fadeOut('slow',function(){$(this).remove();} );      
    };
    
  }
});



