/**
 *	jCookieBookmarks v1.0.3
 *
 *	Version history:
 *	v1.0.3	- Fixed bug: Restoring to defaults after all links are removed is not working, proper opts jq object instead of global var
 *	v1.0.2	- Fixed cookies not saving after browser is closed - added $.fn.jcookiebookmarks.opts.cookie_opts for passing options to cookie plugin
 *	v1.0.1	- Updated css styles, fixed sortable being sortable after cancel & proper cancellation of sortable changes
 *
 *	Known Bugs:
 *		none
*/
;(function($) {
	//var opts;

	$.fn.jcookiebookmarks = function(config) {
		$.fn.jcookiebookmarks.opts = $.extend({
				'store'					:	'jcookiebookmarks',
				'max'					:	15,
                                'notice_position'                       :       'left',
                                'control_link_margin'                   :       20,
				'target'				:	'',
				'def'					:	[],
				'bookmarks_name'		:	'Quick Links',
				'cookie_opts'			:	{'path':'/', 'expires' : 4096},
				'title_delimiter'		:	'|',
				'title_offset'			:	0,
				'use_title_formatter'	:	true,
				title_formatter			:	function(title) {
												var offset = this.title_offset;
												var count, offset_position;

												if ( offset > 0 ) {
													while( count <= offset ) {
														offset_position = title.indexOf( $.fn.jcookiebookmarks.opts.title_delimiter, offset_position);
														count++;
													}
													offset = offset_position;
												}

												var end = title.indexOf( $.fn.jcookiebookmarks.opts.title_delimiter, offset);

												if ( end == -1 ) {
													//Not found, use the whole title
													return title;
												}

												title = title.substring(0, end);

												//ltrim / rtrim
												title = title.replace(/^\s+|\s+$/g,"");

												return title;
											}


		}, config);

		/*********************************
		 *	Internal methods
		*********************************/

		/**
		 *	Make the currently nested anchors default
		 *	This should only be called during initialization
		 *	@param container The bookmark container
		*/

		function save_defaults(container) {
			var c = 0;

			var def = $.fn.jcookiebookmarks.get('bookmarks-default');

			//Prevent multiple containers from being duplicated
			if ( def.length > 0 ||  $(container).hasClass('jcb-init') )
				return false;

			$('a', container).each(function() {
				if ( def.length >= $.fn.jcookiebookmarks.opts.max ) {
					return true;
				}
				def.unshift({
					'url' : $(this).attr('href'),
					'title' : $(this).text()
				});
			});
			$.fn.jcookiebookmarks.set('bookmarks-default', def);

		}
		function add_style_sheet() {
			var styles = '											\
				<style type="text/css">								\
				.notice-wrap {										\
					position: fixed;								\
					top: 20px;										\
					right: 20px;									\
					width: 250px;									\
					z-index: 9999;									\
				}													\
																	\
				html .notice-wrap {									\
					position: absolute;								\
				}													\
				 													\
				.notice-item {										\
					height: 60px;									\
					background: #333;								\
					-moz-border-radius: 6px;						\
					-webkit-border-radius: 6px;						\
					color: #eee;									\
					padding: 6px 6px 0 6px;							\
					font-family: lucida Grande;						\
					font-size: 11px;								\
					border: 2px solid #999;							\
					display: block;									\
					position: relative;								\
					margin: 0 0 12px 0;								\
				}													\
																	\
				.notice-item-close {								\
					position: absolute;								\
					font-family: Arial;								\
					font-size: 12px;								\
					font-weight: bold;								\
					right: 6px;										\
					top: 6px;										\
					cursor: pointer;								\
				}													\
				.jcb-button {										\
					padding:2px !important;							\
					background-color:#999; 							\
					color:#fff; 									\
					display: block; 								\
					margin:5px 5px 10px 0; 							\
					float: left; 									\
					border: 1px solid #666;							\
					font-size: 11px;								\
				}													\
				.jcb-button:hover {									\
					background-color: #EEE !important;				\
					color: #000 !important;							\
				}													\
				</style>											\
				';

				$(styles).appendTo('body');

			return true;
		}

		return this.each(function() {
			if ( $('.jcb-init').size() == 0 ) {
				add_style_sheet();
			}

			//If we can't store data reliable, just exit & leave the container alone
			if ( $.fn.jcookiebookmarks.verify_storage_engine() == true ) {

				//Clear old defaults
				$.fn.jcookiebookmarks.set('bookmarks-default', [] );

// Monty King - Removed the save_default function call and replaced it with our own data for the array.
                                //save_defaults(this);
                                var def = $.fn.jcookiebookmarks.get('bookmarks-default');
                                def.unshift({
                                        'url' : 'http://www.udot.utah.gov/main/f?p=100:pg:0:::1:T,V:1673',
                                        'title' : 'Road Conditions'
                                });
                                def.unshift({
                                        'url' : 'http://www.udot.utah.gov/main/f?p=100:pg:0:::1:T,V:188',
                                        'title' : 'Motor Carrier Division'
                                });
                                def.unshift({
                                        'url' : 'http://www.udot.utah.gov/main/f?p=100:pg:0:::1:T,V:1863',
                                        'title' : 'Rest Areas'
                                });
                                def.unshift({
                                        'url' : 'http://www.udot.utah.gov/main/f?p=100:pg:0:::1:T,V:315',
                                        'title' : 'Bid Letting'
                                });
                                def.unshift({
                                        'url' : 'http://www.udot.utah.gov/main/f?p=100:pg:0:::1:T,V:716',
                                        'title' : 'ePM'
                                });
                                def.unshift({
                                        'url' : 'http://www.udot.utah.gov/main/f?p=100:pg:0:::1:T,V:74',
                                        'title' : 'Contractor Tools'
                                });
                                def.unshift({
                                        'url' : 'http://www.udot.utah.gov/main/f?p=100:pg:0:::1:T,V:8',
                                        'title' : 'Public Involvement'
                                });
                                def.unshift({
                                        'url' : 'http://www.udot.utah.gov/main/f?p=100:pg:0:::1:T,V:13',
                                        'title' : 'Transportation Links'
                                });
                                def.unshift({
                                        'url' : 'http://www.udot.utah.gov/main/f?p=100:pg:0:::1:T,V:7',
                                        'title' : 'Projects, Studies and Future Plans'
                                });
                                def.unshift({
                                        'url' : 'http://www.udot.utah.gov/main/f?p=100:pg:0:::1:T,V:12',
                                        'title' : 'Transportation Commission'
                                });
                                $.fn.jcookiebookmarks.set('bookmarks-default', def);


				$.fn.jcookiebookmarks.attach_view(this);
				$(this).addClass('jcb-init');

			}



		});

	}

	/**********************************
	 *	Properties
	**********************************/
	$.fn.jcookiebookmarks.opts = {};

	/**********************************
	 *	Public methods
	**********************************/

	/**
	 *	Retreieve data from the local storage
	 *	@param id		The key of the data to locate
	 *	@return mixed	False on failure, JSON Object on success
	*/
	$.fn.jcookiebookmarks.get = function(id) {
		var key = $.fn.jcookiebookmarks.opts.store + '['+id+']';
		var d = $.fn.jcookiebookmarks.cookie(key);
		if ( d != undefined ) {
			d = $.evalJSON(d);
			return d;
		}
		return false;
	}

	/**
	 *	Add data to the local storage
	 *	@param id  		The key used to store data
	 *	@param value	The data to set
	 *	@return bool	True on success, false on failure
	*/
	$.fn.jcookiebookmarks.set = function(id,value) {
		var key = $.fn.jcookiebookmarks.opts.store + '['+id+']';
		try {
			if ( $.fn.jcookiebookmarks.cookie(key, $.toJSON(value), $.fn.jcookiebookmarks.opts.cookie_opts ) ) {
				return true;
			}
		} catch(e){}

		return false;
	};


	/**
	 *	Test the storage engine & make sure we can get/set data
	 *	If cookies are disabled & the page is loaded, we're thrown into an infite loop trying to get data
	 *	This function is checked during init to verify cookies, otherwise we'll leave items at default
	 *
	*/
	$.fn.jcookiebookmarks.verify_storage_engine = function() {
		var r = Math.random();
		$.fn.jcookiebookmarks.set('test-engine', r);

		var test = $.fn.jcookiebookmarks.get('test-engine');

		if ( r != test ) {
			return false;
		}
		$.fn.jcookiebookmarks.set('test-engine', null);

		return true;
	};



	/**
	 *	Add an 'Edit' link to the end of bookmark container
	 *	@param container The bookmark container
	*/
	$.fn.jcookiebookmarks.append_edit_link = function(container) {
		//Add the edit button
		$('<a/>')
			.attr({
				'href'	:	'javascript:void(0);',
				'class'	:	'jcb-edit-button jcb-edit-link jcb-button',
				'style'	:	''
			})
			.html('Edit Links')
			.click(function() {
				$.fn.jcookiebookmarks.edit( container );
			})
			.appendTo(container)
		;

		return true;
	};

	/**
	 *	Attach bookmark view to container.  All contents of container will be reset
	 *	@param container The bookmark container object
	*/
	$.fn.jcookiebookmarks.attach_view = function(container) {
		var d = $.fn.jcookiebookmarks.get('bookmarks');
		var html;
		$(container).html('');

		if ( d  != false ) {
			if ( d.length > 0 ) {
				for( i = 0; i < d.length; i++ ) {
					if ( d[i].url && d[i].title ) {
						//Build the anchor
						var a = $('<a/>');
									a.attr({
										'href'		:	d[i].url,
										'title' 	:	d[i].title,
										'target'	:	$.fn.jcookiebookmarks.opts.target

									})
									.html( d[i].title )
						;
						$(a).prependTo(container);

					}
				}

				$.fn.jcookiebookmarks.append_edit_link(container);
				return true;
			}
		}
		else {

			var def = $.fn.jcookiebookmarks.get('bookmarks-default');

			if ( def.length > 0 ) {

				if ( $(container).hasClass('jcb-init') ) {
					//Links have been restored to default AFTER initilization, display a message
					$.fn.jcookiebookmarks.notice( $.fn.jcookiebookmarks.opts.bookmarks_name + ' have been restored to default settings.');
				}

				$.fn.jcookiebookmarks.set('bookmarks', def);
				//return $.fn.jcookiebookmarks.update_all_views();
				return $.fn.jcookiebookmarks.attach_view(container);
			} else {
				//This should not happen unless there were no links in static page
				return false;
			}
		}

	};

	/**
	 *	Mark a link for removal
	 *	@param a The Anchor Object to be removed
	 *
	*/
	$.fn.jcookiebookmarks.remove = function(a) {
		$(a).css({
				'text-decoration':'line-through'
			})
			.fadeTo(300,0.5)
			.addClass('jcb-pending-removal')
		;

		$(a)
			.data('control-link')
			.css({'font-size' : '14px'})
			.html('x')
			.attr({
				'title'	:	'Restore Link',
				'class'	:	'jcb-edit-link jcb-control-link ui-icon ui-icon-arrowreturnthick-1-w'

			})
			.unbind('click')
			.data('link' , $(a) )
			.click(function() {
				$.fn.jcookiebookmarks.cancel_pending_removal(this);
			})
		;
		return true;

	};

	/**
	 *	Cancel removing a specific link
	 *	@param that The jcb-edit-link control anchor
	*/
	$.fn.jcookiebookmarks.cancel_pending_removal = function(that) {
		if ( $(that).data('link').hasClass('jcb-pending-removal') ) {
			$(that)
				.html('-')
				.css({ 'font-size' : '22px' })
				.unbind('click')
				.attr({
					'title' :	'Remove Link',
					'class'	:	'jcb-edit-link jcb-control-link ui-icon ui-icon-circle-minus'
				})
				.bind('click', function() {
					$.fn.jcookiebookmarks.remove( $(that).data('link') );
				})
				.data('link')
				.removeClass('jcb-pending-removal')
				.css({ 'text-decoration' : '' })
				.fadeTo(200,1)
			;
		}
	};

	/**
	 *	Commit all pending changes & exit editor mode
	 *	@param container The bookmark container
	*/
	$.fn.jcookiebookmarks.save = function(container) {
		if ( $.fn.jcookiebookmarks.verify_storage_engine() == false ) {
			//Cannot reliably save information, but add button has been clicked. Display a message for the user.
			$.fn.jcookiebookmarks.notice('Could not save '+$.fn.jcookiebookmarks.opts.bookmarks_name+'.  Cookies do not appear to be working properly.');
			return false;
		}

		var d = [];

		$('.jcb-pending-removal', container).remove();

		$('a', container).not('.jcb-edit-link').each(function() {
			var item = {
				'url'	: $(this).attr('href').toString(),
				'title' : $(this).html().toString()
			};
			d.push(item);
		});

		//IE Has no unshift support
		d.reverse();

		if ( d ) {
			$.fn.jcookiebookmarks.set('bookmarks', d);
		}
		$(container).removeClass('jcb-edit');

		$.fn.jcookiebookmarks.notice('Changes Saved');


		//$.fn.jcookiebookmarks.attach_view(container);
		$.fn.jcookiebookmarks.update_all_views();


	};


	$.fn.jcookiebookmarks.attach_control_link = function(that) {
		var icon = ( $(that).hasClass('jcb-pending-removal') ) ? 'ui-icon-arrowreturnthick-1-w' : 'ui-icon-circle-minus';
		var a = $('<a />')
			.attr({
				'class'	:	'jcb-edit-link jcb-control-link ui-icon ' + icon,
				'href' 	: 	'javascript:void(0);',
				'style' :	'float:left;text-decoration:none;margin-right:5px;line-height:13px;font-size:22px;padding-top:1px;',
				'title'	:	'Remove Link'
			})
			.html('')
			.click(function() {
				$.fn.jcookiebookmarks.remove( $(this).data('link') );
			})
			.css({
				'position'	:	'absolute',
				'top'		:	$(that).offset().top,
				'left'		:	$(that).offset().left - $.fn.jcookiebookmarks.opts.control_link_margin

			})
			.data('link' , $(that) )
		;
		$(that).data('control-link', a);

		return $(a).appendTo('body');


	};

	/**
	 *	Enable bookmark editing mode
	 *	@param that The bookmark container
	*/
	$.fn.jcookiebookmarks.edit = function(that) {

		if ( $(that).hasClass('jcb-init') && !$(that).hasClass('jcb-edit') ) {
			$(that).addClass('jcb-edit');
			$('a', that).not('.jcb-edit-link').each(function() {
				//Setup the delete link
				$.fn.jcookiebookmarks.attach_control_link( this );


			});

			//Change the Edit button to Save
			$('.jcb-edit-button', that)
				.attr({
					'class'	:	'jcb-edit-link jcb-save-button jcb-button',
					'href'	:	'javascript:void(0);',
					'style' :	'',
					'title'	:	'To Add Links, click the Wrench icon in the upper right hand corner.'
				})
				.html('Save')
				.unbind('click')
				.bind('click', function() {
					$.fn.jcookiebookmarks.save( $(this).parents('.jcb-edit') );
				})
			;

			//Create the cancel button
			$('<a/>')
				.attr({
					'class'	:	'jcb-edit-link jcb-cancel-button jcb-button',
					'href'	:	'javascript:void(0);',
					'style' :	'',
					'title'	:	'Cancel Changes'
				})
				.html('Cancel')
				.click(function() {
					//Cancel pending changes
					var container = $(this).parents('.jcb-edit');
					$.fn.jcookiebookmarks.cancel();
				})
				.appendTo( that )
			;

			//Enable drag/drop sorting
			$(that).sortable({
				update: function(event,ui) {
					//Update the control links
					$('a', $(ui.item).parents('.jcb-init') ).not('.jcb-edit.link').each(function() {

						$(this).data('control-link').remove();
						var a = $.fn.jcookiebookmarks.attach_control_link(this);
					});
				}
			});
			$(this).disableSelection();


		}

		return true;
	};

	/**
	 *	Cancel pending updates & restore container
	*/
	$.fn.jcookiebookmarks.cancel = function() {

			//These are attached to body
			$('.jcb-control-link').remove();

			$('.jcb-init').each(function() {
				//Disable sortable links

				$('.jcb-pending-removal', this ).css({ 'text-decoration' : '' }).fadeTo(200,1).removeClass('jcb-pending-removal');
				$('.jcb-edit-link', this).remove();
				$(this).removeClass('jcb-edit');

				//Restores the bookmarks from saved cookies
				$.fn.jcookiebookmarks.attach_view(this);
				$(this).sortable('destroy');

				//$(this).remove();
				//$.fn.jcookiebookmarks.append_edit_link(this);


			});



	};

	/**
	 *	Add a new link to the bookmarks
	 *	@param config Config Object
	 *	Config Options
	 *	---------------
	 *	url - The URL to link (default: current page)
	 *	title - The title of the page ( default: current page)
	 *
	 *	@return bool True on success, false if link was not added
	 *
	*/
	$.fn.jcookiebookmarks.add = function(config) {


		if ( $.fn.jcookiebookmarks.verify_storage_engine() == false ) {
			//Cannot reliably save information, but add button has been clicked. Display a message for the user.
			$.fn.jcookiebookmarks.notice('Could not save '+$.fn.jcookiebookmarks.opts.bookmarks_name+'.  Cookies do not appear to be working properly.');
			return false;
		}

// Monty King - Added these lines to call a function that returns the topic name.
                var get = new htmldb_Get(null,$v('pFlowId'),'APPLICATION_PROCESS=Get_Web_Page_Name',0);
//                get.add('G_TEMP',$v('P1_LOCAL_T'));
                var gReturn=get.get();

		var item = $.extend({
			'url' 		: 	document.location.toString(),
// Monty King - Changes this line to reference the variable gReturn defined a couple lines above.
                        'title'         :       gReturn,
//                        'title'         :       document.title.toString(),
			'target'	:	$.fn.jcookiebookmarks.opts.target
		}, config);

		if ( $.fn.jcookiebookmarks.opts.title_formatter && $.fn.jcookiebookmarks.opts.use_title_formatter == true ) {
			item.title = $.fn.jcookiebookmarks.opts.title_formatter(item.title);
		}

		var d = $.fn.jcookiebookmarks.get('bookmarks');

		//Check if maximum links reached
		if ( d.length >= $.fn.jcookiebookmarks.opts.max ) {
			$.fn.jcookiebookmarks.notice('Sorry, you\'ve reached the maximum number of '+$.fn.jcookiebookmarks.opts.bookmarks_name+' (' + $.fn.jcookiebookmarks.opts.max + ').  Please remove an item to continue.');
			return false;
		}

		//Check for duplicated links
		if ( $.fn.jcookiebookmarks.check_for_dupe(item) == true ) {
			$.fn.jcookiebookmarks.notice('This link has already been added.');
			return false;
		}

		//Add the item to the beginning of the list
		d.push({
			'url' : item.url,
			'title' : item.title
		});

		//Save data
		$.fn.jcookiebookmarks.set('bookmarks', d);

		//Update all the containers
		$.fn.jcookiebookmarks.update_all_views();


		$.fn.jcookiebookmarks.notice($.fn.jcookiebookmarks.opts.bookmarks_name + ' updated.');

		//return true;
	};

	/**
	 *	run attach_view for each initialized bookmark container
	 *	This will syncronize multiple bookmark containers on one page
	*/
	$.fn.jcookiebookmarks.update_all_views = function() {

		$.fn.jcookiebookmarks.cancel();

		$('.jcb-init').each(function() {
			//Cancel editing mode if active
			$.fn.jcookiebookmarks.attach_view(this);
		});
	};


	/**
	 *	Create a notification using jQuery notify
	 *	@param msg string		The message to display
	 *	@param config object	The notify config object (may be omitted)
	 *	@return	mixed jquery notify response
	*/
	$.fn.jcookiebookmarks.notice = function(msg, config) {
		var notice = $.extend({
			'position'	:	$.fn.jcookiebookmarks.opts.notice_position,
			'stay'		:	false,
			'text'		:	msg
		}, config);

		if ( !notice.text ) {
			return false;
		}

		return $.noticeAdd( notice );

	};

	/**
	 *	Check for a duplicated link
	 *	@param item Link object to check
	 *	@return bool true if duplicate, false otherwise
	*/
	$.fn.jcookiebookmarks.check_for_dupe = function(item) {
		var d = $.fn.jcookiebookmarks.get('bookmarks');
		for( i=0; i < d.length; i++ ) {
			if ( item.url == d[i].url ) {
				return true;
			}
		}
		return false;

	};

	/**
	 * jQuery cookie from
	 * http://plugins.jquery.com/files/jquery.cookie.js.txt
	*
	 * Cookie plugin
	 *
	 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
	 * Dual licensed under the MIT and GPL licenses:
	 * http://www.opensource.org/licenses/mit-license.php
	 * http://www.gnu.org/licenses/gpl.html
	 *
	 */
	$.fn.jcookiebookmarks.cookie = function(name, value, options) {
		if (typeof value != 'undefined') { // name and value given, set cookie
			options = options || {};
			if (value === null) {
				value = '';
				options.expires = -1;
			}
			var expires = '';
			if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
				var date;
				if (typeof options.expires == 'number') {
					date = new Date();
					date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
				} else {
					date = options.expires;
				}
				expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
			}
			// CAUTION: Needed to parenthesize options.path and options.domain
			// in the following expressions, otherwise they evaluate to undefined
			// in the packed version for some reason...
			var path = options.path ? '; path=' + (options.path) : '';
			var domain = options.domain ? '; domain=' + (options.domain) : '';
			var secure = options.secure ? '; secure' : '';
			document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
		} else { // only name given, get cookie
			var cookieValue = null;
			if (document.cookie && document.cookie != '') {
				var cookies = document.cookie.split(';');
				for (var i = 0; i < cookies.length; i++) {
					var cookie = jQuery.trim(cookies[i]);
					// Does this cookie string begin with the name we want?
					if (cookie.substring(0, name.length + 1) == (name + '=')) {
						cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
						break;
					}
				}
			}
			return cookieValue;
		}
	};	//end cookie


})(jQuery);


