var $ = function(id){
	return document.getElementById(id);
}

/* navi menu */

function menuFix() {
	var sfEls = document.getElementById("nav").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className += (this.className.length>0? " ": "") + "sfhover";
		}
		sfEls[i].onMouseDown=function() {
			this.className += (this.className.length>0? " ": "") + "sfhover";
		}
		sfEls[i].onMouseUp=function() {
			this.className += (this.className.length>0? " ": "") + "sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className = this.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
		}
	}
}
window.onload = menuFix;


/* company milestone */
function divDrag(){
	var axisHeight = 420;
	var A,B,$cn;
	var zIndex=1;
	this.dragStart = function(e){
		e = e||window.event;
		if((e.which && (e.which!=1))||(e.button && (e.button!=1)))
			return;
		var pos = this.$pos;
		$cn = this.parent||this;
		
		if(document.defaultView){
			_top	= document.defaultView.getComputedStyle($cn,null).getPropertyValue("margin-top");
		}else{
			if($cn.currentStyle){
				_top	= $cn.currentStyle["marginTop"];
			}
		}
		pos.oy = (e.pageY||(e.clientY+document.documentElement.scrollTop ))	- parseInt(_top);
		
		if(!!A){
			if(document.removeEventListener){
				document.removeEventListener("mousemove",	A,	false);
				document.removeEventListener("mouseup",		B,	false);
			}else{
				document.detachEvent("onmousemove",	A);
				document.detachEvent("onmouseup",	B);
			}
		}
		A = this.dragMove.create(this);
		B = this.dragEnd.create(this);
		if(document.addEventListener){
			document.addEventListener("mousemove",	A,	false);
			document.addEventListener("mouseup",	B,	false);
		}else{
			document.attachEvent("onmousemove",	A);
			document.attachEvent("onmouseup",	B);
		}
		$cn.style.zIndex=(++zIndex);
		this.stop(e);
	}
	
	this.dragMove = function(e){
		e = e||window.event;
		var pos = this.$pos;
		$cn = this.parent||this;
		var cnMarginTop = (e.pageY||(e.clientY+document.documentElement.scrollTop )) - parseInt(pos.oy) + 'px';
		if(parseInt(cnMarginTop)<=0){
			cnMarginTop	= 0+'px';
		}else if(parseInt(cnMarginTop)>=axisHeight-10){
			cnMarginTop	= axisHeight-10+'px';
		}
		
		$cn.style.marginTop	= cnMarginTop;
		$('memorabiliaContent').style.marginTop = '-'+(parseInt(cnMarginTop)+parseInt(cnMarginTop)/10*11)+'px';
		//var dragBlockMT = eval(cnMarginTop.substring(0,cnMarginTop.length-2));
		//var axiH = eval($("timeAxis").style.height.substring(0,$("timeAxis").style.height.length-2));
		//var memorabiliaContentH = $("memorabiliaContent").clientHeight;
		//var memorabiliaMT = Math.floor(-1*dragBlockMT/axiH * memorabiliaContentH);
		//$('memorabiliaContent').style.marginTop = memorabiliaMT+"px";
		
		this.stop(e);
	}
	
	this.dragEnd = function(e){
		var pos = this.$pos;              
		e = e||window.event;
		if((e.which && (e.which!=1))||(e.button && (e.button!=1)))
			return;
		$cn = this.parent||this;
		if(!!(this.parent)){
			this.style.backgroundColor = pos.color;
		}
		if(document.removeEventListener){
			document.removeEventListener("mousemove",	A,	false);
			document.removeEventListener("mouseup",		B,	false);}
		else{
			document.detachEvent("onmousemove",	A);
			document.detachEvent("onmouseup",	B);
		}
		A = null;
		B = null;
		$cn.style.zIndex = (++zIndex);
		this.stop(e);
	}
		
	this.position = function (e){ 
		var t = e.offsetTop;
		while(e = e.offsetParent){ 
			t += e.offsetTop;
		}
		return {y:t, oy:0, color:null}
	}
	
	this.stop = function(e){
		if(e.stopPropagation){
			e.stopPropagation();
		}else{
			e.cancelBubble = true;
		}
		
		if(e.preventDefault){
			e.preventDefault();
		}else{
			e.returnValue = false;
		}
	}
	
	this.create = function(bind){
		var B = this;
		var A = bind;
		return function(e){
			return B.apply(A, [e]);
		}
	}
	
	this.dragStart.create	= this.create;
	this.dragMove.create 	= this.create;
	this.dragEnd.create		= this.create;
	
	this.initialize = function(){
		for(var A=0, B=arguments.length; A<B; A++){
			C = arguments[A];
			if(!(C.push)){
				C=[C];
			}
			$C = (typeof(C[0])=='object')?C[0]:(typeof(C[0])=='string'?$(C[0]):null);
			
			if(!$C)
				continue;
			$C.$pos		= this.position($C);
			$C.dragMove	= this.dragMove;
			$C.dragEnd	= this.dragEnd;
			$C.stop		= this.stop;
								
			if($C.addEventListener){
				$C.addEventListener("mousedown", this.dragStart.create($C), false);
			}else{
				$C.attachEvent("onmousedown", this.dragStart.create($C));
			}
		}
	}
	this.initialize.apply(this,arguments);
}

new divDrag(['dragBlock']);

/* Target switchLargePhoto */
function switchLargePhoto(seq, topic, language){
	for(var i=1; i<=4; i++){
		if(i==seq){
			document.getElementById('smallPhoto'+seq).src='http://image.ttcjmall.com/images/'+language+'/company/201001/company_target_small_'+topic+'_on.jpg';
			document.getElementById('smallPhoto'+seq).style.border='2px solid #DB261F';
			document.getElementById('largePhoto').src='http://image.ttcjmall.com/images/'+language+'/company/201001/company_target_large_'+topic+'.jpg';
		}else{
			switch(i){
				case 1: document.getElementById('smallPhoto1').src='http://image.ttcjmall.com/images/'+language+'/company/201001/company_target_small_callcenter_off.jpg'; document.getElementById('smallPhoto1').style.border='none'; break;
				case 2: document.getElementById('smallPhoto2').src='http://image.ttcjmall.com/images/'+language+'/company/201001/company_target_small_boardroom_off.jpg'; document.getElementById('smallPhoto2').style.border='none'; break;
				case 3: document.getElementById('smallPhoto3').src='http://image.ttcjmall.com/images/'+language+'/company/201001/company_target_small_studio_off.jpg'; document.getElementById('smallPhoto3').style.border='none'; break;
				case 4: document.getElementById('smallPhoto4').src='http://image.ttcjmall.com/images/'+language+'/company/201001/company_target_small_office_off.jpg'; document.getElementById('smallPhoto4').style.border='none'; break;
			}
		}
	}
}
