
	//FlashPlayerがインストールされているか判別する
	var isFlashInstalled = function() {
	  if ( navigator.plugins['Shockwave Flash'] ) {
	    return true;
	  }
	  try {
	    new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
	    return true;
	  } catch (e) {
	    return false;
	  }
	}();

	//Flashがインストールされていない場合に適用するスタイル
	if(!isFlashInstalled) {
		(function($) {
			$('<style />',{
			    type:'text/css',
			    text:'#swf { display:none; }'
			}).appendTo('head');
		})(jQuery);
	};
	
	//swfobjectの初期設定
	var flashvars = {};
	var params = {
		quality:'high',
		play:'true',
		wmode:'window',
		scale:'noscale',
		menu:'true',
		salign:'',
		allowScriptAccess:'always'
	};
	var attributes = {
		align: 'top'
	};
	
	//Flashを表示する関数
	function displayFlash(swfFileName){
		$('#btn a').each(function(){
			$(this).parent().removeClass();
		});
		$('#'+swfFileName).parent().addClass('activeSlide');	//ボタンを押したときのクラスを摘要		

		var swfSRC = swfFileName+'.swf';	//htmlに記述してあるidなどをswfのファイル名に変更		
		swfobject.embedSWF(swfSRC, 'swf', '720', '407', '9', flashvars, params, attributes);
	};
	
	$(function () {
		
		//Flashのランダム表示
		var rnd = true;	//ランダムの場合　true そうでない場合は、 false にする
		var fileLen = $('#btn a').size();
		var num = (rnd)? Math.floor(Math.random()*fileLen)+1 : 1;
		
		if(isFlashInstalled) {//FlashPlayerがインストールされている場合
		
			var swfFileName = 'top0'+num;
			displayFlash(swfFileName);
			
			$('#btn a')//ボタンの挙動
				.click(function(){
					if(isFlashInstalled) displayFlash(this.id);
					return false;
				});
		}else{
			//FlashPlayerがインストールされていない場合は、ボタンをクリックするとメイン画像が切り替わる
			$('#swf').cycle({
		        fx:     'fade',
		        speed:  'slow',
		        startingSlide: num,
		        timeout: 0,
		        pager:  '#btn',
		        pagerAnchorBuilder: function(idx, slide) {
		        	return '#btn li:eq(' + idx + ') a'; 
			    } 
		    });
			
		};
		
		$(window)
			.load(function(){
				if(!isFlashInstalled) $('#swf').fadeIn('slow');
			})
			.unload(function(){});
		
			
	});


