/* ------------------------------------------------------------------------------------------------- */
/* Fix Console 																				*/
/* ------------------------------------------------------------------------------------------------- */

// Allow for console.log to not break IE
if (typeof console == "undefined" || typeof console.log == "undefined") {
	var console = { 
		log: function() {},
		profile: function() {},
		profileEnd: function() {}
	};
}

/* ------------------------------------------------------------------------------------------------- */
/* GLOBAL Configuration																				*/
/* ------------------------------------------------------------------------------------------------- */

if(typeof(sms) == 'undefined') {
	var sms = {};
}


// If we need to set up configuration values in the future to modify javascript parameters
// They can be defined here 

sms.config = {
	// nothing at the moment
	title: "Summer Mix Series 2011"
}

/* ------------------------------------------------------------------------------------------------- */
/* Internal Properties																			     */
/* ------------------------------------------------------------------------------------------------- */
sms.busy = false;
sms.cycleCount = 1;


/* ------------------------------------------------------------------------------------------------- */
/* GLOBAL DOMReady																				     */
/* ------------------------------------------------------------------------------------------------- */
$(document).ready(function() {
	if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod')
	{
		// do something special for iOS people?
	}
	$("body:not(.inner) nav ul li a").click(function(){
		hideContent = false;
		
		// is someone clicking the same button again?
		if ($(this).hasClass("active")){
			hideContent = true;	
		}
		// which button was clicked?
		var dest = $(this).attr("class").replace(" active","");
		
		if (!hideContent){
			// is the window even open?
			if ($("#pages").height() < 2){
				$("#pages").animate({
					height: 420
				}, 250, function() {
					
				});	
			}
			
			sms.slideWindow(dest);
			
			$("nav ul li a").removeClass("active");
			$(this).addClass("active");
		} else {
			$(this).removeClass("active");	
			$("#pages").animate({
				height: 1
			}, 250, function() {
					
			});	
			$(document).attr('title', sms.config.title);
		}
		
		return false;
		
	});
	
	// submit a mix
	$("#submit input.button").click(function(){
		var $name = $("#mixUser");
		var $email = $("#mixEmail");
		var $title = $("#mixTitle");
		var $theme = $("#mixTheme");
		var $earl = $("#mixLink");
		var $blurb = $("#mixBlurb");
		
		var formOK = sms.validateSubmission($name, $email, $title, $theme, $earl, $blurb);
		
		if (formOK){
			sms.submitMix($name.val(),$email.val(),$title.val(),$theme.val(),$earl.val(),$blurb.val());	
		} 
		return false;
	});
	
	$("#submissions li.comments a").click(function(){
		sms.showOverlay($(this).attr("rel"));
		return false;
	});
	
	
	// comment submit
	// submit a mix
	$("#mixModal input.button, body.inner .add input.button").click(function(){
		var $name = $("#commentName");
		var $email = $("#commentEmail");
		var $earl = $("#commentLink");
		var $comment = $("#commentBody");
		var $mixID = $("#activeMixID").val();
		
		var formOK = sms.validateComment($name, $email, $earl, $comment);
		
		if (formOK && $mixID){
			sms.submitComment($mixID, $name.val(),$email.val(),$earl.val(),$comment.val());	
		} 
		return false;
	});
	
	$("#mixModal li.info a").live("click",function(){
		if ($(this).hasClass("active"))
		{
			$(this).removeClass("active");
			$(this).html("More Info");
			$(".commentshold").show();
			$(".infohold").hide();
		} else {
			$(this).addClass("active");
			$(this).html("View Comments");
			$(".commentshold").hide();
			$(".infohold").show();	
		}
		return false;
	});
	$("li.download a, .img a").live('click',function(){
		var mixID = $(this).attr("rel");
		sms.trackMix(mixID);
	});
});


/* ------------------------------------------------------------------------------------------------- */
/*      Namespaced Functions and Methods														     */
/* ------------------------------------------------------------------------------------------------- */

