/*
Site: masugadesign.com
File: /assets/js/main.js
===========================================================
masugadesign.com | Copyright 2010-2011
=========================================================== */
$(document).ready( function(){
	
	// Index Slideshow
	$('#client_slides').slides({
		effect: 'fade',
		fadeSpeed: 500,
		crossfade: true,
		preload: true,
		play: 5000,
		pause: 2500,
		hoverPause: true
	});

});

/* ========================================================
	Action Bindings
=========================================================== */

// Uncomment when we add multiple images per portfolio entry.

/*  Click on Portfolio Thumbs */
// $(document).delegate('.highlight-thumb', 'click', function(event) {
// 	event.preventDefault();
// 	slide($(this).attr('href'));
// });
// 
// /*  Mouseover and Mouseout on Portfolio Thumbs */
// $(document).delegate('.highlight-thumb', 'mouseover', function() {
// 	thumbHover($(this).attr('href'), 'in');
// });
// 
// $(document).delegate('.highlight-thumb', 'mouseout', function() {
// 	thumbHover($(this).attr('href'), 'out');
// });

/* ========================================================
	Functions
=========================================================== */

/*  Slide
	Used in portfolio.html
	Takes in a matrix row as 'ref' */
	function slide(ref){
		event.preventDefault();
		if($('.highlight-thumb.' + ref).hasClass('lit')){
			return;
		}
		else {
			$('.highlight-thumb').stop();
			$('.highlight-block:not(.' + ref + ')').fadeOut();
			$('.highlight-block.' + ref).fadeIn();
			$('.highlight-thumb:not(.' + ref + ')').removeClass('lit');
			$('.highlight-thumb.' + ref).addClass('lit');
			$('.highlight-thumb:not(.' + ref + ') img').css("opacity", "0.4");
			$('.highlight-thumb.' + ref + ' img').css("opacity", "1");
		}
	}

/*  ThumbHover
	Used in portfolio.html
	Takes in a matrix row as a 'ref'
	And a direction 'in' or 'out' */
	function thumbHover(ref, direction){
		if($('.highlight-thumb.' + ref).hasClass('lit')){
			return;
		}
		else 
		{
			$('.highlight-thumb.' + ref + ' img').stop();
			if(direction == 'in') {
				$('.highlight-thumb.' + ref + ' img').animate({opacity: 1}, {queue: false, duration: 800});	
			}
			else if(direction == 'out') {
				$('.highlight-thumb.' + ref + ' img').animate({opacity: 0.4}, {queue: false, duration: 800});
			}
		}
	}

/* ========================================================
	Third Party Scripts
=========================================================== */

/**
 * jQuery.LocalScroll - Animated scrolling navigation, using anchors.
 * Copyright (c) 2007-2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 3/10/2008
 * @author Ariel Flesler
 * @version 1.2.5
 **/
