var	sound_status	=	true ;
function	switch_sound() {
	if	(sound_status == true) {
		$('IMG[@name=igotmail_speaker]').attr('src','/images/2005/speaker_stop.gif') ;
		$('IMG[@name=igotmail_speaker_controller]').attr('src','/images/2005/icon_pause.gif') ;
		self.document.igotmail_sound.stop() ;
		sound_status	=	false ;
	}
	else if	(sound_status == false) {
		$('IMG[@name=igotmail_speaker]').attr('src','/images/2004/speaker.gif') ;
		$('IMG[@name=igotmail_speaker_controller]').attr('src','/images/2005/icon_play.gif') ;
		self.document.igotmail_sound.play() ;
		sound_status	=	true ;
	}
}

$(document).ready(function(){
	var	background_sound_url	=	document.parameters.background_sound_url.value ;
	var	background_sound_size	=	document.parameters.background_sound_size.value ;
	if	(background_sound_url != '')	{
		$('LI.sound').html('<EMBED NAME="igotmail_sound" BGCOLOR="e0e0e0" WIDTH="0" HEIGHT="1" SRC="'
			+	background_sound_url + '" LOOP="true" AUTOSTART="true" VOLUME="100"></EMBED>'
			+	'<NOBR><IMG NAME="igotmail_speaker_controller" SRC="/images/2005/icon_play.gif" ALIGN="absmiddle" BORDER="0" onClick="switch_sound()" STYLE="cursor:pointer" TITLE="按我可中止或播放背景音樂 ('
			+	background_sound_size + ')">'
			+	'<A HREF="' + background_sound_url + '" TARGET="_bgsound"><IMG NAME="igotmail_speaker" SRC="/images/2004/speaker.gif" ALIGN="absmiddle" BORDER="0" STYLE="cursor:pointer" TITLE="按滑鼠右鍵可下載背景音樂 ('
			+	background_sound_size + ')"></A></NOBR>') ;
	}
	$('table.thumbnail td').hover(
		function(){ $(this).css('border','#000 solid 1px') ; },
		function(){ $(this).css('border','#eee solid 1px') ; }
	).css('cursor','pointer') ;
	$('A.attachment_link').each(function(){
		var	href	=	$(this).attr('HREF') ;
		var	link	=	href.split('?') ;
		var	url		=	link[0] ;
		if	(url.indexOf('.flv') == url.length - 4) {
			var	resource=	url.split('/') ;
				resource.pop() ;
				resource.push('flash_video.flv') ;
			var	video	=	resource.join('/') + '?' + link[1] ;
			if	(video.indexOf('http://' + location.hostname) == -1)	video	=	'http://' + location.hostname + video ;
			$('<IMG CLASS="clickable" SRC="/images/2007/play.gif" ALIGN="absmiddle">').insertBefore($(this))
				.toggle(function(){
					$('DIV.swf_player').remove() ;
					$('DIV.flv_player').remove() ;
					var	html	=	'<DIV CLASS="flv_player"><CENTER><embed src="/videoplayer.swf?playerMode=mini&loop=true&autoPlay=true&videoUrl=' + video + '" width="320" HEIGHT="240" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" ></embed></CENTER></DIV>' ;
					$(html).insertBefore($(this)) ;
				},function(){
					$('DIV.flv_player').remove() ;
				}) ;
		}
		else if	(url.indexOf('.swf') == url.length - 4) {
			var	resource=	url.split('/') ;
				resource.pop() ;
				resource.push('flash_file.swf') ;
			var	video	=	resource.join('/') + '?' + link[1] ;
			if	(video.indexOf('http://' + location.hostname) == -1)	video	=	'http://' + location.hostname + video ;
			$('<IMG CLASS="clickable" SRC="/images/2007/play.gif" ALIGN="absmiddle">').insertBefore($(this))
				.toggle(function(){
					$('DIV.swf_player').remove() ;
					$('DIV.flv_player').remove() ;
					var	html	=	'<DIV CLASS="swf_player"><CENTER><embed src="' + video + '" width="512" HEIGHT="384" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" ></embed></CENTER></DIV>' ;
					// $('DIV#attachment_block').before(html) ;
					$(html).insertBefore($(this)) ;
				},function(){
					$('DIV.swf_player').remove() ;
				}) ;
		}
		else if	(url.indexOf('.pdf') == url.length - 4) {
			var	resource=	url.split('/') ;
//				resource.pop() ;
//				resource.push('flash_file.swf') ;
			var	pdf_file=	resource.join('/') + escape('?' + link[1]) ;
			if	(pdf_file.indexOf('http://' + location.hostname) == -1)	pdf_file	=	'http://' + location.hostname + pdf_file ;
			$('<IMG CLASS="clickable" SRC="/images/2007/play.gif" ALIGN="absmiddle">').insertBefore($(this))
				.toggle(function(){
					$('DIV.pdf_viewer').remove() ;
					$('DIV.swf_player').remove() ;
					$('DIV.flv_player').remove() ;
					var	html	=	'<DIV CLASS="pdf_viewer" STYLE="width:520px;margin:1em auto;border:#888 solid 1px"><iframe src="http://docs.google.com/gview?url=' + pdf_file + '&embedded=true" style="width:520px;height:600px;" frameborder="0"></iframe></DIV>' ;
					// $('DIV#attachment_block').before(html) ;
					$(html).insertBefore($(this)) ;
				},function(){
					$('DIV.pdf_viewer').remove() ;
				}) ;
		}
		else	{
			$(this).attr('TITLE',url) ;
		}
	}) ;
});
