// --------------------------------------------------------------------
// PRELOAD NAV IMAGES http://jquery-howto.blogspot.com/2009/02/preload-images-with-jquery.html
// --------------------------------------------------------------------
var image1 = $('<img />').attr('src', 'images/stephenhopermediadesign.png');
var image2 = $('<img />').attr('src', 'images/graphicdesign.png');
var image3 = $('<img />').attr('src', 'images/webdesign.png');
var image4 = $('<img />').attr('src', 'images/musicforfilmandtv.png');
var image5 = $('<img />').attr('src', 'images/testimonials.png');
var image6 = $('<img />').attr('src', 'images/contactme.png');




// debug: skip to end of animations when Escape key is pressed
$(document).keyup(function(event){
    if (event.keyCode == 27) {
        //alert('escaped! skip to end of animations');
		$("#lm1,#lm2,#lm3,#lm4,#lm5,#lm6,#leftcontent .heading,#leftcontent .bodytext,#rightcontent .heading,#rightcontent .bodytext,#headerstrip,#menutable,#leftcontent,#rightcontent").stop(true,true);
    }
});
// NB this companion code would dispose of 'skip to end of animation when escape key is pressed'
// BUT I DON'T KNOW WHERE TO PUT IT
// LUCKILY IT IS OTIOSE
//							$(document).unbind('keyup');




$(document).ready(function(){
// --------------------------------------------------------------------
// ON LOAD
// --------------------------------------------------------------------

// fadeIn() will fade in something which is display:none, but animate() won't because it doesn't remove the display:none

// CSS sets #headerstrip, #leftcontent, #rightcontent to display:none

// set nav button opacities to 0 (buttons must be transparent until hover)
$("#nav1,#nav2,#nav3,#nav4,#nav5,#nav6").animate({opacity: 0}, 0);

// set OTHER opacities to 0
$("#navunhover,#leftcontent .heading,#leftcontent .bodytext,#rightcontent .heading,#rightcontent .bodytext").animate({opacity: 0}, 0, function(){

// fadein headerstrip (which was display:none)(???), but all child elements are opacity 0
$("#headerstrip").fadeIn(200, function(){

// animateshow each element of the headerstrip BUT THERE IS NOW ONLY 1
//$("#lm1").animate({opacity: 1}, 100, 'easeInSine', function(){
//$("#lm2").animate({opacity: 1}, 100, 'easeInSine', function(){
//$("#lm3").animate({opacity: 1}, 100, 'easeInSine', function(){
//$("#lm4").animate({opacity: 1}, 100, 'easeInSine', function(){
//$("#lm5").animate({opacity: 1}, 100, 'easeInSine', function(){
//$("#lm6").animate({opacity: 1}, 100, 'easeInSine', function(){
$("#navunhover").animate({opacity: 1}, 200, 'easeInSine', function(){

// fade in grey strip under menu
//$("#menutable").animate({backgroundColor:'#DDD'},300, 'easeInSine', function(){

// fadein leftcontent BG (which was display:none)
$("#leftcontent").fadeIn(200, function(){

// fadein rightcontent BG (which was display:none)
$("#rightcontent").fadeIn(200, function(){

// fadein leftcontent CONTENT (which was display:none)
$("#leftcontent .heading").animate({opacity: 1}, 200, 'easeInSine', function(){
$("#leftcontent .bodytext").animate({opacity: 1}, 400, 'easeInSine', function(){

// fadein rightcontent CONTENT (which was display:none)
$("#rightcontent .heading").animate({opacity: 1}, 200, 'easeInSine', function(){
$("#rightcontent .bodytext").animate({opacity: 1}, 400, 'easeInSine', function(){



});});});});});});});
});});
//});});});});});
//});



// add fadelink class to all non-image i.e. text-based links
$("a:not(:has(img))").addClass("fadelink");

// PREP THE fadelink CLASS SO IT HOVERS PROPERLY
$('.fadelink').css('color','black');

// --------------------------------------------------------------------
// ***NAV FUNCTIONALITY***
// --------------------------------------------------------------------

// MOUSEOVER FADING OF REGULAR HYPERLINKS
      $('.fadelink').hover( 
        function () {
          $(this).animate({color:'#6699FF'}, {queue:false,duration:300});
        }, function () { 
          $(this).animate({color:'#000'}, {queue:false,duration:600});
        }); 
// using info found at http://www.theruntime.com/blogs/thomasswilliams/archive/2008/11/24/jquery-hover-fading-on-mouse-over-and-mouse-out-without.aspx



// MOUSEOVER FADING-IN/OUT OF NAV BUTTONS
$("#nav1,#nav2,#nav3,#nav4,#nav5,#nav6").hover(
        function () {
			$(this).stop().animate({opacity: 1}, 300);
        }, function () { 
			$(this).stop().animate({opacity: 0}, 600);
        }); 



// MOUSEOVER IMAGE SWAP
$("#sendbutton").hover( 
        function () {
          $(this).attr('src', 'images/send_button-over.gif'); return true;
        }, function () { 
          $(this).attr('src', 'images/send_button.gif'); return true;
        }); 

// --------------------------------------------------------------------
// ***OTHER FUNCTIONALITY***
// --------------------------------------------------------------------


// back to top script
$('.backtotop').click(function(){
//	$('html, body').animate({scrollTop:0}, 'slow');
	$('html, body').animate({scrollTop:0}, 3000);
	return false;
});


// attempt at fadeouts on window unload - alert works but animation doesn't
// $(window).unload(
//	function(){
//		$("#container").animate({opacity: 0}, 1000);
//		$("#container").fadeOut(100);
//		alert('bye');
//});

// --------------------------------------------------------------------
}); // end JQ document ready
