/**
 * ma_behavior.js
 * bestehend aus Tabs, Accordion und Slider
 */


// *********************************************************************************************************************
// TABS


/**
 * YAML Tabs - jQuery plugin for accessible, unobtrusive tabs
 * Build to seemlessly work with the CCS-Framework YAML (yaml.de) not depending on YAML though
 * @requires jQuery v1.0.3
 *
 * http://blog.ginader.de/dev/yamltabs/index.php
 *
 * Copyright (c) 2007 Dirk Ginader (ginader.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * Version: 1.1.1
 * 
 * History:
 * * 1.0 initial release
 * * 1.1 added a lot of Accessibility enhancements
 * * * rewrite to use "fn.extend" structure
 * * * added check for existing ids on the content containers to use to proper anchors in the tabs
 * * 1.1.1 changed the headline markup. thanks to Mike Davies for the hint.
 * 
 * Angepasst von Fabian Künzel {fkblog.de} zwecks Listen nutzung im Tab Content 
 */



(function(jQuery) {
    
    jQuery.fn.extend({
        getUniqueId: function(p){
            return p + new Date().getTime();
        },
        accessibleTabs: function(config) {
            var defaults = {
                wrapperClass: 'content', // Classname to apply to the div that is wrapped around the original Markup
                currentClass: 'current', // Classname to apply to the LI of the selected Tab
                tabhead: 'h4', // Tag or valid Query Selector of the Elements to Transform the Tabs-Navigation from (originals are removed)
                tabbody: '.tabbody', // Tag or valid Query Selector of the Elements to be treated as the Tab Body
                fx:'fadeIn', // can be "fadeIn", "slideDown", "show"
                fxspeed: 'slow', // speed (String|Number): "slow", "normal", or "fast") or the number of milliseconds to run the animation
                //currentInfoText: 'current tab: ', // text to indicate for screenreaders which tab is the current one
                currentInfoText: 'Aktuelles ', // text to indicate for screenreaders which tab is the current one
                currentInfoPosition: 'prepend', // Definition where to insert the Info Text. Can be either "prepend" or "append"
                currentInfoClass: 'current-info' // Class to apply to the span wrapping the CurrentInfoText
            };
            var options = jQuery.extend(defaults, config);
            var o = this;
            
            // Script-Fehler bei "Warnung: Unbekannte Pseudoklasse oder Pseudoelement 'gt'.  Falsch verwendeter Kombinator."
            // :gt(0) wäre zu prüfen!!!
            $(options.tabbody+">.content-element-content:gt(0)").animate({ height: 'toggle'}, 10, function() {
						    // Animation complete.
						  }
						);
            
            
            return this.each(function() {
                var el = jQuery(this);
                var list = '';

                var contentAnchor = o.getUniqueId('accessibletabscontent');
                var tabsAnchor = o.getUniqueId('accessibletabs');
                jQuery(el).wrapInner('<div class="'+options.wrapperClass+'"></div>');

                jQuery(el).find(options.tabhead).each(function(i){
                    var id = '';
                    if(i === 0){
                        id =' id="'+tabsAnchor+'"';
                    }
                    list += '<li><a'+id+' href="#'+contentAnchor+'" title="Tab: '+$(this).text()+'">'+$(this).text()+'</a></li>';
                    //$(this).remove();
                    $(this).parent().remove();
                });

                jQuery(el).prepend('<div class="tabfield"><ul class="tabfield">'+list+'</ul><div class="clearer clearer-keep"><br clear="all"/></div></div>');
                //jQuery(el).find(options.tabbody+':first').before('<ul class="tabfield">'+list+'</ul>');
								//jQuery('.tabfield').css('border', '2px solid red');

                //hide all the tabbodys
                jQuery(el).find(options.tabbody).hide();
                jQuery(el).find(options.tabbody).parent().hide();

                // FIRST/"active at the beginning" tabbody anzeigen
                //jQuery(el).find(options.tabbody+':first').show().before('<'+options.tabhead+'><a tabindex="0" class="accessibletabsanchor" name="'+contentAnchor+'" id="'+contentAnchor+'">'+$(el).find("ul>li:first").text()+'</a></'+options.tabhead+'>');
                jQuery(el).find(options.tabbody+':first').show();
                jQuery(el).find(options.tabbody+':first').parent().show();

                // Kennzeichnung des aktiven Tabs
                jQuery(el).find("ul>li:first").addClass(options.currentClass);
                //.find('a')[options.currentInfoPosition]('<span class="'+options.currentInfoClass+'">'+options.currentInfoText+'</span>');
                //jQuery(el).find("ul>li:first").attr('title', (options.currentInfoText + jQuery(this).attr('title')) ).addClass(options.currentClass); 
								jQuery(el).find('ul>li.current>a').attr('title', (options.currentInfoText + jQuery(el).find('ul>li.current>a').attr('title')) ); 

                jQuery(el).find('ul>li>a').each(function(i){
                    jQuery(this).click(function(event){
                   	
                        event.preventDefault();
                        
                        //alert("hier" + (jQuery(el).find(options.tabbody+':visible').index(this)-1) + " - " + i + " - " + jQuery(el).find(options.tabbody+':visible').attr('id') + " " + jQuery(el).find(options.tabbody).eq(i).attr('id') );
												if(	jQuery(el).find(options.tabbody+':visible').attr('id') != jQuery(el).find(options.tabbody).eq(i).attr('id') ){

	                        //jQuery(this).attr('title', 'no title');
	                        //jQuery(el).find('ul>li.current>a').attr('title', 'reseted title');
	                        jQuery(el).find('ul>li.current>a').attr('title', jQuery(el).find('ul>li.current>a').attr('title').substring(options.currentInfoText.length) );

	                        jQuery(el).find('ul>li.current').removeClass(options.currentClass);
	                        //.find("span."+options.currentInfoClass).remove();
	                        
	                        
	                        jQuery(this).blur();

													// Original-"FX"
	                        //jQuery(el).find(options.tabbody).eq(i)[options.fx](options.fxspeed);
                        
	                        jQuery(el).find(options.tabbody+':visible').animate({ height: 'toggle' }, {
														duration: 1000,
														step: function(now, fx){
														},
														complete: function() {
															$(this).hide();
															$(this).parent().hide();
															//$(this).before( jQuery(el).find(options.tabbody).eq(i) );
														}
														
													});
											
													jQuery(el).find(options.tabbody).eq(i).parent().show();
													jQuery(el).find(options.tabbody).eq(i).animate({ height: 'toggle' }, {
														duration: 1000,
														step: function(now, fx){
														},
														complete: function() {
															$(this).show();
															
														}
														
													});

	                        jQuery( '#'+contentAnchor ).text( jQuery(this).text() ).focus();
	                        //jQuery(this)[options.currentInfoPosition]('<span class="'+options.currentInfoClass+'">'+options.currentInfoText+'</span>').parent().addClass(options.currentClass);
	                        jQuery(this).attr('title', (options.currentInfoText + jQuery(this).attr('title')) ).parent().addClass(options.currentClass); 

												}

                        
                    });
                });
            });
        }
    });
})(jQuery);


