$anime = {

	// set initial values to false
	context: false,
	tabs: false,
	acTa: false,
	anObOuSeTy: false,
	anObOuSe: false,

	anObCoSeTy: false,
	anObCoSe: false,

	anObToAnItsRe: false,
	anItsSeTy: false,
	anItsSe: false,

	// animation
	timeout: false,
	slideSpeed: false,
	tabSpeed: false,
	fx: false,

	// hover control
  paOnPaHo: false,
  pa: false,

	// navigation tabs
	naTasEl: false,
	naTasSeTy: false,
	naTasSe: false,

	// navigation tab
	naTaEl: false,
	naTasToTaRe: false,

	// navigation buttons
	naBusHt: false,
	naBusEl: false,
	naBusSeTy: false,
	naBusSe: false,
	naBusSeTyHt: false,
	naBusExCl: false,
	naBusExClHt: false,

	acTaCl: false,

	prev: false,
	prevSeTy: false,
	prevSe: false,
	next: false,
	nextSeTy: false,
	nextSe: false,
	paPlSeTy: false,
	paPlSe: false,
	paCl: false,
	plCl: false,

	prevHt: false,
	nextHt: false,
	paPlH: false,
	naAllBusHt: false,

	// set the context to help speed up selectors/improve performancez
	init: function(pAnimeObject, pAnObOuSeTy, pAnObOuSe) {

	  // SET DEFAULTS

	  // set the context to help speed up selectors/improve performance
	  this.context = pAnimeObject;
	  this.anObOuSeTy = pAnObOuSeTy; // animated object outer selecter type  (id='#' or class='.')
	  this.anObOuSe = pAnObOuSe; 		// 		"					"			"			"

	  // animation
		this.fx = 'fade';   		// the slide effect to use
		this.timeout = 6000;		// time before next slide appears (in ms)
		this.slideSpeed = 1000;	// time it takes to slide in each slide (in ms)
		this.tabSpeed = 300;   	// " 		" 	" 		" 	" 	" 	" 		" 		" when clicking through tabs

		// hover control
		this.paOnPaHo = true;	// pause on pager hover
		this.pa = true;				// pause on hover

	  // structure
		this.anObCoSeTy = '.'; // animated object container selecter type
		this.anObCoSe = 'gics'; // 		"					"			"			"

		this.anObToAnItsRe = ' '; 	// animated object to aniamted items relation
		this.anItsSeTy = '.';		 		// animated items selecter type
		this.anItsSe = 'gici > ul'; 	// 		"				"			"

		// navigation tabs
		this.naTasEl = 'ul';	// navigation tabs element
		this.naTasSeTy = '.';	// 		"					"	 selecter type
		this.naTasSe = 'gins';	// 		"					"	 selecter

		this.naTasToTaRe = ' ';	// 	"					"	 to tab element relation
		this.naTaEl = 'li';    	// 	"					"	 element

		// navigation buttons
		this.naBusEl = 'ul';   				// navigation buttons element
		this.naBusSeTy = '.';    			// 		"					"	 	 selecter type
		this.naBusSe = 'ginbs';    	// 		"					"	 	 selecter
		this.naBusExCl = 'clearfix'; 	// 		"					"	 	 extra class

		this.acTaCl = 'on';

		this.prevSeTy = '.';   				// previous selecter type
		this.prevSe = 'prev';   			// 		"			"
		this.nextSeTy = '.';   				// next selecter type
		this.nextSe = 'next';   			// 		"			"
		this.paPlSeTy = '.';					// pausePlay selecter type
		this.paPlSe = 'pausePlay';		// 		"			"
		this.paCl = 'pause',  				// pause class
		this.plCl = 'play',  					// play class

		this.prevHt = '<li class="ginbi prev"><a href="#">Previous</a><span>&nbsp;</span></li>';   // html to insert for previous button
		this.nextHt = '<li class="ginbi next"><a href="#">Next</a><span>&nbsp;</span></li>';   // html to insert for next button
		this.paPlH = '<li class="ginbi pausePlay play"><a href="#">Pause/Play</a><span>&nbsp;</span></li>';   // thtml to insert for pausePlay button


		// SETTINGS BY ANIMATION TYPE
		if($(this.anObCoSeTy + this.anObCoSe, this.context).parents(this.anObOuSeTy + this.anObOuSe).is('.ani_ss_t1')) {
			// example below
			//this.fx = 'scrollLeft';
		} else if($(this.anObCoSeTy + this.anObCoSe, this.context).parents(this.anObOuSeTy + this.anObOuSe).is('.ani_ss_t2')) {
			// example below
			this.fx = 'fade';
			this.timeout = 0;
			this.slideSpeed = 0;
			this.tabSpeed = 0;
		}

	  // set tabs to current hard coded navigation items
	  $anime.tabs = $(this.naTasEl + this.naTasSeTy + this.naTasSe + this.naTasToTaRe + this.naTaEl, this.context);

	  // remove hard coded navigation items from DOM 
	  // because they aren't hooked up to jQuery cycle and will be re-inserted later
	  this.tabs.remove();
	  
		// build the navigation buttons containing element html
		// if the selector type is an id
		if (this.naBusSeTy == '#') {
			this.naBusSeTyHt = 'id';
			this.naBusExClHt = '" class="' + this.naBusExCl;
		// if the selector type is a class
		} else {
			this.naBusSeTyHt = 'class';
			this.naBusExClHt =  ' ' + this.naBusExCl + '"';
		}
		// the navigation buttons container html
		this.naBusHt = '<' + this.naBusEl + ' ' + this.naBusSeTyHt + '="' + this.naBusSe + this.naBusExClHt;    
		
		// set the previous and next buttons
		this.prev = this.prevSeTy + this.prevSe;
		this.next = this.nextSeTy + this.nextSe;

		// build the all buttons html to insert 
		this.naAllBusHt = this.prevHt + this.nextHt + this.paPlH;

	  // insert nav buttons container code after the main nav element
		$(this.naTasEl + this.naTasSeTy + this.naTasSe, this.context).after(this.naBusHt);
	
	  // insert nav buttons code into the nav buttons container
		$(this.naBusSeTy + this.naBusSe, this.context).append(this.naAllBusHt);
	
	  // need to set object id as value to pas to click toggle function
	  // otherwise refernce is passed which will be reset to last id in final pass
		var anObId = $(this.anObCoSeTy + this.anObCoSe, this.context).attr('id');

	  // prepare animation and jQuery cycle tabs
	  this.prepareAnimation();

		// 	pause/play toggle element
		$(this.paPlSeTy + this.paPlSe, this.context).toggle(function() {

			// 	pause cycle	
  		$('#' + anObId + $anime.anObToAnItsRe + $anime.anItsSeTy + $anime.anItsSe).cycle('pause');

			// 	amend classes to show paused
			$(this).addClass($anime.paCl);
			$(this).removeClass($anime.plCl);

		}, function() {

			// 	resume cycle	
  		$('#' + anObId + $anime.anObToAnItsRe + $anime.anItsSeTy + $anime.anItsSe).cycle('resume', true);

			// 	amend classes to show playing
			$(this).addClass($anime.plCl);
			$(this).removeClass($anime.paCl);

		}); 
	
	},
    
	prepareAnimation: function() {
	  // initialise the jquery cycle plugin -
	  // for information on the options set below go to: 
	  // http://malsup.com/jquery/cycle/options.html
	  $('#' + $(this.anObCoSeTy + this.anObCoSe, this.context).attr('id') + this.anObToAnItsRe + this.anItsSeTy + this.anItsSe).cycle({
	    fx: this.fx,
	    prev: $(this.prev, this.context),
	    next: $(this.next, this.context),
	    timeout: this.timeout,
	    speed: this.slideSpeed,
	    fastOnEvent: this.tabSpeed,
	    pager: $(this.naTasEl + this.naTasSeTy + this.naTasSe, this.context),
	    pagerAnchorBuilder: this.prepareTabs,
	    before: this.activateTab,
	    pauseOnPagerHover: this.paOnPaHo,
	    pause: this.pa
	  });  
           
	},
	
	prepareTabs: function(i, slide) {
	  // return markup from hardcoded tabs for use as jQuery cycle tabs
	  // (attaches necessary jQuery cycle events to tabs)
	  return $anime.tabs.eq(i);
	},

    activateTab: function(currentSlide, nextSlide) {
    	// get the active tab
			var acTa = $('a[href="#' + nextSlide.id + '"]', $(this).parents($anime.anObCoSeTy + $anime.anObCoSe));
	
			//if there is an active tab
			if(acTa.length) {
				// remove active styling from all other tabs
				$('#' + $(this).parents($anime.anObCoSeTy + $anime.anObCoSe).attr('id') + ' ' + $anime.naTasEl + $anime.naTasSeTy + $anime.naTasSe + $anime.naTasToTaRe + $anime.naTaEl).removeClass($anime.acTaCl);
		    
		    // add active styling to active button
		    acTa.parent().addClass($anime.acTaCl);
			}
    }
};

$(function() {
	// add a 'js' class to the body
	$('body').addClass('js');

	// selector to trigger animation object within
	var anObOuSeTy = '.';
	var anObOuSe = 'ani_ss';

	// initiate animation for each found
	$(anObOuSeTy + anObOuSe).each(function(){
		$anime.init(this, anObOuSeTy, anObOuSe);
	});

});  
