/* this prevents dom flickering, needs to be outside of dom.ready event: */
document.documentElement.className += 'js_active';
/* end dom flickering =) */

jQuery.noConflict();

jQuery(document).ready(function() {
	// Do the slide for info site
	jQuery('#iphoneSlider').tinycarousel({
		pager : true,
		duration : 300
	});
	
	jQuery('#androidSlider').tinycarousel({
		pager : true,
		duration : 300
	});
	
	// Slider for corp partners - Footer
	jQuery('#sliderFooter').tinycarousel({
		pager : true,
		duration : 300
	});	
	
	// Footer Tab Switch - Show Hide
	footerTabSwitch();
	
	// Footer - Show & Hide FAQ Entrys
	faq_toggle();
	
	// Login Box - Show Hide
	login_box();
	
	// Login Box - Tooltip
	login_tooltip();
	
	/*	
	// Extend footer to bottom if needed
	footer_extend();
	*/
	
	// Function to slide the nav into viewport
	slide_nav();

	// Search Box Suggestions - Rates
	suggesticator();
	
	// Show payment method tooltips
	payment_tooltip();
	
	//
	loginBoxOverlay();
	
	NavHoverEase();
	
	CountrySelectList();
	
	SwitchTheSlide();
	
	InfieldLabels();
	
	RidMeOfInfo();
	
	});
	
	
function RidMeOfInfo(){
	var info_divs = jQuery('.more_info');
	var info_div_button = jQuery('.info_div_button');
	var info_div_button2 = jQuery('.info_div_button2');
	
	info_divs.hide();
	info_div_button2.hide();
	
	info_div_button.bind('click', function(event){
		event.preventDefault();
		jQuery(this).parent('li').find('.more_info').stop().slideToggle();
		jQuery(this).parent('li').find('.info_div_button2').show();
		jQuery(this).hide();	
	});
	
	info_div_button2.bind('click', function(event){
		event.preventDefault();
		jQuery(this).parent('li').find('.more_info').stop().slideToggle();
		jQuery(this).parent('li').find('.info_div_button').show();
		jQuery(this).hide();	
	});
}


function InfieldLabels(){
	var Input = jQuery('#rates_search_box input');
	
	// Save the value in a data field
	jQuery.data(Input, 'value', Input.attr('value'));
	
	Input.bind('focus', function(){
		Input.val('');
		
		Input.css({
			'color': '#333333'
		});
	});
	
	Input.bind('blur', function(){
		// Fill the field with the saved input value
		var newValue = jQuery.data(Input, 'value');
		
		Input.val(newValue);
		Input.css({
			'color': '#CCCCCC'
		});
	});
}

function SwitchTheSlide(){
	var iPhoneSlide = jQuery('#iphoneSlider');
	var androidSlide = jQuery('#androidSlider');
	var iPhoneButton = jQuery('#iPhoneButton');
	var androidButton = jQuery('#AndroidButton');
	
	androidSlide.hide();
	
	iPhoneButton.bind('click', function(event){
		event.preventDefault();
		if (!jQuery(this).hasClass('active'))
		{ 
			iPhoneSlide.toggle();
			androidSlide.toggle();
			androidButton.toggleClass('active');
			iPhoneButton.toggleClass('active');
		}
	});
	
	androidButton.bind('click', function(event){
		event.preventDefault();
		if (!jQuery(this).hasClass('active'))
		{
			androidSlide.toggle();
			iPhoneSlide.toggle();
			iPhoneButton.toggleClass('active');
			androidButton.toggleClass('active');
		}
	});
}


