// PRELOAD IMAGES SCRIPT
jQuery.preloadImages = function()
		{
		  var image1 = $('<img />').attr('src', 'imageURL.jpg');
		  for(var i = 0; i<arguments.length; i++)
		  {
			// Insert preloaded image after it finishes loading
			$('<img />')
			    .attr('src', arguments[i])
			    .load(function(){
			        $('.profile').append( $(this) );
			        // Your other custom code
			    });
		  }
	}
	
	
$.preloadImages("./images/spacer.gif", 
				"./images/mainpic0.png",
				"./images/mainpic1.png",
				"./images/mainpic2.png",
				"./images/header.png",
				"./images/bg_white_pattern.jpg",
				"./images/menu_bg.png",
				"./images/tagline.png",
				"./images/violin_kid_pic.png",
				"./images/welcome.png"
				);

imgIndex = 1;

// MAIN jQUERY SCRIPTS
$(document).ready(function() {
    // jQuery code for layout controls onload
    layoutPage();                         // for IE -- execute the layout earlier
    $('#header_bg').load(function() {
        layoutPage();                   // do it again for FF after loading the header
    });

// functions to execute at screen resize
$(window).resize(function() {
    //layoutPage();
});


// functions to lay out the page elements
function layoutPage() {

	$('#main_pic').load('main_pic.htm', function() {  
		$(this).fadeIn("slow", function () { 
			animInterZone(); // animate the lower interactive zone
		});
	});
	
	$('#header').load('./menu.htm', function() {
	
		$('#tagline').slideDown('slow', function() {
			$(this).fadeIn('slow');
		});
	});
	
};

	
function animInterZone() {

$('#main_pic').ready(function() {
		$('#learn_more').load('learn_menu.htm', function() {
			$('#interactive_zone').load('izone_content.htm', function() {
				$('#interactive_zone').slideToggle("slow", function() {
					// do stuff when complete
					$('#learn_more').fadeIn("slow");
				});
			});		
		});
		
	});
};

function imageFlip() {
$('#main_pic').fadeOut('slow', function() {   
	mainImg = '<img id="mainPic" src="./images/mainpic'+imgIndex+'.png" width="686" height="422" alt=" " />';
	imgIndex = imgIndex + 1;
		$('#main_pic').html(mainImg);
		$('#main_pic').fadeIn('slow'); 
	if (imgIndex >= 3) { imgIndex = 0; };
});

}; 

window.setInterval(imageFlip, 15000);

});


