var notify_error;
var notify_message;
xtags = {
	init: function(){
		var instance = this;
		instance.notification();
		instance.tooltip();
	},
	notification: function (){
		$.pnotify.defaults.pnotify_history = false;
		$.pnotify.defaults.pnotify_opacity = .8;
		$.pnotify.defaults.pnotify_hide = false;
		$.pnotify.defaults.pnotify_width = "400px";
		$.pnotify.defaults.pnotify_min_height = "60px";
	},
	tooltip: function (){
		$.fn.tipsy.defaults.html = true;
		
		$('.x-tooltip').tipsy({gravity: $.fn.tipsy.autoNS});
		$('.x-tooltip-north').tipsy({gravity: 'n'});
	    $('.x-tooltip-south').tipsy({gravity: 's'});
	    $('.x-tooltip-east').tipsy({gravity: 'e'});
	    $('.x-tooltip-west').tipsy({gravity: 'w'});
	    $('.x-tooltip-north-west').tipsy({gravity: 'nw'});
	    $('.x-tooltip-north-east').tipsy({gravity: 'ne'});
	    $('.x-tooltip-south-west').tipsy({gravity: 'sw'});
	    $('.x-tooltip-south-east').tipsy({gravity: 'se'});
	}
}

xtags.notify = {
	errors: function (title, text){
		$(function() {	
			xtags.notify.clearMessage();
			notify_error = $.pnotify({
				pnotify_title: title,
				pnotify_text: text,
				pnotify_type: 'error',
				pnotify_addclass: 'x-notify x-notify-errors',
				pnotify_error_icon: 'x-icon-48 x-icon-notify-error'
			});
		});
	},
	messages: function (title, text){
		$(function() {
			xtags.notify.clearError();
			notify_message = $.pnotify({
				pnotify_title: title,
				pnotify_text: text,
				pnotify_addclass: 'x-notify',
				pnotify_notice_icon: 'x-icon-48 x-icon-notify-info'
			});
		});
	},
	clearError: function (){
		if (notify_error){
			notify_error.pnotify_remove();
		}
	},
	clearMessage: function (){
		if (notify_message){
			notify_message.pnotify_remove();
		}
	}
}

xtags.fieldset = {
	collapse: function (styleId, options){
		jQuery(function() {
			$("#"+styleId).fieldsetCollapse(options);
		});
	}
}


$(function() {
	xtags.init();
});
