function LinkActive(status_text, id, type) {
	if (status_text)
		window.status=status_text;
	type = (type) ? ".jpg" : ".gif";
	if (id) {
		g=document.getElementById(id);
		g.src="graphics/active/"+id+type;
	}
}

function LinkPassive(id, type) {
	window.status="";
	type = (type) ? ".jpg" : ".gif";
	if (id) {
		g=document.getElementById(id);
		g.src="graphics/"+id+type;
	}
}

function LinkElementActive(status_text, id, serial, type) {
	window.status=status_text;
	type = (type) ? ".jpg" : ".gif";
	g=document.getElementById(id+"_"+serial);
	g.src="graphics/active/"+id+type;
}

function LinkElementPassive(id, serial, type) {
	window.status="";
	type = (type) ? ".jpg" : ".gif";
	g=document.getElementById(id+"_"+serial);
	g.src="graphics/"+id+type;
}

function MenuActive(status_text, id) {
	window.status=status_text;
	g=document.getElementById("menu_mark_"+id);
	g.style.visibility="visible";
}

function MenuPassive(id) {
	window.status="";
	g=document.getElementById("menu_mark_"+id);
	g.style.visibility="hidden";
}

function PhotoActive(id) {
	window.status=photo_enlarge_status_text;
	g=document.getElementById("photo_"+id);
	g.style.borderColor="#B9403C";
}

function PhotoPassive(id) {
	window.status="";
	g=document.getElementById("photo_"+id);
	g.style.borderColor="#4E7533";
}

function MusicShowSong(subdirectory, id) {
	if (active_song) MusicHideActiveSong();
	g=document.getElementById("title "+id);
	g.className="Active";
	g.innerHTML=g.innerHTML.replace(/<A .*><B>/i, "<B>");
	g.innerHTML=g.innerHTML.replace(/<\/A>/, "");
	g=document.getElementById("panel "+id);
	g.style.paddingTop="6px";
	music_panel = (document.Player.controls) ? music_panel_microsoft : music_panel_mozilla;
	music_panel=music_panel.replace(/\[Subdirectory\]/i, subdirectory);
	music_panel=music_panel.replace(/\[SongId\]/i, id);
	g.innerHTML=music_panel;
	if (document.Player.controls) {
		Player.URL="music/"+subdirectory+id+".mp3";
		if (Player.controls.isAvailable('Play')) Player.controls.play();
		music_end=false;
		CheckMusicEnd();
		g=document.getElementById("music_play");
		g.innerHTML=music_play_status;
		g=document.getElementById("music_pause");
		g.innerHTML=music_pause_action;
		g=document.getElementById("music_stop");
		g.innerHTML=music_stop_action;
	} else {
		g=document.getElementById("MusicMozillaPlayer");
		g.innerHTML="<EMBED TYPE=\"application/x-mplayer2\" PLUGINSPAGE=\"http://microsoft.com/windows/mediaplayer/en/download/\" WIDTH=20 HEIGHT=20 SRC=\"music/"+subdirectory+id+".mp3\" AUTOSTART=true></EMBED>";
	}
	active_subdirectory=subdirectory;
	active_song=id;
}

function MusicHideActiveSong() {
	song_link=music_link;
	song_link=song_link.replace(/\[Subdirectory\]/i, active_subdirectory);
	song_link=song_link.replace(/\[SongId\]/i, active_song);
	g=document.getElementById("title "+active_song);
	g.className="";
	g.innerHTML=g.innerHTML.replace(/<B>/i, song_link+"<B>");
	g.innerHTML=g.innerHTML.replace(/<\/B>/, "</B></A>");
	g=document.getElementById("panel "+active_song);
	g.innerHTML="";
	g.style.paddingTop=0;
	if (document.Player.controls) {
		if (Player.controls.isAvailable('Stop')) Player.controls.stop();
		Player.URL="";
	} else {
		g=document.getElementById("MusicMozillaPlayer");
		g.innerHTML="<BR>";
	}
}

