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

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

		LSHelper.addRollover( 'bnr_sound','/images/header/bnr/bnr_sound_on.png' );

		LSHelper.addRollover( 'bnr_maika','/images/header/bnr/bnr_maika_on.png' );

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

		//sideBanner
		LSHelper.addRollover( 'bnr_soundSource','/images/side/bnr/bnr_soundSource_on.png' );

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

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

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

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

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

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

		LSHelper.addRollover( 'gnavi_history','/images/gnavi/history_on.png' );

		LSHelper.addRollover( 'gnavi_contact','/images/gnavi/contact_on.png' );

		LSHelper.addRollover( 'gnavi_ep_sa','/images/gnavi/ep_sa_on.png' );

		LSHelper.addRollover( 'gnavi_ep_to','/images/gnavi/ep_to_on.png' );

		LSHelper.addRollover( 'gnavi_ep_na','/images/gnavi/ep_na_on.png' );

		LSHelper.addRollover( 'gnavi_ep_os','/images/gnavi/ep_os_on.png' );

		LSHelper.addRollover( 'gnavi_ep_fu','/images/gnavi/ep_fu_on.png' );

		LSHelper.addRollover( 'i_q_img','/images/gnavi/i_q_o.png' );

		//btn
		LSHelper.addRollover( 'sa_blog','/images/side/area/sa_blog_on.png' );

		LSHelper.addRollover( 'to_blog','/images/side/area/to_blog_on.png' );

		LSHelper.addRollover( 'na_blog','/images/side/area/na_blog_on.png' );

		LSHelper.addRollover( 'os_blog','/images/side/area/os_blog_on.png' );

		LSHelper.addRollover( 'fu_blog','/images/side/area/fu_blog_on.png' );

		LSHelper.addRollover( 'bnr_teammurevo','/images/side/bnr/bnr_teammurevo_on.png' );

		LSHelper.addRollover( 'bnr_wallpaper','/images/side/bnr/bnr_wallpaper_on.png' );

		LSHelper.addRollover( 'bnr_ymp','/images/side/bnr/bnr_ymp_on.png' );

		LSHelper.addRollover( 'bnr_mrgirl','/images/side/bnr/bnr_mrgirl_on.png' );

		LSHelper.addRollover( 'bnr_mrgirl-2','/images/side/bnr/bnr_mrgirl-2_on.png' );

		LSHelper.addRollover( 'bnr_jfustream','/images/side/bnr/bnr_jfustream_on.png' );

		//history トップ
		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');

		//history 各エリア
		LSHelper.addRollover('btn_top', '/history/images/btn_top_on.png');

		LSHelper.addRollover('btn_sa_entry', '/history/images/btn_sa_entry_on.png');

		LSHelper.addRollover('btn_sa_result', '/history/images/btn_sa_result_on.png');

		LSHelper.addRollover('btn_ho_entry', '/history/images/btn_ho_entry_on.png');

		LSHelper.addRollover('btn_ho_result', '/history/images/btn_ho_result_on.png');

		LSHelper.addRollover('btn_th_entry', '/history/images/btn_th_entry_on.png');

		LSHelper.addRollover('btn_th_result', '/history/images/btn_th_result_on.png');

		LSHelper.addRollover('btn_to_entry', '/history/images/btn_to_entry_on.png');

		LSHelper.addRollover('btn_to_result', '/history/images/btn_to_result_on.png');

		LSHelper.addRollover('btn_na_entry', '/history/images/btn_na_entry_on.png');

		LSHelper.addRollover('btn_na_result', '/history/images/btn_na_result_on.png');

		LSHelper.addRollover('btn_os_entry', '/history/images/btn_os_entry_on.png');

		LSHelper.addRollover('btn_os_result', '/history/images/btn_os_result_on.png');

		LSHelper.addRollover('btn_fu_entry', '/history/images/btn_fu_entry_on.png');

		LSHelper.addRollover('btn_fu_result', '/history/images/btn_fu_result_on.png');

		LSHelper.addRollover('btn_ky_entry', '/history/images/btn_ky_entry_on.png');

		LSHelper.addRollover('btn_ky_result', '/history/images/btn_ky_result_on.png');

		//dl
		LSHelper.addRollover('btn_dl', '/images/side/dl/btn_dl_on.png');

	}

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

