$(document).ready(function(){
	
	$('.header,.subheader,.contentContainer,.contentBG').removeClass("hide");
	
	//HEADER
	$('.header').css("height","0"); //Style init
	$('.headerIn').css("height","0"); //Style init
	setTimeout(function(){
		$('.header').animate({ "height": "85px" },{ duration:750, easing: "easeOutBounce"});
		setTimeout(function(){
			$('.headerIn').animate({ "height": "85px" },{ duration:350, easing: "easeOutQuad"});
		}, 750);
	}, 500);
	
	
	//SUBHEADER
	$('.subheader').css("width","0%"); //Style init
	$('.subheaderBG').css("left",$.ww+"px"); //Style init
	setTimeout(function(){
		$('.subheader').animate({ "width": "100%" }, {duration:750, easing: "easeOutBounce"});
		//Scrollin'
		setTimeout(function(){
			_subheader_scroll();
		}, 3000);
	}, 1000);
	
	
	//CONTENT
	$('.contentContainer').css("background","none"); //Style init
	setTimeout(function(){
		var animationDuration = _contentBG();
		setTimeout(function(){
			setTimeout(function(){ _loadHome(); }, 250);
			setTimeout(function(){ $('body').css("background","#EFEFEF"); $('.contentBG').remove(); }, 200); //Let the animation take some extratime
		}, animationDuration);
	},1500);
	
	
	//MENU
	$('.menu').css("height","0"); //Style init
	setTimeout(function(){
		_menu();
		
		//Rollover menu
		$('.mbutton').mouseenter(function(){
			_mbuttonSelect($(this));
		});
		$('.mbutton').mouseleave(function(){
			_mbuttonUnSelect($(this));
		});
	},2000);
	
	//MENU buttons
	$('.mbutton').click(function(){
		if($.MUTEX_load){ return false; }
		if($(this).hasClass("selected")){ return false; }
		var last = $('.mbutton.selected');
		last.removeClass("selected");
		_mbuttonUnSelect(last);
		$(this).addClass("selected");
		
		//LOAD
		_loadPage($(this).find("a").attr("rel"));
	});
	//AJAX Default -- home
	$.MUTEX_load = false;
	function _loadHome(){
		$.MUTEX_load = true;
		
		var page = $('.mbutton.selected').find("a").attr("rel");
		if(page==""){ page = "p_home.php"; }
		
		$('body').css("overflow","hidden");
		$('.content').css("width",$.ww+"px");
		$('.content').css("margin-left",$.ww+"px");
		$.ajax({
			url: page,
			success: function(data){
				$('.content').html(data);
				
				_add(page);
				$('.content').animate({"margin-left":"0px"},{queue:true, duration:500, easing:"easeOutQuad", 
					complete:function(){ 
						$('.content').css("width","100%");
						$('body').css("overflow","visible");
						$.MUTEX_load = false;
					}
				});
			}
		});
	}
	function _loadPage(page){
		if(page == null || page == "") return false;
		
		$.MUTEX_load = true;
		$('body').css("overflow","hidden");
		$('.content').css("width",$.ww+"px");
		$('.content').animate({"margin-left":"-"+$.ww+"px"},{queue:true, duration:500, easing:"easeInQuad", 
			complete:function(){
				
				$('.content').css("margin-left",$.ww+"px");
				$.ajax({ 
				url: page,
				success: function(data){
					$('.content').html(data);
					
					_add(page);
					$('.content').animate({"margin-left":"0px"},{queue:true, duration:500, easing:"easeOutQuad", 
						complete:function(){
							$('.content').css("width","100%");
							$('body').css("overflow","visible");
							$.MUTEX_load = false;
						}
					});
				}});
				
			}
		});
	}
	
	//ADD code for specific sections
	function _add(page){
		
		_typeit(33,2);
		
		//jQuery TOOLTIPS
		$('.tooltip').tooltip({ dataAttr : 'data', cursor: '' });
		
		if(page.indexOf("portfolio.php") > -1){
			
			_klightbox();
			
			//Portfolio works scrollin'Load
			$('.elementContainer').delay(1000).each(function(index){ $(this).delay(index*100).fadeIn(500); });
			
			//Portfolio filter buttons
			$('.pbutton').click(function(){
				if($.MUTEX_load){ return false; }
				if($(this).hasClass("selected")){ return false; }
				$(this).addClass("selected");
				//LOAD page
				_loadPage($(this).find("a").attr("rel"));
			});
			
			//Rollover menu filters
			$('.pbutton').mouseenter(function(){
				if($(this).hasClass("selected")){ return false; }
				$(this).css("background","#FFFFFF");
				$(this).animate({"padding-bottom": "22px"},{duration:500, easing: "easeOutBounce", queue: false});
				$(this).find('a').css("color","#D50302");
			});
			$('.pbutton').mouseleave(function(){
				if($(this).hasClass("selected")){ return false; }
				$(this).css("background","#BA0403");
				$(this).animate({"padding-bottom": "2px"},{duration:500, easing: "easeOutBounce", queue: false});
				$(this).find('a').css("color","#FFFFFF");
			});
			
			//Rollover elements
			$('.elementContainer').each(function(){
				$(this).css("width",$(this).width()+"px");
				$(this).css("height",$(this).height()+"px");
			});
			if($.browser.msie){
				$('.element').mouseenter(function(){
					$(this).animate({"backgroundColor": "#BA0403"},{duration:350, easing: "easeOutQuad", queue: false});
				});
				$('.element').mouseleave(function(){
					$(this).animate({"backgroundColor": "#FFFFFF"},{duration:350, easing: "easeOutQuad", queue: false});
				});			
			}else{
				$('.element').mouseenter(function(){
					$(this).animate({"margin-top": "-15px"},{duration:350, easing: "easeOutQuad", queue: false});
					$(this).animate({"backgroundColor": "#BA0403"},{duration:350, easing: "easeOutQuad", queue: false});
				});
				$('.element').mouseleave(function(){
					$(this).animate({"margin-top": "0px"},{duration:350, easing: "easeOutQuad", queue: false});
					$(this).animate({"backgroundColor": "#FFFFFF"},{duration:350, easing: "easeOutQuad", queue: false});
				});
			}
		}
		
	}
	
});
