(function(){
// FOOTER IMAGE PATH
var IMG_PATH = ( location.host.match(/^www\.j-wave\.co\.jp/) ) ? "/common/img/" : "http://www.j-wave.co.jp/common/img/"

// FOOTER ELEMENTS
var ELE = []

// ELEMENTS STOCK
ELE.push("<div id='commonFooter'>")
ELE.push("<div id='commonFooterInner'>")
ELE.push("<div class='clrfix'>")
ELE.push("<ul>")
ELE.push("<li id='areaFtNavTop'><a href='http://www.j-wave.co.jp/' title=''><img class='nav-hover' src='"+IMG_PATH+"ft_nav_top.gif' alt='' /></a></li>")
ELE.push("<li id='areaFtNavListen'><a href='http://www.j-wave.co.jp/radiobar/index.htm' title=''><img class='nav-hover' src='"+IMG_PATH+"ft_nav_listen.gif' alt='' /></a></li>")
ELE.push("<li id='areaFtNavRequest'><a href='https://www.j-wave.co.jp/contents/message/' title=''><img class='nav-hover' src='"+IMG_PATH+"ft_nav_req_mes.gif' alt='' /></a></li>")
ELE.push("<li id='areaFtNavToday'><a href='http://www.j-wave.co.jp/today/' title=''><img class='nav-hover' src='"+IMG_PATH+"ft_nav_today.gif' alt='' /></a></li>")
ELE.push("<li id='areaFtNavTimeTable'><a href='http://www.j-wave.co.jp/contents/timetable/contents.htm' title=''><img class='nav-hover' src='"+IMG_PATH+"ft_nav_timetable.gif' alt='' /></a></li>")
ELE.push("<li id='areaFtNavLatest'><a href='http://www.j-wave.co.jp/topics/' title=''><img class='nav-hover' src='"+IMG_PATH+"ft_nav_latest.gif' alt='' ></a></li>")
ELE.push("<li id='areaFtNavToday'><a href='http://www.j-wave.co.jp/event/contents.htm' title=''><img class='nav-hover' src='"+IMG_PATH+"ft_nav_live.gif' alt='' /></a></li>")
ELE.push("<li id='areaFtNavCinema'><a href='http://www.j-wave.co.jp/cinema/contents.htm' title=''><img class='nav-hover' src='"+IMG_PATH+"ft_nav_cinema.gif' alt='' /></a></li>")
ELE.push("<li id='areaFtNavNavigator'><a href='http://www.j-wave.co.jp/contents/navigator/index.htm' title=''><img class='nav-hover' src='"+IMG_PATH+"ft_nav_navigator.gif' alt='' /></a></li>")
ELE.push("<li id='areaFtNavNet'><a href='http://www.j-wave.co.jp/member/main.htm' title=''><img class='nav-hover' src='"+IMG_PATH+"ft_nav_net.gif' alt='' /></a></li>")
ELE.push("<li id='areaFtNavNoa'><a href=\"javascript:void(0)\" onClick=\"window.open('http://www.j-wave.co.jp/alladdin/','noa_player','width=420,height=240,menubar=no,toolbar=no,scrollbars=no,resizable=no')\" title=\"NOW ON AIR\"><img class='nav-hover' src='"+IMG_PATH+"ft_nav_noa.gif' alt='' /></a></li>")
ELE.push("<li id='areaFtNavPastNoa'><a href='http://www.j-wave.co.jp/songlist/index.html' title=''><img class='nav-hover' src='"+IMG_PATH+"ft_nav_past_noa.gif' alt='' /></a></li>")
ELE.push("</ul>")
ELE.push("</div><!--/.clrfix-->")
ELE.push("</div><!--/#footerInner-->")
ELE.push("</div><!--/#footer-->")

// WRITE ELEMENTS
document.write(ELE.join("\n"))


function addEventToElement(){
  var cls = "nav-hover"
  var ele = document.getElementById("commonFooter").getElementsByTagName("img")
  var len = ele.length
  
  for(var i=0;i<len;i++){
    if(ele[i].className == cls){
      var res = ele[i].src.match(/(.+\/)(.+\.(jpg|gif|png))/)
      if(res){
        var p    = ele[i]
        var path = res[1]
        var mouse_on = res[2].replace(/.+(\..+)/, res[2].match(/(.+)?\./)[1]+"_on"+res[2].match(/.+(\..+)/)[1])
        var mouse_off= res[2]
        var imgsrc_on   = document.createElement("img")
        imgsrc_on.src   = path+mouse_on        

        addEvent("mouseover", p, function(m, n){return function(){m.src = n}}(p, imgsrc_on.src))
        addEvent("mouseout" , p, function(m, n){return function(){m.src = n}}(p,path+mouse_off))
      }
    }
  }
}

function addEvent(event, ele, func){
	try{
		ele.addEventListener(event,func,false);
	}catch(e){
		ele.attachEvent("on"+event,func)
	}
}

function removeEvent(event, ele, func){
	try{
		ele.removeEventListener(event,func,false);
	}catch(e){
		ele.detachEvent("on"+event,func)
	}
}

// MOUSE OVER , MOUSE OUT
addEventToElement()

// ONLOAD後再度、最下部へ設定
addEvent("load", window, function(){
  var ft = document.getElementById("commonFooter")
  ft.parentNode.removeChild(ft)
  document.getElementsByTagName("body")[0].appendChild(ft)
  ft.style.display = "block"
  
  document.getElementsByTagName("body")[0].style.paddingBottom = "23px"

  // iPad対応
  if(window.orientation != undefined) {
    ft.style.position = "relative"
    document.getElementsByTagName("body")[0].style.paddingBottom = "0"
  }
  
  // IE6
  if(typeof document.body.style.maxHeight == "undefined")
    document.getElementsByTagName("body")[0].style.paddingBottom = "0"
  
})

})()