// TABS - end.
// *********************************************************************************************************************



// *********************************************************************************************************************
// SLIDER

(function($) {
  $.fn.ContentSlider = function(options)
  {
    var defaults = {
      leftBtn : 'fileadmin/media-arts-online/templates/media/images/h2-pfeile-systemhaus_l.jpg',
      rightBtn : 'fileadmin/media-arts-online/templates/media/images/h2-pfeile-systemhaus.jpg',
      width : '500px',
      height : '200px',
      speed : 8000,
      easing : 'easeOutQuad',
      textResize : false,
      IE_h2 : '26px',
      IE_p : '11px',
      loop_type: 'tennis',
      autoplay: false,
      autoplay_capterinterval: 8000
    }
    var defaultWidth = defaults.width;
    var o = $.extend(defaults, options);
    var w = parseInt(o.width);
    var n = this.children('.cs_wrapper').children('.cs_slider').children('.cs_article').length;
    var firstcsarticle = this.children('.cs_wrapper').children('.cs_slider').children('.cs_article').eq(0).attr('id');
    //alert(firstcsarticle);
    //var firstcsarticle = this.children('.cs_wrapper').children('.cs_slider').children('.cs_article').attr('id');
    var x = -1*w*n+w; // Minimum left value
    var p = parseInt(o.width)/parseInt(defaultWidth);
    var thisInstance = this.attr('id');
    var inuse = false; // Prevents colliding animations
    var timeout;
    var autodirection = 'left';
    var autostep = "leer";
    var currentposition = 0;
		var anchorcsarticle = "-3";

		$(this).parent().parent().find('.slider-chapter-menue').children('li').children('a').toggleClass("aactive", false);
		$(this).parent().parent().find('.slider-chapter-menue').children('li').children('#link'+currentposition).toggleClass("aactive", true);


		if(document.location.hash.substr(1,10) == 'cs_article' ){
			//alert(document.location.hash.substr(11));
			anchorcsarticle = document.location.hash.substr(11);
			//alert(anchorcsarticle);
			//window.location.href = "#top";
			//alert(thisInstance);
			//window.location.hash = "#cs_article5";
			

			if( (anchorcsarticle < firstcsarticle.substr(10)) || (anchorcsarticle > (parseInt(firstcsarticle.substr(10)) + n)) ){
				//alert(firstcsarticle.substr(10) + " - " + anchorcsarticle + " - " + (parseInt(firstcsarticle.substr(10)) + n) );
				anchorcsarticle = "-3";
			}
			else{
				//alert("#" + firstcsarticle);
				//window.location.hash = "#" + this.children('.cs_wrapper').children('.cs_slider').children('.cs_article')[0].attr('id');
				window.location.hash = "#" + firstcsarticle;				
				//window.location.hash = "#default";
			}
			
		}else{
			anchorcsarticle = "-3";
		}

//alert(anchorcsarticle);
// INITIALISIERNUNG
		if(o.autoplay == true){
			clearTimeout(timeout);
			

			$('#'+thisInstance+' .cs_leftBtn').parent().parent().find('.slider-chapter-menue').children('li').children('#link'+currentposition).toggleClass("aactive", true);



			if(anchorcsarticle != "-3"){
				first_autoplay_capterinterval = 100;
				//alert(anchorcsarticle);
			}
			else{
				first_autoplay_capterinterval = o.autoplay_capterinterval;
			}

				timeout = setTimeout(function(){
					// automatisches Auslösen der Blätter-Button anhand der Richtung autodirection
					if(autodirection!='left'){
						$('#'+thisInstance+' .cs_leftBtn').click();
					}else{
						$('#'+thisInstance+' .cs_rightBtn').click();
					}
				}, first_autoplay_capterinterval);

		}	

// INITIALISIERNUNG - end.





    function moveSlider(d, b, step){

			//maalert('test'+thisInstance);



    
			//alert(anchorcsarticle);

			// entsprechend 'anchorcsarticle' bewegen
			if(anchorcsarticle != "-3" && isNaN(step) ){
				//alert(anchorcsarticle);
				//alert(firstcsarticle.substr(10));
				step = parseInt(anchorcsarticle)-firstcsarticle.substr(10);
				//alert(step);		
				//anchorcsarticle = "";
			}else{
				// USER-Auswahl über chaptermenue hat Vorang (anchorcsarticle-Reset)!!!
				anchorcsarticle == "-3"	;
			}

			//alert(step);

    	//alert(thisInstance);
      var l = parseInt(b.siblings('.cs_wrapper').children('.cs_slider').css('left'));
      if(isNaN(l)) {
        var l = 0;
      }


/*
if(!isNaN(step) && is/clearTimeout(timeout);
	//autostep AUF step uebertragen
	step = autostep;
	//m=0;
	d='right';
	//b='';
	// autostep zuruecksetzen
	autostep = "leer";

}
*/




var m = 0;
// IST KEINE MANUELLE AUSWAHL/ZIEL per step AKTIV...
if (isNaN(step)){
	// ...STANDARD-VORGANG
	var m = (d=='left') ? l-w : l+w;
	m = (d=='left') ? l-w : l+w;
	currentposition = Math.abs(m / w);
}
else{
	// MANUELLER VORGANG

	// Eventuell bestehende AUTOMATIC gleich stoppen!!!

	
	//alert(step);
		clearTimeout(timeout);


	m = step*(w*-1);

	/*
	if(currentposition > step){
		autodirection = 'left';
	}
	else{
		autodirection = 'right';
	}
	*/
	currentposition = step;
}


//alert(currentposition);
if(currentposition>=n){
	currentposition = 0;
}


// Richtung-WECHSEL in AUTOMATIC übertragen?
// Konstante richtung für automatisch zurueckspulen???
// -> dann folgende zeile auskommentieren!!!
//autodirection = d;




		// WENN am ANFANG ...
		if(m==0) {
			
			/////
			// Möglichkeit 1 - vorgegebener RICHTUNGSWECHSEL
			autodirection='left';

			//alert(m);
			//m=0;
			// Möglichkeit 1 - vorgegebener RICHTUNGSWECHSEL - end.
			/////
		}

		// WENN am ENDE ...
		//alert(m);
		if(m<x) {
			if(o.loop_type == 'tennis'){
				/////
				// Möglichkeit 1 - vorgegebener RICHTUNGSWECHSEL
				autodirection='right';
	
				//overide wegen nötigem Richtungswechsel
				// gehe zu vorletztem Content
				m=x+w;
				// Möglichkeit 1 - vorgegebener RICHTUNGSWECHSEL - end.
				/////
			}
			else if(o.loop_type == 'rewind'){
				//////
				// Alternativ zum zurueckspuhlen zu 1 - Nur stimmen dann die Buttons nicht !?!?!? Jetzt schon ;)
				autodirection='left';
				m=0;
				// Alternativ zu mzurueckspuhlen zu 1 - end.
				//////
			}			
		}

      //if(m<=0&&m>=x)
      if(m<=0&&m>=x)
      {
        b
          .siblings('.cs_wrapper')
            .children('.cs_slider')
              .animate({ 'left':m+'px' }, o.speed, o.easing, function() {
                inuse=false;
				//setTimeout(, 10000);
// for .slider-chapter-menue
$(this).parent().parent().find('.slider-chapter-menue').children('li').children('a').toggleClass("aactive", false);
$(this).parent().parent().find('.slider-chapter-menue').children('li').children('#link'+currentposition).toggleClass("aactive", true);


				// WENN step keine Number sprich keine MANUELLES Ziel...				
				if ( (isNaN(step) || anchorcsarticle != "-3" ) && o.autoplay == true ){
//alert(anchorcsarticle);
					anchorcsarticle = "-3";


					//alert("timeout set!"+step);
					// ...nächsten Timeout vorsehen:
					clearTimeout(timeout);
					timeout = setTimeout(function(){
						//b.click()}, 3000);
							// automatisches Auslösen der Blätter-Button anhand der Richtung autodirection
							if(autodirection!='left'){
								$('#'+thisInstance+' .cs_leftBtn').click()
							}else{
								$('#'+thisInstance+' .cs_rightBtn').click()
							}
						
						/*
								// Beim Rueckspuhlen immer weiter rightBtn klicken
								if(!isNaN(autostep)) {
									$('#'+thisInstance+' .cs_leftBtn').click()
								}
								else{
									$('#'+thisInstance+' .cs_rightBtn').click()			
								}
						*/
					}, o.autoplay_capterinterval);
}
              });

        if(b.attr('class')=='cs_leftBtn' || m==0) {
          var thisBtn = $('#'+thisInstance+' .cs_leftBtn');
          var otherBtn = $('#'+thisInstance+' .cs_rightBtn');
        } else {
          var thisBtn = $('#'+thisInstance+' .cs_rightBtn');
          var otherBtn = $('#'+thisInstance+' .cs_leftBtn');
        }

		if(m==0||m==x) {
//alert(thisBtn);
          thisBtn.animate({ 'opacity':'0' }, o.speed, o.easing, function() { thisBtn.hide();
			//clearTimeout(timeout);
//		  	alert("test"+m+" - "+x);
		});
        }
        if(otherBtn.css('opacity')=='0') {
          otherBtn.show().animate({ 'opacity':'1' }, { duration:o.speed, easing:o.easing });
        }
      }
    }

///////////////////
// .slider_menu
/*
function activate_slider_menu(b){
	b
	.find('.slider_menu').unbind('click').click(function(){
			//alert("slider_menu" + this.rel + " - currentposition: " + currentposition + inuse);
	
		//$('#info-log').prepend('currentposition' + currentposition + ' - this.rel:' + this.rel + '<br/>');
	
		if (currentposition != n && currentposition != this.rel){
			//$('#info-log').prepend('- - - B E W E G U N G<br/>');
		
			if(inuse===false && $('#sbOverlay').css('display') == 'none' ) {
				if (currentposition < this.rel){
					inuse=true;

					var rightBtn = $(this).children('.cs_rightBtn');
alert("slider_menu" + this.rel + " - currentposition: " + currentposition + inuse +rightBtn);

					moveSlider('left', rightBtn, this.rel);
				}
				else{
					inuse=true;

					var leftBtn = $(this).children('.cs_leftBtn');

					moveSlider('right', leftBtn, this.rel);
				}
	
				//$(this).parent().parent().find('.aactive').toggleClass("aactive");
				//$(this).toggleClass("aactive");
	
			}
		}
		$(this).blur();
		return false; // Keep the link from firing
	});

}
// .slider_menu - end.
///////////////////
*/


    function vCenterBtns(b)
    {
      // Safari and IE don't seem to like the CSS used to vertically center
      // the buttons, so we'll force it with this function
      var mid = parseInt(o.height)/2;
      b
        .find('.cs_leftBtn img').css({ 'top':mid+'px', 'padding':0 }).end()
        .find('.cs_rightBtn img').css({ 'top':mid+'px', 'padding':0 });
    }

		// für alle Slider: !?
    return this.each(function(i) {

			// Problem: findet nur sichtbare und vorhandene .csc-header
      prev_title = $(this).find('.csc-header').eq(i).text();
      next_title = $(this).find('.csc-header').eq(i+1).text();

      
      //temptitle = 'test';


      $(this)
        // Set the width and height of the div to the defined size
        .css({
          width:o.width,
          height:o.height
        });

		 	if(n > 1)
		 	{
       

	      $(this)
	        
	        // Add the buttons to move left and right
	        //.prepend('<a href="#" class="cs_leftBtn" title="zurück zum Inhalt: ' + prev_title + '"><img src="'+o.leftBtn+'" /></a>')
	        .prepend('<a href="#" class="cs_leftBtn" title="zurück zum vorigen Inhalt"><img src="'+o.leftBtn+'" /></a>')
	        
	        //.append('<a href="#" class="cs_rightBtn" title="weiter zum Inhalt: ' + next_title + '"><img src="'+o.rightBtn+'" /></a>');
	        .append('<a href="#" class="cs_rightBtn" title="weiter zum nächsten Inhalt"><img src="'+o.rightBtn+'" /></a>');

			}

      $(this)


        // Dig down to the article div elements
        .find('.cs_article')
          // Set the width and height of the div to the defined size
          .css({
            width:o.width,
            height:o.height
          })
          .end()
        // Animate the entrance of the buttons
        .find('.cs_leftBtn')
          .css('opacity','0')
          .hide()
          .end()
        .find('.cs_rightBtn')
          .hide()
          .animate({ 'width':'show' });

      // Resize the font to match the bounding box
      if(o.textResize===true) {
        var h2FontSize = $(this).find('h2').css('font-size');
        var pFontSize = $(this).find('p').css('font-size');
        $.each(jQuery.browser, function(i) {
          if($.browser.msie) {
             h2FontSize = o.IE_h2;
             pFontSize = o.IE_p;
          }
        });
        $(this).find('h2').css({ 'font-size' : parseFloat(h2FontSize)*p+'px', 'margin-left' : '66%' });
        $(this).find('p').css({ 'font-size' : parseFloat(pFontSize)*p+'px', 'margin-left' : '66%' });
        $(this).find('.readmore').css({ 'font-size' : parseFloat(pFontSize)*p+'px', 'margin-left' : '66%' });
      }

      // Store a copy of the button in a variable to pass to moveSlider()
      var leftBtn = $(this).children('.cs_leftBtn');
      leftBtn.bind('click', function() {
        if(inuse===false && $('#sbOverlay').css('display') == 'none' ) {
          inuse = true;
		  clearTimeout(timeout);

          moveSlider('right', leftBtn);
          //moveSlider('left', rightBtn);

        }
        return false; // Keep the link from firing
      });

      // Store a copy of the button in a variable to pass to moveSlider()
      var rightBtn = $(this).children('.cs_rightBtn');

			// Title setztbar aber hier nicht bekannt???
      //rightBtn.attr('title', $(this).parent().attr('id') );

      rightBtn.bind('click', function() {
        if(inuse===false && $('#sbOverlay').css('display') == 'none' ) {
          inuse=true;
		  clearTimeout(timeout);
          moveSlider('left', rightBtn);
        }
        return false; // Keep the link from firing
      });
	  
	  $(this).bind('mouseover', function() {
			//alert("Mouseover");
			clearTimeout(timeout);
	  });


	  $(this).bind('mouseout', function() {

if(o.autoplay == true){
			clearTimeout(timeout);
			//alert("Mouseout"+autodirection);
			timeout = setTimeout(function(){

/////////////
// NACH MOUSEOUT -> AUTOMATIC wieder anschmeißen!!!
//if(d!='left'){
//	leftBtn.click()
//}else{

// in abhängigkeit der autodirection nach links oder rechts
if(inuse===false && $('#sbOverlay').css('display') == 'none' ) {
	  if(autodirection != 'left') {
		//leftBtn.click()
		moveSlider('right', leftBtn);
	}else{
		//rightBtn.click()
		moveSlider('left', rightBtn);
	}
}
//}
}, o.autoplay_capterinterval);

}

	$('.slider_menu').unbind('click').click(function(){
			//alert("slider_menu" + this.rel + " - currentposition: " + currentposition + inuse);
	
		//$('#info-log').prepend('currentposition' + currentposition + ' - this.rel:' + this.rel + '<br/>');
	
		if (currentposition != n && currentposition != this.rel){
			//$('#info-log').prepend('- - - B E W E G U N G<br/>');
		
			if(inuse===false && $('#sbOverlay').css('display') == 'none' ) {
				if (currentposition < this.rel){
					inuse=true;

					//var rightBtn = $(this).children('.cs_rightBtn');
//alert("slider_menu" + this.rel + " - currentposition: " + currentposition + inuse +rightBtn);

					moveSlider('left', rightBtn, this.rel);
				}
				else{
					inuse=true;

					//var leftBtn = $(this).children('.cs_leftBtn');

					moveSlider('right', leftBtn, this.rel);
				}
	
				//$(this).parent().parent().find('.aactive').toggleClass("aactive");
				//$(this).toggleClass("aactive");
	
			}
		}
		$(this).blur();
		return false; // Keep the link from firing
	});




});


			//activate_slider_menu($(this));
      //vCenterBtns($(this)); // This is a CSS fix function.
    });
  }
})(jQuery)


// SLIDER
// *********************************************************************************************************************


// *********************************************************************************************************************
// SLIDER -> jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/

/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2008 George McGinley Smith
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/

// 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;
	}
});

/*
 *
 * TERMS OF USE - EASING EQUATIONS
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2001 Robert Penner
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
 */
 
// SLIDER -> jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
// *********************************************************************************************************************

