var galleryMatrix = [];

function setGalleryArray(index, value){
	
	galleryMatrix[index] = value;	
	
}

function initgallery(){
	
	initAdreessGallery(0);

}

function initAdreessGallery(time){
	
	var vlr = $.address.value();
	value = vlr.split("/");
	
	if(value[2]!=undefined && value[2]!=""){
		
		if(galleryMatrix[value[2]]!=undefined){
		
			openSingleGallery(galleryMatrix[value[2]], value[2], time);
			
		}else{
			
			closeSingleGallery(time);
			
		}
		
	}else{
			
		closeSingleGallery(time);
			
	}
	
}

function openSingleGallery(id, title, time){
	
	var url = "gallery_single.php?id=" + id +"&ln=" + lang;
	var tm = (time==0) ? 0 : 500;
	
	$("#galleryArea").stop(true, true).fadeOut(tm);
	
	window.setTimeout(function() {
				
		var cnt = document.getElementById("galleryArea");
		cnt.innerHTML = '';
				
		$("#galleryArea").load(url, function() {
					
			$("#galleryArea").stop(true, true).fadeIn(tm);
					 
		});
				
	}, tm);
	
	$.address.value("gallery/" + title);

}

function closeSingleGallery(time){
	
	var tm = (time==0) ? 0 : 500;
	
	$("#galleryArea").stop(true, true).fadeOut(tm);
	
	window.setTimeout(function() {
				
		var cnt = document.getElementById("galleryArea");
		cnt.innerHTML = '';
				
		$("#galleryArea").load("gallery_list.php?ln=" + lang, function() {
					
			$("#galleryArea").stop(true, true).fadeIn(tm);
					 
		});
				
	}, tm);
	
	$.address.value("gallery");
	
}
