var MJS = {
	rList: [],
	
	get: function(id) {
		return document.getElementById(id);
	},
	
	onReady: function(fn) {
		this.rList.push(fn);
	},
	
	_onPLoad: function() {
		this.frameResizer();
		for(var i=0; i<this.rList.length; i++) {
			this.rList[i]();
		}
		
	},
	
	frameResizer: function() {
		var c = this.get('main_container');
		if (c && c.offsetHeight < 750) {
			c.style.height = '750px';
		}
	}
};

var PageGallery = {
	div_ids: {
		p_container: 'photos_container',
		m_image: 'main_image',
		m_comment: 'main_comment'
	},
	photo_class: 'thumb-wrap',
	active_class: 'thumb-wrap thumb-selected',
	img: null,
	comment: null,
	current_selected: null,
	
	init: function() {
		var c = MJS.get(this.div_ids['p_container']);
		this.img = MJS.get(this.div_ids['m_image']);
		this.comment = MJS.get(this.div_ids['m_comment']);
		if (c) {
			var m = c.childNodes;
			var onC = function(ev, el) {
				if(!el) el = this;
				PageGallery.onPictureSelect(el);
			}
			
			var first = true;
			for(var i=0; i<m.length; i++) {
				if (m[i].className == this.photo_class) {
					m[i].onclick = onC;
					if (first) {
						this.onPictureSelect(m[i]);
						first = false;
					}
				}
			}
		}
	},
	
	onPictureSelect: function(el) {
		if (this.current_selected) {
			this.current_selected.className = this.photo_class;
		}
		el.className = this.active_class;
		this.current_selected = el;
		if (this.img) {
			this.img.src = el.getAttribute('_p');
			this.comment.innerHTML = el.getAttribute('_c');
		}
	}
};