/**
 *	jquery.json.min.js
 *
*/

(function($){$.toJSON=function(o)
{if(typeof(JSON)=='object'&&JSON.stringify)
return JSON.stringify(o);var type=typeof(o);if(o===null)
return"null";if(type=="undefined")
return undefined;if(type=="number"||type=="boolean")
return o+"";if(type=="string")
return $.quoteString(o);if(type=='object')
{if(typeof o.toJSON=="function")
return $.toJSON(o.toJSON());if(o.constructor===Date)
{var month=o.getUTCMonth()+1;if(month<10)month='0'+month;var day=o.getUTCDate();if(day<10)day='0'+day;var year=o.getUTCFullYear();var hours=o.getUTCHours();if(hours<10)hours='0'+hours;var minutes=o.getUTCMinutes();if(minutes<10)minutes='0'+minutes;var seconds=o.getUTCSeconds();if(seconds<10)seconds='0'+seconds;var milli=o.getUTCMilliseconds();if(milli<100)milli='0'+milli;if(milli<10)milli='0'+milli;return'"'+year+'-'+month+'-'+day+'T'+
hours+':'+minutes+':'+seconds+'.'+milli+'Z"';}
if(o.constructor===Array)
{var ret=[];for(var i=0;i<o.length;i++)
ret.push($.toJSON(o[i])||"null");return"["+ret.join(",")+"]";}
var pairs=[];for(var k in o){var name;var type=typeof k;if(type=="number")
name='"'+k+'"';else if(type=="string")
name=$.quoteString(k);else
continue;if(typeof o[k]=="function")
continue;var val=$.toJSON(o[k]);pairs.push(name+":"+val);}
return"{"+pairs.join(", ")+"}";}};$.evalJSON=function(src)
{if(typeof(JSON)=='object'&&JSON.parse)
return JSON.parse(src);return eval("("+src+")");};$.secureEvalJSON=function(src)
{if(typeof(JSON)=='object'&&JSON.parse)
return JSON.parse(src);var filtered=src;filtered=filtered.replace(/\\["\\\/bfnrtu]/g,'@');filtered=filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']');filtered=filtered.replace(/(?:^|:|,)(?:\s*\[)+/g,'');if(/^[\],:{}\s]*$/.test(filtered))
return eval("("+src+")");else
throw new SyntaxError("Error parsing JSON, source is not valid.");};$.quoteString=function(string)
{if(string.match(_escapeable))
{return'"'+string.replace(_escapeable,function(a)
{var c=_meta[a];if(typeof c==='string')return c;c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16);})+'"';}
return'"'+string+'"';};var _escapeable=/["\\\x00-\x1f\x7f-\x9f]/g;var _meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};})(jQuery);



/**
 *		jQuery notice
 *		modified to use scrollTop() to position the thing properly if we're scrolled down
 *		Also added left/right positioning option and side_margin
*/
/**
*       jQuery.noticeAdd() and jQuery.noticeRemove()
*       These functions create and remove growl-like notices
*
*   Copyright (c) 2009 Tim Benniks
*
*       Permission is hereby granted, free of charge, to any person obtaining a copy
*       of this software and associated documentation files (the "Software"), to deal
*       in the Software without restriction, including without limitation the rights
*       to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
*       copies of the Software, and to permit persons to whom the Software is
*       furnished to do so, subject to the following conditions:
*
*       The above copyright notice and this permission notice shall be included in
*       all copies or substantial portions of the Software.
*
*       THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
*       IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
*       FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
*       AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
*       LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
*       OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
*       THE SOFTWARE.
*
*       @author         Tim Benniks <tim@timbenniks.com>
*       @copyright  2009 timbenniks.com
*       @version    $Id: jquery.notice.js 1 2009-01-24 12:24:18Z timbenniks $
**/
(function(jQuery)
{
        jQuery.extend({
                noticeAdd: function(options)
                {
                        var defaults = {
                                inEffect:                       {opacity: 'show'},      // in effect
                                inEffectDuration:       600,                            // in effect duration in miliseconds
                                stayTime:                       3000,                           // time in miliseconds before the item has to disappear
                                text:                           '',                                     // content of the item
                                stay:                           false,                          // should the notice item stay or not?
                                type:                           'notice',                        // could also be error, succes
                                side_margin:					'20px',
                                position:						'right'
                        }

                        // declare varaibles
                        var options, noticeWrapAll, noticeItemOuter, noticeItemInner, noticeItemClose;

                        options                 = jQuery.extend({}, defaults, options);
                        noticeWrapAll   = (!jQuery('.notice-wrap').length) ? jQuery('<div></div>').addClass('notice-wrap').appendTo('body') : jQuery('.notice-wrap');
                        noticeItemOuter = jQuery('<div></div>').addClass('notice-item-wrapper');
                        noticeItemInner = jQuery('<div></div>').hide().addClass('notice-item ' + options.type).appendTo(noticeWrapAll).html('<p>'+options.text+'</p>').animate(options.inEffect, options.inEffectDuration).wrap(noticeItemOuter);
                        noticeItemClose = jQuery('<div></div>').addClass('notice-item-close').prependTo(noticeItemInner).html('x').click(function() { jQuery.noticeRemove(noticeItemInner) });


						var css = ( options.position == 'right' ) ?
							{ 'right': options.side_margin, 'left': ''} :
							{ 'left' : options.side_margin, 'right': ''}
						;

						css.top = $(window).scrollTop()+10 ;


                        // hmmmz, zucht
                        // Uh, why only IE?
                        /*
                        if(navigator.userAgent.match(/MSIE 6/i))
                        {
	                        noticeWrapAll.css({top: document.documentElement.scrollTop});
    	                }
    	                */

    	                noticeWrapAll.css(css);
                        if(!options.stay) {
                                setTimeout(function() {
                                        jQuery.noticeRemove(noticeItemInner);
                                }, options.stayTime);
                        }
                },

                noticeRemove: function(obj)
                {
                        obj.animate({opacity: '0'}, 600, function()
                        {
                                obj.parent().animate({height: '0px'}, 300, function()
                                {
                                        obj.parent().remove();
                                });
                        });
                }
        });
})(jQuery);



