/**
 *
 * ロールオーバー等のヘルパー関数郡
 *
 */
var LSHelper;
LSHelper = {
	/**
	 * ロールオーバーの追加
	 */
	addRollover: function(img, rolloverURL) {
		if (typeof img == "string") {  // If img is a string,
			var id = img;              // it is an id, not an image
			img = null;                // and we don't have an image yet.

			// First try looking the image up by id
			if (document.getElementById) img = document.getElementById(id);
			else if (document.all) img = document.all[id];

			// If not found by id, try looking the image up by name.
			if (!img) img = document.images[id];

			// If we couldn't find the image, do nothing and fail silently
			if (!img) return;
		}

		// If we found an element but it is not an <img> tag, we also fail
		if (img.tagName.toLowerCase() != "img") return;

		// Remember the original URL of the image
		var baseURL = img.src;
		img.baseURL = baseURL;

		// Preload the rollover image into the browser's cache
		(new Image()).src = rolloverURL;

		LSHelper.observe(img,'mouseover',function(){ img.src = rolloverURL; });
		LSHelper.observe(img,'mouseout',function(){ img.src = baseURL; });
	},

	/**
	 * ターゲットロールオーバーの追加
	 */
	addTargetRollover: function(triger, img, rolloverURL) {
		if (typeof triger  == "string") {  // If triger is a string,
			var tid = triger;              // it is an id, not an image
			triger = null;                // and we don't have an image yet.

			// First try looking the image up by id
			if (document.getElementById) triger = document.getElementById(tid);
			else if (document.all) img = document.all[tid];

			// If we couldn't find the image, do nothing and fail silently
			if (!triger) return;
		}
		if (typeof img == "string") {  // If img is a string,
			var id = img;              // it is an id, not an image
			img = null;                // and we don't have an image yet.

			// First try looking the image up by id
			if (document.getElementById) img = document.getElementById(id);
			else if (document.all) img = document.all[id];

			// If not found by id, try looking the image up by name.
			if (!img) img = document.images[id];

			// If we couldn't find the image, do nothing and fail silently
			if (!img) return;
		}

		// If we found an element but it is not an <img> tag, we also fail
		if (img.tagName.toLowerCase() != "img") return;

		// Remember the original URL of the image
		var baseURL = img.src;
		img.baseURL = baseURL;

		// Preload the rollover image into the browser's cache
		(new Image()).src = rolloverURL;

		if(triger.onmouseover){
			LSHelper.observe(triger,'mouseover',function(){ img.src = rolloverURL; });
		}else{
			LSHelper.observe(triger,'mouseover',function(){ img.src = rolloverURL; });
		}
		LSHelper.observe(triger,'mouseout',function(){ img.src = baseURL; });
	},

	/**
	 * rollover属性を探してロールオーバーを追加
	 */
	initRollovers: function() {
    		var images = document.getElementsByTagName("img");
	    	for(var i = 0; i < images.length; i++) {
    		    var image = images[i];
    		    var rolloverURL = image.getAttribute("rollover");
    		    if (rolloverURL) LSHelper.addRollover(image, rolloverURL);
    		    var targetRolloverURL = image.getAttribute("targetrollover");
		    if (targetRolloverURL){
		    	var targetsplit = targetRolloverURL.split(":");
    		    	LSHelper.addTargetRollover(image, targetsplit[0], targetsplit[1]);
		    }
    		}
    		var areas = document.getElementsByTagName("area");
		for(var i = 0; i < areas.length; i++) {
			var area = areas[i];
    		    	var originalRolloverURL = area.getAttribute("rollover");
			var areasplit = originalRolloverURL.split(":");
			image = document.getElementById(areasplit[0]);
			if(image){
				var rolloverURL = areasplit[1];
			}
			if (rolloverURL) LSHelper.addTargetRollover(area, image, rolloverURL);
    		    	var targetRolloverURL = area.getAttribute("targetrollover");
		        if (targetRolloverURL){
		   	 	var targetsplit = targetRolloverURL.split(":");
    		    		LSHelper.addTargetRollover(area, targetsplit[0], targetsplit[1]);
		    	}
		}
	},

	/**
	 * css指定によるロールオーバーの追加
	 */
	addRolloverByCss: function(css, rolloverImg){
    		var images = document.getElementsByTagName("img");
	    	for(var i = 0; i < images.length; i++) {
    		    var image = images[i];
    		    var rolloverURL = image.getAttribute("class");
    		    if (rolloverURL == css) LSHelper.addRollover(image, rolloverImg);
    		}
	},

	/**
	 * イベントの追加
	 */
	observe: function(element, eventName, handler){
		if (element.addEventListener) {
			element.addEventListener(eventName, handler, false);
		} else {
			element.attachEvent("on" + eventName, handler);
		}
	},

	/**
	 * 手動でのロールオーバー設定
	 * HTML validator 対応のためrollover属性を使用しないため
	 */
	initRolloversByHand: function(){

		//-- ▼importantMenu --
		LSHelper.addRollover('btn_event', '/images/btn_event_o.png');

		LSHelper.addRollover('btn_storeinfo', '/images/btn_storeinfo_o.png');

		LSHelper.addTargetRollover('btn_contact', 'btn_contact', '/images/btn_contact_o.png');

		LSHelper.addTargetRollover('btn_contact', 'copy_contact', '/images/copy_contact_o.png');

		LSHelper.addTargetRollover('copy_contact', 'btn_contact', '/images/btn_contact_o.png');

		LSHelper.addTargetRollover('copy_contact', 'copy_contact', '/images/copy_contact_o.png');


		//-- ▼topMenu --
		LSHelper.addRollover('btn_aboutus', '/images/btn_aboutus_o.png');

		LSHelper.addRollover('btn_labo', '/images/btn_labo_o.png');

		LSHelper.addRollover('btn_bank', '/images/btn_bank_o.png');

		LSHelper.addRollover('btn_salons', '/images/btn_salons_o.png');

		LSHelper.addRollover('btn_qa', '/images/btn_qa_o.png');

		LSHelper.addRollover('btn_voice', '/images/btn_voice_o.png');


		//-- ▼Button --
		LSHelper.addRollover('btn_contact2', '/images/2ndCommon/btn_contact2_o.png');

		LSHelper.addRollover('btn_contact_oubo', '/images/ouboyoukou/btn_contact_o.png');

		LSHelper.addRollover('btn_contact_oubo2', '/images/ouboyoukou/btn_contact2_o.png');

		LSHelper.addRollover('btn_recruit', '/images/2ndCommon/btn_recruit_o.png');

		//-- ▼campaign --
		LSHelper.addRollover('btn_camp1', '/images/campaign/btn01_o.png');

		LSHelper.addRollover('btn_camp2', '/images/campaign/btn02_o.png');

		LSHelper.addRollover('btn_camp3', '/images/present/btn03_o.png');

		LSHelper.addRollover('btn_camp4', '/images/present/btn04_o.png');


	}

}
LSHelper.observe(window,"load", LSHelper.initRolloversByHand);
