<!-- jQuery Fade in Logo -->
$(document).ready(function() {
    $('.logo').delay(700).fadeIn(1000);
});

<!-- jQuery Nivo Slider Start -->
$(window).load(function() {
	$('.slider').nivoSlider();
});

<!-- Cufon Font Replacement -->				
jQuery(document).ready(function() { /* Start Tag */
							
Cufon.replace('h1,h2,h3,h4,h5,h6,.tabnav li a,#wp-calendar caption,ol.commentlist li div.comment-author a,#wp-calendar caption,ol.commentlist li div.comment-author,ol.commentlist li div.vcard span.says, h2.trigger a', {
fontFamily: 'Aaargh',
color: '#333' });

Cufon.replace('h1.red,h2.red,h3.red,h4.red,h5.red,h6.red', {
fontFamily: 'Aaargh',
color: '#CC0000' });

Cufon.replace('.page-wp h1, .page-wp h2,. page-wp h3, .page-wp h1 a, .page-wp h2 a,. page-wp h3 a, .footer-widgets li h4, .footer-widgets li h4 a', {
fontFamily: 'Aaargh',
color: '-linear-gradient(#fff, #ccc)',
textShadow: '0px 1px #444' });

}); /* End Tag, Light to Dark*/


<!-- jQuery Table ZebraStripe and Even Padding Class for 125 Ads -->
$(document).ready(function(){
   $("tr:even").addClass("even");
   $("tr:odd").addClass("odd");
   $(".squarebanner ul li:even").addClass("even");
});



// Scroll to top animation
$(document).ready(function() {
	
    $('a[href=#top]').click(function(){
        $('html, body').animate({scrollTop:0}, 'slow');
        return false;
    });

});



<!-- jQuery Tabs -->
$(document).ready(function() {
	$("#tabzine> ul").tabs({ fx: { opacity: 'toggle' } }).tabs('rotate', 5000); 
	$('#newtabs> ul').tabs({ fx: {  opacity: 'toggle' } }); 

});



<!-- jQuery Social Icon Hover -->
$(document).ready(function() {
  $('#social-icons li a').hover(
  // on mouse over move to left
  function() {
    $(this).stop().animate({ marginTop: '-6px' },200);
  },
  // on mouse out, move back to original position
  function() {
    $(this).stop().animate({ marginTop: '0px' }, 200);
  });
});



<!-- jQuery Search Highlight Start -->
  jQuery.fn.extend({
    highlight: function(search, insensitive, hls_class){
      var regex = new RegExp("(<[^>]*>)|(\\b"+ search.replace(/([-.*+?^${}()|[\]\/\\])/g,"\\$1") +")", insensitive ? "ig" : "g");
      return this.html(this.html().replace(regex, function(a, b, c){
        return (a.charAt(0) == "<") ? a : "<strong class=\""+ hls_class +"\">" + c + "</strong>";
      }));
    }
  });
  jQuery(document).ready(function($){
    if(typeof(hls_query) != 'undefined'){
      $(".container_12").highlight(hls_query, 1, "hls");
    }
  });



<!-- ColorBox jQuery Lightbox -->
$(document).ready(function(){
	$('.gallery a:has(img)').colorbox();
	$(".colorbox").colorbox();
});

$(document).ready(function(){
	//Examples of how to assign the ColorBox event to elements
	$("a[rel='colorbox']").colorbox();
	$("a[rel='colorbox2']").colorbox({transition:"fade"});
	$("a[rel='colorbox3']").colorbox({transition:"none", width:"75%", height:"75%"});
	$("a[rel='colorbox4']").colorbox({slideshow:true});
	$(".colorbox7").colorbox({width:"80%", height:"80%", iframe:true});
	$(".colorboxif").colorbox({iframe:true, innerWidth:800, innerHeight:550});
});


<!-- Initialise Superfish -->
$(document).ready(function(){ 
	$("ul.sf-menu").superfish(); 
}); 

