$(document).ready(function()
{
	links('#nav-links');
	slide('#slide', 500, .8, -62, 0, 15, 0, 0);
	$(this).delay(500,function(){slide('#nav-links a', 500, .8, 100, 0, 0, 0, 0, 10) });
	$(this).delay(1400,function(){$('#fadeIn img').fadeTo('slow', 1.0) });
	$('#divLine').animate({width:"80%"},600);
	$('#divLineBold').animate({width:"20%"},600);
	$(this).delay(2500,function(){$('#content').fadeTo('slow', 1.0)});
	$(this).delay(3000,function(){$('#footer').fadeTo('slow', 1.0)});
	$(this).delay(3000,function(){$('#award').fadeTo('slow', 0.8)});
	//$(".project img").each(function(){$(this).crossfade()});
	$(".lightbox").lightbox();
	
});

function slide(nav_id, time, multiplier, startML, secML, thirdML, lastML, timer)
{

	var target = nav_id;
	var timer = timer;
	
	$(target).each(function(i)
	{
		$(this).css("margin-left", startML+"px");
		
		timer = (timer*multiplier + time);
		$(this).animate({ marginLeft: secML+"px" }, timer);
		$(this).animate({ marginLeft: thirdML+"px" }, timer);
		$(this).animate({ marginLeft: lastML+"px" }, timer);
	});
}

function links(link_id) {

	$(link_id+' a')
		.css( {backgroundPosition: "0 -35px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:500})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 -35px)"}, {duration:500})
		})
}

function ieHover(div_id){
	var target = div_id+' img';
	
	$(target).each(function(){
			var $$ = $(this);
            var colourImage = $$.css('backgroundImage').replace(/^url|[\(\)"']/g, '');
			var bwImage = $$.attr("src");
			$$.hover(function(){
				$(this).attr('src', colourImage);
							  },
							  function() {
				$(this).attr('src',bwImage);
								  }
					 )
	});
}

function loadContent(id) {
	
	$('#content').fadeTo('fast', 0.0);
	$('#footer').fadeTo('fast', 0.0);
	$(this).delay(500,function(){$("#content").load("da_content.php?o="+id+"")});
	$(document).ready(function()
	{
		if (id == 'portfolio') { 
					if ($.browser.msie && $.browser.version == 7.0) {
						$(this).delay(1000,function(){ieHover("#portHolder")});
						$(this).delay(1000,function(){$("ul").css("padding-bottom","5px")});
					}else{
						$(this).delay(1000,function(){$("#portHolder img").each(function(){$(this).crossfade()})});
					};
					$(this).delay(1000,function(){$(".lightbox").lightbox()});
			};
		$(this).delay(1000,function(){$('#content').fadeTo('fast', 1.0)});
		$(this).delay(1000,function(){$('#footer').fadeTo('slow', 1.0)});
	});
}
