// JavaScript Document

$(document).ready(function(){

	$('.wrapper li img').ajaxStart(function() {
			$(this).parent().attr("style", "background:#900;");
	}).ajaxComplete(function() {
			$(this).parent().attr("style", "background:none;");
	});

	$(".top").click(function() {
		$( 'html, body' ).animate( { scrollTop: 0 }, 'normal' );
	});

	var header = false;
	var portfolio = false;
	var resume = false;
	var titleColor = "#333";
	var contentColor = "#666";
	var hoverColor = "#0A84C1";
	var hoverTime = 600;
	var infoSlideTime = 300;
	var sectionSlideTime = 300;
  $("#header").click(function(){
		if(header == false) {
			$("#header").animate({"top": "-=100px"}, "normal");
			$(".section").animate({"top": "-=30px"}, "normal");
			$(".section").show();
			$(".section ol").hide();
			header = true;
			section = false;
		} else {
			//$("#header").animate({"top": "+=120px"}, "normal");
			//$(".section").slideUp("fast");
			$(".section").slideDown("fast");
			$(".section ol").hide();
			$(".section").removeClass("sectionon");
			$(".section .title").animate({color: titleColor}, hoverTime);
			$(".section .main").animate({color: contentColor}, hoverTime);
			//$(".section").animate({"top": "+=10px"}, "normal");
			$(".content").attr("style", "visibility:hidden; height:0px; overflow:hidden;");
			header = true;
			section = false;
		}
	});


	var section = false;
	
	function hoversection(thissection){
		var t1, t2;
		$(thissection).hover(
			function() {
				var _self = $(thissection);
				if (section == false) {
					clearTimeout(t2);
					t1 = setTimeout(function(){_self.children("ol").slideDown("fast");},infoSlideTime);
				} else {
				}
			},
			function() {
				var _self = $(thissection);
				if (section == false) {
					clearTimeout(t1);
					t2 = setTimeout(function(){_self.children("ol").slideUp("fast");},infoSlideTime);
					_self.addClass("hover");
				} else {
				}
			}
		);
	}
	
	hoversection(".portfolio");
	hoversection(".resume");
	hoversection(".blog");
	hoversection(".contact");
	
	
	function clicksection(thissection, thiscontent) {
		$(thissection).click(
			function(e) {
				if(section == false) {
					$(thissection).addClass("sectionon");
					$(thissection).siblings(".section").slideUp(sectionSlideTime);
					$(thissection).children("ol").slideDown("fast");
					$(thiscontent).attr("style", "visibility:visible; height:auto;");
					section = true;
				} else {
					$(".section").slideDown("normal");
					$(thissection).removeClass("sectionon");
					$(thissection).children("ol").slideUp(sectionSlideTime);
					$(thiscontent).attr("style", "visibility:hidden; height:0px; overflow:hidden;");
					section = false;
				}			
				e.preventDefault();
			}
		);
	}

	clicksection(".portfolio", ".portfolioc");
	clicksection(".resume", ".resumec");
	clicksection(".blog", ".blogc");
	clicksection(".contact", ".contactc");


	$(".hover").hover(function() {
		if(section == false) {
			$(this).find(".title").animate({color: hoverColor}, hoverTime);
			$(this).find(".main").animate({color: hoverColor}, hoverTime);
		} else {
		}
	},
	function() {
		if(section == false) {
			$(this).find(".title").animate({color: titleColor}, hoverTime);
			$(this).find(".main").animate({color: contentColor}, hoverTime);
		} else {
		}
	});

	$(".headerhover").hover(function() {
		if(header == false) {
			$(this).find(".title").animate({color: hoverColor}, hoverTime);
			$(this).find(".main").animate({color: hoverColor}, hoverTime);
		} else {
		}
	},
	function() {
		if(header == false) {
			$(this).find(".title").animate({color: titleColor}, hoverTime);
			$(this).find(".main").animate({color: contentColor}, hoverTime);
		} else {
		}
	});

});