<!-- Initialise Contact Form AJAX -->
//<![CDATA[
jQuery(document).ready(function(){
        
        $('#contactform').submit(function(){
        
                var action = $(this).attr('action');
                
                $('#contactform #submit').attr('disabled','disabled').after('<img src="http://alteredstudio.com/test3/wp-content/themes/simplemachine/images/ajax-loader.gif" class="loader" />');
                
                $("#message").slideUp(750,function() {
                $('#message').hide();                   
                
                $.post(action, { 
                        name: $('#name').val(),
                        email: $('#email').val(),
                        phone: $('#phone').val(),
                        subject: $('#subject').val(),
                        comments: $('#comments').val(),
                        verify: $('#verify').val()
                },
                        function(data){
                                document.getElementById('message').innerHTML = data;
                                $('#message').slideDown('slow');
                                $('#contactform img.loader').fadeOut('fast',function(){$(this).remove()});
                                $('#contactform #submit').attr('disabled',''); 
                                if(data.match('success') != null) $('#contactform').slideUp('slow');
                                
                        }
                );
                
                });
                
                return false; 
        
        });
        
});
//]]>



//<![CDATA[
$(document).ready(function() {
        $('form#contactForm').submit(function() {
                $('form#contactForm .error').remove();
                var hasError = false;
                $('.requiredField').each(function() {
                        if(jQuery.trim($(this).val()) == '') {
                                var labelText = $(this).prev('label').text();
                                $(this).parent().append('<span class="error">You forgot to enter your '+labelText+'.<\/span>');
                                hasError = true;
                        } else if($(this).hasClass('email')) {
                                var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
                                if(!emailReg.test(jQuery.trim($(this).val()))) {
                                        var labelText = $(this).prev('label').text();
                                        $(this).parent().append('<span class="error">You entered an invalid '+labelText+'.<\/span>');
                                        hasError = true;
                                }
                        }
                });
                if(!hasError) {
                        $('form#contactForm li.buttons button').fadeOut('normal', function() {
                                $(this).parent().append('<img src="http://alteredstudio.com/test3/wp-content/themes/simplemachine/images/loading.gif" alt="Loading&hellip;" height="31" width="31" />');
                        });
                        var formInput = $(this).serialize();
                        $.post($(this).attr('action'),formInput, function(data){
                                $('form#contactForm').slideUp("fast", function() {                                 
                                        $(this).before('<p class="thanks"><strong>Thanks!<\/strong> Your email was successfully sent.<\/p>');
                                });
                        });
                }
                
                return false;
                
        });
});
//]]>



<!-- Initialise Supersubs -->
$(document).ready(function(){ 
	$("ul.sf-menu, ul.menu").supersubs({ 
		minWidth:    14,   // minimum width of sub-menus in em units 
		maxWidth:    33,   // maximum width of sub-menus in em units 
		extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
						   // due to slight rounding differences and font-family 
	}).superfish();  // call supersubs first, then superfish, so that subs are 
});



/*
 *  Supersubs v0.2b - jQuery plugin
 *  Copyright (c) 2008 Joel Birch
 */

;(function($){ // $ will refer to jQuery within this closure

	$.fn.supersubs = function(options){
		var opts = $.extend({}, $.fn.supersubs.defaults, options);
		// return original object to support chaining
		return this.each(function() {
			// cache selections
			var $$ = $(this);
			// support metadata
			var o = $.meta ? $.extend({}, opts, $$.data()) : opts;
			// get the font size of menu.
			// .css('fontSize') returns various results cross-browser, so measure an em dash instead
			var fontsize = $('<li id="menu-fontsize">&#8212;</li>').css({
				'padding' : 0,
				'position' : 'absolute',
				'top' : '-999em',
				'width' : 'auto'
			}).appendTo($$).width(); //clientWidth is faster, but was incorrect here
			// remove em dash
			$('#menu-fontsize').remove();
			// cache all ul elements
			$ULs = $$.find('ul');
			// loop through each ul in menu
			$ULs.each(function(i) {	
				// cache this ul
				var $ul = $ULs.eq(i);
				// get all (li) children of this ul
				var $LIs = $ul.children();
				// get all anchor grand-children
				var $As = $LIs.children('a');
				// force content to one line and save current float property
				var liFloat = $LIs.css('white-space','nowrap').css('float');
				// remove width restrictions and floats so elements remain vertically stacked
				var emWidth = $ul.add($LIs).add($As).css({
					'float' : 'none',
					'width'	: 'auto'
				})
				// this ul will now be shrink-wrapped to longest li due to position:absolute
				// so save its width as ems. Clientwidth is 2 times faster than .width() - thanks Dan Switzer
				.end().end()[0].clientWidth / fontsize;
				// add more width to ensure lines don't turn over at certain sizes in various browsers
				emWidth += o.extraWidth;
				// restrict to at least minWidth and at most maxWidth
				if (emWidth > o.maxWidth)		{ emWidth = o.maxWidth; }
				else if (emWidth < o.minWidth)	{ emWidth = o.minWidth; }
				emWidth += 'em';
				// set ul to width in ems
				$ul.css('width',emWidth);
				// restore li floats to avoid IE bugs
				// set li width to full width of this ul
				// revert white-space to normal
				$LIs.css({
					'float' : liFloat,
					'width' : '100%',
					'white-space' : 'normal'
				})
				// update offset position of descendant ul to reflect new width of parent
				.each(function(){
					var $childUl = $('>ul',this);
					var offsetDirection = $childUl.css('left')!==undefined ? 'left' : 'right';
					$childUl.css(offsetDirection,emWidth);
				});
			});
			
		});
	};
	// expose defaults
	$.fn.supersubs.defaults = {
		minWidth		: 13,		// requires em unit.
		maxWidth		: 24,		// requires em unit.
		extraWidth		: 0			// extra width can ensure lines don't sometimes turn over due to slight browser differences in how they round-off values
	};
	
})(jQuery); // plugin code ends



