var profileLoaded = false;
var skillsLoaded = false;
var educationLoaded = false;
function bodyLoaded(){
$("body").css({"visibility":"visible"});

var actualSection="profile";
$(document).ready(function(){
	
	conf();
	$(document).data({"working":"false"});
	
	var lastImage = "";
	var ni=1;
	function loadTopImage(){
		var topImages = ["baseBackground.png","baseBackground2.png","baseBackground3.png","baseBackground4.png","baseBackground5.png","baseBackground6.png"];
		var img = topImages[ni];
		$("#imgb").animate(
		{
			opacity:0
		},1000,function(){
		$("#imgb").attr('src','img/changing/'+img).animate({opacity:1},1000);
		});
		alert(img+" "+ni);
		lastImage = img;
		ni++;
		if(ni>topImages.length-1){
			ni=0;
		}	
		}
		
		function loadTopImage2(img){
			$("#imgb").animate(
			{
				opacity:0
			},1000,function(){
			$("#imgb").attr('src','img/changing/'+img).animate({opacity:1},1000);
			});
		}
	
	function loadLeftImage(img){
	
	if($(document).data("working")=="false"){
	$(document).data({"working":"true"});
		$("#imgl").animate(
		{
			opacity:0
		},1000,function(){
		$("#imgl").attr('src','img/'+img).animate({opacity:1},1000,function(){$(document).data({"working":"false"});});
		});
		
	}
	}
	
	//$(document).everyTime(15000,function(){loadTopImage()});
	
	
	$("#mSkills").bind("click",function(e){if($(document).data("working")=="false"){if($("#imgl").attr("src")!="img/firestar.jpg"){
			$("#mSkills").effect("shake",{times:3,distance:2},80);
			loadTopImage2("baseBackground6.png");
			loadLeftImage("firestar.jpg");
			showSkills();
		}}});
	
	$("#mProfile").bind("click",function(e){if($(document).data("working")=="false"){if($("#imgl").attr("src")!="img/fire2.jpg"){
			$("#mProfile").effect("shake",{times:3,distance:3},80);
			loadTopImage2("baseBackground.png");
			loadLeftImage("fire2.jpg")
			showProfile();
	}}});
	
	$("#mEducation").bind("click",function(e){if($(document).data("working")=="false"){if($("#imgl").attr("src")!="img/feathers.jpg"){
			$("#mEducation").effect("shake",{times:3,distance:3},80);
			loadTopImage2("baseBackground4.png");
			loadLeftImage("feathers.jpg")
			showEducation();
	}}});
	
	$("#mExperience").bind("click",function(e){if($(document).data("working")=="false"){if($("#imgl").attr("src")!="img/experience.jpg"){
			$("#mExperience").effect("shake",{times:3,distance:3},80);
			loadTopImage2("baseBackground7.png");
			loadLeftImage("experience.jpg")
			showExperience();
	}}});
	
	$("#mContact").bind("click",function(e){if($(document).data("working")=="false"){if($("#imgl").attr("src")!="img/contact.jpg"){
			$("#mContact").effect("shake",{times:3,distance:3},80);
			loadTopImage2("baseBackground3.png");
			loadLeftImage("contact.jpg");
			showContact();
	}}});
	
	$("#mGuest").bind("click",function(e){writeSign();if($(document).data("working")=="false"){if($("#imgl").attr("src")!="img/sign.jpg"){
			$("#mGuest").effect("shake",{times:3,distance:3},80);
			loadTopImage2("baseBackground2.png");
			loadLeftImage("sign.jpg")
	}}});
	
	//$("#shadow").draggable();
		
	
	function writeSign(){
		$("#navIn").hide();

		$.ajax({url:"html/guestbook/signGuestBook.html",success:function(html){$("#navIn").html(html);$("#navIn").fadeIn("slow")}});
		$.ajax({
			url: "html/guestbook/js/js.js",
			dataType: 'script'
		});
	}
	
	function showProfile(){
		$("#navIn").hide();

		$.ajax({url:"html/profile/profile.html?nocache=Math.random()*1000",success:function(html){$("#navIn").html(html);$("#navIn").fadeIn("slow")}});
		$.ajax({
			url: "html/profile/js/js.js?nocache=Math.random()*1000",
			dataType: 'script'
		});
	}
	
	function showSkills(){
		$("#navIn").hide();

		$.ajax({url:"html/skills/skills.html?nocache=Math.random()*1000",success:function(html){$("#navIn").html(html);$("#navIn").fadeIn("slow")}});
		/*$.ajax({
			url: "html/skills/js/js.js?nocache=Math.random()*1000",
			dataType: 'script'
		});*/
	}
	
	function showExperience(){
		$("#navIn").hide();

		$.ajax({url:"html/experience/experience.html?nocache=Math.random()*1000",success:function(html){$("#navIn").html(html);$("#navIn").fadeIn("slow")}});
		$.ajax({
			url: "html/experience/js/js.js?nocache=Math.random()*1000",
			dataType: 'script'
		});
	}
	
		function showContact(){
		$("#navIn").hide();

		$.ajax({url:"html/contact/contact.html?nocache=Math.random()*1000",success:function(html){$("#navIn").html(html);$("#navIn").fadeIn("slow")}});
		/*$.ajax({
			url: "html/contact/js/js.js?nocache=Math.random()*1000",
			dataType: 'script'
		});*/
	}
	
		function showEducation(){
		$("#navIn").hide();

		$.ajax({url:"html/education/education.html?nocache=Math.random()*1000",success:function(html){$("#navIn").html(html);$("#navIn").fadeIn("slow")}});
		$.ajax({
			url: "html/education/js/js.js?nocache=Math.random()*1000",
			dataType: 'script'
		});
	}
	
	
	function stopRKey(evt) { 
		var evt = (evt) ? evt : ((event) ? event : null); 
		var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); 
		if ((evt.keyCode == 13) && (node.type=="text"))  {return false;} 
	} 

	document.onkeypress = stopRKey;
	
	setTimeout(showProfile,1500);
	
});


}
	
	function conf(){
		$("#shadow").hide();
		$("#shadow").fadeIn(3000);
		$("li").hide();
		setTimeout(function(){$("li").show('drop',{direction:"up"},700)},1000);
		$("#imgb").attr('src','img/changing/baseBackground.png');
		$("#imgl").attr('src','img/fire2.jpg');
	}