function CountrySelectList(){
	// Prevent the navigation from using CSS for slide behaviour, because hover doesnt work on mobile devices
	// erase the no_js class from element
	countryList = jQuery('#language_list_container');
	countryList.removeClass('no_js');
	
	// Save the ul in a variable
	countryUl = countryList.find('ul');
	
	// Number of lis in the country list:
	liNumber = countryUl.children().size();
	
	// Determine the pixel needed to hide the countryList
	pixelCount = 0;
	pixelIncrement = countryUl.find('a').innerHeight();
	
	for (i = 1; i < liNumber; i++){
		pixelCount += pixelIncrement;
	}
	
	// Set the top attribute to minus the computed pixelCount for the list to vanish up
	countryList.css({
		'top': '-'+pixelCount+'px',
		'height': pixelCount+pixelIncrement+'px'
		});
	
	// Add a click effect and slide out the ul. This is necessary for the ul to work on 
	// mobile devices
	countryUl.bind('click', function(){
		countryList.stop().animate({top:'0px'}, {queue:false, duration: 400});
	});
	
	// Trigger the mouseleave event, when the animation is complete and ONLY if the mouse is NOT hovering any a tags within the list
	countryUl.bind('mouseleave', function(){
		countryList.stop().animate({top:'-'+pixelCount+'px'}, {queue:false, duration: 400});
	});
}



function NavHoverEase(){
	
	// #main_nav links
	navLinkLis = jQuery('#main_nav > li');
	navLinks = jQuery('a.dropdown');
	
	// prevent links with dropdowns to be executeable
	navLinks.live('click', function(event){
		event.preventDefault();
	})
	
	triggeredUl = navLinkLis.find('ul');
	triggeredUl.css({
		'opacity' : 0
	});
    
    navLinkLis.live('click', function(){
    	
    	//Remove outline from links
        jQuery(this).find('a:first-child').blur();
        
        // fixes issue when dealing with mobile devices
        ul = jQuery(this).closest('li').children('ul');
		//alert('this is love... baby dont hurt me! :*  and that is the html');
		
		ul.css('display', 'block');
    });
    
    visCheck = 1;
    
    //When mouse rolls over
    navLinkLis.live('mouseenter', function(){
        if(visCheck == 0){
        	jQuery(this).children('ul').css('display', 'block');
        }
        jQuery(this).children('ul').stop().animate({opacity:'1'},{queue:false, duration:200});
    });
    
    //When mouse is removed
    navLinkLis.live('mouseleave', function(){
        jQuery(this).children('ul').stop().animate({opacity:'0'},{queue:false, duration:200}).css({
        	'display': 'none'
        	});
        visCheck = 0;
    });
}



function loginBoxOverlay() {  
 
    jQuery('span[name=openLogin]').click(function(e) {
        e.preventDefault();
        jQuery('#login_overlay').fadeIn(300);
		jQuery('#login_dialog').fadeIn(600);
		jQuery('#login_dialog').show();
	});
	jQuery('a.close').click(function(e){
		e.preventDefault();	  
		jQuery('#login_dialog').fadeOut(200);
        jQuery('#login_overlay').fadeOut(150);   
	});
	
	jQuery('#login_overlay').click(function(){
		jQuery('#login_dialog').fadeOut(300);
        jQuery('#login_overlay').fadeOut(600);
	});	
}





function footerTabSwitch() {
 	jQuery('li.tab1').click(function() {
 		jQuery(this).addClass('activeTab');
 		jQuery('.tab2, .tab3').removeClass('activeTab');
 		jQuery('.tabContent1').css('display','inline');
 		jQuery('.tabContent2, .tabContent3').css('display','none');
 	});

 	jQuery('.tab2').click(function() {
 		jQuery(this).addClass('activeTab');
 		jQuery('.tab1, .tab3').removeClass('activeTab');
 		jQuery('.tabContent1, .tabContent3').css('display','none');
 		jQuery('.tabContent2').css('display','inline');
 	});

 	jQuery('.tab3').click(function() {
 		jQuery(this).addClass('activeTab');
 		jQuery('.tab1, .tab2').removeClass('activeTab');
 		jQuery('.tabContent1, .tabContent2').css('display','none');
 		jQuery('.tabContent3').css('display','inline');
 	});
}


