
var imgArray = Array(
					Array("slideshow/Rays_img.jpg", "http://8speed.net/manufacturer/rays/"),	
					Array("slideshow/axis_img.jpg", "http://8speed.net/manufacturer/axis/"),	
					Array("slideshow/isweep_img.jpg", "http://8speed.net/manufacturer/isweep/"),	
					Array("slideshow/neuspeed_img.jpg", "http://www.ishikawa-engineering.com/neuspeed/"),	
					Array("slideshow/conti_img.jpg", "http://www.conti-online.com/generator/www/jp/jp/continental/tires/general/home/index_jp.html"),
					Array("slideshow/cox_img.jpg", "http://www.cox.co.jp/"),	
					Array("slideshow/gruppem_img.jpg", "http://8speed.net/manufacturer/GruppeM/"),	
					Array("slideshow/philips_img.jpg", "http://8speed.net/manufacturer/phirips/"),	
					Array("slideshow/cpm_img.jpg", "http://8speed.net/manufacturer/cpm/"),
					Array("slideshow/oz_img.jpg", "http://8speed.net/manufacturer/oz/"),
					Array("slideshow/seabass_img.jpg", "http://8speed.net/manufacturer/seabass/"),
					Array("slideshow/blex_img.jpg", "http://www.brex.jp/"),
					Array("slideshow/door_img.jpg", "http://8speed.net/manufacturer/doordefender/"),
					Array("slideshow/xpel_img.jpg", "http://8speed.net/manufacturer/xpel/"),
					Array("slideshow/bellof_img.jpg", "http://8speed.net/manufacturer/bellof/"),
					Array("slideshow/koni_img.jpg", "http://www.fet-japan.co.jp/koni/index.html"),
					Array("slideshow/prodrive_img.jpg", "http://8speed.net/manufacturer/prodrive/"));

var max = imgArray.length;  //広告の数
var interval = 5000; //表示間隔 ミリ秒

var tid;
var cnt=0;
var isPlay = false;

var jun = Array();
for(var ii=0;ii < max;ii++) {
	jun[ii] = ii;
}
jun = shuffle(jun);

$(function($) {
	
	$("#bimg").html('<a href="'+imgArray[jun[cnt]][1]+'" id="link" target="_blank"><img src="'+imgArray[jun[cnt]][0]+'" id="imgarea" width="293" height="225"/></a>');
	$("#ctrArea").html('<a href="#" onclick="previmg()" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'prev\',\'\',\'slideshow/img/left_allow_white.gif\',1)"><img src="slideshow/img/left_allow_.gif" name="prev" width="10" height="12" border="0" id="prev" /></a>&nbsp;');
	$("#ctrArea").append('<span id="playCtr"></span>');
	$("#playCtr").html('<a href="#" onclick="stop();blur();" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'play\',\'\',\'slideshow/img/stop_icon_white.gif\',1)"><img src="slideshow/img/stop_icon_.gif" name="play" width="11" height="13" border="0" id="play"  /></a>&nbsp;');
	$("#ctrArea").append('<a href="#" onclick="nextimg()" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'next\',\'\',\'slideshow/img/right_allow_white.gif\',1)"><img src="slideshow/img/right_allow_.gif" name="next" width="10" height="12" border="0" id="next"  /></a>');

//$("#debug").html("cnt:"+cnt+" maker:"+imgArray[jun[cnt]][0]);

	start();

});


function shuffle(list) {
  var i = list.length;

  while (--i) {
    var j = Math.floor(Math.random() * (i + 1));
    if (i == j) continue;
    var k = list[i];
    list[i] = list[j];
    list[j] = k;
  }

  return list;
}

function loadImage() {

//$("#debug").html("cnt:"+cnt+" maker:"+imgArray[jun[cnt]][0]);

	var imgObj = document.getElementById("imgarea");
	imgObj.setAttribute("src", imgArray[jun[cnt]][0]);
	var linkObj = document.getElementById("link");
	linkObj.setAttribute("href", imgArray[jun[cnt]][1]);	
}

function nextimg() {
	cnt += 1;
	if(cnt >= max)
		cnt=0; 
	
	loadImage();
}
function previmg() {
	cnt -= 1;
	if(cnt < 0)
		cnt=max - 1; 
	
	loadImage();
}

function start() {

	if(isPlay) {
		clearInterval(tid);
		isPlay = false;

		$("#playCtr").html('<a href="#" onclick="start();blur();" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'play\',\'\',\'slideshow/img/start_icon_white.gif\',1)"><img src="slideshow/img/start_icon_.gif" name="play" width="11" height="13" border="0" id="play"  /></a>&nbsp;');

	} else {
		tid = setInterval("nextimg()", interval);
		isPlay = true;

		$("#playCtr").html('<a href="#" onclick="start();blur();" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'play\',\'\',\'slideshow/img/stop_icon_white.gif\',1)"><img src="slideshow/img/stop_icon_.gif" name="play" width="11" height="13" border="0" id="play"  /></a>&nbsp;');
	}
}

/*
function stop() {
	if(isPlay) {
		clearInterval(tid);
		isPlay = false;
	} else {
		tid = setInterval("nextimg()", interval);
		isPlay = true;
	}
}
*/

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

