// yep
(function($) {
	// Add class to html
	$('html').addClass('js-enabled');
	
	// Open external URLs in a new window
	$('a.external').live('click', function() {
		window.open(this.href);
		return false;
	});
	
	// grab the hash of the current url
	var pathname = location.pathname;
	
	// Home page rotator
	if (pathname == "/") { // only run this on home
	$('.rotator').cycle({ 
		fx:     'fade',
		speed:  '1500',
		timeout: 7000,
		next:   '.rotator-next', 
		prev:   '.rotator-prev',
		pause:   1
	});
	}
		
	// Work detail rotator
	if (pathname.indexOf("/work/") != -1 && pathname != "/work/") { // only run this on the work page / sub pages
	$('.case-rotator').cycle({ 
	    fx:     'scrollLeft', 
	    speed:  'slow', 
	    timeout: 8000, 
	    next:   '.rotator-next', 
	    prev:   '.rotator-prev',
	    pager:	'.case-nav',
		pause:   1,
        pagerAnchorBuilder: function(idx, slide) {
        	// Return selector
	        return '.case-nav li:eq(' + idx + ') a';
	    } 
	});
	}
})(jQuery);


// yip
jQuery(document).ready(function($) {
	// grab the hash (if there is one)
	var hashname = $(location).attr('hash');
	
	
	// "all" selected by default
	$("li.all").addClass("selected");
	
	
	// clicks of the controls
	$("ul.controls li").click(function () {
		// don't do anything if the selected was clicked again
		if ($(this).hasClass('selected')) {
			return false;
		}
		
		// get the clicked control
		var thisControl = $(this).attr('class');
		
		// remove "selected" class from the current control
		$(".controls li").removeClass("selected");
	
		// add "selected" class to this control
		$(".controls li."+thisControl).addClass("selected");
		
		if (thisControl == "all") {
			// remove highlight and fade to normal state on all <li>s
			$("#clients li").fadeTo("slow", 1).removeClass("highlight");
		} else {		
			// fade all out all non-selected <li>
			$("#clients li:not(."+thisControl+")").fadeTo(700, 0.33);
			
			// remove all highlights
			$("#clients li").removeClass("highlight");
		
			// fade in selected <li>
			$("#clients ."+thisControl).fadeTo("slow", 1.0);
			
			// add highlight class
			$("#clients li."+thisControl).addClass("highlight");
		}
		
		return false;
	});
	
	
	// if there is a hash
	if (hashname.length > 0) {
		// trim the #
		var hashname = hashname.substring(1, hashname.length);
		
		// update the controls
		$(".controls li").removeClass("selected");
		$(".controls li."+hashname).addClass("selected");
		
		// update the <li>s
		$("#clients li:not(."+hashname+")").fadeTo(700, 0.33);
		$("#clients li."+hashname).addClass("highlight");
			
		return false;
	}
	
	// add hover cursor and click to the clients div on home
	$('.home #content .clients').hover(function(){$(this).css("cursor", "pointer");}).click(function(){window.location = "/clients/";});
});