function Music(action) {
	if (document.Player.controls) {
		switch (action) {
			case "play":
				if (Player.controls.isAvailable('Play')) Player.controls.play();
				g=document.getElementById("music_play");
				g.innerHTML=music_play_status;
				g=document.getElementById("music_pause");
				g.innerHTML=music_pause_action;
				g=document.getElementById("music_stop");
				g.innerHTML=music_stop_action;
				music_end=false;
				CheckMusicEnd();
				break;
			case "pause":
				if (Player.controls.isAvailable('Pause')) Player.controls.pause();
				g=document.getElementById("music_play");
				g.innerHTML=music_play_action;
				g=document.getElementById("music_pause");
				g.innerHTML=music_pause_status;
				break;
			case "stop":
				if (Player.controls.isAvailable('Stop')) Player.controls.stop();
				g=document.getElementById("music_play");
				g.innerHTML=music_play_action;
				g=document.getElementById("music_pause");
				g.innerHTML=music_pause_inactive;
				g=document.getElementById("music_stop");
				g.innerHTML=music_stop_status;
				music_end=true;
				break;
		}
	} else {
		switch (action) {
			case "play":
				g=document.getElementById("MusicMozillaPlayer");
				g.innerHTML="<EMBED TYPE=\"application/x-mplayer2\" PLUGINSPAGE=\"http://microsoft.com/windows/mediaplayer/en/download/\" WIDTH=20 HEIGHT=20 SRC=\"music/"+active_subdirectory+active_song+".mp3\" AUTOSTART=true></EMBED>";
				g=document.getElementById("music_play");
				g.innerHTML=music_play_status;
				g=document.getElementById("music_stop");
				g.innerHTML=music_stop_action;
				break;
			case "stop":
				g=document.getElementById("MusicMozillaPlayer");
				g.innerHTML="<BR>";
				g=document.getElementById("music_play");
				g.innerHTML=music_play_action;
				g=document.getElementById("music_stop");
				g.innerHTML=music_stop_status;
				break;
		}
	}
}

function CheckMusicEnd() {
	if (document.Player.controls && !music_end) {
		clearTimeout(check_music_end);
		if (Player.playState==1) {
			music_end=true;
			g=document.getElementById("music_play");
			g.innerHTML=music_play_action;
			g=document.getElementById("music_pause");
			g.innerHTML=music_pause_inactive;
			g=document.getElementById("music_stop");
			g.innerHTML=music_stop_status;
		}
		check_music_end=setTimeout("CheckMusicEnd()", 1000);
	}
}

function PhotoEnlarge(photo_serial) {
	active_photo=photo_serial;
	PhotoPrepare();
}

function PhotoStep(direction) {
	switch (direction) {
		case "previous":
			active_photo--;
			if (active_photo<0) active_photo=0;
			break;
		case "next":
			active_photo++;
			if (active_photo>photos.length-1) active_photo=photos.length-1;
			break;
	}
	photo_step_direction=direction;
	PhotoPrepare();
}

function PhotoPrepare() {
	clearTimeout(fade_timeout);
	photo_step_direction="";

	photo_id=photos[active_photo][0];
	caption=photos[active_photo][1];
	width=Number(photos[active_photo][2]);
	height=Number(photos[active_photo][3]);

	photo_src=photo_large_image_src.replace(/\[PhotoId\]/, photo_id);
	photo=photo_large_image;
	photo=photo.replace(/\[PhotoSrc\]/, photo_src);
	photo=photo.replace(/\[Width\]/, width);
	photo=photo.replace(/\[Height\]/, height);
	photo=photo.replace(/\[Caption\]/, caption);

	layer_top=PositionTop()+2;

	wait_left=26+Math.round((width-282)/2);
	if (wait_left<26) wait_left=26;
	wait_top=layer_top+Math.round((height-16)/2);
	if (wait_top<layer_top) wait_top=layer_top;

	left_half_width=Math.round(width/2);
	right_half_width=width-left_half_width;

	if (caption.indexOf("|")!=-1) {
		temp=caption.split("|");
		lines=temp.length;
		while (caption.indexOf("|")!=-1) caption=caption.replace(/\|/, "<BR>");
	} else {
		lines=1;
	}
	photo_panel_height=lines*15+13;

	g=document.getElementById("photo_border");
	g.style.width=width+4;
	g.style.height=height+photo_panel_height+4;
	g.style.top=layer_top-2;

	g=document.getElementById("photo_background");
	g.style.width=width;
	g.style.height=height;
	g.style.top=layer_top;

	g=document.getElementById("photo_wait");
	g.style.left=wait_left;
	g.style.top=wait_top;

	g=document.getElementById("photo_layer");
	g.style.top=layer_top;

	g=document.getElementById("photo_large");
	g.style.width=width;
	g.style.height=height;
	g.style.opacity=0;
	g.style.filter="alpha(opacity=0)";
	g.innerHTML="<BR>";

	g=document.getElementById("photo_large_left_half");
	g.style.left=0;
	g=document.getElementById("photo_large_right_half");
	g.style.left=left_half_width;

	g=document.getElementById("photo_panel");
	g.style.width=width;
	g.style.height=photo_panel_height;

	if (active_photo>0) {
		g=document.getElementById("photo_previous_cell");
		g.innerHTML=photo_previous;
		g=document.getElementById("photo_large_left_half");
		g.innerHTML=photo_large_left_half;
		g=document.getElementById("photo_large_left_half_link");
		g.style.width=left_half_width;
		g.style.height=height;
	} else {
		g=document.getElementById("photo_previous_cell");
		g.innerHTML="<BR>";
		g=document.getElementById("photo_large_left_half");
		g.innerHTML="<BR>";
	}

	if (active_photo<photos.length-1) {
		g=document.getElementById("photo_next_cell");
		g.innerHTML=photo_next;
		g=document.getElementById("photo_large_right_half");
		g.innerHTML=photo_large_right_half;
		g=document.getElementById("photo_large_right_half_link");
		g.style.width=right_half_width;
		g.style.height=height;
	} else {
		g=document.getElementById("photo_next_cell");
		g.innerHTML="<BR>";
		g=document.getElementById("photo_large_right_half");
		g.innerHTML="<BR>";
	}

	g=document.getElementById("photo_caption");
	g.innerHTML=caption;

	g=document.getElementById("photo_background");
	g.style.visibility="visible";

	g=document.getElementById("photo_wait");
	g.style.visibility="visible";

	g=document.getElementById("photo_prepare");
	g.src=photo_src;
}

