jQuery( function($) {
	$('div#featured-work div.slideshow').each( function() {
		var slideshow = this;
		$.getScript('/cms/wp-content/themes/hm/-/js/libs/jquery.hoverscroll.js', function(){
			$('ul', slideshow).hoverscroll({
				width: 1000,
				height:200,
				arrows: false
			});
		});
	});
	
	if( $('div#work-intro div.slideshow li').length > 1 ) {
		$.getScript('/cms/wp-content/themes/hm/-/js/libs/jquery.cycle.js', function(){
			$prev = $('<a href="#" class="nc ir prev">Previous</a>').appendTo( $('div#work-intro div.slideshow') );
			$next = $('<a href="#" class="nc ir next">Next</a>').appendTo( $('div#work-intro div.slideshow') );
			$('div#work-intro div.slideshow ul').cycle({
				fx: 'scrollHorz',
				next: $next,
				prev: $prev,
				timeout: 0,
				speed: 300,
				nowrap: true,
				after: function( curr, next, options, flag ) {
					console.log( options );
					if( $(next).index() == 0 ) {
						$( options.prev ).hide();
					}else {
						$( options.prev ).show();
					}
					
					if( $(next).index()+1 == options.slideCount ) {
						$( options.next ).hide();
					}else {
						$( options.next ).show();
					}
				}
			});
		});
	}
	
	if( $('div#home div.slideshow li').length > 1 ) {
		$.getScript('/cms/wp-content/themes/hm/-/js/libs/jquery.cycle.js', function(){
			$prev = $('<a href="#" class="nc ir prev">Previous</a>').appendTo( $('div#home div.slideshow') );
			$next = $('<a href="#" class="nc ir next">Next</a>').appendTo( $('div#home div.slideshow') );
			$('div#home div.slideshow ul').cycle({
				fx: 'scrollHorz',
				next: $next,
				prev: $prev,
				timeout: 0,
				speed: 300,
				nowrap: true,
				after: function( curr, next, options, flag ) {
					console.log( options );
					if( $(next).index() == 0 ) {
						$( options.prev ).hide();
					}else {
						$( options.prev ).show();
					}
					
					if( $(next).index()+1 == options.slideCount ) {
						$( options.next ).hide();
					}else {
						$( options.next ).show();
					}
				}
			});
		});
	}
	
	if( $('div#story-intro ul.slides li').length > 1 ) {
		$.getScript('/cms/wp-content/themes/hm/-/js/libs/jquery.cycle.js', function(){
			$('div#story-intro ul.slides').cycle({
				fx: 'scrollLeft',
				timeout: 0,
				speed: 300,
				pager: 'div#story-intro div.menu ul',
				pagerEvent: 'click',
				pagerAnchorBuilder: function(idx, slide) {
					return 'div#story-intro div.menu ul li:eq(' + idx + ') a';
				},
				before: function( curr, next ) {
					i = $(next).index();
					if( !$('div#story-intro div.menu').hasClass('on') && i > 0) {
						$('div#story-intro div.menu').addClass('on');
					}
				}
			});
			
		});
	}
	
	$('a[href$=".jpg"],a[href$=".png"],a[href$=".gif"]').addClass('fancybox');
	if( $('a.fancybox').length > 0 ) {
		$.getScript('/cms/wp-content/themes/hm/-/js/libs/jquery.fancybox.pack.js', function(){
			$('a.fancybox').fancybox({
				padding: 0,
				closeBtn: true,
				helpers: {
					overlay: {
						opacity: 0.01
					}
				}
			});
			
			$('a.fancybox.modal').fancybox({
				padding: 0,
				minWidth: 670,
				maxWidth: 670,
				closeBtn: true,
				helpers: {
					overlay: {
						opacity: 0.01
					}
				}
			});
		});
	}
	
});


window.log = function(){
  log.history = log.history || [];  
  log.history.push(arguments);
  arguments.callee = arguments.callee.caller;  
  if(this.console) console.log( Array.prototype.slice.call(arguments) );
};
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c})(window.console=window.console||{});
