// onload function
jQuery(document).ready(function(){
	chgImg();
	var uaName = jQuery.browser;
	var uaVer = jQuery.browser.version;
	if (uaName.msie && uaVer <= 6.0) {
		wrapperHeight();	
	}
});


// rollover (onload)
function chgImg() {
	var imgNodeList = getElementsByClassName('chgImg');
	var node;
	for (var i=0, len=imgNodeList.length; i<len; i++) {
		node = imgNodeList[i];
		node.originalSrc = node.src;
		node.rolloverSrc = node.src.replace(/(\.gif|\.jpg|\.png)/, '_ovr'+"$1");
		preloadImg(node.rolloverSrc);
		node.onmouseover = function() {
			this.src = this.rolloverSrc;
		}
		node.onmouseout = function() {
			this.src = this.originalSrc;
		}
	}
}

// get elements by class
function getElementsByClassName(name) {
	if (document.all) {
		var classElements = new Array();
		var allElements = document.all;
		for (i = 0, j = 0; i < allElements.length; i++) {
			if (allElements[i].className == name) {
				classElements[j] = allElements[i];
				j++;
			}
		}    
	} else if (document.getElementsByTagName) {
		var classElements = new Array();
		var allElements = document.getElementsByTagName("*");
		for (i = 0, j = 0; i < allElements.length; i++) {
			if (allElements[i].className == name) {
				classElements[j] = allElements[i];
				j++;
			}
		}
	} else {
		return;
	}
	return classElements;
}

// preload
var preloadImages = [];
function preloadImg(url) {
	var p = preloadImages;
	var l = p.length;
	p[l] = new Image();
	p[l].src = url;
}


// #wrapper height 100% for winIE6
function wrapperHeight() {
	if (window.innerHeight) {
		h=window.innerHeight;
	}
	if (document.documentElement && document.documentElement.clientHeight) {
		h=document.documentElement.clientHeight;
	}
	else if (document.body && document.body.clientHeight) {
		h=document.body.clientHeight;
	}
	if (document.getElementById) {
		a=document.getElementById('wrapper');
		if (a && a.style && a.style.height<h) {
			a.style.height=h+'px';
		}
	}
}


// print
function print_out() {
	var ua = navigator.userAgent;
	var WIN = (ua.indexOf("Windows") != -1);
	var MAC = (ua.indexOf("Mac") != -1);
	var IE = (ua.indexOf("MSIE") != -1);
	if (MAC && IE) {
		alert("お使いのブラウザではこの機能は利用できません。\nブラウザのメニューから印刷してください。");	
	} else {
		self.print();
	}
}


// search result - photo vertical align
jQuery(function(){
	jQuery("#search .photoListBlock p.pict img").each(function(){
		this.photoHeight = this.height;
		this.mgnTop = Math.round((160-this.photoHeight)/2);
		this.style.marginTop = this.mgnTop+'px';
	});
});

// my cart - photo vertical align
jQuery(function(){
	jQuery("#mycart .photoListBlock p.pict img").each(function(){
		this.photoHeight = this.height;
		this.mgnTop = Math.round((160-this.photoHeight)/2);
		this.style.marginTop = this.mgnTop+'px';
	});
});

// special - photo vertical align
jQuery(function(){
	jQuery("#special .photoListBlock p.pict img").each(function(){
		this.photoHeight = this.height;
		this.mgnTop = Math.round((230-this.photoHeight)/2);
		this.style.marginTop = this.mgnTop+'px';
	});
});
// theme - photo vertical align
jQuery(function(){
	jQuery("#theme .photoListBlock p.pict img").each(function(){
		this.photoHeight = this.height;
		this.mgnTop = Math.round((160-this.photoHeight)/2);
		this.style.marginTop = this.mgnTop+'px';
	});
});

