﻿/*
▼atricot.jp　サイト全体のjavaScript
*/



/*�　　ロールオーバー　　*/

function initRollOvers() {
	if (!document.getElementById){
		return;
	}
	
	var preLoads = new Array();
	var allImages = document.getElementsByTagName('img');

	for (var i = 0; i < allImages.length; i++) {		
		if (allImages[i].className == 'rollover') {
			var src = allImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var oSrc = src.replace(ftype, '_on'+ftype);

			//-- スワップ元、スワップ先画像の登録
			allImages[i].setAttribute('pSrc', src);
			allImages[i].setAttribute('oSrc', oSrc);

			//-- イメージのプリロード
			preLoads[i] = new Image();
			preLoads[i].src = oSrc;

			//-- イベントの設定
			allImages[i].onmouseover = function() {
				this.setAttribute('src', this.getAttribute('oSrc'));
			}
			allImages[i].onmouseout = function() {
				this.setAttribute('src', this.getAttribute('pSrc'));
			}
		}
	}
}

function addOnload(func){
	if ( typeof window.addEventListener != "undefined" ){
		window.addEventListener( "load", func, false );
	}else if ( typeof window.attachEvent != "undefined" ) {
		window.attachEvent( "onload", func );
	}else{
		if ( window.onload != null ){
			var oldOnload = window.onload;
			window.onload = function ( e ) {
			oldOnload( e );
			window[func]();
		};
	}else
		window.onload = func;
	}
}
addOnload(initRollOvers);





/*�　　ドロップダウンメニュー　*/

var section_id = "menuBar";
var toggle_initial = "t";
var target_initial = "m";

function menuOpen() {
	var toggleId = this.getAttribute("id"), targetId = target_initial+toggleId;
	var targetItem = document.getElementById(targetId);
	targetItem.style.display = "block";
}
function menuClose() {
	var toggleId = this.getAttribute("id"), targetId = target_initial+toggleId;
	var targetItem = document.getElementById(targetId);
	targetItem.style.display = "none";
}

function setMenuBar(){
	var tUL = document.getElementById(section_id).childNodes;
	for(var i=0; i<tUL.length; i++) {
		if(tUL[i].tagName =="UL") {
			var tLI = tUL[i].childNodes;
			for(var j=0; j<tLI.length; j++) {
				if(tLI[j].tagName =="LI") {
					var tULc = tLI[j].childNodes;
					for(var k=0; k<tULc.length; k++) {
						if(tULc[k].tagName == "UL") {
							tULc[k].setAttribute("id",target_initial+toggle_initial+j+k);
							tLI[j].setAttribute("id",toggle_initial+j+k);
							tLI[j].onmouseover = menuOpen;
							tLI[j].onmouseout = menuClose;
							tLI[j].onclick = menuClose;
						} else { continue; }
					}
				} else { continue; }
			}
		} else { continue; }
	}
}

function addListener(elem,eventType,func,cap) {
	if(elem.addEventListener) {
		elem.addEventListener(eventType,func,cap);
	} else if(elem.attachEvent) {
		elem.attachEvent('on' + eventType,func);
	} else {
		alert(browser_disable);
		return false;
	}
}

addListener(window,'load',setMenuBar,false);






/*�　　ページ内スムーズスクロール　　*/

function backToTop() {
  var x1 = x2 = x3 = 0;
  var y1 = y2 = y3 = 0;
  if (document.documentElement) {
      x1 = document.documentElement.scrollLeft || 0;
      y1 = document.documentElement.scrollTop || 0;
  }
  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("backToTop()", 25);
  }
}






/* 　ブックマーク　 */

