/**
 * Old Monk JS display
 * Added tracking, fixed scale (hiding menu in very small browsers)
 * 
 * @version 1.2
 * @link ajbnet.com
 * @author sprky0 <avery@averyisgreat.com>
 */
var OM = {

	original : {},

	Update : function(from,atTop) {

		var h = $("#header");
		var c = $("#common");
		var b = $("body");

		// only do this by hitting the top of the page
		if (!$(from).is("a") && c.hasClass("bottom_menu") && (!$(from).parent().prev().is("li") || atTop == true)) {

			$("h2.like_h1").animate({opacity:1},1000);

			h.css("display","none");//addClass("hidden");

			var _c = c, _b = b;
			b.css("overflow","hidden");

			c.animate(
				{top:this.original.top,left:this.original.left},
				600,
				function(){

					_c
						.css("top",0)
						.css("left",0)
						.css("position","relative")
						.removeClass("bottom_menu");
						
					// _b.css("overflow","auto");

				}
			);
			
		} else if (!c.hasClass("bottom_menu") && ($(from).parent().prev().is("li"))) {

			$("h2.like_h1").animate({opacity:0},1000);

			h.slideDown(function(){
				$(this).removeClass("hidden");
			});
			
			// b.css("overflow","hidden");
		
			this.original = c.offset();

			var x = this.original.left;
			var y = $(window).height() - c.height() - 20; // this.original.top;
			c
				.addClass("bottom_menu")
				.css("position","fixed")
				.css("top",y)
				.css("left",x);

			var middle = (b.width() / 2) - (c.width() / 2) - 20;

			c.animate({"left":middle},1000);

			b.css("overflow","auto");

		}
				

	},
	
	FixedLogo : function() {
		
		
		return;
	},
	
	Init : function() {
		
	// handle refresh / load with anchor here

	if (window.location.hash != "") {
		$(window).scrollTop(0);
		setTimeout(function(){
			$("a[href="+window.location.hash+"]","#menu").click();
		}, 300);
	}


	$(".page").each(function(){
	
		// A page's height is the height of the window.  Post cardzzzzz
		$(this).height( $(window).height() );

	});

	$(window).bind("scroll",function(e) {
		
		if ($(this).scrollTop() == 0) {
			
			OM.Update(null,true);
			
		}
		
	});

	$("#menu a").each(function(){
		
		if (!$(this).is("[rel=external]")) {
			
			$(this).bind("click",function(e){
				
				e.preventDefault();

				var _a = this;

				OM.Update(this);
				// OM.FixedLogo();

				$( "body" ).scrollTo(
					$(this).attr("href"),
					600,
					{
						onAfter : function() {
							window.location.hash = $(_a).attr("href");
							OM.Track();
						}
					}
				);
				
				
			});
			
			
			
			
			
		}
		
		
	});

	},
	
	Track : function() {

		var val = new String("/" + window.location.hash ).replace('#', 'section/');
		
		if (!pageTracker || !pageTracker._trackPageview) {
			return false;
		}

		return pageTracker._trackPageview(val);

	}

}