;(function($){var g=location.href.replace(/#.*/,''),h=$.localScroll=function(a){$('body').localScroll(a)};h.defaults={duration:1e3,axis:'y',event:'click',stop:1};h.hash=function(a){a=$.extend({},h.defaults,a);a.hash=0;if(location.hash)setTimeout(function(){i(0,location,a)},0)};$.fn.localScroll=function(b){b=$.extend({},h.defaults,b);return(b.persistent||b.lazy)?this.bind(b.event,function(e){var a=$([e.target,e.target.parentNode]).filter(c)[0];a&&i(e,a,b)}):this.find('a').filter(c).bind(b.event,function(e){i(e,this,b)}).end().end();function c(){var a=this;return!!a.href&&!!a.hash&&a.href.replace(a.hash,'')==g&&(!b.filter||$(a).is(b.filter))}};function i(e,a,b){var c=a.hash.slice(1),d=document.getElementById(c)||document.getElementsByName(c)[0],f;if(d){e&&e.preventDefault();f=$(b.target||$.scrollTo.window());if(b.lock&&f.is(':animated')||b.onBefore&&b.onBefore.call(a,e,d,f)===!1)return;if(b.stop)f.queue('fx',[]).stop();f.scrollTo(d,b).trigger('notify.serialScroll',[d]);if(b.hash)f.queue(function(){location=a.hash})}}})(jQuery);

/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Date: 2/19/2008
 * @author Ariel Flesler
 * @version 1.3.3
 */
;(function($){var o=$.scrollTo=function(a,b,c){o.window().scrollTo(a,b,c)};o.defaults={axis:'y',duration:1};o.window=function(){return $($.browser.safari?'body':'html')};$.fn.scrollTo=function(l,m,n){if(typeof m=='object'){n=m;m=0}n=$.extend({},o.defaults,n);m=m||n.speed||n.duration;n.queue=n.queue&&n.axis.length>1;if(n.queue)m/=2;n.offset=j(n.offset);n.over=j(n.over);return this.each(function(){var a=this,b=$(a),t=l,c,d={},w=b.is('html,body');switch(typeof t){case'number':case'string':if(/^([+-]=)?\d+(px)?$/.test(t)){t=j(t);break}t=$(t,this);case'object':if(t.is||t.style)c=(t=$(t)).offset()}$.each(n.axis.split(''),function(i,f){var P=f=='x'?'Left':'Top',p=P.toLowerCase(),k='scroll'+P,e=a[k],D=f=='x'?'Width':'Height';if(c){d[k]=c[p]+(w?0:e-b.offset()[p]);if(n.margin){d[k]-=parseInt(t.css('margin'+P))||0;d[k]-=parseInt(t.css('border'+P+'Width'))||0}d[k]+=n.offset[p]||0;if(n.over[p])d[k]+=t[D.toLowerCase()]()*n.over[p]}else d[k]=t[p];if(/^\d+$/.test(d[k]))d[k]=d[k]<=0?0:Math.min(d[k],h(D));if(!i&&n.queue){if(e!=d[k])g(n.onAfterFirst);delete d[k]}});g(n.onAfter);function g(a){b.animate(d,m,n.easing,a&&function(){a.call(this,l)})};function h(D){var b=w?$.browser.opera?document.body:document.documentElement:a;return b['scroll'+D]-b['client'+D]}})};function j(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);

/** http://wayfarerweb.com/jquery/plugins/simplethumbs/ **/
/**
 * Simplethumbs Gallery
 * Version 0.9.2b
 * Author Abel Mohler
 * Released with the MIT License: http://www.wayfarerweb.com/mit.php
 */
(function(a){a.fn.simplethumbs=function(d,c){var b={slideshow:"",preload:true,activeClass:"active",speed:600,next:"#next-image",prev:"#prev-image",wrap:false,cycle:false,cycleWrap:true,interval:3000,reverse:false,startCycle:"#start-cycle",stopCycle:"#stop-cycle",toggleCycle:"#toggle-cycle",hoverPause:false,callAfter:function(f){},callBefore:function(f){},beforeCycle:function(){},afterCycle:function(){}};if(typeof d=="string"&&typeof c!="undefined"){b[d]=c;d={}}else{if(typeof c=="function"){b.callAfter=c}}d=a.extend(b,d||{});if(d.slideshow==""){return this}if(d.cycle){d.cycleMem=d.wrap}var e=a(d.slideshow).find("img")[0].src;a(d.slideshow).css({position:"relative",lineHeight:0,overflow:"hidden"});a("<img>").attr("src",a(d.slideshow).find("img").attr("src")).appendTo(d.slideshow);a(d.slideshow).find("img").eq(0).css({position:"absolute",top:0,left:0});a(d.slideshow).find("img").eq(1).css({position:"relative"});this.find("a").each(function(){if(d.preload&&this.href){var f=new Image();f.src=this.href}if(this.href==e){a(this).addClass(d.activeClass)}});return this.each(function(){var f=a(this).find("a"),g=false,k,i;f.click(function(){if(!g&&!a(this).hasClass(d.activeClass)){g=true;d.callBefore.call(this,this);var p=this.href,r=this.title,q=false,o=this;var n=a(d.slideshow).find("img").eq(1);if(a(d.slideshow).siblings("#caption").length){q=true}a(d.slideshow).find("img").eq(0).attr("src",p);if(q){a(d.slideshow).siblings("#caption").slideUp("normal")}a(f).removeClass(d.activeClass);a(this).addClass(d.activeClass);a(n).fadeOut(d.speed,function(){a(n).attr("src",p).css("display","block");if(q){a(d.slideshow).siblings("#caption").find("div").text(r);a(d.slideshow).siblings("#caption").slideDown("normal")}d.callAfter.call(o,o);g=false})}return false});function m(){for(var n=0;n<f.length;n++){if(f.eq(n).hasClass(d.activeClass)){if((f.length-1)==n){if(d.wrap){f.eq(0).trigger("click")}}else{f.eq(n+1).trigger("click")}break}}return false}function h(){for(var n=0;n<f.length;n++){if(f.eq(n).hasClass(d.activeClass)){if(n==0){if(d.wrap){f.eq(f.length-1).trigger("click")}}else{f.eq(n-1).trigger("click")}break}}return false}function l(){d.beforeCycle();d.cycle=true;d.wrapMem=d.wrap;d.wrap=d.cycleWrap;if(d.reverse){h()}else{m()}k=setTimeout(function(){if(d.reverse){h()}else{m()}i=setTimeout(arguments.callee,d.speed+d.interval)},d.speed+d.interval);return false}function j(){clearTimeout(k);clearTimeout(i);d.cycle=false;d.wrap=d.wrapMem;d.afterCycle();return false}a(d.next).click(function(){j();return m()});a(d.prev).click(function(){j();return h()});a(d.startCycle).click(function(){return l()});a(d.stopCycle).click(function(){return j()});a(d.toggleCycle).click(function(){if(d.cycle){return j()}else{return l()}});if(d.hoverPause){a(d.slideshow).hover(function(){j()},function(){l()})}if(d.cycle){l()}})}})(jQuery);

/*
* Slides, A Slideshow Plugin for jQuery
* Intructions: http://slidesjs.com
* By: Nathan Searles, http://nathansearles.com
* Version: 1.1.6
* Updated: March 23th, 2011
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

(function($){$.fn.slides=function(g){g=$.extend({},$.fn.slides.option,g);return this.each(function(){$('.'+g.container,$(this)).children().wrapAll('<div class="slides_control"/>');var d=$(this),control=$('.slides_control',d),total=control.children().size(),width=control.children().outerWidth(),height=control.children().outerHeight(),start=g.start-1,effect=g.effect.indexOf(',')<0?g.effect:g.effect.replace(' ','').split(',')[0],paginationEffect=g.effect.indexOf(',')<0?effect:g.effect.replace(' ','').split(',')[1],next=0,prev=0,number=0,current=0,loaded,active,clicked,position,direction,imageParent,pauseTimeout,playInterval;function animate(a,b,c){if(!active&&loaded){active=true;g.animationStart(current+1);switch(a){case'next':prev=current;next=current+1;next=total===next?0:next;position=width*2;a=-width*2;current=next;break;case'prev':prev=current;next=current-1;next=next===-1?total-1:next;position=0;a=0;current=next;break;case'pagination':next=parseInt(c,10);prev=$('.'+g.paginationClass+' li.current a',d).attr('href').match('[^#/]+$');if(next>prev){position=width*2;a=-width*2}else{position=0;a=0}current=next;break}if(b==='fade'){if(g.crossfade){control.children(':eq('+next+')',d).css({zIndex:10}).fadeIn(g.fadeSpeed,g.fadeEasing,function(){if(g.autoHeight){control.animate({height:control.children(':eq('+next+')',d).outerHeight()},g.autoHeightSpeed,function(){control.children(':eq('+prev+')',d).css({display:'none',zIndex:0});control.children(':eq('+next+')',d).css({zIndex:0});g.animationComplete(next+1);active=false})}else{control.children(':eq('+prev+')',d).css({display:'none',zIndex:0});control.children(':eq('+next+')',d).css({zIndex:0});g.animationComplete(next+1);active=false}})}else{control.children(':eq('+prev+')',d).fadeOut(g.fadeSpeed,g.fadeEasing,function(){if(g.autoHeight){control.animate({height:control.children(':eq('+next+')',d).outerHeight()},g.autoHeightSpeed,function(){control.children(':eq('+next+')',d).fadeIn(g.fadeSpeed,g.fadeEasing)})}else{control.children(':eq('+next+')',d).fadeIn(g.fadeSpeed,g.fadeEasing,function(){if($.browser.msie){$(this).get(0).style.removeAttribute('filter')}})}g.animationComplete(next+1);active=false})}}else{control.children(':eq('+next+')').css({left:position,display:'block'});if(g.autoHeight){control.animate({left:a,height:control.children(':eq('+next+')').outerHeight()},g.slideSpeed,g.slideEasing,function(){control.css({left:-width});control.children(':eq('+next+')').css({left:width,zIndex:5});control.children(':eq('+prev+')').css({left:width,display:'none',zIndex:0});g.animationComplete(next+1);active=false})}else{control.animate({left:a},g.slideSpeed,g.slideEasing,function(){control.css({left:-width});control.children(':eq('+next+')').css({left:width,zIndex:5});control.children(':eq('+prev+')').css({left:width,display:'none',zIndex:0});g.animationComplete(next+1);active=false})}}if(g.pagination){$('.'+g.paginationClass+' li.current',d).removeClass('current');$('.'+g.paginationClass+' li:eq('+next+')',d).addClass('current')}}}function stop(){clearInterval(d.data('interval'))}function pause(){if(g.pause){clearTimeout(d.data('pause'));clearInterval(d.data('interval'));pauseTimeout=setTimeout(function(){clearTimeout(d.data('pause'));playInterval=setInterval(function(){animate("next",effect)},g.play);d.data('interval',playInterval)},g.pause);d.data('pause',pauseTimeout)}else{stop()}}if(total<2){return}if(start<0){start=0}if(start>total){start=total-1}if(g.start){current=start}if(g.randomize){control.randomize()}$('.'+g.container,d).css({overflow:'hidden',position:'relative'});control.children().css({position:'absolute',top:0,left:control.children().outerWidth(),zIndex:0,display:'none'});control.css({position:'relative',width:(width*3),height:height,left:-width});$('.'+g.container,d).css({display:'block'});if(g.autoHeight){control.children().css({height:'auto'});control.animate({height:control.children(':eq('+start+')').outerHeight()},g.autoHeightSpeed)}if(g.preload&&control.find('img').length){$('.'+g.container,d).css({background:'url('+g.preloadImage+') no-repeat 50% 50%'});var f=control.find('img:eq('+start+')').attr('src')+'?'+(new Date()).getTime();if($('img',d).parent().attr('class')!='slides_control'){imageParent=control.children(':eq(0)')[0].tagName.toLowerCase()}else{imageParent=control.find('img:eq('+start+')')}control.find('img:eq('+start+')').attr('src',f).load(function(){control.find(imageParent+':eq('+start+')').fadeIn(g.fadeSpeed,g.fadeEasing,function(){$(this).css({zIndex:5});$('.'+g.container,d).css({background:''});loaded=true;g.slidesLoaded()})})}else{control.children(':eq('+start+')').fadeIn(g.fadeSpeed,g.fadeEasing,function(){loaded=true;g.slidesLoaded()})}if(g.bigTarget){control.children().css({cursor:'pointer'});control.children().click(function(){animate('next',effect);return false})}if(g.hoverPause&&g.play){control.bind('mouseover',function(){stop()});control.bind('mouseleave',function(){pause()})}if(g.generateNextPrev){$('.'+g.container,d).after('<a href="#" class="'+g.prev+'">Prev</a>');$('.'+g.prev,d).after('<a href="#" class="'+g.next+'">Next</a>')}$('.'+g.next,d).click(function(e){e.preventDefault();if(g.play){pause()}animate('next',effect)});$('.'+g.prev,d).click(function(e){e.preventDefault();if(g.play){pause()}animate('prev',effect)});if(g.generatePagination){d.append('<ul class='+g.paginationClass+'></ul>');control.children().each(function(){$('.'+g.paginationClass,d).append('<li><a href="#'+number+'">'+(number+1)+'</a></li>');number++})}else{$('.'+g.paginationClass+' li a',d).each(function(){$(this).attr('href','#'+number);number++})}$('.'+g.paginationClass+' li:eq('+start+')',d).addClass('current');$('.'+g.paginationClass+' li a',d).click(function(){if(g.play){pause()}clicked=$(this).attr('href').match('[^#/]+$');if(current!=clicked){animate('pagination',paginationEffect,clicked)}return false});$('a.link',d).click(function(){if(g.play){pause()}clicked=$(this).attr('href').match('[^#/]+$')-1;if(current!=clicked){animate('pagination',paginationEffect,clicked)}return false});if(g.play){playInterval=setInterval(function(){animate('next',effect)},g.play);d.data('interval',playInterval)}})};$.fn.slides.option={preload:false,preloadImage:'/img/loading.gif',container:'slides_container',generateNextPrev:false,next:'next',prev:'prev',pagination:true,generatePagination:true,paginationClass:'pagination',fadeSpeed:350,fadeEasing:'',slideSpeed:350,slideEasing:'',start:1,effect:'slide',crossfade:false,randomize:false,play:0,pause:0,hoverPause:false,autoHeight:false,autoHeightSpeed:350,bigTarget:false,animationStart:function(){},animationComplete:function(){},slidesLoaded:function(){}};$.fn.randomize=function(c){function randomizeOrder(){return(Math.round(Math.random())-0.5)}return($(this).each(function(){var $this=$(this);var $children=$this.children();var a=$children.length;if(a>1){$children.hide();var b=[];for(i=0;i<a;i++){b[b.length]=i}b=b.sort(randomizeOrder);$.each(b,function(j,k){var $child=$children.eq(k);var $clone=$child.clone(true);$clone.show().appendTo($this);if(c!==undefined){c($child,$clone)}$child.remove()})}}))}})(jQuery);
