// Array for backgrounds

		var bgs=new Array();
		bgs[0] = "http://images.static-rd.com/images/greenBackground.jpg";
		bgs[1] = "http://images.static-rd.com/images/blueBackground.jpg";
		bgs[2] = "http://images.static-rd.com/images/flowerBackground.jpg";
		
		var currImg = 0;

// Document Ready
$(document).ready(function(){

	// Animated collapse
	animatedcollapse.addDiv('presentContent', 'fade=1,speed=400,group=content')
	animatedcollapse.addDiv('pastContent', 'fade=1,speed=400,group=content')
	animatedcollapse.addDiv('futureContent', 'fade=1,speed=400,group=content')
	
	animatedcollapse.ontoggle=function($, divobj, state){ //fires each time a DIV is expanded/contracted
		//$: Access to jQuery
		//divobj: DOM reference to DIV being expanded/ collapsed. Use "divobj.id" to get its ID
		//state: "block" or "none", depending on state
	}
	
	animatedcollapse.init();
	
	// Resize window
	jQuery.event.add(window, "resize", resizeFrame);
	resizeFrame()
	
	function resizeFrame() 
	{
		var w = $(window).width();
		if (w < 1247) {
		$("#tagLines").hide();
		//$(".doingBlock").text(w);
		} else {
		if ($("#tagLines").css('display') =='none' ) {
			$("#tagLines").fadeIn("fast");
		}
		}
	}
	
		 
	// Hide javascript warning and show CV images
	$('.javascriptWarning, #areWeHuman').hide();
	$('#cvImage').show();
	
								   
		jQuery.preloadImages = function()
			{
			  for(var i = 0; i<arguments.length; i++)
			  {
				jQuery("<img>").attr("src", arguments[i]);
			  }
			}
			
		$.preloadImages("http://images.static-rd.com/images/greenBackground.jpg", "http://images.static-rd.com/images/blueBackground.jpg", "http://images.static-rd.com/images/flowerBackground.jpg");
	
	// Change sidebar text 
	
		$("#present .moveMe").click(function(){
		resetZ(0);
			});
		$("#past .moveMe").click(function(){
		resetZ(1);									  
			});
		$("#future .moveMe").click(function(){
		resetZ(2);
			});
		
		function resetZ(nowImg) {
			if (currImg != nowImg) {
			for (i=0;i<=2;i++) {
			//document.getElementById("block"+i).style.display = "none";
			document.getElementById("block"+i).style.zIndex = -3;
			}
	
			document.getElementById("block"+currImg).style.zIndex = -1;
			document.getElementById("block"+currImg).style.display = "block";
			document.getElementById("block"+nowImg).style.display = "block";
			document.getElementById("block"+nowImg).style.zIndex = -2;
			$("#block"+currImg).fadeOut("slow");
			
			$("#tag"+currImg).fadeOut("slow", callback(nowImg));
			currImg = nowImg;
			}
	
		function callback(nowImg) {
			$("#tag"+nowImg).fadeIn("slow");
		}
		}
	
	
	// Reveal section meaning
	
	$("#present .moveMe").hover(
		  function () {
			$("#present .explain").fadeIn("slow");
		  }, 
		  function () {
			$("#present .explain").fadeOut("slow");
		  }
		);
	
	$("#past .moveMe").hover(
		  function () {
			$("#past .explain").fadeIn("slow");
		  }, 
		  function () {
			$("#past .explain").fadeOut("slow");
		  }
		);
	
	$("#future .moveMe").hover(
		  function () {
			$("#future .explain").fadeIn("slow");
		  }, 
		  function () {
			$("#future .explain").fadeOut("slow");
		  }
		);
	
	// CV
	
	$(".cvContent").hover(
		  function () {
			$("#cvImage").fadeOut("fast");
		  }, 
		  function () {
			$("#cvImage").fadeIn("fast");
		  }
		);
	
	// Tooltip
	
	$("#companies .toolTrigger").tooltip({ effect: 'slide'}); 
	
	// Overlay
	
	$(".bingOverlay a[rel], a[rel='#mainPhoto']").overlay({
		expose: { 
			color: '#000', 
			loadSpeed: 200, 
			opacity: 0.8 
		}
	});
	
	$("a[rel='#mainPhoto']").click(function(){
		$("#mainPhoto img").attr("src", "http://images.static-rd.com/images/4032636211_543216c944_b.jpg"); 
	});
	
	// Contact me
	$("#submitBut").click(function(){
	
	$("input[name='name'],input[name='email'],input[name='subject'],textarea[name='message']").css({'background' : '#FFFFFF url(http://images.static-rd.com/images/formFade.gif) repeat-x 0 0'});
	
	var name = $("input[name='name']").val();  
	if (name == "") {  
	$("input[name='name']").css({'background' : '#fff url(http://images.static-rd.com/images/formError.png) no-repeat top right'});
	$("input[name='name']").focus();  
	var weHaveError = true;
	}
	
	var name = $("input[name='email']").val();  
	if (name == "") {  
	$("input[name='email']").css({'background' : '#fff url(http://images.static-rd.com/images/formError.png) no-repeat top right'});
	$("input[name='email']").focus();  
	var weHaveError = true;
	}
	
	var name = $("input[name='subject']").val();  
	if (name == "") {  
	$("input[name='subject']").css({'background' : '#fff url(http://images.static-rd.com/images/formError.png) no-repeat top right'});
	$("input[name='subject']").focus();  
	var weHaveError = true;
	}
	
	var name = $("textarea[name='message']").val();  
	if (name == "") {  
	$("textarea[name='message']").css({'background' : '#fff url(http://images.static-rd.com/images/formError.png) no-repeat top right'});
	$("textarea[name='message']").focus();  
	var weHaveError = true;
	}
	
	// Recaptcha validation
	var name = $("input[name='recaptcha']").val();  
	var name = jQuery.trim(name);
	var name = name.toLowerCase();
	
	if (name == "" || name != "cat") {  
	$("input[name='recaptcha']").css({'background' : '#fff url(http://images.static-rd.com/images/formError.png) no-repeat top right'});
	$("input[name='recaptcha']").focus();  
	if (weHaveError == null && name != "cat") {  
	$("#formError").html("Sorry, wrong animal!");
	} else {
	$("#formError").html("Whoops! The below fields need to be filled in!");
	}
	var weHaveError = true;
	}
	
	if (weHaveError == true) {
	$("#formError").fadeIn("fast");
	return false; 
	}
	document.getElementById('submitBut').setAttribute('value', 'Submitting...');
	document.getElementById('submitBut').disabled = 'true';
	$.post("includes/ajax.php", $("#contactMe").serialize(),  function(data){
	//alert("Data Loaded: " + data);
	$('.form').html(data);
	
	});
	  return false;
	});
	
	// Blog posts 
	$("#viewMore").click(function(){
	$("#viewMore").hide();
	$("#moreBlogs").load("includes/blog.html");
	$("#moreBlogs").show();
	$("#hideMore").show();
	});
	
	$("#hideMore").toggle(
	function () {
		$("#moreBlogs").hide();
		$("#hideMore").html("Click here to view previous posts");
	},
	function () {
		$("#moreBlogs").show();
		$("#hideMore").html("Click here to close");
	}
	   );
	
	// Recaptcha
	$("textarea[name='message']").focus(function () {
		$("#areWeHuman").fadeIn("slow");										  
	});
	
	
	// Embed Flash
	swfobject.embedSWF("http://images.static-rd.com/images/o2mpu.swf", "myContent", "300", "250", "9.0.0");
	swfobject.embedSWF("http://images.static-rd.com/images/bingLeader.swf", "bingLeader", "728", "90", "9.0.0");
	swfobject.embedSWF("http://images.static-rd.com/images/bingSky.swf", "bingSky", "120", "600", "9.0.0");
	swfobject.embedSWF("http://images.static-rd.com/images/bingMpu.swf", "bingMpu", "300", "250", "9.0.0");

// End of Document Ready
});


