(function ($) {
	var steve = {
		ini : function () {
			steve.events.bind();
			steve.events.initialPage();
		},
		events : {
			bind : function () {
				$("#nav a").bind("mouseover", function () {
					$(this).parent().addClass("active");
				}).bind("mouseout", function () {
					$(this).parent().removeClass("active");
				}).bind("click", function () {
					$(this).parent().parent().children(".main").removeClass("main");
					$(this).parent().addClass("main");
					steve.events.parseUrl($(this).attr("href"));
				});
				$(".link").bind("click", function () {
					if ($(this).closest(".bar").css("left") === "-700px") {
						$(this).closest(".bar").animate({"left" : "0px"}, "slow");
					} else {
						$(this).closest(".bar").animate({"left" : "-700px"}, "slow");
					}
				});
				$(".gallery-link").bind("click", function (ev) {
					steve.ui.remove.activeClient();
					$(this).addClass("open");
					steve.ui.client.hide();
					steve.ui.client.show($(this).attr("rel"));
				});
			},
			parseUrl : function (url) {				
				var url_arr = [], page = "", url = url.substr(url.indexOf('#'));
				if (url !== "") {
					url_arr = url.split("/");
					page = url_arr[1].substr(0, url_arr[1].length);
					steve.ui.show(page);
				} else {
					steve.ui.show("home");
				}
			},
			initialPage : function () {
				var hash = window.location.hash, hash_arr = [];
				if (hash === "") {
					steve.ui.show("home");
				} else {
					hash_arr = hash.split("/");
					steve.ui.show(hash_arr[1]);
					steve.ui.setActiveLink(hash_arr[1]);
					if (hash_arr[1] === "gallery" && hash_arr[2].length>0 ) {
						steve.ui.set.activeClient(hash_arr[2]);
						steve.ui.client.show(hash_arr[2],false);
					}
				}
			}
		},
		ajax : {
			
		},
		callback : {
			
		},
		ui : {
			insert : {
				lines : function () {
					var i = 1, maximum = steve.sys.getMax();
					for ( i; i < maximum; i = i + 1 ) {
						$("#line-numbers").append("<p>" + i + "</p>").children("p").last().hide().delay(i * 140).show('slow');
					}
				}
			},
			remove : {
				lines : function () {
					$("#line-numbers").html("");
				},
				activeClient : function () {
					$(".gallery-link").each(function () {
						$(this).removeClass("open");
					});
				}
			},
			set : {
				activeClient : function (page) {
					$(".gallery-link").each(function () {
						if ($(this).attr("rel") === page) {
							$(this).addClass("open");
						}
					});
				}
			},
			show : function (page) {
				$(".page").hide("fast", steve.ui.remove.lines);
				$("#"+page).show("fast", steve.ui.insert.lines);
			},
			setActiveLink : function (page) {
				$(".main").removeClass("main");
				$("#nav li a").each(function () {
					if ($(this).html() === page) {
						$(this).parent().addClass("main");
					}
				});
			},
			client : {
				show : function (id, showLines) {
					showLines = (typeof showLines === "undefined") ? true : showLines;
					if ( showLines ) {
						$("#" + id).fadeIn("fast", steve.ui.insert.lines);
					} else {
						$("#" + id).fadeIn("fast");
					}
				},
				hide : function () {
					$(".client").each(function() {
						$(this).hide("fast");
					});
					steve.ui.remove.lines();
				}
			}
		},
		sys : {
			getMax : function () {
				var height = $("#content").height(), units = 14;
				return Math.round(height / units) + 1;
			}
		}
	};
	$(document).ready(function () {
		steve.ini();
	});
}(jQuery));
