// nvIR.js Version 2.0.0
// 2011-08-20
// www.synck.com

var nvIRObj = new Object();

nvIRObj.imageRoot = website.images;
nvIRObj.pulldown = null;
nvIRObj.pulldownHN = null;
nvIRObj.pulldownTimer = 2500;
nvIRObj.opacityTime = 70;

// SoundEffect disabled = false;
nvIRObj.SoundEffect = false;

nvIRObj.currentId = "";

if(navigator.userAgent.indexOf("MSIE") > -1)
	nvIRObj.lang = navigator.browserLanguage.toLowerCase();
else
	nvIRObj.lang = navigator.language.toLowerCase()

//nvIRObj.lang = "en";

if(nvIRObj.lang.indexOf('ja') > -1 || nvIRObj.lang.indexOf('jp') > -1)
	nvIRObj.lang = "";
else
	nvIRObj.lang = "e_";

function nvIR_onload(){
	var d = window.document;
	var aObj = d.getElementsByTagName("a");
	for (i=0;i<aObj.length;i++) {
		if(aObj[i].id.indexOf("ir-") > -1){
			var nvIRpref = new Array();
			nvIRpref = aObj[i].id.split('-');
			// [1] path , [2] width , [3] height , [4] external
			aObj[i].style.backgroundImage = 'url('+nvIRObj.imageRoot+nvIRObj.lang+nvIRpref[1]+'.gif?123)';
			aObj[i].style.display = "block";
			aObj[i].style.lineHeight = "1em";
			aObj[i].style.fontSize = "1px";
			aObj[i].style.width = nvIRpref[2]+"px";
			aObj[i].style.height = nvIRpref[3]+"px";
			
			if(nvIRObj.lang == "")
				aObj[i].style.textIndent = "-5000px";
			if(location.href.replace("index.html","").split(document.domain)[1] == aObj[i].href.replace("index.html","").split(document.domain)[1])
				aObj[i].style.backgroundPosition = "0px "+((nvIRpref[3]*2)*-1)+"px";
			else if(location.href.replace("index.html","").split(document.domain)[1] != "/" && location.href.replace("index.html","").split(document.domain)[1].indexOf(aObj[i].href.replace("index.html","").split(document.domain)[1]) > -1)
				aObj[i].style.backgroundPosition = "0px "+((nvIRpref[3]*2)*-1)+"px";
			
			if(nvIRpref[4] != undefined)
				aObj[i].target = '_blank';
			//
			aObj[i].onmouseover = function(){
				nvIR_over(this);
			}
			aObj[i].onmouseout = function(){
				nvIR_out(this);
			}
			aObj[i].onmousedown = function(){
				nvIR_down(this);
			}
			aObj[i].onmouseup = function(){
				nvIR_up(this);
			}
		}
		else if(aObj[i].className == "nvIRPDn"){
			aObj[i].onmouseover = function(){
				nvIR_puldown_over();
			}
			aObj[i].onmouseout = function(){
				nvIR_puldown_out();
			}
		}
		else if(aObj[i].className == "pagetop"){
			aObj[i].onclick = function(){
				jumpToPageTop();
			}
			aObj[i].onkeypress = function(){
				jumpToPageTop();
			}
		}
		if(aObj[i].href.indexOf(document.domain) == -1)
			aObj[i].target = '_blank';
		if(aObj[i].rel == "external")
			aObj[i].target = '_blank';
		if(aObj[i].href.indexOf('https://') > -1)
			aObj[i].href = aObj[i].href.replace('https','http');
	}
	try {
		var bodyObj = d.getElementsByTagName("body").item(0);
		var audioObj = d.createElement('audio');
		if(navigator.userAgent.indexOf("Safari") > -1 && navigator.userAgent.indexOf("Chrome") == -1)
			audioObj.src = nvIRObj.imageRoot + "click.wav";
		else
			audioObj.src = nvIRObj.imageRoot + "click.ogg";
		audioObj.id = 'clickSE';
		audioObj.autobuffer = true;
		bodyObj.appendChild(audioObj);
		d.getElementById('clickSE').load();
	}
	catch (e) {
		nvIRObj.SoundEffect = false;
	}
}
function nvIR_up(obj){
	var nvIRpref = new Array();
	nvIRpref = obj.id.split('-');
	if(location.href.replace("index.html","").split(document.domain)[1] == obj.href.replace("index.html","").split(document.domain)[1])
		obj.style.backgroundPosition = "0px "+((nvIRpref[3]*2)*-1)+"px";
	else if(location.href.replace("index.html","").split(document.domain)[1] != "/" && location.href.replace("index.html","").split(document.domain)[1].indexOf(obj.href.replace("index.html","").split(document.domain)[1]) > -1)
		obj.style.backgroundPosition = "0px "+((nvIRpref[3]*2)*-1)+"px";
}
function nvIR_down(obj){
	var nvIRpref = new Array();
	nvIRpref = obj.id.split('-');
	var d = window.document;
	if(nvIRObj.SoundEffect)
		d.getElementById('clickSE').play();
	if(obj.href != location.href && location.href.replace("index.html","").split(document.domain)[1].indexOf(obj.href.replace("index.html","").split(document.domain)[1]) == -1)
		obj.style.backgroundPosition = "0px "+((nvIRpref[3]*3)*-1)+"px";
	return false;
}
function nvIR_over(obj){
	var nvIRpref = new Array();
	nvIRpref = obj.id.split('-');
	var d = window.document;
	if(nvIRObj.pulldownHN != null)
		clearTimeout(nvIRObj.pulldownHN);
	if(obj.href != location.href && location.href.replace("index.html","").split(document.domain)[1].indexOf(obj.href.replace("index.html","").split(document.domain)[1]) == -1)
		obj.style.backgroundPosition = "0px "+((nvIRpref[3])*-1)+"px";
	if(nvIRObj.pulldown != null && nvIRObj.pulldown != obj.id && obj.id.indexOf(nvIRObj.pulldown) == -1)
		nvIR_hide_pulldown(nvIRObj.pulldown);
	if(d.getElementById("pd_"+obj.id+"_navigator") && nvIRObj.currentId != obj.id){
		nvIRObj.pulldown = obj.id;
		$(function(){$("#pd_"+obj.id+"_navigator").delay(0).fadeIn(500);});
		if(d.getElementById("pd_"+obj.id+"_background")){
			$(function(){$("#pd_"+obj.id+"_background").delay(0).fadeIn(500);});
		}
		nvIRObj.currentId = obj.id;
	}
}
function nvIR_out(obj){
	if(typeof obj != "undefined" && obj != null){
		if(obj.href != location.href && location.href.replace("index.html","").split(document.domain)[1].indexOf(obj.href.replace("index.html","").split(document.domain)[1]) == -1 && obj.id != nvIRObj.pulldown)
			obj.style.backgroundPosition = "0px 0px";
		if(nvIRObj.pulldown != null)
			nvIRObj.pulldownHN = setTimeout("nvIR_hide_pulldown('"+nvIRObj.pulldown+"')",nvIRObj.pulldownTimer);
	}
}
function nvIR_puldown_over(){
	if(nvIRObj.pulldownHN != null){
		clearTimeout(nvIRObj.pulldownHN);
	}
}
function nvIR_puldown_out(){
	if(nvIRObj.pulldownHN != null)
		clearTimeout(nvIRObj.pulldownHN);
	nvIRObj.pulldownHN = setTimeout("nvIR_hide_pulldown('"+nvIRObj.pulldown+"')",nvIRObj.pulldownTimer);
}
function nvIR_hide_pulldown(id){
	var d = window.document;
	if(nvIRObj.pulldownHN != null)
		clearTimeout(nvIRObj.pulldownHN);
	nvIRObj.pulldown = null;
	nvIR_out(d.getElementById(id));
	if(d.getElementById("pd_"+id+"_background")){
		$(function(){$("#pd_"+id+"_background").delay(0).fadeOut(100);});
	}
	if(d.getElementById("pd_"+id+"_navigator")){
		$(function(){$("#pd_"+id+"_navigator").delay(0).fadeOut(100);});
	}
	nvIRObj.currentId = "";
}
function nvIR_setOpacity(id,opt){
	var d = window.document;
	if(navigator.appVersion.indexOf("Safari") > -1 || navigator.userAgent.indexOf("Opera") > -1)
		d.getElementById(id).style.opacity = (opt/100);
	else if(navigator.userAgent.indexOf('Gecko') != -1)
		d.getElementById(id).style.MozOpacity = (opt/100);
}
try{
	window.addEventListener("load",function(){nvIR_onload();},false);
}
catch(e){
	window.attachEvent("onload",function(){nvIR_onload();});
}

//addEventSet(window,"load",function(){nvIR_onload();});
//$(document).ready(nvIR_onload);
