//  #######################################################
//			This is the main javascript/jQuery code
//  #######################################################



	var picId = 0;
	
	$(document).ready( 
		function(){
	
			loadContent("jq_menu_login.php", "logout", false);	
			loadContent("jq_menu_links.php", "topMenu", false);
			loadContent("jq_doGetFtpUpload.php", "container", false); //do this before you fill the container with actual content. 
			loadContent("jq_pagePictureViewer.php", "container", false);
			
		}
	);
	
	$(document).keypress( function(e){
	//	alert(e.keyCode);
		if(e.keyCode==39){
			getNextPic();
		}
		if(e.keyCode==38){
//			getNewestPic();
		}
/*
		if(e.keyCode==27){
			//alert("Escape");
			getNewestPic();
		}
*/
		if(e.keyCode==37){
			getPreviousPic();
		}
	});
	
	
	function loadContent(sourceURL, pageElementId, loadAsync){

		if (!loadAsync) loadAsync = false;
		
		$.ajax({
			url: sourceURL,
			type: "GET",
			async: false,
			success: function(response){
				$("#"+pageElementId).html(response)
			}
		});
		
	}
	
	function runScript(sourceURL){
		$.ajax({
			url: sourceURL,
			type: "GET",
			async: false
		});
	}
	
	function getPreviousPic(){
		setPicId_previous();
		drawPicture();
		loadComments();
	}
	
	function getNextPic(){
		setPicId_next();
		drawPicture();
		loadComments();
	}
	
	function getNewestPic(){
		setPicId_newest();
		drawPicture();
		loadComments();
	}
	
	function setPicId_newest(){
		$.ajax({
			url: "jq_picId_newest.php",
			async: false,
			type: "GET",
			dataType: "script"
		});
	//	alert(picId);
	}
	
	function setPicId_next(){
		$.ajax({
			url: "jq_picId_next.php?picId="+picId,
			async: false,
			type: "GET",
			dataType: "script"
		});
	//	alert(picId);
	}
	
	function setPicId_previous(){
		$.ajax({
			url: "jq_picId_previous.php?picId="+picId,
			async: false,
			type: "GET",
			dataType: "script"
		});
	//	alert(picId);
	}
	
	function drawPicture(){
		$.ajax({
			url: "jq_do_drawPicture.php?picId="+picId,
			type: "GET",
			success: function(response){
				var tmp = new Image();
				tmp.src = response.src;
				$("#pictureDiv").html(response);
			}
		});
	}
	
	function loadComments(){
		$.ajax({
			url: "jq_page_comments.php?picId="+picId,
			type: "GET",
			success: function(response){
				$("#commentDiv").html(response);
			}
		});
	}