function faq_toggle() {
	jQuery('.question').bind('click', function() {
		jQuery(this).toggleClass('active');
		var question = jQuery(this);
		if(question.hasClass('active'))
        {
            question.next('.answer').slideDown('slow');
        }
        else
        {
            question.next('.answer').stop(true, true).slideUp('slow');
        }
	});
}


function login_box() {
    var login_button = jQuery('.login_button input');
    
    
	jQuery('.login_button #Login').click(function(event) {
            event.preventDefault();
            jQuery('.login_form').fadeToggle('800', function(){
                jQuery('#phone_number').focus();
            });
	});
}

function login_tooltip() {

	jQuery('a.tooltip_button')
		.click(function() {
			jQuery('.tooltips').fadeIn('800');
	});
	
	jQuery('a.tooltip_button')
		.mouseleave(function() {
			jQuery('.tooltips').fadeOut('800');
	});
}


function payment_tooltip()
{
    // Use the title of label tags to create a tooltip shown on payment
    // page 1
    
    // Save some vars
    var tooltip_box = jQuery('#payment_method_info');
    
    if(tooltip_box.length != 0)
    {
        var method_inputs = jQuery('#choose_payment input:radio');
        var selected_input = jQuery('#choose_payment input:checked');
        var selected_label = selected_input.parent().find('label');
        
        //console.log('Selected input value is: "'+selected_input.val()+'" \nTitle of selected input label is: "'+selected_label.attr('title')+'"');
        
        if(selected_label.attr('title') != 0)
        {
            tooltip_box.html('<p>'+selected_label.attr('title')+'</p>');
        }
        
        method_inputs.bind('click', function(){
            if(tooltip_box.find('p') != 0)
            {
                tooltip_box.find('p').replaceWith('<p>'+jQuery(this).parent().find('label').attr('title')+'</p>');
                
                // Strip previously selected item of class "clicked" and distribute
                // on clicked element.
                var clicked = jQuery('.clicked_radio');
                clicked.removeClass('clicked_radio');
                jQuery(this).parent().addClass('clicked_radio');
            }
        });
    }
}


function image_loader() {

	jQuery('.preload').preloadImages({
		showSpeed : 500, // length of fade-in animation, 500 is default
		easing : 'easeOutQuad' // optional easing, if you don't have any easing
	// scripts - delete this option
	});
}

jQuery.fn.preloadImages = function(options) {

	var defaults = {
		showSpeed : 500,
		easing : 'easeOutQuad'
	};

	var options = jQuery.extend(defaults, options);

	return this
			.each(function() {
				var container = jQuery(this);
				var image = container.find('img');

				jQuery(image).css({
					"visibility" : "hidden",
					"opacity" : "0"
				});
				jQuery(image)
						.bind('load error', function() {
							jQuery(this).css({
								"visibility" : "visible"
							}).animate({
								opacity : "1"
							}, {
								duration : options.showSpeed,
								easing : options.easing
							}).parent(container).removeClass('preload');
							//console.log('to here and no further4');
						})
						.each(
								function() {
									if (this.complete
											|| (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6)) {
										$(this).trigger('load');
									}
								});
			});
}

