 /**
  * Function
	*/
if(!jQuery.isFunction(jQuery.doOverlay)) {
	jQuery.doOverlay = function() 
	{
		<!-- ui-dialog -->
		var txt = '';
		txt += '<div class="ui-overlay">';
			txt += '<div class="ui-widget-overlay">';
				txt += '<div class="ui-widget-shadow ui-corner-all" style="width: 302px; height: 110px; margin:200px auto;">';				
					txt += '<div style="padding: 10px; width: 280px; height: 90px; text-align:center;" class="ui-widget ui-widget-content ui-corner-all">';
						txt += '<div style="margin:20px auto;" class="pop-up">';
							txt += '<p>Saving... Please wait.</p><br />';
							txt += '<img src="/skins/Atomic/core/images/ajax-loader-bw.gif" alt="please wait..." />';
						txt += '</div>';				
					txt += '</div>';				
				txt += '</div>';
			txt += '</div>';
		txt += '</div>';
		
		jQuery('body').append(txt);
	};
}

/**
 * set meta title
 */
if(!jQuery.isFunction(jQuery.setMetaTitle)) {
	jQuery.setMetaTitle = function(title) {
		document.title = title;
	};
}


/**
 * get meta title
 */
if(!jQuery.isFunction(jQuery.getMetaTitle)) {	
	jQuery.getMetaTitle = function() 
	{
		return document.title;
	};	
}

/**
 * Validate Form
 */
if(!jQuery.isFunction(jQuery.validateForm)) {
	jQuery.validateForm = function(element)
	{
		element.validate({
			invalidHandler: function(form, validator) 
			{
				var errors = validator.numberOfInvalids();
				if (errors) {
					var message = errors == 1
						? 'You missed 1 field. It has been highlighted'
						: 'You missed ' + errors + ' fields. They have been highlighted';
					element.prepend('<div id="formValidateMessage" style="display:none;"></div>');
					jQuery('#formValidateMessage').html(message);
					jQuery('#formValidateMessage').fadeIn();
				} else {
					jQuery('#formValidateMessage').hide();
				}
			},
			
			submitHandler: function() { form.submit(); }
	 });
	};
}

/**
 * taber-rific
 */
if(!jQuery.isFunction(jQuery.tabs)) {
	jQuery.tabs = function(ul_el) {
		var links = jQuery(ul_el+' li a');
		links.each(function() {			
			var next_tab = jQuery(this).attr('href');
			jQuery(this).click(function() {
				links.removeClass('active');
				jQuery(this).addClass('active');
				jQuery('div.tab').hide();
				jQuery(next_tab).fadeIn();
				return false;	
			});
		});
	};
}

/**
 * preload images
 * @uses core.js MM_preloadImages
 * kind of bogs down page load
 */
if(!jQuery.isFunction(jQuery.loadImages)) {
	jQuery.loadImages = function() {
		var images = jQuery('img');
		images.each(function() {
			var src = jQuery(this).attr('src');
			MM_preloadImages(src);
		});	
	};
}


/**
 * setup rollovers
 */
if(!jQuery.isFunction(jQuery.setupRollovers)) {
	jQuery.setupRollovers = function() {
		var rollovers = jQuery('.rollover');
		rollovers.each(function() {
			var rsrc = jQuery(this).attr('rsrc');
			MM_preloadImages(rsrc);
		});	
	
		jQuery('.rollover').hover(
			function() {
				var src_blur = jQuery(this).attr('src');
				var src_focus = jQuery(this).attr('rsrc');
				jQuery(this).attr('src',src_focus);
				jQuery(this).attr('rsrc',src_blur);
			},
			function() {
				var src_blur = jQuery(this).attr('src');
				var src_focus = jQuery(this).attr('rsrc');
				jQuery(this).attr('src',src_focus);
				jQuery(this).attr('rsrc',src_blur);
			}			
		);	
		
	};
}

/**
 * Reminder
 */
if(!jQuery.isFunction(jQuery.openReminderWindow)) {
	jQuery.openReminderWindow = function ()
	{
		MM_openBrWindow(BASE_URL+'reminder','','status=yes,width=400,height=400');
		return false;	
	};
}

/**
 * Fadetoggle
 */
if(!jQuery.isFunction(jQuery.fn.fadeToggle)) {
	jQuery.fn.fadeToggle = function(speed, easing, callback) {
		 return this.animate({opacity: 'toggle'}, speed, easing, callback);	
	};
}

/**
 * Loader
 */
if(!jQuery.isFunction(jQuery.doLoader)) {
	jQuery.doLoader = function(el, img) {	 
		if(!img) img = '/skins/Atomic/core/images/loaders/ajax-loader.gif';
		el.html('<div style="padding:50px 100px;"><img src="'+img+'" alt="loading..." /></div>');
	}; 
}


/* set hash */
if(!jQuery.isFunction(jQuery.setHash)) {
	jQuery.setHash = function(hashish) {
		window.location.hash = hashish;
		return null;
	};
}

