﻿Listener.add(window,"load",function(){

window.SEIKO = {} ;

if(window.location.host == "") window.SEIKO.isLocal = true ;

var d = document ;
var $id = function(id){return document.getElementById(id)};
var $tag = function(tag,parent){
	if(!parent) parent = d ;
	return parent.getElementsByTagName(tag);
};

var addClass = function(node,value){
	var currentclass = node.className ;
	var regclass = new RegExp("\\b" + value + "\\b","g");
	if(!currentclass) currentclass = value ;
	else if(currentclass.search(regclass) != -1) return ;
	else currentclass += " " + value ;
	node.className = currentclass ;
};

var removeClass = function(node,value){
	var currentclass = node.className ;
	var regclass = new RegExp("\\b" + value + "\\b","g");
	var regblank = /\b\s*\s$/;
	if(currentclass == value) node.removeAttribute("class") || node.removeAttribute("className");
	else if(currentclass.search(regclass) == -1) return ;
	else {
		currentclass = currentclass.replace(regclass,"");
		currentclass = currentclass.replace(regblank,"");
		node.className = currentclass ;
	}
};

var hasClass = function(node,value){
	if(node == "body") node = d.body ;
	else if(typeof node == "string") node = $id(node);
	var currentclass = node.className ;
	var regclass = new RegExp("\\b" + value + "\\b","g");
	if(currentclass.search(regclass) == -1) return false ;
	else return true ;
};
var $Class = function(name,parent){
	if(!parent) parent = d ;
	var es = $tag("*",parent);
	var klasses = [];
	for(var i = 0 ; i<es.length; i++){
		if(hasClass(es[i],name)) klasses.push(es[i]);
	}
	return klasses ;
};

var isIE = function(){
	return ((window.navigator.userAgent).indexOf("MSIE") != -1);
};
var isIE6 = function(){
	return (typeof document.body.style.maxHeight == "undefined");
};
var isSafari = function(){
	return ((window.navigator.userAgent).indexOf("Safari") != -1);
};
var isFirefox = function(){
	return ((window.navigator.userAgent).indexOf("Firefox") != -1);
};
var isMac = function(){
	return ((window.navigator.userAgent).indexOf("Macintosh") != -1);
};



// footer copyrights
if($id("year")) $id("year").lastChild.data = (new Date()).getFullYear();


// other popup Settings
(function(){
		 
	var a = d.links ;
	var isIE6 = (typeof document.body.style.maxHeight == "undefined");

	for(var i = 0 ; i < a.length; i++){
		var reg = /popup=(.+)&(.+)$/i;
		var rel = a[i].getAttribute("rel");
		
		if(!rel) continue ;
		
		if(rel.match(reg) != null){				
			Listener.add(a[i],"click",function(e){
				var rel = this.getAttribute("rel");
				
				rel.match(reg)
				var name = RegExp.$1;
				var param = RegExp.$2;
				if(param == "full"){
					var width = window.screen.availWidth ;
					var height = window.screen.availHeight ;
					var left = 0 ;
					var top = 0 ;
					var scrl = "no";
					if(isIE6){
						width = width -10 ;
						height = height -29 ;
					}
				}
				else {
					data = param.split("+");
					var width = isIE()?(parseInt(data[0])+17):(data[0]);
					var height = data[1];
					var top = (window.screen.height/2) - (height/2) ;
					var left = (window.screen.width/2) - (width/2) ;
					var scrl = "yes";
				}
				
				var popup = window.open(this.href,name,'width=' + width + ', height=' + height + ', menubar=no, toolbar=no, scrollbars=' + scrl + ' ,top=' + top + ' ,left=' + left);
				if(popup) popup.focus();
				
				e.preventDefault();
				e.stopPropagation();
			});
		}
		
	}
})();	



// IEAlphaShadow -----------------------------------------------------
(function(){
	
	if(!isIE()) return ;
	if(!isIE6()) return ;
	if(!$id("global")) return ;
	
	var root= "power_design_project";
	var path = window.location.pathname ;
	var start = path.indexOf(root)
	var dir = path.substring(start + root.length + 1);
	var count_arr = dir.match(/[\/|\\]/g);
	var relative_path = [,"../","../../","../../../","../../../../","../../../../../"]; 
	
	var target = $id("global");
	var shadow = d.createElement("div");
	shadow.id = "IEAlphaShadow";
	if(d.body.id != "topIndex"){/*debug();*/ shadow.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\"" + relative_path[count_arr.length] + "images/bg_nav_shadow.png\", sizingMethod=\"scale\")";}
	else shadow.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\"images/top_bg_nav_shadow.png\", sizingMethod=\"scale\")";
	target.parentNode.appendChild(shadow);	

	function debug(){
		alert(path + " : " + start)
		alert(dir);
		alert(count_arr instanceof Array);
		alert(count_arr.length);
		alert(relative_path[count_arr.length] + "images/bg_nav_shadow.png");
	}
})();


(function(){
	
	if(blockIE5()) return ;
	
	var id = d.body.id ;
	if(id=="topIndex"){
		
		var p = $tag("h2",$id("contents"));
		
		for(var i = 0 ; i < p.length; i++){
			p[i].animate = new Animate(p[i]);
			
			p[i].animate.fadeTo(1100,1);
			Listener.add(p[i],"mouseover",function(e){
				var _$ = this ;
				this.animate.fadeTo(600,0.5);
			});
			Listener.add(p[i],"mouseout",function(e){
				var _$ = this ;
				this.animate.fadeTo(600,1);
			});
		}
	}
	
	if(id=="aboutIndex" || id=="tokyoIndex" || id=="standardIndex")(new Animate($id("mainImg"))).fadeTo(1500,1);

})();


// wordbreak -----------------------------------------------------
(function(){
			 
	if(isIE()) return ;
	
	var name = "wordBreak";
	var es = $tag("*",$id("contents"));
	
	for(var i = 0 ; i<es.length; i++){
		if(hasClass(es[i],name)) wordBreak(es[i]);
	}
	
	function wordBreak(target){
		
		insertBreak(target);
		
		function insertBreak(target){
			for(var e = target.firstChild ; e != null ; e = e.nextSibling){
				switch(e.nodeType){
				case 1 :
					arguments.callee(e);
					break ;
				case 3 :
					if(e.data.match(/^\n/) || e.data.match(/^\t/)) break ;
					var str = [];
					for(var i = 0 ; i<e.data.length; i++) str.push(e.data[i]);
					e.data = str.join(String.fromCharCode(8203));
					break ;
				}
			}
		}
	}

})();




Listener.add(window,"unload",function(){
	window.SEIKO = null;
});

});


function preloadHide(e){

	if(blockIE5()) return ;
	var isIE = ((window.navigator.userAgent).indexOf("MSIE") != -1);
	
	if(typeof e != "string"){
		for(var i = 0 ; i < e.length; i++){
			if(isIE) e[i].style.filter = "alpha(opacity=0)" ;
			else e[i].style.opacity = 0 ;
		}
	}
	else {
		e = document.getElementById(e);
		if(isIE) e.style.filter = "alpha(opacity=0)" ;
		else e.style.opacity = 0 ;
	}
}

function blockIE5(){
	var md = window.showModelessDialog; /* Win 5+, WinCE 5.5+ */
	var ns = document.namespaces; /* Win 5.5+, WinCE 5.5+ */
	var im = document.implementation; /* Win 6, Mozilla */
	var isIE = (navigator.userAgent.indexOf("MSIE") != -1);
	var isIE50 = (md && !ns && !im);
	var isIE55 = (md && ns && !im);
	if(isIE55 || isIE50) return true ;
}