/*
 * hoverIntent
 * hoverIntent by Brian Cherne *
 */

(function($){
	/* hoverIntent by Brian Cherne */
	$.fn.hoverIntent = function(f,g) {
		// default configuration options
		var cfg = {
			sensitivity: 7,
			interval: 100,
			timeout: 0
		};
		// override configuration options with user supplied object
		cfg = $.extend(cfg, g ? { over: f, out: g } : f );

		// instantiate variables
		// cX, cY = current X and Y position of mouse, updated by mousemove event
		// pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
		var cX, cY, pX, pY;

		// A private function for getting mouse position
		var track = function(ev) {
			cX = ev.pageX;
			cY = ev.pageY;
		};

		// A private function for comparing current and previous mouse position
		var compare = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			// compare mouse positions to see if they've crossed the threshold
			if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
				$(ob).unbind("mousemove",track);
				// set hoverIntent state to true (so mouseOut can be called)
				ob.hoverIntent_s = 1;
				return cfg.over.apply(ob,[ev]);
			} else {
				// set previous coordinates for next time
				pX = cX; pY = cY;
				// use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
				ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
			}
		};

		// A private function for delaying the mouseOut function
		var delay = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			ob.hoverIntent_s = 0;
			return cfg.out.apply(ob,[ev]);
		};

		// A private function for handling mouse 'hovering'
		var handleHover = function(e) {
			// next three lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut
			var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
			while ( p && p != this ) { try { p = p.parentNode; } catch(e) { p = this; } }
			if ( p == this ) { return false; }

			// copy objects to be passed into t (required for event object to be passed in IE)
			var ev = jQuery.extend({},e);
			var ob = this;

			// cancel hoverIntent timer if it exists
			if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }

			// else e.type == "onmouseover"
			if (e.type == "mouseover") {
				// set "previous" X and Y position based on initial entry point
				pX = ev.pageX; pY = ev.pageY;
				// update "current" X and Y position based on mousemove
				$(ob).bind("mousemove",track);
				// start polling interval (self-calling timeout) to compare mouse coordinates over time
				if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}

			// else e.type == "onmouseout"
			} else {
				// unbind expensive mousemove event
				$(ob).unbind("mousemove",track);
				// if hoverIntent state is true, then call the mouseOut function after the specified delay
				if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
			}
		};

		// bind the function to the two event listeners
		return this.mouseover(handleHover).mouseout(handleHover);
	};
	
})(jQuery);



/*
 * Superfish v1.4.8 - jQuery menu widget
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 */