function slide_nav() {
	var scrollingDiv = jQuery("div#slide_nav");
	if(scrollingDiv.length > 0)
    {
        // check for main div lower border to set the navigation so, that it
        // doesnt exceeds this value when scrolling
        
        // save the main divs lower border position from top
        var main_div = jQuery('div#main');
        var main_div_position = main_div.position();
        var main_div_lower_reach = main_div_position.top + main_div.height();
        
        var scrollingDiv_offset = scrollingDiv.offset();
        var initial_offset = scrollingDiv_offset.top;
        
        // Create small helper dog to look up position when finished animating
        var wrapper = jQuery('div#wrapper');
        wrapper.before('<div id="watchdog"></div>');
        
        var watchdog = jQuery('div#watchdog');
        
        watchdog.css({
                'background': 'transparent',
                'height': scrollingDiv.height(),
                'width': scrollingDiv.width(),
                'position': 'absolute',
                'top': scrollingDiv_offset.top,
                'left': scrollingDiv_offset.left
        });
        
        jQuery(window).scroll(function() {
            setTimeout(function() {
                scroll_this_dog(scrollingDiv)
            }, 500);
        });
        
        function scroll_this_dog(element) 
        {
            watchdog.css({
                "marginTop" : (jQuery(window).scrollTop() + 1) + "px"
            });
            
            var watchdog_offset = watchdog.offset();
            var watchdog_lowerend = watchdog_offset.top+watchdog.height();
            
            //console.log("BARK! thats my lower end: "+watchdog_lowerend);
            //console.log("maindiv lower end: "+main_div_lower_reach);
            
            
            if((watchdog.height()+watchdog_offset.top) > main_div_lower_reach)
            {
                //console.log("BARK! im lower!");
                element.stop().animate({
                    "marginTop" : main_div_lower_reach - element.height() - initial_offset + "px"
                }, 1000, "easeOutExpo");
            }
            else
            {
                //console.log("BARK! im above!");
                element.stop().animate({
                    "marginTop" : (jQuery(window).scrollTop() + 1) + "px"
                }, 1000, "easeOutExpo");
            }
        }
    }
}

function footer_extend() {
	// get the viewport height. compare it to the height of the page
	// if the viewport is bigger than the page content, create a div
	// with a height matching the difference between viewport and site height.
	// Purpose is to fix the footer at the bottom of the page.
	var viewportwidth;
	var viewportheight;

	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use
	// window.innerWidth and window.innerHeight

	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerWidth, viewportheight = window.innerHeight
	}

	// IE6 in standards compliant mode (i.e. with a valid doctype as the first
	// line in the document)

	else if (typeof document.documentElement != 'undefined'
			&& typeof document.documentElement.clientWidth != 'undefined'
			&& document.documentElement.clientWidth != 0) {
		viewportwidth = document.documentElement.clientWidth,
				viewportheight = document.documentElement.clientHeight
	}

	// older versions of IE
	else {
				viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
				viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}

	// console.log(viewportwidth);
	// console.log(viewportheight);

	var footer = jQuery('#footer');

	footer
			.after('<div id="marker" style="position: relative; float: left; width: 100px; height: 2px;"></div>');

	var pagesize = jQuery('#marker').offset();

	if (viewportheight > pagesize.top) {
		var spacer_height = Math.round((viewportheight - pagesize.top));
		footer
				.before('<div id="footer_positioner" style="float: left; position: relative; clear: both;"></div>');
		jQuery('#footer_positioner').animate({
			height : spacer_height
		}, 200, function() {
			jQuery('#marker').remove();
		});
	} else {
		jQuery('#marker').remove();
	}
}

function suggesticator() {
	
    var search_data_item = jQuery('#search_values');
	var search_data_json = jQuery('#search_values').html();
	var search_data = jQuery.parseJSON(search_data_json);
	
	if(search_data_item.length != 0)
    {
        jQuery(".input_box").autocomplete({
            source: search_data,
            select: function(event, ui) {
            	// This following line sets the click event for the li items of
            	// the search result
                window.location.href = ui.item.link;
            return false;
            }
           }).data("autocomplete")._renderItem = function( ul, item ) {
           return jQuery( "<li></li>" )
               .data( "item.autocomplete", item )
               .append( "<a class='search_result_item' href='#'>"
                       + "<span class='flagwrap_search'><img src='"+item.flag_link+"'/></span>"
                       + "<span class='country_search'>"+item.value+"</span>"
                       + "<span class='mobile_search'>"+item.mobile+"</span>"
                       + "<span class='landline_search'>"+item.landline+"</span>" 
                       + "</a>" )
               .appendTo( ul );
               jQuery('.search_result_item').bind('click', function(event){
               		event.preventDefault();
               });
           };
           jQuery.ui.autocomplete.prototype._renderMenu = function( ul, items ) {
               var self = this;
               jQuery.each( items, function( index, item ) {
                  if (index < 50) // here we define how many results to show
                     {self._renderItem( ul, item );}
                  });
            }
    	
        
        // getter
        var appendTo = jQuery(".input_box").autocomplete("option", "appendTo");
        // setter
        jQuery(".input_box").autocomplete("option", "appendTo", "#search_results");
	}
}