$.extend(sms, {
	slideWindow: function(targ){
		// where is that in the window stack?
		var $parent = $("#pages .mask");
		
		var index = $parent.find("#"+targ).index();
		var width = $("#pages").width();
		var margin = (width * index) * -1;
		
		$($parent).animate({
			marginLeft: margin,
			opacity: 1,
		}, 250, function() {
			// Animation complete.
		});	
		
		var title = $("#"+targ).attr("rel");
		if (title){
			$(document).attr('title', title + " - " + sms.config.title);
		}
	},
	
	validateSubmission: function($name, $email, $title, $theme, $earl, $blurb){
		$("#submit label").removeClass("error");
		
		var targ = "";
		var ret = true;
		
		if (!$.validateEmail($email.val())){
			ret = false;
			targ = $email.attr("id");
			$("#lbl-"+targ).addClass("error");
		}
		if (!$name.val()){
			ret = false;
			targ = $name.attr("id");
			$("#lbl-"+targ).addClass("error");
		}
		if (!$title.val()){
			ret = false;
			targ = $title.attr("id");
			$("#lbl-"+targ).addClass("error");
		}
		if (!$theme.val()){
			ret = false;
			targ = $theme.attr("id");
			$("#lbl-"+targ).addClass("error");
		}
		if (!$earl.val()){
			ret = false;
			targ = $earl.attr("id");
			$("#lbl-"+targ).addClass("error");
		}

		return ret;
	},
	submitMix: function($name, $email, $title, $theme, $earl, $blurb){
		$.getJSON("api/rest/?method=sms.submit&format=json",{name: $name, email:$email,title:$title,theme:$theme,earl:encodeURIComponent($earl),blurb:encodeURIComponent($blurb)},
			function(data){
				
				if(data["failed"] == false){
				 	$("#submit .form").fadeOut('fast');
					$("#submit .third").css("border-right","none").animate({
							marginLeft: '37%'
						}, 350, 'easeOutQuad')
					.find("h1").html("Thanks! Mix submitted. Once this is approved, look for it here.");
					//$("#submit .third").addClass("submitted");
					//$("#submit .third.submitted h1").html("Thanks! Mix submitted. Once this is approved, look for it here.");
				}
				// base.closeBottleSave();
			}	
		);
	},
	showOverlay: function(mixID) {
	
		var isOldIE = ($.browser.msie && parseInt($.browser.version, 10) < 9),
			$modal = $(".modal.details");
			// show the preloader
			$(".modal.details").find(".loader").css("marginTop",0);
	
			// reveal the modal
			if(isOldIE) {
				$.dimScreen(0, 0.5);
				var $dimmer = $('#dimmer');
					
				$modal.show();
				// close on dimmer click
				$modal.one('click', sms.closeModal);
				
			} else {
				
				$.dimScreen(200, 0.5, function() {
					// selectors
					var $dimmer = $('#dimmer');
					// animate up and in
					
					$modal
						.show()
						.animate({
							opacity: 1,
							marginTop: '0px'
						}, 350, 'easeOutQuad'
					)
				;
				// close on dimmer click
				$dimmer.one('click', sms.closeModal);
				});
				
				// mobile devices are funky
				if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod')
				{
					$modal.css("position","absolute");
				
					$(document).bind('touchmove',function(){
							console.log( $(document).scrollTop() );
							$modal.css({top: $(document).scrollTop() + modalTop});
							$dimmer.css({top: $(document).scrollTop()});
						});
					$(document).bind('scroll',function(){
							console.log( $(document).scrollTop() );
							$modal.css({top: $(document).scrollTop() + modalTop});
							$dimmer.css({top: $(document).scrollTop()});
						});
	
				};
			}
		// load the details
		$.getJSON("./api/rest/?method=sms.getMix&format=json",
		  {
			seo: mixID
		  },
		  function(data) {
			 if (data.errors == false){
				 // put the new data into the modal
				var mixDetails = data.data[0];
				// pick out each var
				var id = mixDetails.id,
					title = mixDetails.title,
					author = mixDetails.author,
					seo = mixDetails.seo_url,
					download = mixDetails.link,
					cover = mixDetails.cover,
					mixYear = mixDetails.add_date.substr(0,4),
					comments = mixDetails.comments,
					blurb = mixDetails.blurb,
					$modal = $(".modal.details");
					
					
				$modal
					.find("h1").removeClass("long").html($.stripslashes(title))
					.end()
					.find("h2").html(author)
					.end()
					.find(".img a").attr("href",download).attr("rel",id)
					.end()
					.find(".img a img").attr("src","./_img/"+mixYear+"/"+cover+"_l.jpg")
					.end()
					.find("ul.options li.download a").attr("href",download).attr("rel",id)
					.end();

					
				// do we have a blurb?
				if (!blurb){
					$modal.find("li.info").addClass("hidden");	
					$modal.find(".infohold").html("").hide();
				} else {
					$modal.find("li.info").removeClass("hidden");
					$modal.find(".infohold").html("<p>"+$.nl2br(blurb)+"</p>");
				}
				
				$(".commentshold").show();
				$(".infohold").hide();
				
				var $commentList = $("#mixModal dl.list");
					$commentList.html("");
					
				// do we have comments?
				if (comments.length){

					$.each(comments, function(index, value) { 	
						var username = "";
						//var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);
						var thedate = $.mysqlTimeStampToDate(value.add_date);
						// should the name be linked?
						if (value.yurl){
							username = "<a href='"+decodeURIComponent(value.yurl)+"' target='_blank'>"+value.yname+"</a>";
						} else {
							username = value.yname;
						}
						// can we determine the date?
						
						$commentList.append("<dt>"+decodeURIComponent(value.ycomment)+"</dt>");
						$commentList.append("<dd>"+username+" &middot; " + sms.formatDate(thedate)+"</dd>");

					});
				} else {
					$commentList.append("<dt class='empty'>Oh, this is unfortunate. No comments found!</dt>");
					$commentList.append("<dd class='empty'>Leave some feedback below!</dd>");

				}
				
				
			
					
				$("#activeMixID").val(id);
				
				if (title.length > 25){
					$modal.find("h1").addClass("long");
				}
				 // hide the loader
				$(".modal.details .loader").animate({
						marginTop: '-500px'
					}, 350, 'easeOutQuad'
				)
			 } else {
				 alert(data.errors);
			 }
		  }
		);
	
	},
	closeModal:  function(){
		var isOldIE = ($.browser.msie && parseInt($.browser.version, 10) < 9),
			$modal = $('.modal.details');		
			
			if(isOldIE) {
				$modal.hide();
				$.unDimScreen(0);
			} else {
				// close it up
				$modal
				.animate({
							opacity: 0,
							marginTop: '-500px'
						}, 350, 'easeOutQuad',
						function(){ 
							$modal.hide()
							.removeAttr('style');
							$(".modal.details").find(".loader").css("marginTop",0);
						}
					)
				// undim screen
				$.unDimScreen(200);
			}
	},
	validateComment: function($name, $email, $earl, $comment){
		$(".div dl label").removeClass("error");
		
		var targ = "";
		var ret = true;
		
		if (!$.validateEmail($email.val())){
			ret = false;
			targ = $email.attr("id");
			$("#cmt-lbl-"+targ).addClass("error");
		}
		if (!$name.val()){
			ret = false;
			targ = $name.attr("id");
			$("#cmt-lbl-"+targ).addClass("error");
		}
		if (!$earl.val()){
			ret = false;
			targ = $earl.attr("id");
			$("#cmt-lbl-"+targ).addClass("error");
		}
		if (!$comment.val()){
			ret = false;
			targ = $comment.attr("id");
			$("#cmt-lbl-"+targ).addClass("error");
		}

		return ret;
	},
	submitComment: function(mixID, $name, $email, $earl, $comment){
		// save these values as cookies
		$.cookie('sms_comment_name', $name);
		$.cookie('sms_comment_email', $email);
		$.cookie('sms_comment_link', $earl);
		
		if ($earl.substr(0,7) == "http://"){
			$earl = $earl.substr(7); // remove the http://
			
		}
		
		$.getJSON("api/rest/?method=sms.addComment&format=json",{mix_id: mixID, name: $name, email:$email, earl:encodeURIComponent($earl), comment:encodeURIComponent($comment)},
			function(data){
				if(data["failed"] == false){
					
				 	var $list = $(".commentshold .list");
					
					$list.append("<dt>"+$comment+"</dt>");
					$list.append("<dd>"+$name+" &middot; Just added!</dd>");
					
					$list.find(".empty").remove();
					
					$("#commentBody").val("");
				} else {
					alert(data.failed);	
				}
				// base.closeBottleSave();
			} 
		);
	},
	trackMix: function(mixID){
		$.getJSON("api/rest/?method=sms.mixDownload&format=json",{mix_id: mixID},
			function(data){
				
				// no callback on success or failure, just crossed fingers
			} 
		);
	},
	formatDate: function(thedate){
		var months = Array("January","February","March","April","May","June","July","August","September","October","November","December");
		var returnStr = "";
		
		returnStr = months[thedate.getMonth()] + " " + thedate.getDate();
		returnStr += " &middot; ";
		if (thedate.getHours() > 12){
			returnStr += thedate.getHours()-12;
			returnStr += ":"+thedate.getMinutes() + "pm";
		} else {
			returnStr += thedate.getHours();
			returnStr += ":"+thedate.getMinutes() + "am";
		}
		
		return returnStr;
	}
});




