try {
	var x = document.getElementsByTagName('body');
	x[0].className='js';
} catch(err) {}

function rotate(c){
    var i = $(c).index($(c+":visible")[0]);
    var j = (i+1 == $(c).size()) ? 0 : i +1;
    if ($.browser.msie && ($.browser.version == 6)) {
        $(c+":eq("+i+")").hide();$(c+":eq("+j+")").show();
    } else {
        $(c+":eq("+i+")").fadeOut(600, function(){$(c+":eq("+j+")").fadeIn();});
    }
}

function resetPortfolio(){
	$('.case-study').hide();
	$('#portfolio li a').removeClass('detail');
	$('#portfolio li').show();
}

$(document).ready(function(){
	
	if (!$('body').hasClass('js')) $('body').addClass('js'); // check for js class on document ready
	if ($.browser.msie && $.browser.version < 7) $('body').addClass('isIE'); // apply isIE class for IE6
	
	// Sets label as input value
	$('label.titleset').each(function(){
        var label = $(this).text();
        $(this).next().attr('title', label).val(label).focus(function(){
            if($(this).val()==label){
                $(this).val('');
            }
        }).blur(function(){
            if($(this).val()==''){
                $(this).val(label);
            }
        });
		$(this).hide();
    });

	$('.jsHide').removeClass('jsHide').addClass('hide');
	
	$("#portfolio a.preview").click(function(){
		$('#portfolio li').hide();
		$(this).addClass('detail');
		$(this).parent().show();
		$(this).next().show();
		$('.case-study:visible h3').before($('#btnClose'));
		$('#btnClose').show().click(function(){
			resetPortfolio();
		});
		return false;
	}).tooltip({showBody:"|",track:true,showURL:true});

	$('#btnWork').toggle(function(){
		$('.introduction p,.introduction h1').hide();
		$(this).text('Back');
		$('.introduction').css('background-color', 'rgba(255,255,255,0)').animate({left:'380px',top:'295px'});
		$('#portfolio').fadeIn();
	}, function(){
		resetPortfolio();
		$('#portfolio').hide();
		$('.introduction').css('background-color', 'rgba(255,255,255,0.75)').animate({left:'0',top:'0'},function(){
			$('#btnWork').text('View some of our recent work.');
			$('.introduction h1').fadeIn('fast');
			$('.introduction p').fadeIn('fast');
		});
	});
	
	$('.section').each(function(){
		var s = this;
		$('.data > li', this).slice(1).hide();
		$('.filter > li:eq(0)', this).addClass('selected');
		$('.filter a', this).click(function(){
			var h = $(this).attr('href');
			var l = $(this).parent().parent();
			$('li', l).removeClass('selected');
			$(this).parent().addClass('selected');
			$('.data > li', s).hide();
			$(h).show();
			return false;
		});
		
		$(this).append($('<a href="#masthead" class="back">&laquo; Back to top</a>').click(function(){
			$.scrollTo({top:0,left:0}, 800);
			return false;
		}));
		
		$('.jumplinks a').click(function(){
			var l = $(this).attr('href');
			$.scrollTo($(l), 800);
			return false;
		});
	});
	
});