
window.addEvent('domready', function() {
	initDomGallery();
});

function initDomGallery() {
		$$('.gallery-opener').each(function(obj){
			obj.addEvent('click', function (e){
				new Event(e).stop(); 
				openGallery(this);
			});
		});
}


function openGallery(el){
	
	tmpGalleryBox = new Element('div', {
		'id' : 'gallery_box',
		'title' : 'close',
		'styles': {
			'position': 'absolute',
			'top': 0,
			'left': 0,
			'cursor' : 'pointer'
		}
	});
	tmpGalleryBox.addEvent('click', closeGallery);
	
	tmpGalleryBox.inject($('mainWrap'), 'after');
	
	window.addEvents({ 'scroll': posGallery, 'resize': posGallery });
	
	tmpGallery = $('gallery');
	
	tmpGallery.setStyles({
			position: 'absolute',	
			width: 1040,
			height: 780
	});
	posGallery();
	
	tmpFrame = $('galleryIframe');
	tmpFrame.setStyles({
		width : 1040,
		height:780,
		display: 'block'
	})
	
	tmpFrame.setProperty('src', document.location.protocol + '//' + document.location.hostname + '/' + el.getProperty('href'));		
	
		
}


function posGallery() {
	
		tmpGalleryBox = $('gallery_box');
		
		tmpGalleryBox.setStyles({
			'width': window.getSize().scrollSize.x + 'px',
			'height': (window.getSize().scrollSize.y) + 'px'
		});
	
		
		var iTop = window.getScrollTop() + (window.getSize().size.y / 2) - 404;
		var iLft = (window.getSize().size.x / 2) - 532;
		
		tmpGallery.setStyles({
			'top': iTop + 'px',
			'left': iLft + 'px',
			 'display': 'block'
		});
		
}

function closeGallery(){
	$('gallery').setStyle('display', 'none');
	$('gallery_box').setStyle('display', 'none');
	$('galleryIframe').setStyle('display', 'none');
	$('galleryIframe').setProperty('src', '');
	window.removeEvents('scroll');
	window.removeEvents('resize');
}
