/*
	Standards Compliant Rollover Script
	Author : Daniel Nolan
	http://www.bleedingego.co.uk/webdev.php
*/
/*
	上記を元にjQuery用に書き換え。
	2010/03/10	Ver 1.0.3
*/
jQuery(document).ready(function() {
	var aPreLoad = new Array();
	/*
	var imageExists = function(sImageUrl) {
		var img = new Image();
		img.src = sImageUrl;
		return img.height > 0;//noimage > return false
	};
	*/
	jQuery('img.btn,input.btn,a.btn>img').each(function(i){
		var src = jQuery(this).attr('src');
		var ftype = src.substring(src.lastIndexOf('.'), src.length);
		var hsrc = src.replace(ftype, '_o'+ftype);

		// ロールオーバー画像が存在しなかったら処理抜ける
		/*if (!imageExists(hsrc)) return;*/

		jQuery(this).attr('hsrc', hsrc);
		jQuery(this).attr('osrc', src);
		aPreLoad[i] = new Image();
		aPreLoad[i].src = hsrc;

		if (jQuery(this).parent("a.btn").size() != 0){
			// .selectedだったらover用画像と差し替えておく
			if (jQuery(this).parent("a.btn").hasClass('selected')){
				jQuery(this).attr('src',hsrc);
			}
			jQuery(this).parent("a.btn").mouseover(function() {
				if (!jQuery(this).hasClass('selected')){
					sTempHsrc = jQuery(this).children("img").attr('hsrc');
					jQuery(this).children("img").attr('src', sTempHsrc);
				}
			}).mouseout(function() {
				if (!jQuery(this).hasClass('selected')){
					sTempOsrc = jQuery(this).children("img").attr('osrc');
					jQuery(this).children("img").attr('src', sTempOsrc);
				}
			}).blur(function() {
				if (!jQuery(this).hasClass('selected')){
					sTempOsrc = jQuery(this).children("img").attr('osrc');
					jQuery(this).children("img").attr('src', sTempOsrc);
				}
			});
		} else {
			// .selectedだったらover用画像と差し替えておく
			if (jQuery(this).hasClass('selected')){
				jQuery(this).attr('src',hsrc);
			}
			jQuery(this).mouseover(function() {
				if (!jQuery(this).hasClass('selected')){
					sTempHsrc = jQuery(this).attr('hsrc');
					jQuery(this).attr('src', sTempHsrc);
				}
			}).mouseout(function() {
				if (!jQuery(this).hasClass('selected')){
					sTempOsrc = jQuery(this).attr('osrc');
					jQuery(this).attr('src', sTempOsrc);
				}
			}).blur(function() {
				if (!jQuery(this).hasClass('selected')){
					sTempOsrc = jQuery(this).attr('osrc');
					jQuery(this).attr('src', sTempOsrc);
				}
			});
		}
	});
});