/**
*  jquery.imageButton.js . image Over an change
*
*	@Since 2009-10-17
* @author jsyang < yakuyaku@gmail.com >
*/
(function($) {

	$.fn.imageButton = function(options) {

		var imageElements = this;
		var selectedIndex = -1;
		var defaultSelect = -1;
		var elements = [];
		var opts = $.extend({}, $.fn.imageButton.defaults, options);
		if(opts.prebuild) build();
		this.css("cursor" ,"pointer");

		function build()
		{
			imageElements.each(function(i)
			{
				var source     = this.src;
				var overSource = "";
				if(this.src) overSource =  getOverSource(source);
				var layer      = (opts.layers[i]) ? opts.layers[i] : null;
				if(opts.target) source = $(opts.target).src;

				$(this).bind("mouseover" , function(e){ imageOver(e , i) } );
				if(opts.out) $(this).bind("mouseout" , function(e){ imageOut(e , i) } );

				elements[i] = {
					image: this ,
					source: source,
					overSource: overSource,
					layer: layer
				};

				if($(this).hasClass(opts.selectClassName) || $(this).hasClass(opts.defaultClassName) )
				{
					this.src = overSource;
					this.selectedIndex = i;
					if (layer) imageSelect(i);

					if ($(this).hasClass(opts.defaultClassName))
					{
						if(opts.container) $(this).bind("mouseout" , function(e){imageOut(e,i)});
					}
				}
			});

		};

		function imageSelect(index)
		{
			var el = elements[index];
			imageUnSelect(index);

			if(opts.target) $(opts.target).attr("src",el.overSource ) ;
			else el.image.src = el.overSource;

			if (el.layer) {
				if (opts.fade) $('#'+el.layer).fadeIn("slow");
				else $('#'+el.layer).css('display', opts.displayView);
			}

			$(el.image).addClass(opts.overClassName);
			selectedIndex = index;
		};

		function imageUnSelect(currentIndex)
		{
			if (selectedIndex > -1 && selectedIndex != currentIndex) {
				var el = elements[selectedIndex];

				if(opts.target)   $(opts.target).attr("src",el.source) ;
				else el.image.src = el.source;

				if (el.layer) {
					if (opts.fade) $('#'+el.layer).fadeOut("slow");
					else $('#'+el.layer).css('display','none');
				}

				$(el.image).removeClass(opts.overClassName);
				this.selectedIndex = -1;
			}
		};

		function imageOver(event,index) {
			imageSelect(index);
		};

		function imageOut(event,index) {
			imageUnSelect(-1);
		};

		function getOverSource(img)
		{
			return img.replace(RegExp("(\.[^\.]+)$"), opts.overSuffix + "$1");
		};
	};

	$.fn.imageButton.defaults  = {
		overSuffix: '_r',
		out: true,
		container: null,
		layers: [],
		target: null,
		selectClassName: 'ibSelected',
		defaultClassName:'ibDefault',
		overClassName:   'RotatorSelected',
		fade: true ,
		displayView: 'block',
		prebuild: true
	};

})(jQuery);



//flash(Ãâ·Â¿µ¿ªID¹×NAME,ÇÃ·¡½ÃÆÄÀÏ°æ·Î,WIDTH,HEIGHT,FLASHVARS,BackgroundColor,WMOD)

function flash(fid,fnm,wid,hei,fvs,bgc,wmd) {
	var flash_tag = "";
	flash_tag = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+wid+'" height="'+hei+'" id="'+fid+'" align="middle">';
	flash_tag +='<param name="allowScriptAccess" value="always" />';
	flash_tag +='<param name="allowFullScreen" value="false" />';
	flash_tag +='<param name="movie" value="'+fnm+'" />';
	flash_tag +='<param name="FlashVars" value="'+fvs+'" />';
	flash_tag +='<param name="quality" value="high" />';
	flash_tag +='<param name="bgcolor" value="'+bgc+'" />';
	flash_tag +='<param name="wmode" value="'+wmd+'" />';
	flash_tag +='<embed src="'+fnm+'" quality="high" bgcolor="'+bgc+'" FlashVars="'+fvs+'" wmode="'+wmd+'" width="'+wid+'" height="'+hei+'" name="'+fid+'" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	flash_tag +='</object>';
	
	document.write(flash_tag);
}