var basecssurl = document.getElementById("basecss").href;
var basecssfnm = 'css/base.css';
var basecssfnmlengh = basecssfnm.length;
var basecssurllengh = basecssurl.length;
var rooturllength = basecssurllengh - basecssfnmlengh;
var rooturl = basecssurl.substring(0, rooturllength);
document.write ('<!--[if lte IE 6 ]>');
document.write ('<link href="' + rooturl + 'css/lteie6.css" rel="stylesheet" type="text/css" media="all" />');
document.write ('<link href="' + rooturl + 'css/print.css" rel="stylesheet" type="text/css" media="print" />');
document.write ('<![endif]-->');
document.write ('<meta http-equiv="Imagetoolbar" content="no" />');
//config
var lhostname = location.hostname;
var conf_gmapkey;

if (lhostname.match(/^www\.uw/)) {
	conf_gmapkey = '';
}
if (lhostname.match(/^www\.is/)) {
	conf_gmapkey = '';
}
if (lhostname.match(/^192/)) {
	conf_gmapkey = '';
}
if (lhostname.match(/^ci/)) {
	conf_gmapkey = '';
}


//(c)
function imageswapnavi(elmId,ext,imgwidth,imgheight){
  var i;
  var v = 2;//バージョン
  if(document.getElementById){
  	var preImageNavi = new Array();
    var divnavi  = document.getElementById(elmId);
    var rooturl  = document.getElementById("linkHomePage").href;
    var rooturllength = rooturl.length;
    var bodyId =  document.getElementsByTagName("body")[0].id;
    var idKey = bodyId.substring(4, bodyId.length);// "body.id" - "body"
    var naviElement   = document.getElementById(elmId);
    var plis          = naviElement.getElementsByTagName("li"); 
    for (i = 0; i < plis.length; i++) {
      var pli = plis.item(i);
      var aElement       = pli.getElementsByTagName("a")[0];
      if(typeof(pli.id) == "string" && pli.id != ""){//idあり
        var aalt         = aElement.innerHTML;
        var navifile     = pli.id+'N';
        var navifileO    = pli.id+'O';
        var rex = new RegExp(idKey, "i");
        if (pli.id.match(rex) && idKey !='') {
        	var navifile     = pli.id+'S';
        	var navifileO    = pli.id+'Z';
        }
      }
      //navifile = elmId;
      //navifileO = elmId+"O";
       var onmover = 'onMouseOver="this.src=' + "'" +rooturl + 'img/'+elmId + v + '/' + navifileO  +'.' +ext + "'" + '"';
       var onmout  = 'onMouseOut ="this.src=' + "'" +rooturl + 'img/'+elmId + v + '/' + navifile + '.'+ext + "'" + '"';
       aElement.innerHTML = '<img src="' + rooturl + 'img/'+elmId + v + '/' + navifile +'.'+ ext+'" alt="' +aalt+'" width="'+imgwidth+'" height="'+imgheight+'"'  + onmover +onmout + ' />';
       preImageNavi[navifile] = new Image();
       preImageNavi[navifile].src = rooturl + 'img/'+elmId + v + '/' + navifileO  +'.' +ext;
    }
  }
}

//a href="***" target="***" 
function linktarget(elementId,linktarget){
	var i;
	if (document.getElementById) {
		var linkElms = document.getElementById(elementId).getElementsByTagName('a');
		for(i = 0; i < linkElms.length; i++){
			linkElms[i].target = linktarget;
			linkElms[i].className = elementId + linktarget;
			linkElms[i].title = linkElms[i].innerHTML  + ' ' + linkElms[i].href;
		}
	}
}

//a href="***" img src="" alt="****" target="***" 
function linktargetimgalt(elementId,linktarget){
	var i;
	if (document.getElementById) {
		var linkElms = document.getElementById(elementId).getElementsByTagName('a');
		for(i = 0; i < linkElms.length; i++){
			linkElms[i].target = linktarget;
			linkElms[i].className = elementId + linktarget;
			linkElms[i].title = linkElms[i].getElementsByTagName('img')[0].alt  + ' ' + linkElms[i].href;
		}
	}
}

