var Gallery=
{
	init:function()
	{
	   
		
		
		
		var eee=document.createElement("div");
		eee.innerHTML=''
			+'<div style="background-image: url(media/layout/blend.png); display:none; position:fixed; width:100%; height:100%; text-align:center; cursor:pointer; z-index:99999;">'
			+'<div style="position:absolute; width:100%; height:100%" onclick="Gallery.closeImage();"></div>'
			+'<div style="background-color:#ffffff; position:absolute; left:50%; top:50%; ">'
			+'<div style="position:absolute; width:90px; height:100%; left:0px;"></div>'
			+'<div style="position:absolute; width:90px; height:100%; right:0px;"></div>'
			+'<img src="media/layout/blank.png" style="margin:20px;"/>'
			+'</div>'
			+'</div>';
		
		Gallery._element=eee.firstChild.children[1].children[2];
		Gallery._element.onload=Gallery.imageLoaded;
		Gallery._elementContainer=eee.firstChild.children[1];
		Gallery._elementRootContainer=eee.firstChild;
		
		divLeft=eee.firstChild.children[1].children[0];
		divRight=eee.firstChild.children[1].children[1];
		divLeft.onclick=function(event)
		{
			Gallery.prevImage();
		};
		divLeft.onmouseover=function(event)
		{
			var $s=Gallery.getSelected();
			if ($s===null||$s==0)
				return;
			this.style.backgroundImage="url(media/layout/gallery/left.png)";
			this.style.backgroundRepeat="no-repeat";
			this.style.backgroundPosition="left center";
		};
		divLeft.onmouseout=function(event)
		{
			this.style.backgroundImage="url(media/layout/blank.png)";
		};
		
		divRight.onclick=function(event)
		{
			Gallery.nextImage();
		};
		divRight.onmouseover=function(event)
		{
			var $s=Gallery.getSelected();
			if ($s===null||$s>=Gallery._elements.length-1)
				return;
			this.style.backgroundImage="url(media/layout/gallery/right.png)";
			this.style.backgroundRepeat="no-repeat";
			this.style.backgroundPosition="right center";
		};
		divRight.onmouseout=function(event)
		{
			this.style.backgroundImage="url(media/layout/blank.png)";
		};
		
		document.body.insertBefore(eee,document.body.firstChild);
		
	},
		
	_elements:[],
	_element:null,
	_elementContainer:null,
	_elementRootContainer:null,
	
	closeImage:function()
	{
		Gallery._elementRootContainer.style.display='none';
	},
	imageLoaded:function(event)
	{
		
		Gallery._elementContainer.style.marginLeft="-"+((Gallery._element.clientWidth)/2-10)+"px";
		Gallery._elementContainer.style.marginTop="-"+((Gallery._element.clientHeight)/2-10)+"px";
		setTimeout("Gallery._elementContainer.appendChild(Gallery._element)",500);
	},
	addImage:function($element)
	{
		var $selected=0;
		for(var $i=0,$len=Gallery._elements.length;$i<$len;$i++)
		{
			if (!$element.localeCompare(Gallery._elements[$i]))
				return $i;
		}
		Gallery._elements.push($element);
		return $i;
	},
	
	showImage:function($src)
	{
		Gallery._element.src=$src;
		Gallery._elementRootContainer.style.display="block";
	},
	
	nextImage:function()
	{
		var $selected=Gallery.getSelected();
		if ($selected!==null&&$selected<Gallery._elements.length-1)
			Gallery.showImage(Gallery._elements[$selected+1]);
	},

	prevImage:function()
	{
		var $selected=Gallery.getSelected();
		if ($selected!==null&&$selected>0)
			Gallery.showImage(Gallery._elements[$selected-1]);
	},
	getSelected:function()
	{
		for(var $i=0,$len=Gallery._elements.length;$i<$len;$i++)
		{
			if (!Gallery._element.src.localeCompare(Gallery._elements[$i]))
				return $i;
		}
		return null;
	}

};