/*sms.getComments = function(){
	$.getJSON("/api/rest/?method=photos.checkForUpdates&format=json",
	  {
		set_id: $("#eventID").val(),
		last_order_id: $("#last_order_id").val()
	  },
	  function(data) {
		 var status = data['status'];

		 if (status == "ok")
		 {
			 var arrLength = data['data'].length;
			 var order_id = data['data'][0]['order_id'];
			 var current_order_id = $("#last_order_id").val();
			 
			 $("#last_order_id").val(order_id);
			 
			 
			 // no photos msg?
			 if ($("#noPhotos").exists()){
				 $("#noPhotos").slideUp();
			 }
			 
			 
			$.each(data['data'], function(i,item){
		  		
				
				var order_id = item['order_id'];
				
				$("#photo-items").prepend(newPhoto);
				$("#"+item['filename']).delay(500).animate({
					opacity: 1
				  }, 500, function() {
						// animateion done
				  });;
				
			});
			
			
		 }
		
		
	  });
	  
	  // json'ed.. restart the cycle!
	  gendom.startCycle();
}*/

jQuery.extend( {
	getViewPort: function() {
		return [$(window).width(), $(window).height(), $(document).scrollLeft(), $(document).scrollTop() ];
	}
});


/*	******************************
		PLUGIN - Dim Screen
		Author: Jack Lukic - KNI 
		Last revision: June 2009
	******************************	*/