function bookmarkYahoo(){
window.open('http://bookmarks.yahoo.co.jp/bookmarklet/showpopup?t='+encodeURIComponent(document.title)+'&u='+encodeURIComponent(window.location.href)+'&opener=bm&ei=UTF-8','popup','width=550px,height=480px,status=1,location=0,resizable=1,scrollbars=0,left=100,top=50',0);
}
function bookmarkDel(){
url='http://atricot.jp/';
title='ニット＆羊　atricot.jp';
newWin=window.open();
newWin.location.href='http://del.icio.us/post?url='+encodeURIComponent(url)+'&title='+encodeURIComponent(title);
}
function bookmarkFC2(){
location.href='http://bookmark.fc2.com/user/post?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title);
}
function bookmarkNewsing(){
window.location='http://newsing.jp/nbutton?title='+encodeURIComponent('ニット＆羊　atricot.jp')+'&url='+encodeURIComponent('http://atricot.jp');
}

function bookmark(){
document.write('<ol> \n');
document.write('<!-- Yahoo --> \n');
document.write('<li><a href="javascript:bookmarkYahoo()"><img src="http://i.yimg.jp/images/sicons/ybm16.gif" width="16" height="16" alt="" /></a></li> \n');
document.write('<!-- google --> \n');
document.write('<li><a href="http://www.google.com/bookmarks/mark?op=edit&bkmk=http://atricot.jp/&title=ニット＆羊　atricot.jp" target="_blank"><img alt="" src="http://www.google.co.jp/favicon.ico" border="0" width="16" height="16" /></a></li> \n');
document.write('<!-- はてな --> \n');
document.write('<li><a href="http://b.hatena.ne.jp/append?http://atricot.jp/" target="_blank"><img src="http://b.hatena.ne.jp/images/append.gif" alt="" width="16" height="12" border="0" /></a></li> \n');
document.write('<!-- del.icio.us --> \n');
document.write('<li><a href="javascript:bookmarkDel()"><img src="http://del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="" /></a></li> \n');
document.write('<!-- ニフティクリップ --> \n');
document.write('<li><a href="http://clip.nifty.com/create?url=http://atricot.jp&title=ニット＆羊　atricot.jp" rel="nofollow"><img src="http://clip.nifty.com/images/addclip_icn.gif" alt="" width="12" height="12" border="0" /></a></li> \n');
document.write('<!-- Livedoorクリップ --> \n');
document.write('<li><a href="http://clip.livedoor.com/clip/add?link=window.self.location.href&title=document.title&jump=myclip" target="_blank"><img src="http://parts.blog.livedoor.jp/img/cmn/clip_16_16_b.gif" width="16" height="16" alt="" /></a></li> \n');
document.write('<!-- Buzzurl --> \n');
document.write('<li><a href="http://buzzurl.jp/entry/http://atricot.jp/" target="_blank"><img src="http://buzzurl.jp/static/image/api/icon/add_icon_mini_08.gif" alt="" style="border:0"></a></li> \n');
document.write('</ol> \n');
}







/* 　背景画像ランダム変更　 */

wall = new Array();
wall[0] = "img/index/back_001.jpg";
wall[1] = "img/index/back_002.jpg";
wall[2] = "img/index/back_003.jpg";
wall[3] = "img/index/back_004.jpg";
rnd = Math.round(Math.random() * (wall.length - 1));
document.write('<style type="text/css">div#back { background:url(' , wall[rnd] , ') ; }</style>');






/* 　透過PNGをIE6で表示　 */


var clear="../img/unitpngfix/clear.gif"

pngfix=function(){var els=document.getElementsByTagName('*');var ip=/\.png/i;var i=els.length;while(i-- >0){var el=els[i];var es=el.style;if(el.src&&el.src.match(ip)&&!es.filter){es.height=el.height;es.width=el.width;es.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+el.src+"',sizingMethod='crop')";el.src=clear;}else{var elb=el.currentStyle.backgroundImage;if(elb.match(ip)){var path=elb.split('"');var rep=(el.currentStyle.backgroundRepeat=='no-repeat')?'crop':'scale';es.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+path[1]+"',sizingMethod='"+rep+"')";es.height=el.clientHeight+'px';es.backgroundImage='none';var elkids=el.getElementsByTagName('*');if (elkids){var j=elkids.length;if(el.currentStyle.position!="absolute")es.position='static';while (j-- >0)if(!elkids[j].style.position)elkids[j].style.position="relative";}}}}}
window.attachEvent('onload',pngfix);