/*=== Sloths Js */

$(bokan);

function bokan() {
	$('#features').find('em').switchCont($('#banner')).parent().hoverClass();
	$('#infos').find('ol li').hoverClass();
	$('#infos').displayCont();
	$('#nav').find('li').isNav();

	if ($('#cases').length) {cases();}
	if ($('#info').find('img').length) {featuredPic();};
}


$.fn.switchCont = function(__obj) {	
	return this.each(function(){
		var nav = $(this).parents('div');
		var con = __obj.find('ul');
		$(this).click(function(){
			nav.find('.sp').removeClass('sp');
			$(this).parent().addClass('sp');
			var leftNum = 0 - (parseInt($(this).attr('className').replace('f','')) - 1)*950;
			con.animate({left: leftNum}, 1000); 
		});
	});
}

$.fn.hoverClass = function() {	
	return this.each(function(){
		$(this).hover(function(){
			$(this).addClass('hover');
		},function(){
			$(this).removeClass('hover');
		});
	});
}

$.fn.displayCont = function() {	
	return this.each(function(){
		var nav = $(this).find('.child');
		var navItem = nav.find('p');

		var con = $(this).find('ul');
		var conItem = con.find('li');

		navItem.hoverClass().click(function(){
			var index = parseInt($(this)[0].className.replace('sp','').replace('f', '')) - 1;

			nav.find('.sp').removeClass('sp');
			con.find('.sp').removeClass('sp');

			$(this).addClass('sp');
			$(conItem[index]).addClass('sp');
		});
	});
}

$.fn.isNav = function() {	
	return this.each(function(){
		var nav = $(this);
		if (!nav.find('p').length) return;
		nav.unbind('hover').hover(function(){
			$(this).find('p').show();
		},function(){
			$(this).find('p').slideUp();
		});
	});
}

function cases() {
	var url = window.location;
	var page = url.toString().split('#')[1];
	if (page) {$('#' + page).click();}
	window.location.replace('#', '');
}

function featuredPic() {
	var m = Math.random();
	m > 0.5 ? $('#info').find('.project p.n').eq(0).show() : $('#info').find('.project p.n').eq(1).show();
}