jQuery.extend( {
    dimScreen: function(speed, opacity, callback) {
		
		if(typeof speed == 'function') {
            callback = speed;
            speed = null;
        }
        if(typeof opacity == 'function') {
            callback = opacity;
            opacity = null;
        }
        if(speed < 1 && speed > 0) {
            var placeholder = opacity;
            opacity = speed;
            speed = placeholder;
        }
        if(opacity >= 1) {
            var placeholder = speed;
            speed = opacity;
            opacity = placeholder;
        }
		
		speed = (speed >= 0) ? speed : 200;
        opacity = (opacity > 0) ? opacity : 0.22;
		
		if($('#dimmer').size() < 1) {
			jQuery('<div/>').attr('id','dimmer-wrapper').appendTo("body").html(jQuery('<div/>').attr('id','dimmer'));
			var curOpacity = $('#dimmer').css('opacity');
			
			if(curOpacity != opacity) {
				if(speed == 0) {
					$('#dimmer').css({ opacity: opacity, visibility: 'visible' });
					$('#dimmer-wrapper').css({ visibility: 'visible' });
				}
				else {
					$('#dimmer, #dimmer-wrapper').css({	visibility: 'visible'});
					$('#dimmer').css({ opacity: '0.00'});
					
					$('#dimmer').fadeTo(speed, opacity, callback);
				}			
			}
		}
	},
    unDimScreen: function(speed) {
		speed = (speed >= 0 && typeof(speed) != 'undefined') ? speed : 200;
		if($('#dimmer').size() > 0) {
			if(speed == 0) {
				return $('#dimmer, #dimmer-wrapper').css({
					visibility: 'hidden'
				});
				$('#dimmer, #dimmer-wrapper').remove();
			}
			else {
				$('#dimmer').fadeTo(speed, '0.00', function(){					
					$('#dimmer, #dimmer-wrapper').remove();
				});
			}
		}
	},
	ucwords: function (str) {
		// http://kevin.vanzonneveld.net
		// +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
		// +   improved by: Waldo Malqui Silva
		// +   bugfixed by: Onno Marsman
		// +   improved by: Robin
		// +      input by: James (http://www.james-bell.co.uk/)
		// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// *     example 1: ucwords('kevin van  zonneveld');
		// *     returns 1: 'Kevin Van  Zonneveld'
		// *     example 2: ucwords('HELLO WORLD');
		// *     returns 2: 'HELLO WORLD'
		return (str + '').replace(/^([a-z])|\s+([a-z])/g, function ($1) {
			return $1.toUpperCase();
    	});
	},
	validateEmail: function(email){
		// [a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?	
		
		// LAMEST EMAIL VALIDATION EVER - but it gets the job done (kinda)
		return (email.indexOf(".") > 2) && (email.indexOf("@") > 0);
	},
	mysqlTimeStampToDate: function(timestamp) {
		//function parses mysql datetime string and returns javascript Date object
		//input has to be in this format: 2007-06-05 15:26:02
		var regex=/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/;
		var parts=timestamp.replace(regex,"$1 $2 $3 $4 $5 $6").split(' ');
		return new Date(parts[0],parts[1]-1,parts[2],parts[3],parts[4],parts[5]);
	  },
	nl2br: function (str, is_xhtml) {
    	// http://kevin.vanzonneveld.net
    	var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';

   		 return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
		},
	stripslashes: function (str) {
		// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// +   improved by: Ates Goral (http://magnetiq.com)
		return (str + '').replace(/\\(.?)/g, function (s, n1) {
			switch (n1) {
			case '\\':
				return '\\';
			case '0':
				return '\u0000';
			case '':
				return '';
			default:
				return n1;
			}
		});
	}
});


/*	******************************
		PLUGIN - Utility Functions 
		Author: Jack Lukic - KNI (all plugins)
		Notes: Used to extend jQuery functionality and shorten code
	******************************	*/

jQuery.fn.extend({
	// test if el is animated
	animated: function() {
		if(this.filter(':animated').size() > 0) {
			return true;
		}
		else {
			return false;	
		}
	},
	// test if el is visible
	visible: function() {
		if(this.filter(':visible').size() > 0) {
			return true;
		}
		else {
			return false;	
		}
	},
	// test if el exists
	exists: function() {
		if(this.size() > 0) {
			return true;
		}
		else {
			return false;	
		}
	}
});

// 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;
	}
});


