RedCliffConcierge = {
	mouseX : 0,
	mouseY : 0,
	leftPos : 0,
	topPos: 0,
	path: "http://www.redcliff2.jp/",
	rndm: "",

	getElem : function(elem){
		if(document.getElementById && !document.all || document.layers) obj = document.getElementById(elem);
		else if(document.all) obj = document.all(elem);
		return obj;
	},

	getMousePosition : function(e){
		var obj = new Object();
		
		if (!e) var e=window.event;
		if (!e.pageX) e.pageX = e.clientX + document.body.scrollLeft;
		if (!e.pageY) e.pageY = e.clientY + document.body.scrollTop;
		
		obj.x = e.pageX;
		obj.y = e.pageY;
		
		return obj;
 	},
 	
	setStyler : function(elem,prm){
		var _F = RedCliffConcierge;
		var obj = _F.getElem(elem);
		for (var i in prm) {
		   obj.style[i] = prm[i];
		}
	},
	
	brzSize : function(elm){
		var _$d=document,_h,_w;

		if (_$d.all) {
			if(window.opera){ _h = _$d.body.clientHeight; _w = _$d.body.clientWidth;}
			else{ _h = _$d.documentElement.clientHeight; _w = _$d.documentElement.clientWidth; }
		}else if (_$d.getElementById && !_$d.all || _$d.layers) {
			_h = window.innerHeight; _w = window.innerWidth;
		}
		return { height:_h , width:_w };
	},
 	
	inputOpen : function(){
		
		var _F = RedCliffConcierge;
		var obj = this.getElem("RedCliffConciergeInput");
		
		var fH=[];

		var wl = window.location;
		var URL = (wl.protocol+ "//" + wl.hostname + wl.pathname)

		fH.push('<div style="text-align:center;">');
		fH.push('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="RedCliffConciergeInputexternal" ');
		fH.push('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="89" height="18">');
		fH.push('<param name="movie" value="' + _F.path + 'concierge/input.swf" />');
		fH.push('<param name="quality" value="high" />');
		fH.push('<param name="menu" value="false" />');
		fH.push('<param name="allowScriptAccess" value="always" />');
		fH.push('<embed src="' + _F.path + 'concierge/input.swf" menu="false" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" ');
		fH.push('type="application/x-shockwave-flash" width="89" height="18" allowScriptAccess="always"></embed>');
		fH.push('</object>');
		fH.push('</div>');

		obj.innerHTML = fH.join("");
		_F.setStyler("RedCliffConciergeInput",{"width":"90px","height":"19px","top":"97px","left":"137px", "position":"absolute"});
	}, 	

	inputOpen2 : function(){
		var obj = this.getElem("RedCliffConciergeInput");
		obj.style.top = "97px";
	},
	
	inputClose : function(){
		var obj = this.getElem("RedCliffConciergeInput");
		obj.style.top = "-9999px";
	},

	commentOpen : function(){
		var obj = this.getElem("RedCliffConciergeLayer");
		//obj.style.width = "310px";
		obj.style.width = "347px";
	},

	commentClose : function(){
		var obj = this.getElem("RedCliffConciergeLayer");
		obj.style.width = "165px";
	},

	charaClose : function(){
		var _F = RedCliffConcierge;
		var obj = this.getElem("RedCliffConciergeLayer");
		var scr = document.body.scrollTop  || document.documentElement.scrollTop;
		
		_F.topPos += ( (scr+100) - _F.topPos )/5;
		
		obj.style.left = "0px";
		obj.style.top = _F.topPos + "px";
		obj.style.width = "165px";
	},

	
	alert: function(){
		alert("alert");
	},
	
	rnd : function(){
		var _F = RedCliffConcierge;
		return _F.rndm;
	},

	getTitle : function(){

		if(!document.getElementsByTagName){ return; }
		var anchors = document.getElementsByTagName('title');

		_ancl = anchors[0].innerHTML;

		return _ancl;
	},

	getAngle : function(num){

		var _F = RedCliffConcierge;
		var obj = _F.getElem("RedCliffConciergeLayer");
		var brz = _F.brzSize();

		lPos = obj.offsetLeft;
		tPos = obj.offsetTop;


		var scr = document.body.scrollTop  || document.documentElement.scrollTop;		

		if(num==0){
			_F.leftPos += 1;
			_F.topPos += 1;
			var rot = 0;
		}else if(num==1){
			_F.leftPos += 1;
			_F.topPos -= 1;
			var rot = 0;
		}else if(num==2){
			_F.leftPos -= 1;
			_F.topPos -= 1;
			var rot = 179;
		}else if(num==3){
			_F.leftPos -= 1;
			_F.topPos += 1;
			var rot = 179;
			
		}else if(num==4){
			_F.leftPos += 1;
			var rot = 1;
		}else if(num==5){
			_F.leftPos -= 1;
			var rot = 179;
		}else if(num==6){
			_F.topPos += 1;
			var rot = 90;
		}else if(num==7){
			_F.topPos -= 1;
			var rot = -90;
		}else{
		

			var dx = _F.mouseX - (lPos + 44);
			var dy = _F.mouseY - (tPos + 64);

			var radians = Math.atan2(dy,dx);
			var rot = Math.round( radians * 180 / Math.PI );


			if(_F.getElem("RedCliffConciergeLayer")){
				_F.leftPos = obj.offsetLeft;
				_F.topPos = obj.offsetTop;
				obj.style.position = "absolute";
							
				_F.leftPos += (_F.mouseX - (_F.leftPos + 44) )/150;
				_F.topPos += (_F.mouseY - (_F.topPos + 64) )/150;
			}
			
		}
		
		if(_F.leftPos<0) _F.leftPos = 0;
		if(_F.topPos<0) _F.topPos = 0;
		
		
		if(_F.getElem("flashcontent")) var num = _F.getElem("flashcontent").offsetWidth;
		else var num = brz.width;
				
		if(_F.leftPos >= ( num - obj.offsetWidth - 10) && _F.leftPos > 0 ){
			_F.leftPos = num - obj.offsetWidth - 10;
		}


		if(!_F.getElem("flashcontent")){
			if(scr > _F.topPos){
				_F.topPos = scr + 1;
			}else if( (scr + brz.height) < (_F.topPos + obj.offsetHeight)){
				_F.topPos = (scr + brz.height) -obj.offsetHeight -1;
			}
		}


		obj.style.left = _F.leftPos + "px";
		obj.style.top = _F.topPos + "px";

		return rot;
	},

	init : function(){
		var _F = RedCliffConcierge;
		var timer;

		_F.rndm = Math.round( Math.random()*100000 );

		var createElem = function(markup,idName){
			var divNode = document.createElement(markup);
			divNode.id = idName;
			document.body.appendChild(divNode);
		}	
		
		var evtLtn = function(elm, type, func, useCapture){
				
			if(!elm) return false;
			if(!useCapture) useCapture = false;
			
			 (elm.addEventListener) ? elm.addEventListener(type, func, false) :
			 (elm.attachEvent) ? elm.attachEvent('on'+type, func) :
			 false;

			return true;
		}
		
		
		var mmove = function(e){
			_F.mouseX = _F.getMousePosition(e).x;
			_F.mouseY = _F.getMousePosition(e).y;
		}

		var init = function(){
			createElem("div","RedCliffConciergeLayer");
			_F.setStyler("RedCliffConciergeLayer",{"width":"165px","height":"164px","top":"0px","left":"10px", "position":"absolute", zIndex:1000});

			var fH=[];

			var wl = window.location;
			var URL = (wl.protocol+ "//" + wl.hostname + wl.pathname)

			fH.push('<div style="text-align:center;">');
			fH.push('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="RedCliffConciergeexternal" ');
			fH.push('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="100%" height="164">');
			fH.push('<param name="movie" value="' + _F.path + 'concierge/concierge.swf" />');
			fH.push('<param name="wmode" value="transparent" />');
			fH.push('<param name="quality" value="high" />');
			fH.push('<param name="menu" value="false" />');
			fH.push('<param name="flashVars" value="URLaddress='+ URL +'" />');
			fH.push('<param name="allowScriptAccess" value="always" />');
			fH.push('<embed src="' + _F.path + 'concierge/concierge.swf" menu="false" wmode="transparent" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" ');
			fH.push('type="application/x-shockwave-flash" width="100%" height="164" allowScriptAccess="always" flashVars="URLaddress=' + URL + '"></embed>');
			fH.push('</object>');
			fH.push('</div><div id="RedCliffConciergeInput"></div>');

			_F.getElem("RedCliffConciergeLayer").innerHTML = fH.join("");

			evtLtn(document, "mousemove", mmove, false);
		}
		

		evtLtn(window, "load", init, false);

	}

}

RedCliffConcierge.init();
