var Site = {

	start : function($)
	{
		
		// Popup Links
		jQuery("a.popup").click(
			function(event) {
				event.preventDefault();
				window.open($(this).attr("href"));
			}
		);     

		// Home page loading animation
			function startQue() {
				clearTimeout(showStart);
				jQuery("#wordmark").fadeOut("slow", loadContent);
				setTimeout(loadcontent, 6000);
			}
			function loadContent(){
				jQuery("#content").fadeIn("slow", loadHero);
				$("#nav").fadeIn("slow");
			};	
			function loadHero() {	
				setTimeout(showHero1, 2000);
				setTimeout(hideHero1, 6000);
			};
			function showHero1() {
				$("#featImg01").fadeIn("slow");
			};
			function hideHero1() {
				$("#featImg01").parent().fadeOut("slow");
				setTimeout(showHero2, 2000);
				setTimeout(hideHero2, 6000);
			};
			function showHero2() {
				$("#featImg02").fadeIn("slow");
			};
			function hideHero2() {
				$("#featImg02").parent().fadeOut("slow");
				setTimeout(showHero3, 2000);
				setTimeout(hideHero3, 6000);
				};
			function showHero3() {
				$("#featImg03").fadeIn("slow");
			};
			function hideHero3() {
				$("#featImg03").parent().fadeOut("slow");
				setTimeout(showHero4, 2000);
				setTimeout(hideHero4, 6000);
				};
			function showHero4() {
				$("#featImg04").fadeIn("slow");
			};
			function hideHero4() {
				$("#featImg04").parent().fadeOut("slow");
				setTimeout(showHero5, 2000);
				setTimeout(hideHero5, 6000);
				};
			function showHero5() {
				$("#featImg05").fadeIn("slow");
			};
			function hideHero5() {
				$("#featImg05").parent().fadeOut("slow");
				setTimeout(showHero6, 2000);
				setTimeout(hideHero6, 6000);
				};
			function showHero6() {
				$("#featImg06").fadeIn("slow");
			};
			function hideHero6() {
				$("#featImg06").parent().fadeOut("slow");
				setTimeout(showHero7, 2000);
				setTimeout(hideHero7, 6000);
			};
			function showHero7() {
				$("#featImg07").fadeIn("slow");
			};
			function hideHero7() {
				$("#featImg07").parent().fadeOut("slow");
				setTimeout(showHero8, 2000);
				setTimeout(hideHero8, 6000);
			};
			function showHero8() {
				$("#featImg08").parent().fadeIn("slow");
			};
			function hideHero8() {
				$("#featImg08").parent().fadeOut("slow");
				setTimeout(showHero9, 3000);
			};
			function showHero9() {
				$("#featImg09").parent().fadeIn("slow");
				rloadHero();
			};

		var loading = $("#wordmark").size();
		if (loading == 1) {	
                        $("#wordmark").show();	
			var showStart = setTimeout(startQue,6000);
			
		} else {  
			showHero();
		}

		function showHero() {
			rloadHero();
		}
			
			function rloadHero() {	
				setTimeout(rshowHero1, 2000);
				setTimeout(rhideHero1, 6000);
			};
			function rshowHero1() {
				$("#featImg02").parent().hide();
				$("#featImg03").parent().hide();
				$("#featImg04").parent().hide();
				$("#featImg05").parent().hide();
				$("#featImg06").parent().hide();
				$("#featImg07").parent().hide();
				$("#featImg08").parent().hide();
				$("#featImg09").parent().hide();
				$("#featImg01").parent().fadeIn("slow");
			};
			function rhideHero1() {
				$("#featImg01").parent().fadeOut("slow");	
				setTimeout(rshowHero2, 2000);
				setTimeout(rhideHero2, 6000);
			};
			function rshowHero2() {
				$("#featImg02").parent().fadeIn("slow");
			};
			function rhideHero2() {
				$("#featImg02").parent().fadeOut("slow");	
				setTimeout(rshowHero3, 2000);
				setTimeout(rhideHero3, 6000);
			};
			function rshowHero3() {
				$("#featImg03").parent().fadeIn("slow");
			};
			function rhideHero3() {
				$("#featImg03").parent().fadeOut("slow");	
				setTimeout(rshowHero4, 2000);
				setTimeout(rhideHero4, 6000);
			};
			function rshowHero4() {
				$("#featImg04").parent().fadeIn("slow");
			};
			function rhideHero4() {
				$("#featImg04").parent().fadeOut("slow");	
				setTimeout(rshowHero5, 2000);
				setTimeout(rhideHero5, 6000);
			};
			function rshowHero5() {
				$("#featImg05").parent().fadeIn("slow");
			};
			function rhideHero5() {
				$("#featImg05").parent().fadeOut("slow");	
				setTimeout(rshowHero6, 2000);
				setTimeout(rhideHero6, 6000);
			};
			function rshowHero6() {
				$("#featImg06").parent().fadeIn("slow");
			};
			function rhideHero6() {
				$("#featImg06").parent().fadeOut("slow");	
				setTimeout(rshowHero7, 2000);
				setTimeout(rhideHero7, 6000);
			};
			function rshowHero7() {
				$("#featImg07").parent().fadeIn("slow");
			};
			function rhideHero7() {
				$("#featImg07").parent().fadeOut("slow");	
				setTimeout(rshowHero8, 2000);
				setTimeout(rhideHero8, 6000);
			};
			function rshowHero8() {
				$("#featImg08").parent().fadeIn("slow");
			};
			function rhideHero8() {
				$("#featImg08").parent().fadeOut("slow");	
				setTimeout(rshowHero9, 2000);
				setTimeout(rhideHero9, 6000);
};
			function rshowHero9() {
				$("#featImg09").parent().fadeIn("slow");
			};
			function rhideHero9() {
				$("#featImg01").parent().fadeOut("slow");	
				setTimeout(rshowHero1, 2000);
				setTimeout(rhideHero1, 6000);
			};

		// Projects Slideshow
                if ($(".slide").size()==1){
		$(".slide>ul>li").css("display","block");
		$.getScript("index_files/mousewheel.plugin.js");
		$.getScript("index_files/ufslide.plugin.js", function(){
			 $("#desc").hide();
			 $(".slide").slide({
			  btnNext: ".next",
			  btnPrev: ".prev",
			  auto: false,
			  mouseWheel: true
		 	});
		});
  		}

		// Project Details Pop-up
		$("#prjPopup").toggle(function(event){
		  event.preventDefault();
		  showProjectDesc();
		  },function(){$("#desc").fadeOut("slow");$("#desc").attr("style","display:none;");});
		//$("#desc").bind("mouseleave",function(){$(this).fadeOut("slow");$(this).attr("style","display:none;");});
		function showProjectDesc(){
		var prjDesc = $("#desc");
		var prjDescH = prjDesc.height();
		var prjNav = $("#slidenav");
		var prjPosition = prjNav.position();
		var prjDescTop = prjPosition.top;
		$("#desc").show().animate({top: (prjDescTop-prjDescH) - 10, opacity: '0.7'}, "12000",'easeInOutQuad');			
		}
		$("#desc").removeClass("descPop");

		// Email obfuscator
  		$("dd#email").each(function()
   		{
   		var email = String($("dd#email").html()).replace(/\s*\(.+\)\s*/, "@");
   		$("dd#email").html(email);
   		});

	}
	
}



jQuery.noConflict();

//slide easing start
jQuery.easing['jswing'] = jQuery.easing['swing'];
jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	}
});
//slide easing Over


jQuery(document).ready(function($){
	Site.start($);
});