/* get hash */
if(!jQuery.isFunction(jQuery.getHash)) {
	jQuery.getHash = function() {
		var hash = window.location.hash;
		var exp = hash.split('#');
		return exp[1];
	};
}

 /**
  * jquery qtip - tooltips
	*/
if(!jQuery.isFunction(jQuery.getTippers)) {
	jQuery.getTippers = function()
	{
		var tippers = jQuery(".qtip");
			
		tippers.each(function(i) {
			var tip_text = jQuery(this).attr('tip');
			var id = jQuery(this).attr('id');
			var img_id = id + '_info';
	
			jQuery(this).qtip({
				content: tip_text,
				position: {
					corner: { 
						target: 'topRight',
						tooltip: 'bottomLeft'
					}
				},
				style: {
					name: 'dark',
					tip: 'bottomLeft',
					border: {
						 width: 1,
						 radius: 8
					}			
				}
			});
	
			var img = ' <img style="position:absolute; margin-left:-17px;" class="info-icon" id="'+img_id+'" src="/skins/Atomic/core/images/icons/led/help.png" alt="?" width="12" height="12" align="top" />';
			jQuery(this).before(img);			
			jQuery('#'+img_id).qtip({
				content: tip_text,
				position: {
					corner: { 
						target: 'topRight',
						tooltip: 'bottomLeft'
					}
				},
				style: {
					name: 'dark',
					tip: 'bottomLeft',
					border: {
						 width: 1,
						 radius: 8
					}			
				}
			});	
		});//each
	};//function
}//if



/**
 * Logout link
 */
if(!jQuery.isFunction(jQuery.logoutLink)) {
	jQuery.logoutLink = function(c)
	{
		if(c!='' && c)
		{
			var conf = confirm("Are you sure?");
			if(conf)
			{
				window.location.href= str_replace('admin','',BASE_URL) + 'logout';				
				return false;
			}
		}
		if(!c || c=='')
		{
			window.location.href= str_replace('admin','',BASE_URL) + 'logout';				
			return false;
		}
	};
}

/**
 * dynamicClassses
 */
if(!jQuery.isFunction(jQuery.getDynamicClasses)) {
	
	jQuery.getDynamicClasses = function()
	{
		jQuery.setupRollovers();	
		jQuery.getTippers();

		/**
		 * button loader
		 */
		jQuery('.ui-button').hover(
			function() 
			{
				jQuery(this).addClass('ui-state-hover');
			},
			function() 
			{
				jQuery(this).removeClass('ui-state-hover');
			}
		); 
	
		/**
		 * button loader
		 */
		jQuery('.butt-submit').click(function() {
			var loader = '<img src="/skins/Atomic/core/images/ajax-loader-button-submit.gif" alt="loading" class="butt-submit-loader" />';
			jQuery(this).hide();
			jQuery(this).after(loader);
		}); 
			
	
	 /**
		* toggle buddy list
		*/
		jQuery("#toggleBuddyList").click(function () {
			//jQuery("#bl").fadeToggle();		
		}); 
		
														
	 /**
		* hover tablesorter rows.
		*/
		jQuery(".tablesorter tbody tr").hover(
			function()
			{
				jQuery(this).children('td').addClass("highlight");
			},
			function()
			{
				jQuery(this).children('td').removeClass("highlight");
			}																			
		);
	
	 /**
		* disabled form elements - add 'disabled' class
		*/
		var disableders =	jQuery(':input:disabled');
		disableders.each(function(i) {
			jQuery(this).addClass('disabled');
		});
	
	
	 /**
		* info message - insert ui info icon
		*/
		jQuery('div.error span.ui-icon').remove();
		jQuery('div.info-message').prepend('<span class="ui-icon ui-icon-info" style="float: left; margin-right: 0.3em;"></span>');
	
	
	 /**
		* error hanlding - insert ui error image on div.error
		*/
		jQuery('div.error span.ui-icon-red-alert').remove();
		jQuery('div.error-visible span.ui-icon-red-alert').remove();
		jQuery('div.error').prepend('<span class=" ui-icon-red-alert" style="float: left; margin-right: 0.3em;"></span>');
		jQuery('div.error-visible').prepend('<span class=" ui-icon-red-alert" style="float: left; margin-right: 0.3em;"></span>');	
	
	 /**
		* Add shadows
		*/
		if(jQuery.isFunction(jQuery.fn.addShadow)) {
			jQuery('.add-shadow').addShadow();
		}
	};
}


/**
 * document ready functions
 */
jQuery(document).ready(function($) {
	jQuery.getDynamicClasses();

 /**
  * Hijax!!
  * this magic uses hashes for ajax and browser forward/back
  */
	if(jQuery.isFunction(jQuery.History.bind)) {
		jQuery.History.bind(function() {
				// Our Generic Handler - Always runs last.
		});
	}

});



