var picLib={
	view:{},
	lang:{},
	show:function(){

		var html='<div id="__picLib">';
		html+='<div style="background-color:#000;width:100%;height:100%;left:0;top:0;position: absolute;z-index:99999990;filter:alpha(opacity=80);opacity:0.80;" id="__bg">&nbsp;</div>';
			html+='<div style="width:100%;height:100%;left:0;top:0;position: absolute;z-index:99999999;overflow:auto">';
				html+='<div id="__box" style="background:#fff;padding:10px 0;position:absolute">';
					html+='<img id="__img_base" src="" />';
					html+='<div id="__forward_btn" onclick="picLib.forward()" style="cursor: pointer;position: absolute;left:0;top:0px;width:50%;background:#fff;filter:alpha(opacity=0);opacity:0.0;height:150px;">&nbsp;</div>';
					html+='<div id="__next_btn" onclick="picLib.next()" style="cursor: pointer;position: absolute;right:0;top:0px;width:50%;background:#fff;filter:alpha(opacity=0);opacity:0.0;height:150px;">&nbsp;</div>';
					html+='<div style="font-size:14px;color:#999;font-weight:bold;padding:10px;"><span id="__step" style="float:left">&nbsp;</span><span onclick="picLib.close()" style="cursor: pointer;float:right" >'+picLib.lang.close+'</span><span onclick="picLib.forward()" style="cursor: pointer;padding:0 10px;">'+picLib.lang.forward+'</span>|<span onclick="picLib.next()" style="cursor: pointer;padding:0 10px;">'+picLib.lang.next+'</span></div>';
				html+='</div>';
			html+='</div>';
		html+='</div>';

		document.body.style.height = ( window.innerHeight || document.documentElement.clientHeight )+'px';
		document.body.style.width = ( window.innerWidth || document.documentElement.clientWidth )+'px';

		document.body.innerHTML+=html;
		document.body.style.overflow="hidden";

		picLib.current = 0;
		picLib.view.bg = document.getElementById('__bg');
		picLib.view.img = document.getElementById('__img_base');
		picLib.view.box = document.getElementById('__box');
		picLib.view.img.onload=picLib.onload;
		picLib.view.base = document.getElementById('__picLib');
		picLib.view.next_btn = document.getElementById('__next_btn');
		picLib.view.forward_btn = document.getElementById('__forward_btn');
		picLib.view.step = document.getElementById('__step');

		picLib.view.base.style.height = (window.innerHeight || document.documentElement.clientHeight) + 'px';
		picLib.view.base.style.width = (window.innerWidth || document.documentElement.clientWidth) + 'px';

		picLib.load();

		document.onkeyup = picLib.onkey;

		return false;
	},
	onkey:function(e){

		switch(e.keyCode){
			case 27:
				picLib.close();
			break;

			case 39:
				picLib.next();
			break;

			case 40:
				picLib.next();
			break;

			case 37:
				picLib.forward();
			break;

			case 38:
				picLib.forward();
			break;

			default:
				alert(e.keyCode);
			break;
		}
		return false;
		
	},
	next:function(){
		if(picLib.current<(picLib.pics.length-1)){
			picLib.current++;
			picLib.load();
		}
	},
	forward:function(){
			if(picLib.current>0){
			picLib.current--;
			picLib.load();
		}
	},
	onload:function(evt){

		picLib.view.step.innerHTML = picLib.lang.step.replace('%1',picLib.current+1).replace('%2',picLib.pics.length);

		 picLib.view.box.style.left = ( ((window.innerWidth || document.documentElement.clientWidth) -picLib.view.img.offsetWidth) /2 ) +'px';
		 picLib.view.box.style.top = ( ((window.innerHeight || document.documentElement.clientHeight) -picLib.view.img.offsetHeight) /2.5 ) +'px';
		 picLib.view.box.style.width = ( picLib.view.img.offsetWidth+20 ) +'px';
		 picLib.view.box.style.height = ( picLib.view.img.offsetHeight+20 ) +'px';

		 picLib.view.next_btn.style.height = ( picLib.view.img.offsetHeight+20 ) +'px';
		 picLib.view.forward_btn.style.height = ( picLib.view.img.offsetHeight+20 ) +'px';
	},
	close:function(){
		document.onkeyup = null;
		picLib.view.base.parentNode.removeChild(picLib.view.base);
		document.body.style.height = null;
		document.body.style.width = null;
		document.body.style.overflow = null;
	},
	purl:function(imgurl){
			return (imgurl.substr(0,4).toLowerCase()=='http')?imgurl:picLib.basedir +'/'+imgurl;
	 },
	load:function(){
		picLib.view.img.src =  picLib.purl(picLib.pics[picLib.current]);
	}
}