function PhotoShow() {
	g=document.getElementById("photo_wait");
	g.style.visibility="hidden";

	g=document.getElementById("photo_layer");
	g.style.visibility="visible";

	g=document.getElementById("photo_large");
	g.innerHTML=photo;
	opacity=0;
	PhotoFadeIn();
}

function PhotoFadeIn() {
	opacity+=opacity_step;
	if (opacity>100) opacity=100;
	opacity_integer=opacity;
	opacity_decimal=opacity/100;
	g=document.getElementById("photo_large");
	g.style.opacity=opacity_decimal;
	g.style.filter="alpha(opacity="+opacity_integer+")";
	if (opacity<100) {
		fade_timeout=setTimeout("PhotoFadeIn()", fade_cycle);
	} else {
		g=document.getElementById("photo_panel");
		g.style.visibility="visible";
		g=document.getElementById("photo_border");
		g.style.visibility="visible";
		if ((!photo_step_direction || photo_step_direction=="previous") && active_photo>0) {
			photo_preload=new Image();
			photo_preload.src=photo_large_image_src.replace(/\[PhotoId\]/, photos[active_photo-1][0]);
		}
		if ((!photo_step_direction || photo_step_direction=="next") && active_photo<photos.length-1) {
			photo_preload=new Image();
			photo_preload.src=photo_large_image_src.replace(/\[PhotoId\]/, photos[active_photo+1][0]);
		}
	}
}

function PhotoClose() {
	clearTimeout(fade_timeout);
	g=document.getElementById("photo_border");
	g.style.visibility="hidden";
	g=document.getElementById("photo_background");
	g.style.visibility="hidden";
	g=document.getElementById("photo_panel");
	g.style.visibility="hidden";
	g=document.getElementById("photo_layer");
	g.style.visibility="hidden";
	active_photo="";
}

function LargeImage(id, width, height) {
	x=screen.availWidth-10-width;
	if (x<0) x=0;
	window.open("large_image.php?id="+id, "large_image", "left="+x+", top=0, width="+width+", height="+height);
}

function LogPage(log_http_referer, log_query_string, log_remote_addr, log_remote_host, log_http_user_agent) {
	ajaxRequest=createXmlHttp();
	if (ajaxRequest) {
		ajaxRequest.open("get", "ajax.php?action=log_page&log_http_referer="+log_http_referer+"&log_query_string="+log_query_string+"&log_remote_addr="+log_remote_addr+"&log_remote_host="+log_remote_host+"&log_http_user_agent="+log_http_user_agent+"&navigator_name="+URLEncode(navigator.appName)+"&navigator_version="+URLEncode(navigator.appVersion)+"&platform="+URLEncode(navigator.platform)+"&screen="+screen.availWidth+"x"+screen.availHeight, true);
		ajaxRequest.send(null);
	}
}

