var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-16216873-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);
})();

$(document).ready(function(){

	if ($('.syntax').length) {
		$.getScript(site_root + "sh/jquery.syntax.min.js", function () {
			$.syntax({root: site_root+"sh/"});
		});
	}

	var slogan = {
		child_count: $("#slogan > .inner").children().size(),
		current: 1,
		hover_time: 12000,
		hover: false,
		anim_active: false
	}
	
	$("#slogan").show();
	$("#slogan > .inner > div.item:not(':eq(0)')").hide();
	
	function fader() {
		slogan.anim_active = true;
		$("#slogan > .inner").children(':gt(0):visible').fadeOut("slow", function() {
			slogan.current++;
			if (slogan.current % slogan.child_count == 0) {
				slogan.current = 1;
			}
			$("#slogan > .inner").children().eq(slogan.current).delay(250).fadeIn("fast", function() {
				slogan.anim_active = false;
			});
		});
		if (slogan.hover == true) { clearInterval(anim); }
	}
	var anim = setInterval(function(){ fader(); }, slogan.hover_time);
	
	$("#slogan > .inner").children().hover(
		function() {
			slogan.hover = true;
			clearInterval(anim);
		}, function() {
			slogan.hover = false;
			anim = setInterval(function(){ fader(); }, slogan.hover_time);
		}
	);
	
	$("#slogan > .inner > #slogannav > ul > li").mouseover(function() {
		var index = $("#slogan > .inner > #slogannav > ul > li").index(this);
		if ((slogan.anim_active == false) && (slogan.current !== (index+1))) {
			slogan.anim_active = true;
			slogan.current = index+1;
			$("#slogan > .inner").children(':gt(0):visible').fadeOut("slow", function() {
				$("#slogan > .inner").children().eq(index+1).delay(250).fadeIn("fast", function() {
					slogan.anim_active = false;
				});
			});
		}
	});
	
});
