$(function(){fantaco.tag.slideshow = {
	show_selector_menu : function (select_menu_id){
		var select_menu = $(select_menu_id);
		if( select_menu.style.visibility == "inherit"){
			var menu_content = select_menu.firstChild;
			if(navigator.userAgent.indexOf('MSIE')>=0){
				menu_content.style.marginBottom = "0";
				var select_menu_height = select_menu.offsetHeight;
				var timer = setInterval(
									function(){
										var marginb = parseInt(menu_content.style.marginBottom);
										if( marginb<=parseInt("-"+select_menu_height) ){
											menu_content.style.marginBottom = "0";
											select_menu.style.visibility = "hidden";
											clearInterval(timer);	
										}else{
											menu_content.style.marginBottom = (marginb-20)+"px";
										}
									}
									,1);
			}else{
				select_menu.style.visibility = "hidden";
			}
		}else{
			var menu_content = select_menu.firstChild;
			if(navigator.userAgent.indexOf('MSIE')>=0){
				menu_content.style.marginBottom = "-"+ select_menu.offsetHeight+"px";
				var timer = setInterval(
									function(){
										var marginb = parseInt(menu_content.style.marginBottom);
										if(marginb>=0){
											menu_content.style.marginBottom = "0";
											clearInterval(timer);	
										}else{
											menu_content.style.marginBottom = (marginb+20)+"px";
										}
									}
									,1);
			}
			selector_is_clicked[select_menu_id] = true;
			select_menu.style.visibility = "inherit";
		}
	},
	showImageIndex : -1,
	imageTimer : '',
	fImgs : new Array(),
	showImage: function (imageIndex){
		var flash_img_div = document.getElementById("flash_img");
			
		if(imageIndex>this.fImgs.length-1){
			imageIndex = 0;
		}
		
		if(!this.fImgs[imageIndex] || imageIndex==this.showImageIndex)
			return false;	
		var imgId = "__fImg"+imageIndex;
		flash_img_div.filters && flash_img_div.filters[0].Apply();
		for(i=0; i<flash_img_div.childNodes.length; i++){
			flash_img_div.childNodes[i].style.display = "none";
		}
		if( document.getElementById(imgId) ){
			var imga = document.getElementById(imgId);
			imga.style.display = "block";
			if(imga.tagName=="OBJECT"){
				imga.rewind();
				imga.Play();
			}
		}else{
			var pos = this.fImgs[imageIndex].img.lastIndexOf(".");
			if( this.fImgs[imageIndex].img.substr(pos+1).substr(0,3).toLowerCase()=="swf" ){
				flash_img_div.innerHTML += '\
					<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="600" height="190" id="'+imgId+'">\
						<param name="movie" value="'+this.fImgs[imageIndex].img+'" />\
						<param name="quality" value="high" />\
						<embed src="'+this.fImgs[imageIndex].img+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="600" height="190"></embed>\
					</object>';

			}else{
				var img = new Image();
				img.border = "0";
				img.src = this.fImgs[imageIndex].img;
				img.width = "600";
				img.height = "190";
				var a = document.createElement("a");
				a.href = this.fImgs[imageIndex].href;
				a.target = "_blank";
				a.id = imgId;
				a.appendChild(img);
				flash_img_div.appendChild(a);
			}
		}
		flash_img_div.filters && flash_img_div.filters[0].Play();
		var flash_show_ctl_msg = document.getElementById("flash_show_ctl_msg");
		flash_show_ctl_msg.filters && flash_show_ctl_msg.filters[0].Apply();
		flash_show_ctl_msg.filters && flash_show_ctl_msg.filters[0].Play();
		this.showImageIndex = imageIndex;
		
		$('#flash_btn').find('div').each(function(){
			$(this).find('img').attr('src',$(this).find('img').attr('src').replace('_current.gif','.gif'));
		});
		var tarImg =$('#flash_btn').find('div:eq('+this.showImageIndex+')').find('img');
		var newImg = tarImg.attr('src').replace('.gif','_current.gif');
		tarImg.attr('src',newImg);
		return true;
	},
	imagePlay : function (){
		if(this.imageTimer) return;
		if(this.showImageIndex>=this.fImgs.length-1){
			this.showImageIndex = -1;
		}
		this.showImage(this.showImageIndex+1);
		this.imageTimer = setInterval(function(){
						var slide = fantaco.tag.slideshow;
						var stat = slide.showImage(slide.showImageIndex+1);
						if(!stat){
							slide.stop();
						}	
					},5000);
	},
	stop : function (){
		clearInterval(this.imageTimer);
		this.imageTimer = null;
	},
	showNextImage : function (){
		this.showImage(this.showImageIndex+1);
	},
	showPrevImage : function (){
		this.showImage(this.showImageIndex-1);
	}
}});