;(function($){
	$.fn.superfish = function(op){

		var sf = $.fn.superfish,
			c = sf.c,
			$arrow = $(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
			over = function(){
				var $$ = $(this), menu = getMenu($$);
				clearTimeout(menu.sfTimer);
				$$.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function(){
				var $$ = $(this), menu = getMenu($$), o = sf.op;
				clearTimeout(menu.sfTimer);
				menu.sfTimer=setTimeout(function(){
					o.retainPath=($.inArray($$[0],o.$path)>-1);
					$$.hideSuperfishUl();
					if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}
				},o.delay);	
			},
			getMenu = function($menu){
				var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
				sf.op = sf.o[menu.serial];
				return menu;
			},
			addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); };
			
		return this.each(function() {
			var s = this.serial = sf.o.length;
			var o = $.extend({},sf.defaults,op);
			o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){
				$(this).addClass([o.hoverClass,c.bcClass].join(' '))
					.filter('li:has(ul)').removeClass(o.pathClass);
			});
			sf.o[s] = sf.op = o;
			
			$('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
				if (o.autoArrows) addArrow( $('>a:first-child',this) );
			})
			.not('.'+c.bcClass)
				.hideSuperfishUl();
			
			var $a = $('a',this);
			$a.each(function(i){
				var $li = $a.eq(i).parents('li');
				$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
			});
			o.onInit.call(this);
			
		}).each(function() {
			menuClasses = [c.menuClass];
			if (sf.op.dropShadows  && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
			$(this).addClass(menuClasses.join(' '));
		});
	};

	var sf = $.fn.superfish;
	sf.o = [];
	sf.op = {};
	sf.IE7fix = function(){
		var o = sf.op;
		if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity!=undefined)
			this.toggleClass(sf.c.shadowClass+'-off');
		};
	sf.c = {
		bcClass     : 'sf-breadcrumb',
		menuClass   : 'sf-js-enabled',
		anchorClass : 'sf-with-ul',
		arrowClass  : 'sf-sub-indicator',
		shadowClass : 'sf-shadow'
	};
	sf.defaults = {
		hoverClass	: 'sfHover',
		pathClass	: 'overideThisToUse',
		pathLevels	: 1,
		delay		: 800,
		animation	: {opacity:'show'},
		speed		: 'normal',
		autoArrows	: true,
		dropShadows : false,
		disableHI	: false,		// true disables hoverIntent detection
		onInit		: function(){}, // callback functions
		onBeforeShow: function(){},
		onShow		: function(){},
		onHide		: function(){}
	};
	$.fn.extend({
		hideSuperfishUl : function(){
			var o = sf.op,
				not = (o.retainPath===true) ? o.$path : '';
			o.retainPath = false;
			var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
					.find('>ul').hide().css('visibility','hidden');
			o.onHide.call($ul);
			return this;
		},
		showSuperfishUl : function(){
			var o = sf.op,
				sh = sf.c.shadowClass+'-off',
				$ul = this.addClass(o.hoverClass)
					.find('>ul:hidden').css('visibility','visible');
			sf.IE7fix.call($ul);
			o.onBeforeShow.call($ul);
			$ul.animate(o.animation,o.speed,function(){ sf.IE7fix.call($ul); o.onShow.call($ul); });
			return this;
		}
	});

})(jQuery);



/*
 * jQuery EasIng v1.1.2 - http://gsgd.co.uk/sandbox/jquery.easIng.php
 *
 * Uses the built In easIng capabilities added In jQuery 1.1
 * to offer multiple easIng options
 *
 * Copyright (c) 2007 George Smith
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 */

// t: current time, b: begInnIng value, c: change In value, d: duration

jQuery.extend( jQuery.easing,
{
	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;
	}
});




<!-- Nivo Slider -->

//<![CDATA[
/* jQuery Nivo Slider v2.0 */
/*
 * jQuery Nivo Slider v2.0
 * http://nivo.dev7studios.com
 *
 * Copyright 2010, Gilbert Pellegrom
 * Free to use and abuse under the MIT license.
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * May 2010 - Pick random effect from specified set of effects by toronegro
 * May 2010 - controlNavThumbsFromRel option added by nerd-sh
 * May 2010 - Do not start nivoRun timer if there is only 1 slide by msielski
 * April 2010 - controlNavThumbs option added by Jamie Thompson (http://jamiethompson.co.uk)
 * March 2010 - manualAdvance option added by HelloPablo (http://hellopablo.co.uk)
 */

