/*!
 * NIUProject 1.0.0
 *
 * Copyright (c) 2009 Note It Up Oy
 * All rights reserved.
 *
 */

var NIUPROJECT_UIMESSAGES_TYPE_INFO="info";var NIUPROJECT_UIMESSAGES_TYPE_ALERT="alert";
var NIUPROJECT_UIMESSAGES_TYPE_WARNING="warning";var NIUPROJECT_UIMESSAGES_TYPE_ERROR="error";
var NIUPROJECT_UIMESSAGES_TYPE_DEBUG="debug";var UIMessagesBase=function(){var B={position:"tr",holder_path:"#niuproject-uimessages-holder",message_class:"niuproject_uimessages_message",type_classes:{NIUPROJECT_UIMESSAGES_TYPE_INFO:"niuproject_uimessages_message_type_info",NIUPROJECT_UIMESSAGES_TYPE_ALERT:"niuproject_uimessages_message_type_alert",NIUPROJECT_UIMESSAGES_TYPE_WARNING:"niuproject_uimessages_message_type_warning",NIUPROJECT_UIMESSAGES_TYPE_ERROR:"niuproject_uimessages_message_type_error",NIUPROJECT_UIMESSAGES_TYPE_DEBUG:"niuproject_uimessages_message_type_debug"},removable:true,highlight_errors:false,slide:{speed:1000,delay:5000}};
var C;var A=0;return{init:function(D){B=jQuery.extend({},B,D||{});C=jQuery(B.holder_path);
this._prepareHolder();},addMessage:function(M){var E="niuproject_uimessages_message_"+A;
var J=M.type||"info";var G=M.removable||B.removable;var D=J;var F=B.type_classes[J];
var L=J;switch(J){case"info":case"debug":D="highlight";L="info";break;case"alert":case"warning":D="error";
case"error":L="alert";break;}var H=jQuery('<div class="ui-widget" />').addClass(B.message_class).addClass(F).attr({id:E});
var I=jQuery('<div class="ui-state-'+D+' ui-corner-all" />');var K=jQuery('<span class="ui-icon ui-icon-'+L+'" />');
I.append(K);if(M.title){I.append(jQuery("<h2 />").html(M.title));}I.append(M.content);
I.click(function(){jQuery(this).parent().slideUp(B.slide.speed);jQuery(this).parent().unbind(jQuery(this).attr("id")+"_timer");
if(!G){return;}jQuery(this).parent().oneTime(B.slide.delay+500,jQuery(this).attr("id")+"_timer",function(){jQuery(this).remove();
});});H.html(I);C.append(H);switch(J){case NIUPROJECT_UIMESSAGES_TYPE_INFO:case NIUPROJECT_UIMESSAGES_TYPE_DEBUG:H.oneTime(B.slide.delay,E+"_timer",function(){jQuery(this).slideUp(B.slide.speed);
if(!G){return;}jQuery(this).oneTime(B.slide.delay+500,jQuery(this).attr("id")+"_timer",function(){jQuery(this).remove();
});});break;case NIUPROJECT_UIMESSAGES_TYPE_ERROR:if(!B.highlight_errors){break;}H.everyTime(7000,E+"_shake",function(){jQuery(this).effect("pulsate",{times:1},500);
});break;case NIUPROJECT_UIMESSAGES_TYPE_ALERT:case NIUPROJECT_UIMESSAGES_TYPE_WARNING:default:break;
}A++;},clearMessages:function(){jQuery.each(jQuery("."+B.message_class,C),function(){var D=jQuery(this).attr("id");
jQuery(this).oneTime(B.slide.delay/2,D+"_timer",function(){jQuery(this).slideUp(B.slide.speed*2);
jQuery(this).oneTime(B.slide.delay/2+500,jQuery(this).attr("id")+"_timer",function(){jQuery(this).remove();
});});});},_prepareHolder:function(){if(B.position.match("b")){C.css({position:"fixed",top:"auto",bottom:0});
}if(B.position.match("m")){C.css({right:"auto",left:"35%"});}if(B.position.match("l")){C.css({right:"auto",left:0});
}}};};var UIMessages=new UIMessagesBase();jQuery.niuproject_uimessages_add=function(A){UIMessages.addMessage(A);
};
