/**
 *
 * 画像切り替え
 *
**/
function smartRollover(base, flip) {
  var imgs = document.images;
  if (!document.images) {
    return false;
  }
  var pre = new Array();
  for (var i = 0; i < imgs.length; i++) {
    var src = imgs[i].src;
    if (src.match(base)) {
      // 画像先読み
      pre[i] = new Image();
      pre[i].src = src.replace(base, flip);

      // ロールオーバー設定
      imgs[i].onmouseover = function() {
        this.src = this.src.replace(base, flip);
      }
      imgs[i].onmouseout = function() {
        this.src = this.src.replace(flip, base);
      }
    }
  }
}

/**
 *
 * イベント追加
 *
**/
function addEvent(elm, eventName, func) {
  if (elm.addEventListener) {
    elm.addEventListener(eventName, func, false);
    return true;

  } else if (elm.attachEvent) {
    elm.attachEvent("on"+eventName, func);
    return true;

  } else {
    return false;

  }
}


/**
 *
 * 別窓オープン
 *
**/
function external() {
	if (!document.getElementsByTagName) {
		return;
	}
	var anchors = document.getElementsByTagName('a');
	for (var i = 0; i < anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute('class') == 'external' || anchor.getAttribute('className') == 'external') {
			anchor.setAttribute('target', '_blank');
		}
	}
}

/**
 *
 * フラッシュロード
 *
**/
function load_movie() {
	if (!document.getElementById("TopImage")) {
		return false;
	}
	var flashvars = {};
	var params = {bgcolor:"#ffffff"};
	var attributes = {};
	swfobject.embedSWF('sekisui.swf', 'TopImage', '740', '240', '9', 'js/swfobject/expressInstall.swf', flashvars, params, attributes);
}


addEvent(window, 'load', function(){smartRollover('_off.', '_on.');});
addEvent(window, 'load', external);

var j$ = jQuery.noConflict();

j$(document).ready(function() {
	if (!j$("#ResultProduct").hasClass('opend')) {
		j$("#ResultProduct").hide();
	}

	if (!j$("#ResultUsage").hasClass('opend')) {
		j$("#ResultUsage").hide();
	}
	if (!j$("#ResultShape").hasClass('opend')) {
		j$("#ResultShape").hide();
	}
	if (!j$("#ResultMaterial").hasClass('opend')) {
		j$("#ResultMaterial").hide();
	}

	if (!j$("#ResultGenre").hasClass('opend')) {
		j$("#ResultGenre").hide();
	}

	var open_time;
	if (typeof document.documentElement.style.maxHeight != "undefined") {
		// IE6以外
		open_time = 500;
	} else {
		// IE6
		open_time = 0;
	}

	j$("#SearchByProduct").click(function() {
		j$("#ResultProduct").slideToggle(open_time);
	});
	j$("#SearchByUsage").click(function() {
		j$("#ResultUsage").slideToggle(open_time);
	});
	j$("#SearchByShape").click(function() {
		j$("#ResultShape").slideToggle(open_time);
	});
	j$("#SearchByMaterial").click(function() {
		j$("#ResultMaterial").slideToggle(open_time);
	});
	j$("#SearchByGenre").click(function() {
		j$("#ResultGenre").slideToggle(open_time);
	});
});