function windowonlod(){
	imageswapnavi('mainnavi','gif','180','34')
	toThisTopLinkAdd();
}
function toThisTopLinkAdd(){
	if (document.getElementById) {
		var linkElms = document.getElementsByTagName('a');
		for(i = 0; i < linkElms.length; i++){
			if(linkElms[i].href.match(/#WRAPPER$/)){
				linkElms[i].onclick = function(){toThisTop(); return false;}
			}
		}
	}
}

function gmapjssrc(){
	var tag = '<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=' + conf_gmapkey + '" type="text/javascript"></script>';
	document.write(tag);
}
//window.onload = windowonlod;


function repeatItem(elementId,numIn,tag,styleclass){
	var num = parseInt(numIn);
	if (document.getElementById) {
		var targetElms = document.getElementById(elementId).getElementsByTagName(tag);
		for(i = 0; i < targetElms.length; i++){
			targetElms[i].className = styleclass+((i % num) + 1) + ' '+ targetElms[i].className;
		}
	}
}

//(c) M



function toThisTop() {
	var x1 = x2 = x3 = 0;
	var y1 = y2 = y3 = 0;
	if (document.documentElement) {
		x1 = document.documentElement.scrollLeft || 0;
		y1 = document.documentElement.scrollTop || 0;
	}else if (document.body) {
		x2 = document.body.scrollLeft || 0;
		y2 = document.body.scrollTop || 0;
	}
	x3 = window.scrollX || 0;
	y3 = window.scrollY || 0;
	var x = Math.max(x1, Math.max(x2, x3));
	var y = Math.max(y1, Math.max(y2, y3));
	window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));
	if (x > 0 || y > 0) {
		window.setTimeout("toThisTop()", 20);
	}
}

function fadetop(){
	if (document.getElementById) {
		var tag =  '<img src="img/fade6/botchanressha.jpg" alt="" width="380" height="240" id="ft" />';
		document.getElementById("topimages").innerHTML = tag;
		fadeElm('ft','out',1,0);
	}
}
function fadeElm(elm,inout,imgopacity,num){
	var imgAry= new Array('img/fade6/botchanressha.jpg','img/fade6/jr.jpg','img/fade6/matsusho.jpg','img/fade6/shiroyama.jpg');
	var urlAry= new Array('./#0','./#1');
	imgopacity = imgopacity *.90 -0.01;
	if(inout == "in"){opa = 1-imgopacity}
	if(inout == "out"){opa = imgopacity}
	if(imgopacity > 0.01){
		document.getElementById(elm).style.opacity= (1-opa);
		document.getElementById(elm).style.filter = "alpha(opacity="+(1-opa)*100 + ")";
		showtimeoutid = setTimeout("fadeElm('"+elm+"','"+inout+"'," + imgopacity +"," +num +")",40);
	}else{
		try{
			clearTimeout(showtimeoutid);
		}catch(e) {}
		if(inout =="out"){
//			document.getElementById("testa").href = urlAry[num];
//	document.getElementById("ft").style.backgroundImage = "url("+imgAry[(num+1)%imgAry.length]+")";
			document.getElementById("ft").src = imgAry[num];
			timeoutid = setTimeout("fadeElm('"+elm+"','in',1,"+num+")", 7000);
		}else{
			num = (num+1)%imgAry.length;
//			document.getElementById("testa").href = urlAry[num];
			document.getElementById("ft").src = imgAry[num];
			timeoutid = setTimeout("fadeElm('"+elm+"','out',1,"+num+")", 40);
		}
	}
}

/*松山らしさ*/
function faderashisa(){
	if (document.getElementById) {
		var tag =  '<img src="img/top/rashisa_saisho.gif" alt="" width="360" height="390" id="fr" />';
		document.getElementById("myinfoimg").innerHTML = tag;
		//fadeElm('fr','out',1,0);
	}
}

function fadeElmRashisa(elm,inout,imgopacity,num){
	var imgAry= new Array('rashisa_saisho','img/top/castle.jpg','img/top/sakakumo.jpg');
	var urlAry= new Array('./#0','./#1');
	imgopacity = imgopacity *.8 -0.1;
	if(inout == "in"){opa = 1-imgopacity}
	if(inout == "out"){opa = imgopacity}
	if(imgopacity > 0.01){
		document.getElementById(elm).style.opacity= (1-opa);
		document.getElementById(elm).style.filter = "alpha(opacity="+(1-opa)*100 + ")";
		showtimeoutid = setTimeout("fadeElm('"+elm+"','"+inout+"'," + imgopacity +"," +num +")",30);
	}else{
		try{
			clearTimeout(showtimeoutid);
		}catch(e) {}
		if(inout =="out"){
			document.getElementById("testa").href = urlAry[num];
			document.getElementById("ft").src = imgAry[num];
			timeoutid = setTimeout("fadeElm('"+elm+"','in',1,"+num+")", 100);
		}else{
			num = (num+1)%imgAry.length;
//			document.getElementById("testa").href = urlAry[num];
			document.getElementById("ft").src = imgAry[num];
			timeoutid = setTimeout("fadeElm('"+elm+"','out',1,"+num+")", 100);
		}
	}
}
