var JComponents = {};
if (typeof console == "undefined") var console = { log: function() {} };

function number_format(number, decimals, dec_point, thousands_sep) {
    var n = !isFinite(+number) ? 0 : +number, 
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return '' + Math.round(n * k) / k;
        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }
    return s.join(dec);
}

function rgbToHex(rgb) { 
  if (/^#?([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?$/i.test(rgb))
  {
	return rgb;
  }
  else
  {
	  var rgbvals = /rgb\((.+),(.+),(.+)\)/i.exec(rgb); 
	  var rval = parseInt(rgbvals[1]).toString(16); 
	  if (rval.length == 1)
	  {
		rval = '0' + rval;
	  }
	  
	  var gval = parseInt(rgbvals[2]).toString(16);
	  if (gval.length == 1)
	  {
		gval = '0' + gval;
	  }
	  
	  var bval = parseInt(rgbvals[3]).toString(16);
	  if (bval.length == 1)
	  {
		bval = '0' + bval;
	  }
	  
	  return '#' + ( 
		rval + 
		gval + 
		bval
	  ).toUpperCase(); 
  }
} 

var Request = {
	currentNamespace: [],
	action: '',
	params: [],
	getCurrentNamespace: function(offset)
	{
		if (typeof(offset) == "undefined")
		{
			offset = 0;
		}
		
		if (offset != 0)
		{
			return Request.currentNamespace.slice(0, offset);
		}
		else
		{
			return Request.currentNamespace;
		}
	},
	getCurrentNamespaceUrl: function(offset)
	{
		return '/' + Request.getCurrentNamespace(offset).join('/');
	},
	getAction: function()
	{
		return Request.action;
	},
	getParams: function()
	{
		return Request.params;
	}
};


$('div.checkbox_handle').each(function(i, el)
{
	var labelOn = $(this).find('label.on');
	var labelOff = $(this).find('label.off');
	var handle = $(this).find('div.handle');
	var checkbox = $(this).find('input');
	
	if (checkbox.attr('disabled'))
	{
		$(this).addClass('disabled');
	}
	
	$(el).css('width', handle.width() + Math.min(labelOn.width(), labelOff.width()) + Math.max(parseInt(labelOn.css('padding-left')), parseInt(labelOn.css('padding-right'))));
});

$('div.checkbox_handle').live('click', function()
{
	if ($(this).hasClass('disabled'))
	{
		return;
	}
	
	var labelOn = $(this).find('label.on');
	var labelOff = $(this).find('label.off');
	var handle = $(this).find('div.handle');
	var handlePos = handle.position();
	
	if (handlePos.left == -1)
	{
		// Currently On
		$(this).find('input').removeAttr('checked', 'checked').trigger('change');
		
		labelOff.css('left', -1 * (labelOff.width() + parseInt(labelOff.css('padding-left')) + parseInt(labelOff.css('padding-right'))));
		
		labelOn.animate({ right: -1 * (labelOn.width() + parseInt(labelOn.css('padding-left')) + parseInt(labelOn.css('padding-right'))) }, 500);
		labelOff.animate({ left: 0 }, 500);
		handle.animate({ left: $(this).width() - handle.width() - 1 }, 500);
	  
	}
	else
	{
		// Currently Off
		$(this).find('input').attr('checked', 'checked').trigger('change');
	
		labelOn.css('right', -1 * (labelOn.width() + parseInt(labelOn.css('padding-left')) + parseInt(labelOn.css('padding-right'))));
		handle.css({ left: $(this).width() - handle.width() - 2}); // Chrome fix
		
		labelOn.animate({ right: 0 }, 500);
		labelOff.animate({ left: -1 * (labelOff.width() + parseInt(labelOff.css('padding-left')) + parseInt(labelOff.css('padding-right'))) }, 500);
		handle.animate({ left: -1 }, 500);
	}
});



$(document).ready(function()
{
	$.fn.extend({
		insertAtCaret: function(myValue){
			this.each(function(i) {
				if (document.selection) {
					this.focus();
					sel = document.selection.createRange();
					sel.text = myValue;
					this.focus();
				}
				else if (this.selectionStart || this.selectionStart == '0') {
					var startPos = this.selectionStart;
					var endPos = this.selectionEnd;
					var scrollTop = this.scrollTop;
					this.value = this.value.substring(0, startPos)+myValue+this.value.substring(endPos,this.value.length);
					this.focus();
					this.selectionStart = startPos + myValue.length;
					this.selectionEnd = startPos + myValue.length;
					this.scrollTop = scrollTop;
				} else {
					this.value += myValue;
					this.focus();
				}
			})
		}
	});
	
      $.fn.tipsy.defaults.gravity = 's';
 
  $(document).ready(function() {
      
  });
  
	jQuery.extend({
		post: function(url, data, callback, type)
		{
			// shift arguments if data argument was omited
			if (jQuery.isFunction(data))
			{
				type = type || callback;
				callback = data;
				data = {};
			}
	
			return jQuery.ajax({
				type: "POST",
				url: url,
				data: data,
				success: callback,
				error: function(xhr)
				{
					// @TODO Display error dialog with the message
					//alert(xhr.status);
					//window.console.log(xhr);
				},
				dataType: type
			});
		},
		
		htmlentities: function(string)
		{
			return $('<div/>').text(string).html();
		}
	});
	
	
	
    $.fn.jdialog = function()
    {
    	$(this).click(function(event)
    	{
			event.preventDefault();
			event.stopPropagation();
			
        	var href = $(this).attr('href');
        	
        	if (href.substring(0, 11) == 'javascript:')
        	{
        		var icon = $(this).find('img');
        		
        		$.dialog({
        			yesno: {
        				title: $(this).attr('dialogTitle'),
        				content: $(this).attr('dialogContent'),
        				label: $(this).attr('dialogLabel') || $(this).find('img').attr('original-title') || $(this).find('img').attr('title'),
        				action: href
        			},
        			opener: this
        		});
        	}
        	else
        	{
        		$.dialog({
        			url: href,
        			opener: this
        		});
        	}
        	
        	return false;
    	});
    	
    	return $(this);
    };
    
    $.fn.focusFirst = function()
    {
    	var elem = $('input:visible', this).get(0);
    	var select = $('select:visible', this).get(0);
    	if (select && elem)
    	{
    		if (select.offsetTop < elem.offsetTop)
    		{
    			elem = select;
    		}
    	}
    	
    	var textarea = $('textarea:visible', this).get(0);
    	
    	if (textarea && elem)
    	{
    		if (textarea.offsetTop < elem.offsetTop)
    		{
    			elem = textarea;
    		}
    	}
  
    	if (elem)
    	{
    		elem.focus();
    	}
    	
    	return this;
    }
    
    $(document).bind('beforeReveal.dialog.datepicker', function()
    {
    	$('.jdpicker').jdPicker({date_min: $('.jdpicker').val()});
    });
    
    $('form[validate]').each(function(key, form)
    {
    	$(this)
    		.ketchup()
    		.removeAttr('validate');
    });

    $(document).bind('afterReveal.dialog', function()
	{
    	$('#dialog').find('form').focusFirst();
		$('form[validate]').ketchup();
	});
    


    
    $('#tip > a.tip_close').live('click', function()
    {
    	// @todo Save preferences
    	$(this).parent().slideUp();
	});
        
    $('a[rel="dialog"]').live('click', function(event)
    {
    	event.preventDefault();
		event.stopPropagation();
    	
    	$(this)
    		.removeAttr('rel')
    		.jdialog()
    		.click();

		return false;
    });

    $('span[title]').not('.cke_html_message').live('hover', function(event)
	{
		if ($(this).parent().is('.wysiwyg'))
		{
			return;
		}
		
    	event.preventDefault();
    	
    	$(this)
    		.tipsy()
    		.mouseenter();
	});
    
    $('img[title]').live('hover', function(event)
	{
    	event.preventDefault();
    	
    	$(this)
    		.tipsy()
    		.mouseenter();
	});
    
    $('span.button_dropdown > a.button').live('click', function(event)
	{
    	event.preventDefault();
    	
    	var options = $(this).next('ul'); 
    	
		var pageHeight = $(document).height();
		var pageWidth = $(document).width();
		
    	options
    		.css('min-width', $(this).parent().width())
    		.css('display', 'block');

		if (pageHeight < options.position().top + options.height())
		{
			options.css('top', $(this).position().top - options.height() - 8);
		}
		
		if (pageWidth < $(this).parent().position().left + options.width())
		{
			options.css('left', $(this).parent().offset().left - options.width() + $(this).parent().width());
		}
		else
		{
			options.css('left', $(this).parent().position().left);
		}
		
		/*
    	$(options).bind('click.button_dropdown', function(event)
		{
    		event.stopPropagation();
		});
		*/
    	
    	$('body').bind('click.button_dropdown', function()
		{
    		options.css('display', 'none');
    		$('body').unbind('click.button_dropdown');
		});
	});
    
	$('ul.tabs > li').live('click', function(event)
	{
		event.preventDefault();
		
		if ($(this).children('a').length > 0)
		{
			document.location.href = $(this).children('a:eq(0)').attr('href');
		}
	});
	
	/*
	$('span.button_dropdown > ul > li').live('click', function(event)
	{
		if ($(this).children('a').length > 0)
		{
			document.location.href = $(this).children('a:eq(0)').attr('href');
		}
	});
	*/
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		$('div.paging select').change(function(event)
		{
			var url = $(this).attr('url');
			document.location.href = url.replace("{$perPage}", this.value);
		});
		
		$('table').bind('afterRefresh', function()
		{
			$('div.paging select').bind('change', function(event)
			{
				var url = $(this).attr('url');
				document.location.href = url.replace("{$perPage}", this.value);
			});
		});
		
		$(document).bind('afterReveal.dialog', function() {
			$('div.paging select').change(function(event)
			{
				var url = $(this).attr('url');
				document.location.href = url.replace("{$perPage}", this.value);
			});
		});
	}
	else
	{
		// Parts of mailing.js depend on this...
		$('div.paging:not(.custom) select').live('change', function(event)
		{
			var $this = $(this);
			
			var url = $this.attr('url');
			document.location.href = url.replace("{$perPage}", $this.val());
		});
	}
	
	// Parts of mailing.js depend on this...
	$('div.paging:not(.custom) input.text').live('change', function(event)
	{
		var $this = $(this);
		
		var url = $this.attr('url');
		
		var page = parseInt(this.value);
		
		if (!isNaN(page))
		{
			if (page < 1)
			{
				page = 1;
			}
			else if (page > parseInt($(this).next('span.last_page').html()))
			{
				$(this).select();
				return;
			}
			
			document.location.href = url.replace("{$page}", $this.val());
		}
	}).live('focus', function(event)
	{
		$(this).select();
	}).live('keypress', function(event)
	{
		var url = $(this).attr('url');
		

		if(event.keyCode == 13){
				$(this).change();
				event.returnValue=false;
				return false;
		}
		//return false;
		
	});
    
    $('div.month_picker div.year_selector a').live('click', function(event)
	{
    	event.preventDefault();
    	
    	var input = $(this).parents('div.month_picker').find('input.text');
    	
    	if ($(this).index() == 0)
    	{
    		input.val(parseInt(input.val()) - 1)
    	}
    	else
    	{
    		input.val(parseInt(input.val()) + 1)
    	}
    	
		$(this).parents('div.month_picker').find('ol button').removeClass('selected');
		$(this).parents('div.month_picker').find('ol button:eq(0)').addClass('selected');
		$(this).parents('div.month_picker').find('input.text').change();
	});
    
    $('div.month_picker ol button').live('click', function(event)
	{
    	event.preventDefault();
    	
    	var year = $(this).parents('div.month_picker').find('input.text').val();
    	var month = $(this).attr('value');
    	
    	if (!$(this).hasClass('selected'))
    	{   
    		$(this).parents('ol').find('button.selected').removeClass('selected');
    		$(this).addClass('selected');
    	}
    	
    	$(this).parents('div.month_picker').trigger('datechange', year + "-" + month + "-01");
	});
	
	$('div.big_button').click(function()
	{
		document.location.href = $(this).find('a').attr('href');
	});
	
	$('div.big_button').mouseenter(function()
	{
		$(this).find('div.grayscale').each(function(i, imagePlaceholder)
		{
			imagePlaceholder = $(imagePlaceholder);
			
			var width = imagePlaceholder.width();
			var imageSrc = imagePlaceholder.find('img').attr('src');
			var colorPlaceholder = imagePlaceholder.find('div');
			
			if (colorPlaceholder.length == 0)
			{
				var colorPlaceholder = 	$('<div></div>')
					.css('height', width + 'px')
					.css('width', width + 'px')
					.css('position', 'absolute')
					.css('backgroundImage', 'url("' + imageSrc + '")')
					.css('backgroundPosition', '0 -' + width + 'px')
					.css('backgroundColor', 'none')
					.css('opacity', '0');
				
				imagePlaceholder.prepend(colorPlaceholder);	
			}
			else
			{
				colorPlaceholder.stop();	
			}
			
			colorPlaceholder.animate({opacity: 1}, 200);
		});
	});
	
	$('div.big_button').mouseleave(function()
	{
		$(this).find('div.grayscale').each(function(i, imagePlaceholder)
		{
			imagePlaceholder = $(imagePlaceholder);
			
			var colorPlaceholder = imagePlaceholder.find('div');
			
			colorPlaceholder.stop();
			colorPlaceholder.animate({opacity: 0}, 200);
		});
	});
	
	$('.search_filter form').live('submit', function(event)
	{
		event.preventDefault();
		var query = encodeURIComponent($(this).children(':input').val());
		if (!$.url.param('query'))
		{
			if (query != '')
			{
				var url = $.url.attr('source') + '&query=' + query;
				if (!$.url.attr('query'))
				{
					url = url.replace('&query', '?query');
				}
			}
		}
		else
		{
			var url = $.url.attr('source');
			if (query != '')
			{
				url = url.replace('query=' + $.url.param('query'), 'query=' + query);
			}
			else
			{
				url = url.replace('&query=' + $.url.param('query'), '');
				url = url.replace('?query=' + $.url.param('query') + '&', '?');
				url = url.replace('?query=' + $.url.param('query'), '');
			}
		}
		if (url)
		{
			document.location.href = url;
		}
	});
	
	$('.quick_action_icon a').live('click', function(event)
	{
		event.preventDefault();
		$(this).parents('form:eq(0)').submit();
	});
	
	$('.quick_action_icon div img').live('click', function(event)
	{
		event.preventDefault();
		$(this).parents('.quick_action_icon').find(':input').val('');
		$(this).parents('form:eq(0)').submit();
	});
	
	$(document).bind('afterReveal.dialog', function()
	{
		$('#dialog li.disabled :input').attr('disabled', 'disabled');
	});
		
	$('.ajax_upload_form iframe.upload_frame').load(function()
	{ 
		if ($(this).contents()[0].URL.indexOf('/blank.html') == -1)
		{
			var uploadField = $(this).parent('.ajax_upload_form').find('input[type="file"].ajax_upload');
			uploadField.attr('value', '').show().trigger('upload', $(this).contents().find("body").html());
		}
	});
			
	$('.color_picker').live('click', function(event)
	{
		event.preventDefault();
		
		var pos_offset = $(this).position();
		var this_height = $(this).height();
		var this_width = $(this).width();
		
		$(this).parents('td:eq(0)').append("<div class=\"farbtastic_overlay default_overlay\"></div><div class=\"farbtastic_dialog\">\n" +
			"<div class=\"farbastic_header_hex\"><label for=\"color\">" + colorPicker.Labels.labelHex + ":</label><input type=\"text\" id=\"color\" name=\"color\" value=\"" + $(this).children(':input').val() + "\" /></div><div id=\"picker\"></div>\n" +
			"<div class=\"farbastic_footer_btn\"><input type=\"button\" class=\"dialog_button button\" value=\"" + colorPicker.Labels.btnApply + "\"><input type=\"button\" class=\"dialog_button dialog_button_cancel button\" value=\"" + colorPicker.Labels.btnClose + "\"></div</div>"
		);
		
		$('#picker').farbtastic('#color');
		var dialog_width = $('.farbtastic_dialog').width();
		$('.farbtastic_dialog').css({'left': pos_offset.left - dialog_width + this_width, 'top': pos_offset.top + this_height}).slideDown(300);
		$('.farbtastic_overlay').show();
	});

	$('.farbtastic_overlay').live('click', function(event)
	{
		event.preventDefault();
		
		$('.farbtastic_overlay').fadeOut(300, function()
		{
			$(this).remove();
		});
		
		$('.farbtastic_dialog').slideUp(300, function()
		{
			$(this).remove();
		});
	});
	
	$('.farbtastic_dialog .button:eq(1)').live('click', function()
	{
		$('.farbtastic_overlay').click();
	});
	
	$('.farbtastic_dialog .button:eq(0)').live('click', function()
	{
		$(this).parents('.farbtastic_dialog').parent().find('.color_picker:eq(0)').fadeOut(300, function()
		{
			$(this).children(':hidden').val($('#color').val()).change();
			$(this).css('background',$('#color').val()).fadeIn(200);
		})
		$('.farbtastic_overlay').click();
	});
	
	$('#page_columns div.page_side_menu li.active').live('click', function(event)
	{
		event.preventDefault();
	});
	
	$('#page_columns div.page_side_menu div.paging a').live('click', function(event)
	{
		event.preventDefault();
		var current = $(this);

		$.post(
			current.attr('href'),
			function(data, textStatus)
			{
				current.parents('ol:eq(0)').replaceWith($(data));
			}
		);
	});
});


