//Browser Check
var browserType=new checkBrowserType();
var osType=new checkOsType();
function checkBrowserType(){
	//↓推奨
	this.IE=(navigator.userAgent.indexOf("MSIE")!=-1);
	this.Gecko=(navigator.userAgent.indexOf("Gecko")!=-1);

	//↓細かいバージョンの区別が必要な場合のみ使用
	this.IE6=(navigator.userAgent.indexOf("MSIE 6.")!=-1);
	this.IE5=(navigator.userAgent.indexOf("MSIE 5.")!=-1);
	this.NC71=(navigator.userAgent.indexOf("Netscape/7.1")!=-1);
	this.NC70=(navigator.userAgent.indexOf("Netscape/7.0")!=-1);
	this.NC6=(navigator.userAgent.indexOf("Netscape/6.")!=-1);
	this.NC7=(navigator.userAgent.indexOf("Netscape/7.")!=-1);
	this.NC4=(navigator.userAgent.indexOf("Netscape/4.")!=-1);
}
function checkOsType(){
	this.Win=(navigator.appVersion.indexOf("Win")!=-1);
	this.Mac=(navigator.appVersion.indexOf("Mac")!=-1);
	this.Unix=(navigator.appVersion.indexOf("X11")!=-1);
}

//CSS Setting
if(!browserType.IE){
	document.write('<style type="text/css">body,td,th{font-size:small;color:#000000;}</style>');
}

//PreloadImages
function preloadImages(){
	var imgDir="/common/img/";
	var imgFileName=new Array("menu_top_over.gif","menu_trial_over.gif","menu_catalog_over.gif","menu_ranking_over.gif","menu_special_over.gif","menu_community_over.gif","btn_top_over.gif","btn_back_over.gif","btn_pagetop_over.gif");
	var imgArray=new Array();
	for(i=0;i<imgFileName.length;i++){
		imgArray[i]=new Image();
		imgArray[i].src=imgDir+imgFileName[i];
	}
}

//ChangeImages
function changeImages(){
	if (document.images){
		for(i=0;i<changeImages.arguments.length;i+=2){
			document[changeImages.arguments[i]].src=changeImages.arguments[i+1];
		}
	}
}

function changeThisImage(){
	if (document.images){
		changeThisImage.arguments[0].src=changeThisImage.arguments[1];
	}
}

//AdSense for text
google_ad_client='ca-nifty_js';
google_ad_output='js';
google_max_num_ads=5;
google_language='ja';
google_encoding='sjis';
google_safe='high';
google_adtest='off';
google_ad_channel='car';

function google_ad_request_done(){
	if(google_ads.length>0){
		var str="";
		str+='<div class="title3"><img src="/common/img/title_adsense.gif" width="300" height="18" alt="Ads by Google"></div>';
		str+='<div class="tab60">';
		for(i=0;i<google_ads.length;i++){
			str+='<div style="margin: 0 0 10px;"><a href="'+google_ads[i].url+'" style="font-size:1.1em;font-weight: bold;">'+google_ads[i].line1+'</a>　<span style="color:#209020">'+google_ads[i].visible_url+'</span><br>'+google_ads[i].line2+""+google_ads[i].line3+'</div>';
		}
		str+='</div>';
		str+='<br><br><br>';
		document.write(str);
	}
}

//RectangleControl
rectangleFlg=0;

function rectangleControl(){
	rectangleFlg=1;
}

onload=doRectangleControl;

function doRectangleControl(){
	if(rectangleFlg){
		if(browserType.IE){
			if(document.all["rectangle"].scrollHeight<10){
				document.all["rectangle"].style.display="none";
			}
		}
		else{
			if(document.getElementById("rectangle").scrollHeight<10){
				document.getElementById("rectangle").style.display="none";
			}
		}
	}
}

//WriteCopy
function writeCopy(){
	var copyNum=Math.floor(Math.random()*copyArray.length);
	var str="";
	str+='';
	str+='<div class="topTitle" style="background-image:url(\''+copyArray[copyNum][0]+'\');"><div id="copyPalette" class="lh125" onmouseover="startOpenAnimation();" onmouseout="startCloseAnimation();">'+copyArray[copyNum][2]+'</div><a href="'+copyArray[copyNum][3]+'" onmouseover="startOpenAnimation();" onmouseout="startCloseAnimation();"><img src="/common/img/s.gif" width="100%" height="70" border="0" alt="'+copyArray[copyNum][1]+'"></a></div>';
	document.write(str);
}

//CopyPalette
var copyPaletteOffsetX=-300;
var copyPaletteOffsetY=150;
var fadeTimer=0;
var fadeCounter=0;

function startOpenAnimation(){
	showCopyPalette();
	clearTimeout(fadeTimer);
	if(browserType.IE && osType.Win){
		document.all["copyPalette"].filters.alpha.opacity=0;
		fadeinCopyPalette();
	}
}

function startCloseAnimation(){
	clearTimeout(fadeTimer);
	if(browserType.IE && osType.Win){
		fadeoutCopyPalette();
	}
	else{
		hideCopyPalette();
	}
}

function fadeinCopyPalette(){
	fadeCounter+=1;
	document.all["copyPalette"].filters.alpha.opacity=fadeCounter*10;
	document.all["copyPalette"].style.left=copyPaletteX-Math.round(Math.pow(10-fadeCounter,2)*0.2);
	if(fadeCounter<10){
		fadeTimer=setTimeout("fadeinCopyPalette()",10);
	}
}

function fadeoutCopyPalette(){
	fadeCounter-=1;
	document.all["copyPalette"].filters.alpha.opacity=fadeCounter*10;
	document.all["copyPalette"].style.left=copyPaletteX-Math.round(Math.pow(10-fadeCounter,2)*0.2);
	if(fadeCounter>0){
		fadeTimer=setTimeout("fadeoutCopyPalette()",10);
	}
}

function showCopyPalette(){
	//PalettePositionSet
	var WindowWidth=document.body.clientWidth;
	if(WindowWidth<980 && WindowWidth>780){
		copyPaletteX=WindowWidth+copyPaletteOffsetX;
	}
	else if(WindowWidth<780){
		copyPaletteX=780+copyPaletteOffsetX;
	}
	else{
		copyPaletteX=Math.floor((WindowWidth+980)/2)+copyPaletteOffsetX;
	}
	copyPaletteY=copyPaletteOffsetY;

	if(browserType.IE){
		document.all["copyPalette"].style.visibility="visible";
		document.all["copyPalette"].style.left=copyPaletteX;
		document.all["copyPalette"].style.top=copyPaletteY;
	}
	else{
		document.getElementById("copyPalette").style.visibility="visible";
		document.getElementById("copyPalette").style.left=copyPaletteX;
		document.getElementById("copyPalette").style.top=copyPaletteY;
	}
}

function hideCopyPalette(){
	if(browserType.IE){
		document.all["copyPalette"].style.visibility="hidden";
		document.all["copyPalette"].style.left=0;
	}
	else{
		document.getElementById("copyPalette").style.visibility="hidden";
		document.getElementById("copyPalette").style.left=0;
	}
}


//Script For Change Image
function initRollovers() {
	if (!document.getElementById) return

	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');
	var iImages = document.getElementsByTagName('input');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_on'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_on'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}

	for (var i = 0; i < iImages.length; i++) {		
		if (iImages[i].className == 'imgover') {
			var src = iImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_on'+ftype);

			iImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			iImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			iImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_on'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}

}

//onload Script
window.onload = function() {
	initRollovers();
	doRectangleControl();
}