Boboku={
	$:function(element){
		return document.getElementById(element);
	},
	Show:function(element){
		this.$(element).style.display='block';
	},
	Hide:function(element){
		this.$(element).style.display='none';
	},
	Center:function(element, width, height){
		element=this.$(element);
		var x=0, y=0; w=0, h=0;
		if( typeof( window.innerWidth)=='number'){
			w=window.innerWidth;
			h=window.innerHeight;
		} else if( document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
			w=document.documentElement.clientWidth;
			h=document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight)){
			w=document.body.clientWidth;
			h=document.body.clientHeight;
		}
		if( typeof( window.pageYOffset)=='number'){
			y=window.pageYOffset;
			x=window.pageXOffset;
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop)){
			y=document.body.scrollTop;
			x=document.body.scrollLeft;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop)){
			y=document.documentElement.scrollTop;
			x=document.documentElement.scrollLeft;
		}
		l=x+(w-parseInt(width))/2;
		t=y+(h-parseInt(height))/4;
		element.style.left=l+'px';
		element.style.top=t<0 ? '5px' : (t+'px');
		element.style.width=width;
		element.style.height=height;
	},
	ShowEffect:function(id, image, title, remark, message){
		this.$('effect_id').value=id;
		this.$('effect_image').innerHTML='<img id="effect_sample" src="/images/loader_0.gif" style="border:1px solid #ccc;padding:2px;margin-right:8px;"/>';
		this.$('effect_sample').src=image;
		this.$('effect_title').innerHTML=title;
		this.$('effect_remark').innerHTML=remark;
		this.$('effect_file').innerHTML='<input id="m_file" name="m[file]" type="file" size="13" onchange="Boboku.Upload()"/><iframe id="result" name="result" style="width:0px;height:0px;display:none"></iframe>';
		this.$('effect_message').innerHTML=message;
		this.Hide('poster');
		this.Hide('message');
		this.Hide('effect_loader');
		this.Show('effect_file');
		this.Show('effect');
	},
	ShowMms:function(id, image, width, height){
		this.$('size').value=id;
		this.$('mms_image').src=image;
		this.Center('mms',width, height);
		this.Show('mms');
	},
	ShowPoster:function(image, width, height, mmscode){
		this.$('poster_image').innerHTML='<img id="poster_file" src="/images/loader_0.gif" style="border:1px solid #ccc;padding:2px;margin-right:8px;"/>';
		this.$('poster_code').innerHTML=mmscode;
		this.$('poster_file').src=image;
		this.Hide('effect');
		this.Center('poster',width,height);
		this.Show('poster');
	},
	ShowMessage:function(message){
		this.Hide('effect');
		this.$('message_text').innerHTML=message;
		this.Center('message','300px','60px');
		this.Show('message');
	},
	Upload:function(){
		this.$('effect_message').innerHTML=this.Message["Uploading"];
		this.$('upload').submit();
		this.Hide('effect_file');
		this.Show('effect_loader');
		this.Counter=0;
		if(this.Timer!=undefined){
			clearTimeout(this.Timer);
		}
		this.Timer = setInterval(Boboku.Progress, 100);
	},
	Counter:0,
	Timer:undefined,
	Progress:function(){
		if(Boboku.$('effect_loader').style.display!='none'){
			if(Boboku.Counter<50){
				Boboku.Counter+=(10*Math.random()/10);
			}else if(Boboku.Counter<90){
				Boboku.Counter+=(2*Math.random()/30);
			}else if(Boboku.Counter<95){
				Boboku.Counter+=(2*Math.random()/50);
			}else{
				Boboku.Counter+=(1*Math.random()/100);
			}
			if(Boboku.Counter < 99.9){
				Boboku.ShowProgress(Boboku.Counter);
			}else if(Boboku.Counter > 100.9){
				Boboku.ShowTimeout();
			}
		}else{
			clearInterval(Boboku.Timer);
		}
	},
	ShowProgress:function(percent){
		Boboku.Counter = percent;
		if(Boboku.Counter >= 100){
			Boboku.Hide('effect_loader');
		}else{
			percent = Boboku.Counter.toFixed(1);
		}	
		Boboku.$('effect_message').innerHTML=Boboku.Message['Uploading']+' ('+percent+'%)';
	},
	ShowTimeout:function(){
		Boboku.Hide('effect_loader');
		Boboku.$('effect_message').innerHTML=Boboku.Message['Timeout'];
	},
	Download:function(element, url, token_name, token_value){
		var f=document.createElement('form');
		f.style.display='none';
		element.parentNode.appendChild(f);
		f.method='POST';
		f.action=url;
		var m=document.createElement('input');
		m.setAttribute('type', 'hidden');
		m.setAttribute('name', '_method');
		m.setAttribute('value', 'post');
		f.appendChild(m);
		var s=document.createElement('input');
		s.setAttribute('type', 'hidden');
		s.setAttribute('name', token_name);
		s.setAttribute('value', token_value);
		f.appendChild(s);
		f.submit();
	},
	Message:{"Timeout":"","Uploading":""},
	AddFavorite:function(){
		if(document.all){
			window.external.addFavorite('http://www.boboku.com','Boboku.com');
		}else if (window.sidebar){
			window.sidebar.addPanel('Boboku.com', 'http://www.boboku.com', "");
		}		
	}
}
loader_0=new Image();
loader_0.src="/images/loader_0.gif";
loader_2=new Image();
loader_2.src="/images/loader_2.gif";