var currentProject = 0;
var newImage = new Image;
var initImage = new Image;
var nextImage = new Image;

var imageRollovers = function(scope) {
	$(sID + "-images img", scope).hover(
		function () {if($(this).css("opacity") != 0.5){$(this).css("opacity", 0.6);}},
		function () {if($(this).css("opacity") != 0.5){$(this).css("opacity", 1.0);}}		
	);
}	
imageRollovers(this);

var imageChange = function(scope) {
    $(sID + "-images img", scope).click(
        function () {
		if($(this).css("opacity") != 0.5){
			currentImage = $(this).attr("alt");
			$(sID + "-images img").css("opacity", 1.0);
			$(this).css("opacity", 0.5);
			$(sID + "-image").fadeTo(0,0,function () {
				$('#loading').css('visibility', 'visible');
				newImage.src = "./pages/" + sLocation + "/" + sGallery + "/images/" + currentImage;					
			});
		}
	});
}	
imageChange(this);

$(document).ready(function() {
	$(sID + "-menu div").hover(
		function () {if($(this).css("opacity") != 0.5){$(this).fadeTo(0.0,0.7,function () {});}},
		function () {if($(this).css("opacity") != 0.5){$(this).stop();$(this).fadeTo(0.0,1.0,function () {});}}
	);
	$(sID + "-images img").hover(
		function () {if($(this).css("opacity") != 0.5){$(this).fadeTo(0.0,0.7,function () {});}},
		function () {if($(this).css("opacity") != 0.5){$(this).stop();$(this).fadeTo(0.0,1.0,function () {});}}		
	);
	
	$(sID + "-menu div").click(
		function () {
			if($(this).css("opacity") == 0.7){
				sGallery = $(this).attr("name");
				
				$(sID + "-menu div").fadeTo(0,1,function () {});
				$(this).stop();
				$(this).css("opacity", 0.5);
				$.get(sRequest, { project: sGallery, type: 0 },function(data){	
					currentImage = data;
					$(sID + "-info").fadeTo(0,0.0,function () {});
					$(sID + "-images").fadeTo(0,0.0,function () {});
					$(sID + "-image").fadeTo(0,0.0,function () {
						$('#loading').css('visibility', 'visible');				
						nextImage.src = "./pages/" + sLocation + "/" + sGallery + "/images/" + currentImage;					
					});
				});
			}
		}
	);
	$(sID + "-images img").click(
		function () {
			if($(this).css("opacity") == 0.7){
				currentImage = $(this).attr("alt");
				$(sID + "-images img").fadeTo(0,1,function () {});
				$(this).stop();
				$(this).css("opacity", 0.5);
				$(sID + "-image").fadeTo(0,0,function () {
					$('#loading').css('visibility', 'visible');
					newImage.src = "./pages/" + sLocation + "/" + sGallery + "/images/" + currentImage;					
				});
			}
		}
	);
	initializeShow();
});
newImage.onload = function(){
	$('#loading').css('visibility', 'hidden');
	$(sID + "-image").html("<img src='./pages/" + sLocation + "/" + sGallery + "/images/" + currentImage+"'/>");
	$(sID + "-image").fadeTo(0,1.0,function () {});          
}
initImage.onload = function(){
	$('#loading').css('visibility', 'hidden');
	$(sID + "-image").html("<img src='./pages/" + sLocation + "/" + sGallery + "/images/" + currentImage+"'/>");
	$(sID + "-image").fadeTo(0,1.0,function () {
		$(sID + "-info").fadeTo(0,1.0,function () {
			$(sID + "-images").fadeTo(0,1.0,function () {});					
		});
	});      
}
nextImage.onload = function(){
    $('#loading').css('visibility', 'hidden');
    $(sID + "-image").html("<img src='./pages/" + sLocation + "/" + sGallery + "/images/" + currentImage+"'/>");
    $(sID + "-image").fadeTo(0,1.0,function () {
		$.get(sRequest, { project: sGallery, type: 1 },function(data){
			$(sID + "-info").html(data);
			$(sID + "-info").fadeTo(0,1.0,function () {
				$.get(sRequest, { project: sGallery, type: 2 },function(data){
			    	$(sID + "-images").html(data);
					$(sID + "-images").fadeTo(0,1.0,function () {});
					$("#image0").fadeTo(0,0.5,function () {});
					imageRollovers(this);
					imageChange(this);
				});				
			});
		});
	});        
}
function initializeShow(){
	initImage.src = "./pages/" + sLocation + "/" + sGallery + "/images/" + currentImage;
	$("#image0").fadeTo(0,0.5,function () {});
	$("#project00").fadeTo(0,0.5,function () {});
}
