	
	var picturesfull = new Array();
	var descriptions = new Array();
	var loadedPicture = new Array();
	var pictureId = 0;
	var lastId;
	var loaderPicture = null;
	var loadDone = false;
	var timeId = null;
	var f_height = 300;
	var f_width = 300;
    var strSearchResultsOf= "";
    
    function newImage(source) {
        if (document.images) {
            img = new Image();
        	img.src = source;
        	return img;
        }
	}
	
	var displayDone = false;
	var loadDone = false;
	var loaderDone = false;
	var loadBuffDone = false;
	var loadedBuffPicture = null;

	function loadImage(src, name) {
		if(document.images) {
    		loadedPicture[name] = newImage(src);
            loadDone = true;
        }
	}
	function loadBuffImage(src) {
		if(document.images) {
    		loadedBuffPicture = newImage(src);
            loadBuffDone = true;
        }
	}
	function loadLoader() {
		if(document.images) {
    		loaderPicture = newImage("images/loader.gif");
            loaderDone = true;
        }
	}
	
	loadLoader();

	 function displayPicture(func, state, desc) {
	 	
    	if (func == 1 && state != 1) {
    		//loadedPicture["main"] = loadedPicture["buff"];
    		loadImage(picturesfull[pictureId],"main");;
    	} 
    	if(document.images && loadedPicture["main"].complete == true && loadDone == true) {
			$("#picture").hide();
			document.images.picture.src = loadedPicture["main"].src;
			$("#picture_canvas").width(loadedPicture["main"].width+20).height(loadedPicture["main"].height+20);
			$("#picture_canvas").css({position: "absolute", left: ((screen.width/2)-(loadedPicture["main"].width/2)-10), top: ((screen.height/2)-(loadedPicture["main"].height/2)-(screen.height/8) + $(document).scrollTop())});
			$("#picture_canvas").show();
			
			$("#desc").show().width(loadedPicture["main"].width+10).text(desc);
			$("#gallery_menu2").text((pictureId+1)+" "+connective_of+" "+lastId);
			$("#picture").css({position: "relative", top: 0, left: 0});
			$("#picture").fadeIn("slow", function() {
				$("#close_obj").slideDown("slow");
			});
			f_height = $("#picture_canvas").height();
			f_width = $("#picture_canvas").width();
			loadDone = false;
			displayDone = true;
			loadImage(picturesfull[pictureId+1],"buff");

		} else { 
		
			if (state != 1) {
				$("#picture").hide();				
				$("#close_obj").hide();
				$("#desc").hide();
				$("#close_obj").slideUp("slow");
				document.images.picture.src = loaderPicture.src;
				//if (document.images && loaderPicture.complete == true) {
					$("#picture_canvas").width(f_width).height(f_height);
					$("#picture_canvas").css({position: "absolute", left: ((screen.width/2)-(f_width/2)), top: ((screen.height/2)-(f_height/2)-(screen.height/8)+10 + $(document).scrollTop())}).show();
			
					$("#picture").css({position: "relative", top: f_height/2-30, left: f_width/2-30});
					$("#picture").show();
					
				//}
				
			}
			
			setTimeout("displayPicture("+func+", 1, \""+desc+"\");",500);
		}
    }

	function galleryInit(last_id, state, pic_id) {
		pictureId = pic_id - 1;
		
		if (typeof document.height != "undefined") {
			docHeight = document.height;
		} else if (document.body && typeof document.body.scrollHeight != "undefined") {
			docHeight = document.body.scrollHeight;
		}
		if (docHeight < document.documentElement.clientHeight) {
			docHeight = document.documentElement.clientHeight;
		}
		$(".selectField").hide();
		$("#overDiv1").css({display: "block", height: docHeight, background: "color: black"}).show();
		$("#overDiv1").mousedown(function(){
	    	closeGallery();
	    });
		$("#gallery_menu").css({top: $(document).scrollTop()}).slideDown();
		loadImage(picturesfull[pictureId], "main");
			
		lastId = last_id;
		
		displayPicture(0, 0, descriptions[pictureId]);
	}
	
	function pictureAction(action, state) {
		
		if (action == "next" && pictureId < lastId-1) {
			pictureId++;
		} else if(action == "prev" && pictureId > 0) {
			pictureId--;
		} else if (action == "play" && pictureId < lastId-1) {
			document.images.button_stop.src = 'images/iconPlayerStop_20x20.gif';
			document.images.button_play.src = 'images/iconPlayerPlayG_20x20.gif';
						
			if (loadedPicture["main"].complete == true) {
				pictureId++;
				action = 'play';
				timeId = setTimeout("pictureAction(\""+action+"\",\""+state+"\");",4000);
			} else {
				action = 'play';
				timeId = setTimeout("pictureAction(\""+action+"\",\""+state+"\");",4000);
				action = 'stop';
			}
		} else if (action == "stop") {
			clearTimeout(timeId);
			document.images.button_play.src = 'images/iconPlayerPlay_20x20.gif';
			document.images.button_stop.src = 'images/iconPlayerStopG_20x20.gif';
		} else {
			closeGallery();		
			pictureId = 0;
			return true;
		}
		
		if (action != 'stop') {
			$("#close_obj").slideUp("fast", function() {
				$("#picture").fadeOut("slow", function(){
					displayPicture(1, 0, descriptions[pictureId]);
				});
			});
		}
	}
	    
		function newImage(source) {
        	if (document.images) {
	            img = new Image();
	        	img.src = source;
	        	return img;
        	}
		}
		function loadImage(source, name) {
			if (document.images) {
				loadedPicture[name] = newImage(source);
				loadDone = true;
			}
		}
		
		function closeGallery() {
			if(timeId != null) {
				clearTimeout(timeId);
			}
			$(".selectField").show();
			$("#overDiv1").hide();
			$("#picture_canvas").hide();
			$("#close_obj").hide();
			$("#desc").hide();
			$("#gallery_menu").slideUp();
			document.images.button_play.src = 'images/iconPlayerPlay_20x20.gif';
			document.images.button_stop.src = 'images/iconPlayerStopG_20x20.gif';
		}