$(document).ready(function()
{
	
	$('.linkOverlaying').hover(function(){
		var href = $(this).attr("href")
		var color = $(this).css("color");
		var fontSize = $(this).css("fontSize");
		var fontFamily = $(this).css("fontFamily");
		var background = $(this).parent().parent().css("backgroundColor");
		var position = $(this).position();
		var content = $(this).html()
		var jQnewElement = $("<a class='linkOverlay'>"+content+"</a>")
		jQnewElement.attr("href",href)
		jQnewElement.css({
			"color":color,
			"fontSize":fontSize,
			"fontFamily":fontFamily,
			"backgroundColor":background,
			"top":position.top,
			"left": position.left,
			"padding":"6px 8px",
			"position":'absolute',
			"margin":"-9px 0 0 -10px"
		});
		$("body").append(jQnewElement);
	},
	function(){
			
	})
	$(".linkOverlay").live('mouseleave', function(){
		$(".linkOverlay").remove();
	})
	
	$('.toolbarToggler').live('mouseenter', function()
	{
		$('.toolbarBubble').hide();
		
		var toggler = $(this);
		var toolbar = $(this).next('.toolbarBubble');
		
		var jQdatagrid = toggler.closest(".data_grid")
		
		var offset = toggler.position();
		
		
		if (toolbar.hasClass('right'))
		{	
			toolbar.css('left', offset.left - toolbar.width() + toggler.width());
		}
		if(jQdatagrid.parent().css("overflow") == "auto"){

			toolbar.css('top', offset.top);

			toolbar.css('marginTop', "-10px");
		}
			
		toolbar
			.delay(275)
			.queue(function () { $(this).show(); $(this).dequeue(); });

		toolbar.bind('mouseleave', function()
		{
			toolbar.hide();
		});
	}).live('mouseleave', function()
	{
		$(this).next('.toolbarBubble').stop(true);
	});
});

$(document).ready(function()
{
	$('div.help span.close').click(function()
	{
		$(this).parents('div.help').slideUp(500);
	});	
});


$(document).ready(function()
{
	$('div.page_side_menu > ol > li, div.page_side_menu > ol > li.menu > ol > li').live('click', function()
	{
		var link = $(this).children('a');
		if (link.length > 0 && link.attr('href'))
		{
			document.location.href = link.attr('href');
		}
	});
});

$(document).ready(function()
{
	// Inline help
	$('a.help').click(function(e)
	{
		e.preventDefault();
		var toggle = Number(!$($(this).attr('help')).toggleClass('hidden').hasClass('hidden'));
		
		if (toggle)
		{
			$(this).find('img').addClass('toggled');
		}
		else
		{
			$(this).find('img').removeClass('toggled');
		}
		
		$.post(
			'/' + Request.getCurrentNamespace()[0] + "/settings/users/ajaxToggleHelp",
			{help_visible: toggle},
			function(data, textStatus) { },
			'json'
		);
	});
});


// EASE


// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

