var Neoworks = {
	Site: {
		init: function(){

			// Initiali(s|z)e the code highlighting
			$(".code-javascript").each(function(){
				$(this).attr("class","brush: js;");
			});
			$(".code-java").each(function(){
				$(this).attr("class","brush: java;")
			});
			$(".code-xml").each(function(){
				$(this).attr("class","brush: xml;")
			});
			SyntaxHighlighter.all();

			// Setup contact form validation
			$("#contactForm").validate({
				submitHandler: function(form) {
					form.submit();
				}
			});

			$(".submitContactForm").click(function(e){
				e.preventDefault();
				e.stopPropagation();
				$("#contactForm").submit();
			});

			// Setup herobanner things
			$(function(){
				$("#herobannerSelector ul li").click(function(e){
					// Stop the banner rolling if the user has explicitly started clicking on things.
					Neoworks.Site.isBannerRolling = false;
					Neoworks.Site.showHeroBanner($(e.target).data("bannerid"));
				});
			});
		},
		showHeroBanner: function(heroBannerId)
		{
			var showBanner = $("#"+heroBannerId);

			$("#herobannerSelector>ul>li").removeClass("selected");
			$('#herobannerSelector>ul>li[data-bannerid="'+heroBannerId+'"]').addClass("selected");

			showBanner.css("z-index","100").fadeIn(1000,function(){
				$("#herobanners>.herobannerContainer").not(this).css("z-index","auto").hide();
				$(this).css("z-index","auto").show();
			});
		},
		isBannerRolling: true,
		herobannerRoll: function() {
			var rollTime = 10000;
			var callback = function(){
				if(Neoworks.Site.isBannerRolling) {
					var currentBanner = $("#herobanners>.herobannerContainer:visible").first();
					var newBanner = currentBanner.next();
					if(newBanner.length==0) {
						newBanner = currentBanner.siblings().first();
					}
					Neoworks.Site.showHeroBanner(newBanner.attr("id"));
					window.setTimeout(callback, rollTime);
				}
			};
			if(Neoworks.Site.isBannerRolling) window.setTimeout(callback, rollTime);
		}
	}
};