(function($) {

        $.fn.nivoSlider = function(options) {

                //Defaults are below
                var settings = $.extend({}, $.fn.nivoSlider.defaults, options);

                return this.each(function() {
                        //Useful variables. Play carefully.
                        var vars = {
                                currentSlide: 0,
                                currentImage: '',
                                totalSlides: 0,
                                randAnim: '',
                                running: false,
                                paused: false,
                                stop:false
                        };
                
                        //Get this slider
                        var slider = $(this);
                        slider.data('nivo:vars', vars);
                        slider.css('position','relative');
                        slider.addClass('nivoSlider');
                        
                        //Find our slider children
                        var kids = slider.children();
                        kids.each(function() {
                                var child = $(this);
                                var link = '';
                                if(!child.is('img')){
                                        if(child.is('a')){
                                                child.addClass('nivo-imageLink');
                                                link = child;
                                        }
                                        child = child.find('img:first');
                                }
                                //Get img width and height
                var childWidth = child.width();
                if(childWidth == 0) childWidth = child.attr('width');
                var childHeight = child.height();
                if(childHeight == 0) childHeight = child.attr('height');
                //Resize the slider
                if(childWidth > slider.width()){
                    slider.width(childWidth);
                }
                if(childHeight > slider.height()){
                    slider.height(childHeight);
                }
                if(link != ''){
                    link.css('display','none');
                }
                child.css('display','none');
                vars.totalSlides++;
                        });
                        
                        //Set startSlide
                        if(settings.startSlide > 0){
                                if(settings.startSlide >= vars.totalSlides) settings.startSlide = vars.totalSlides - 1;
                                vars.currentSlide = settings.startSlide;
                        }
                        
                        //Get initial image
                        if($(kids[vars.currentSlide]).is('img')){
                                vars.currentImage = $(kids[vars.currentSlide]);
                        } else {
                                vars.currentImage = $(kids[vars.currentSlide]).find('img:first');
                        }
                        
                        //Show initial link
                        if($(kids[vars.currentSlide]).is('a')){
                                $(kids[vars.currentSlide]).css('display','block');
                        }
                        
                        //Set first background
                        slider.css('background','url('+ vars.currentImage.attr('src') +') no-repeat');
                        
                        //Add initial slices
                        for(var i = 0; i < settings.slices; i++){
                                var sliceWidth = Math.round(slider.width()/settings.slices);
                                if(i == settings.slices-1){
                                        slider.append(
                                                $('<div class="nivo-slice"><\/div>').css({ left:(sliceWidth*i)+'px', width:(slider.width()-(sliceWidth*i))+'px' })
                                        );
                                } else {
                                        slider.append(
                                                $('<div class="nivo-slice"><\/div>').css({ left:(sliceWidth*i)+'px', width:sliceWidth+'px' })
                                        );
                                }
                        }
                        
                        //Create caption
                        slider.append(
                                $('<div class="nivo-caption"><p><\/p><\/div>').css({ display:'none', opacity:settings.captionOpacity })
                        );                      
                        //Process initial  caption
                        if(vars.currentImage.attr('title') != ''){
                                $('.nivo-caption p', slider).html(vars.currentImage.attr('title'));                                     
                                $('.nivo-caption', slider).fadeIn(settings.animSpeed);
                        }
                        
                        //In the words of Super Mario "let's a go!"
                        var timer = 0;
                        if(!settings.manualAdvance && kids.length > 1){
                                timer = setInterval(function(){ nivoRun(slider, kids, settings, false); }, settings.pauseTime);
                        }

                        //Add Direction nav
                        if(settings.directionNav){
                                slider.append('<div class="nivo-directionNav"><a class="nivo-prevNav">Prev<\/a><a class="nivo-nextNav">Next<\/a><\/div>');
                                
                                //Hide Direction nav
                                if(settings.directionNavHide){
                                        $('.nivo-directionNav', slider).hide();
                                        slider.hover(function(){
                                                $('.nivo-directionNav', slider).show();
                                        }, function(){
                                                $('.nivo-directionNav', slider).hide();
                                        });
                                }
                                
                                $('a.nivo-prevNav', slider).live('click', function(){
                                        if(vars.running) return false;
                                        clearInterval(timer);
                                        timer = '';
                                        vars.currentSlide-=2;
                                        nivoRun(slider, kids, settings, 'prev');
                                });
                                
                                $('a.nivo-nextNav', slider).live('click', function(){
                                        if(vars.running) return false;
                                        clearInterval(timer);
                                        timer = '';
                                        nivoRun(slider, kids, settings, 'next');
                                });
                        }
                        
                        //Add Control nav
                        if(settings.controlNav){
                                var nivoControl = $('<div class="nivo-controlNav"><\/div>');
                                slider.append(nivoControl);
                                for(var i = 0; i < kids.length; i++){
                                        if(settings.controlNavThumbs){
                                                var child = kids.eq(i);
                                                if(!child.is('img')){
                                                        child = child.find('img:first');
                                                }
                        if (settings.controlNavThumbsFromRel) {
                            nivoControl.append('<a class="nivo-control" rel="'+ i +'"><img src="'+ child.attr('rel') + '" alt="" /><\/a>');
                        } else {
                            nivoControl.append('<a class="nivo-control" rel="'+ i +'"><img src="'+ child.attr('src').replace(settings.controlNavThumbsSearch, settings.controlNavThumbsReplace) +'" alt="" /><\/a>');
                        }
                                        } else {
                                                nivoControl.append('<a class="nivo-control" rel="'+ i +'">'+ i +'<\/a>');
                                        }
                                        
                                }
                                //Set initial active link
                                $('.nivo-controlNav a:eq('+ vars.currentSlide +')', slider).addClass('active');
                                
                                $('.nivo-controlNav a', slider).live('click', function(){
                                        if(vars.running) return false;
                                        if($(this).hasClass('active')) return false;
                                        clearInterval(timer);
                                        timer = '';
                                        slider.css('background','url('+ vars.currentImage.attr('src') +') no-repeat');
                                        vars.currentSlide = $(this).attr('rel') - 1;
                                        nivoRun(slider, kids, settings, 'control');
                                });
                        }
                        
                        //Keyboard Navigation
                        if(settings.keyboardNav){
                                $(window).keypress(function(event){
                                        //Left
                                        if(event.keyCode == '37'){
                                                if(vars.running) return false;
                                                clearInterval(timer);
                                                timer = '';
                                                vars.currentSlide-=2;
                                                nivoRun(slider, kids, settings, 'prev');
                                        }
                                        //Right
                                        if(event.keyCode == '39'){
                                                if(vars.running) return false;
                                                clearInterval(timer);
                                                timer = '';
                                                nivoRun(slider, kids, settings, 'next');
                                        }
                                });
                        }
                        
                        //For pauseOnHover setting
                        if(settings.pauseOnHover){
                                slider.hover(function(){
                                        vars.paused = true;
                                        clearInterval(timer);
                                        timer = '';
                                }, function(){
                                        vars.paused = false;
                                        //Restart the timer
                                        if(timer == '' && !settings.manualAdvance){
                                                timer = setInterval(function(){ nivoRun(slider, kids, settings, false); }, settings.pauseTime);
                                        }
                                });
                        }
                        
                        //Event when Animation finishes
                        slider.bind('nivo:animFinished', function(){ 
                                vars.running = false; 
                                //Hide child links
                                $(kids).each(function(){
                                        if($(this).is('a')){
                                                $(this).css('display','none');
                                        }
                                });
                                //Show current link
                                if($(kids[vars.currentSlide]).is('a')){
                                        $(kids[vars.currentSlide]).css('display','block');
                                }
                                //Restart the timer
                                if(timer == '' && !vars.paused && !settings.manualAdvance){
                                        timer = setInterval(function(){ nivoRun(slider, kids, settings, false); }, settings.pauseTime);
                                }
                                //Trigger the afterChange callback
                                settings.afterChange.call(this);
                        });
                });
                
                function nivoRun(slider, kids, settings, nudge){
                        //Get our vars
                        var vars = slider.data('nivo:vars');
                        if((!vars || vars.stop) && !nudge) return false;
                        
                        //Trigger the beforeChange callback
                        settings.beforeChange.call(this);
                                        
                        //Set current background before change
                        if(!nudge){
                                slider.css('background','url('+ vars.currentImage.attr('src') +') no-repeat');
                        } else {
                                if(nudge == 'prev'){
                                        slider.css('background','url('+ vars.currentImage.attr('src') +') no-repeat');
                                }
                                if(nudge == 'next'){
                                        slider.css('background','url('+ vars.currentImage.attr('src') +') no-repeat');
                                }
                        }
                        vars.currentSlide++;
                        if(vars.currentSlide == vars.totalSlides){ 
                                vars.currentSlide = 0;
                                //Trigger the slideshowEnd callback
                                settings.slideshowEnd.call(this);
                        }
                        if(vars.currentSlide < 0) vars.currentSlide = (vars.totalSlides - 1);
                        //Set vars.currentImage
                        if($(kids[vars.currentSlide]).is('img')){
                                vars.currentImage = $(kids[vars.currentSlide]);
                        } else {
                                vars.currentImage = $(kids[vars.currentSlide]).find('img:first');
                        }
                        
                        //Set acitve links
                        if(settings.controlNav){
                                $('.nivo-controlNav a', slider).removeClass('active');
                                $('.nivo-controlNav a:eq('+ vars.currentSlide +')', slider).addClass('active');
                        }
                        
                        //Process caption
                        if(vars.currentImage.attr('title') != ''){
                                if($('.nivo-caption', slider).css('display') == 'block'){
                                        $('.nivo-caption p', slider).fadeOut(settings.animSpeed, function(){
                                                $(this).html(vars.currentImage.attr('title'));
                                                $(this).fadeIn(settings.animSpeed);
                                        });
                                } else {
                                        $('.nivo-caption p', slider).html(vars.currentImage.attr('title'));
                                }                                       
                                $('.nivo-caption', slider).fadeIn(settings.animSpeed);
                        } else {
                                $('.nivo-caption', slider).fadeOut(settings.animSpeed);
                        }
                        
                        //Set new slice backgrounds
                        var  i = 0;
                        $('.nivo-slice', slider).each(function(){
                                var sliceWidth = Math.round(slider.width()/settings.slices);
                                $(this).css({ height:'0px', opacity:'0', 
                                        background: 'url('+ vars.currentImage.attr('src') +') no-repeat -'+ ((sliceWidth + (i * sliceWidth)) - sliceWidth) +'px 0%' });
                                i++;
                        });
                        
                        if(settings.effect == 'random'){
                                var anims = new Array("sliceDownRight","sliceDownLeft","sliceUpRight","sliceUpLeft","sliceUpDown","sliceUpDownLeft","fold","fade");
                                vars.randAnim = anims[Math.floor(Math.random()*(anims.length + 1))];
                                if(vars.randAnim == undefined) vars.randAnim = 'fade';
                        }
            
            //Run random effect from specified set (eg: effect:'fold,fade')
            if(settings.effect.indexOf(',') != -1){
                var anims = settings.effect.split(',');
                vars.randAnim = $.trim(anims[Math.floor(Math.random()*anims.length)]);
            }
                
                        //Run effects
                        vars.running = true;
                        if(settings.effect == 'sliceDown' || settings.effect == 'sliceDownRight' || vars.randAnim == 'sliceDownRight' ||
                                settings.effect == 'sliceDownLeft' || vars.randAnim == 'sliceDownLeft'){
                                var timeBuff = 0;
                                var i = 0;
                                var slices = $('.nivo-slice', slider);
                                if(settings.effect == 'sliceDownLeft' || vars.randAnim == 'sliceDownLeft') slices = $('.nivo-slice', slider).reverse();
                                slices.each(function(){
                                        var slice = $(this);
                                        slice.css('top','0px');
                                        if(i == settings.slices-1){
                                                setTimeout(function(){
                                                        slice.animate({ height:'100%', opacity:'1.0' }, settings.animSpeed, '', function(){ slider.trigger('nivo:animFinished'); });
                                                }, (100 + timeBuff));
                                        } else {
                                                setTimeout(function(){
                                                        slice.animate({ height:'100%', opacity:'1.0' }, settings.animSpeed);
                                                }, (100 + timeBuff));
                                        }
                                        timeBuff += 50;
                                        i++;
                                });
                        } 
                        else if(settings.effect == 'sliceUp' || settings.effect == 'sliceUpRight' || vars.randAnim == 'sliceUpRight' ||
                                        settings.effect == 'sliceUpLeft' || vars.randAnim == 'sliceUpLeft'){
                                var timeBuff = 0;
                                var i = 0;
                                var slices = $('.nivo-slice', slider);
                                if(settings.effect == 'sliceUpLeft' || vars.randAnim == 'sliceUpLeft') slices = $('.nivo-slice', slider).reverse();
                                slices.each(function(){
                                        var slice = $(this);
                                        slice.css('bottom','0px');
                                        if(i == settings.slices-1){
                                                setTimeout(function(){
                                                        slice.animate({ height:'100%', opacity:'1.0' }, settings.animSpeed, '', function(){ slider.trigger('nivo:animFinished'); });
                                                }, (100 + timeBuff));
                                        } else {
                                                setTimeout(function(){
                                                        slice.animate({ height:'100%', opacity:'1.0' }, settings.animSpeed);
                                                }, (100 + timeBuff));
                                        }
                                        timeBuff += 50;
                                        i++;
                                });
                        } 
                        else if(settings.effect == 'sliceUpDown' || settings.effect == 'sliceUpDownRight' || vars.randAnim == 'sliceUpDown' || 
                                        settings.effect == 'sliceUpDownLeft' || vars.randAnim == 'sliceUpDownLeft'){
                                var timeBuff = 0;
                                var i = 0;
                                var v = 0;
                                var slices = $('.nivo-slice', slider);
                                if(settings.effect == 'sliceUpDownLeft' || vars.randAnim == 'sliceUpDownLeft') slices = $('.nivo-slice', slider).reverse();
                                slices.each(function(){
                                        var slice = $(this);
                                        if(i == 0){
                                                slice.css('top','0px');
                                                i++;
                                        } else {
                                                slice.css('bottom','0px');
                                                i = 0;
                                        }
                                        
                                        if(v == settings.slices-1){
                                                setTimeout(function(){
                                                        slice.animate({ height:'100%', opacity:'1.0' }, settings.animSpeed, '', function(){ slider.trigger('nivo:animFinished'); });
                                                }, (100 + timeBuff));
                                        } else {
                                                setTimeout(function(){
                                                        slice.animate({ height:'100%', opacity:'1.0' }, settings.animSpeed);
                                                }, (100 + timeBuff));
                                        }
                                        timeBuff += 50;
                                        v++;
                                });
                        } 
                        else if(settings.effect == 'fold' || vars.randAnim == 'fold'){
                                var timeBuff = 0;
                                var i = 0;
                                $('.nivo-slice', slider).each(function(){
                                        var slice = $(this);
                                        var origWidth = slice.width();
                                        slice.css({ top:'0px', height:'100%', width:'0px' });
                                        if(i == settings.slices-1){
                                                setTimeout(function(){
                                                        slice.animate({ width:origWidth, opacity:'1.0' }, settings.animSpeed, '', function(){ slider.trigger('nivo:animFinished'); });
                                                }, (100 + timeBuff));
                                        } else {
                                                setTimeout(function(){
                                                        slice.animate({ width:origWidth, opacity:'1.0' }, settings.animSpeed);
                                                }, (100 + timeBuff));
                                        }
                                        timeBuff += 50;
                                        i++;
                                });
                        }  
                        else if(settings.effect == 'fade' || vars.randAnim == 'fade'){
                                var i = 0;
                                $('.nivo-slice', slider).each(function(){
                                        $(this).css('height','100%');
                                        if(i == settings.slices-1){
                                                $(this).animate({ opacity:'1.0' }, (settings.animSpeed*2), '', function(){ slider.trigger('nivo:animFinished'); });
                                        } else {
                                                $(this).animate({ opacity:'1.0' }, (settings.animSpeed*2));
                                        }
                                        i++;
                                });
                        }
                }
        };
        

        
        $.fn.reverse = [].reverse;
        
})(jQuery);
//]]>

<!-- Nivo Slider Settings -->
$.fn.nivoSlider.defaults = {
	effect: 'fade',
	slices: 10,
	animSpeed: 400 ,
	pauseTime : 8000 ,
	startSlide : 0,
	directionNav : true,
	directionNavHide : true,
	controlNav: false,
	controlNavThumbs: false,
	controlNavThumbsFromRel: false,
	controlNavThumbsSearch: '.jpg',
	controlNavThumbsReplace: '_thumb.jpg',
	keyboardNav: true,
	pauseOnHover: true,
	manualAdvance: false,
	captionOpacity: 0,
	beforeChange: function() {},
	afterChange: function() {},
	slideshowEnd: function() {}
}; 
