/**
 *
 * ロールオーバー等のヘルパー関数郡
 *
 */
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(){

		//gnavi(blue)
		LSHelper.addRollover( 'bhome','/images/gnavi/blue/home_on.png' );

		LSHelper.addRollover( 'bwhatsmr','/images/gnavi/blue/whatsmr_on.png' );

		LSHelper.addRollover( 'bentry','/images/gnavi/blue/entry_on.png' );

		LSHelper.addRollover( 'bareafinal','/images/gnavi/blue/areafinal_on.png' );

		LSHelper.addRollover( 'bjapanfinal','/images/gnavi/blue/japanfinal_on.png' );

		LSHelper.addRollover( 'bqa','/images/gnavi/blue/qa_on.png' );

		LSHelper.addRollover( 'bgeneralcontact','/images/gnavi/blue/generalcontact_on.png' );

		LSHelper.addRollover( 'barchive','/images/gnavi/blue/archive_on.png' );

		//gnavi(orange)
		LSHelper.addRollover( 'ohome','/images/gnavi/orange/home_on.png' );

		LSHelper.addRollover( 'owhatsmr','/images/gnavi/orange/whatsmr_on.png' );

		LSHelper.addRollover( 'oentry','/images/gnavi/orange/entry_on.png' );

		LSHelper.addRollover( 'oareafinal','/images/gnavi/orange/areafinal_on.png' );

		LSHelper.addRollover( 'ojapanfinal','/images/gnavi/orange/japanfinal_on.png' );

		LSHelper.addRollover( 'oqa','/images/gnavi/orange/qa_on.png' );

		LSHelper.addRollover( 'ogeneralcontact','/images/gnavi/orange/generalcontact_on.png' );

		LSHelper.addRollover( 'oarchive','/images/gnavi/orange/archive_on.png' );


		//rightMenu
		LSHelper.addRollover('bnr_myspace', '/images/rightmenu/bnr_myspace_on.png');

		LSHelper.addRollover('bnr_youtube', '/images/rightmenu/bnr_youtube_on.png');

		LSHelper.addRollover('btn_dl_4thMRt', '/images/rightmenu/btn_dl_4thMR_on.png');

		LSHelper.addRollover('bnr_myspacemaika', '/images/rightmenu/bnr_myspacemaika_on.png');

		LSHelper.addRollover('bnr_ongen', '/images/rightmenu/bnr_ongen_on.png');

		LSHelper.addRollover('bnr_yamazaki', '/images/rightmenu/bnr_yamazaki_on.png');

		//archive
		LSHelper.addRollover('top1', '/images/archive/btn_top_on.gif');

		LSHelper.addRollover('top2', '/images/archive/btn_top_on.gif');

		LSHelper.addRollover('result1', '/images/archive/btn_result_on.gif');

		LSHelper.addRollover('result2', '/images/archive/btn_result_on.gif');

		LSHelper.addRollover('photo1', '/images/archive/btn_photo_on.gif');

		LSHelper.addRollover('photo2', '/images/archive/btn_photo_on.gif');

		LSHelper.addRollover('mov1', '/images/archive/btn_mov_on.gif');

		LSHelper.addRollover('mov2', '/images/archive/btn_mov_on.gif');


	}

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