$(document).ready(function() {
	// when header is hovered
	$('#header').hover(function() {
		$('#header').stop(true, false).animate({height: '56px'}, {queue: false, duration: 200, easing: 'easeInQuad'});
		$('#nav > span').stop(true, true).animate({marginTop: '15px'}, {queue: false, duration: 200, easing: 'easeInQuad'});
		if ($.browser.msie && $.browser.version.substr(0,1)<9) {$('#nav > ol > li:nth-child(1)').css('display','block');}
		else {$('#nav > ol > li:nth-child(1)').stop(true, true).fadeIn(200);}
	}, function() {
		$('#header').stop(true, true).animate({height: '40px'}, {queue: false, duration: 200, easing: 'easeInQuad'});
		$('#nav > span').stop(true, true).animate({marginTop: '8px'}, {queue: false, duration: 200, easing: 'easeInQuad'});
		if ($.browser.msie && $.browser.version.substr(0,1)<9) {$('#nav > ol > li:nth-child(1)').css('display','none');}
		else {$('#nav > ol > li:nth-child(1)').stop(true, true).fadeOut(200);}
	});
	// when parent line is hovered
	$('#nav > ol').hover(function() {
		if ($.browser.msie && $.browser.version.substr(0,1)<9) {$(this).children('li:nth-child(2)').css('display','block');}
		else {$(this).children('li:nth-child(2)').stop(true, true).fadeIn(200);}
	}, function() {
		if ($.browser.msie && $.browser.version.substr(0,1)<9) {$(this).children('li:nth-child(2)').css('display','none');}
		else {$(this).children('li:nth-child(2)').stop(true, true).fadeOut(200);}
	});
	// when services is hovered
	$('.swap').hover(function() {$('.swap > li:nth-child(1) > a').text('Design');}, function() {$('.swap > li:nth-child(1) > a').text('Services');});
	// behaviour for home
	if ($('body').hasClass('home')) {
		$('#header').stop(true, true).animate({height: '56px'}, {queue: false, duration: 400, easing: 'easeInQuad'});
		$('#nav > span').stop(true, true).animate({marginTop: '15px'}, {queue: false, duration: 400, easing: 'easeInQuad'});
		$('#nav > ol > li:nth-child(1)').stop(true, true).delay(400).fadeIn(800).delay(4000).fadeOut(800, function(){
			$('#header').stop(false, false).animate({height: '40px'}, {queue: false, duration: 400, easing: 'easeInQuad' });
			$('#nav > span').stop(false, false).animate({marginTop: '8px'}, {queue: false, duration: 400, easing: 'easeInQuad'});
		});
		setTimeout(function() {
			$('#header').stop(true, true).animate({height: '56px'}, {queue: false, duration: 800, easing: 'easeInQuad'});
			$('#nav > span').stop(true, true).animate({marginTop: '15px'}, {queue: false, duration: 800, easing: 'easeInQuad'});
			$('#nav > ol > li:nth-child(1)').stop(true, true).delay(800).fadeIn(800);
		}, 9000);
	}
	// behaviour for profile
	if ($('body').hasClass('profile')) {
		setTimeout(function() {
			$('#header').stop(true, true).animate({height: '56px'}, {queue: false, duration: 400, easing: 'easeInQuad'});
			$('#nav > span').stop(true, true).animate({marginTop: '15px'}, {queue: false, duration: 400, easing: 'easeInQuad'});
			$('#nav > ol > li:nth-child(1)').stop(true, true).delay(400).fadeIn(400);
		}, 3000);
	}
	// simpletabs.js
	function switch_tabs(obj) {
		$('.tab').hide();
		$('.tabs').removeClass('live');
		var id = obj.attr('rel');
		$('.' + id).fadeIn(1000);
		obj.addClass('live');
	}
	$('.tabs').click(function() {
		switch_tabs($(this));
		$('.jScrollbar').jScrollbar();
		var player = $('#video');
		player.sendEvent('STOP');
		/*$('.tab').galleria();*/
	});
	switch_tabs($('.default'));
	
	// project exhibition enlarge notice
	$('#project #exhibition').hover(function() {
		$(this).append('<div class="notice">Click to Enlarge</div>').find('.notice').stop(true, true).delay(2400).fadeIn(600).delay(4000).fadeOut(600);
	}, function() {
		$(this).find('.notice').stop(true, true).fadeOut(300).remove();
	}).trigger('hover');
	
	// project video flash notice
	$('#project #video a').hover(function() {
		$(this).append('<div class="notice">Click to visit Adobe Flash Player page</div>').find('.notice').stop(true, true).delay(600).fadeIn(600).delay(4000).fadeOut(600);
	}, function() {
		$(this).find('.notice').stop(true, true).fadeOut(300).remove();
	}).trigger('hover');
});

$(window).load(function() {	
	
	// fadein
	if ($.browser.msie && $.browser.version.substr(0,1)<9) {$('.fade1','.fade2','.fade3','.fade4','.fade5').show();}
	else {
		$('.fadeq').each(function (i) {var $item = $(this);setTimeout(function() {$item.animate({'opacity': 1}, 1000);}, 60*i);});
		$('.fade1').each(function (i) {var $item = $(this);setTimeout(function() {$item.animate({'opacity': 1}, 1000);}, 200*i);});
		$('.fade2').each(function (i) {var $item = $(this);setTimeout(function() {$item.delay(500).animate({'opacity': 1}, 1000);}, 200*i);});
		$('.fade3').each(function (i) {var $item = $(this);setTimeout(function() {$item.delay(1000).animate({'opacity': 1}, 1000);}, 200*i);});
		$('.fade4').each(function (i) {var $item = $(this);setTimeout(function() {$item.delay(1500).animate({'opacity': 1}, 1000);}, 200*i);});
		$('.fade5').each(function (i) {var $item = $(this);setTimeout(function() {$item.delay(2000).animate({'opacity': 1}, 1000);}, 200*i);});
	}

	// jscrollbar
	//$(window).load(function() {$('.jScrollbar').jScrollbar();}); // ISOLATE not needed? check how projects works, oh i know now, tabs activates, may still be needed on first tab text
});

// apply :last-child styles in ie6
if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {
	$('p:first-child').css('margin-top','0');
	$('p:last-child').css('margin-bottom','0');
	$('#testimonials .article:last-child').css('margin','0');
}

// google analytics
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22423830-1']);
_gaq.push(['_trackPageview']);
(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