/*
 * Slider Plugin
 */
(function($) {
	$.fn.tinycarousel = function(options) {
		var defaults = {
			start : 1,
			display : 1,
			axis : 'x',
			controls : true,
			pager : true,
			interval : true,
			intervaltime : 6000,
			rewind : false,
			animation : true,
			duration : 4000,
			callback : null
		};
		var options = $.extend(defaults, options);
		var oSlider = $(this);
		var oViewport = $('.viewport:first', oSlider);
		var oContent = $('.overview:first', oSlider);
		var oPages = oContent.children();
		var oBtnNext = $('.next:first', oSlider);
		var oBtnPrev = $('.prev:first', oSlider);
		var oPager = $('.pager:first', oSlider);
		var iPageSize, iSteps, iCurrent, oTimer, bPause, bForward = true, bAxis = options.axis == 'x';
		return this.each(function() {
			initialize();
		});
		function initialize() {
			iPageSize = bAxis ? $(oPages[0]).outerWidth(true) : $(oPages[0])
					.outerHeight(true);
			var iLeftover = Math
					.ceil(((bAxis ? oViewport.outerWidth() : oViewport
							.outerHeight()) / (iPageSize * options.display)) - 1);
			iSteps = Math.max(1, Math.ceil(oPages.length / options.display)
					- iLeftover);
			iCurrent = Math.min(iSteps, Math.max(1, options.start)) - 2;
			oContent.css(bAxis ? 'width' : 'height',
					(iPageSize * oPages.length));
			move(1);
			setEvents();
		}
		function setEvents() {
			if (options.controls && oBtnPrev.length > 0 && oBtnNext.length > 0) {
				oBtnPrev.click(function() {
					move(-1);
					return false;
				});
				oBtnNext.click(function() {
					move(1);
					return false;
				});
			}
			if (options.interval) {
				oSlider.hover(function() {
					clearTimeout(oTimer);
					bPause = true
				}, function() {
					bPause = false;
					setTimer();
				});
			}
			if (options.pager && oPager.length > 0) {
				$('a', oPager).click(setPager);
			}
		}
		function setButtons() {
			if (options.controls) {
				oBtnPrev.toggleClass('disable', !(iCurrent > 0));
				oBtnNext.toggleClass('disable', !(iCurrent + 1 < iSteps));
			}
			if (options.pager) {
				var oNumbers = $('.pagenum', oPager);
				oNumbers.removeClass('active');
				$(oNumbers[iCurrent]).addClass('active');
			}
		}
		function setPager(oEvent) {
			if ($(this).hasClass('pagenum')) {
				iCurrent = parseInt(this.rel) - 1;
				move(1);
			}
			return false;
		}
		function setTimer() {
			if (options.interval && !bPause) {
				clearTimeout(oTimer);
				oTimer = setTimeout(function() {
					iCurrent = !options.rewind && (iCurrent + 1 == iSteps) ? -1
							: iCurrent;
					bForward = iCurrent + 1 == iSteps ? false
							: iCurrent == 0 ? true : bForward;
					move((options.rewind ? (bForward ? 1 : -1) : 1));
				}, options.intervaltime);
			}
		}
		function move(iDirection) {
			if (iCurrent + iDirection > -1 && iCurrent + iDirection < iSteps) {
				iCurrent += iDirection;
				var oPosition = {};
				oPosition[bAxis ? 'left' : 'top'] = -(iCurrent * (iPageSize * options.display));
				oContent.animate(oPosition, {
					queue : false,
					duration : options.animation ? options.duration : 0,
					complete : function() {
						if (typeof options.callback == 'function')
							options.callback.call(this, oPages[iCurrent],
									iCurrent);
					}
				});
				setButtons();
				setTimer();
			}
		}
	};
})(jQuery);

/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 */

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