Sizes = function() {
	this.body = document.body;
	this.html = this.body.parentNode;
	this.el = document.getElementById( 'sizes-wrap' );
	this.inner = document.getElementById( 'sizes' );
	this.close = document.getElementById( 'close' );
	
	if( this.close ) {
		var self = this;
		var hide = function( ev ) {
			self.hide();
		}

		if( document.addEventListener ) {
			this.close.addEventListener( 'click', hide, false );
		} else {
			this.close.attachEvent( 'onclick', hide );
		}
	}
}

Sizes.prototype.show = function() {
	if( !this.el || !this.html || !this.body ) return false;
	//this.html.style.overflow = 'hidden';
	//this.body.style.overflow = 'hidden';
	//this.body.className = 'withoutSelect';
	this.el.className = 'sizes-wrap invisible';
	this.setTopOffset();
	this.el.className = 'sizes-wrap';
}


Sizes.prototype.hide = function() {
	if( !this.el || !this.html || !this.body ) return false;
	this.el.className = 'sizes-wrap hidden';
	//this.html.style.overflow = 'auto';
	//this.body.style.overflow = 'auto';
	this.body.className = '';
}

Sizes.prototype.setTopOffset = function() {
	if( !this.inner || !this.inner.style ) return false;
	this.inner.style.marginTop = -1 * parseInt( this.inner.offsetHeight / 2 ) + 'px';
}

var showHandlers = function( el ) {
	if( !el ) return false;
	var show = function( ev ) {
		ev = ev || window.event;
		ev.preventDefault ? ev.preventDefault() : ev.returnValue = false;
		sizes.show();
	}

	if( document.addEventListener ) {
		el.addEventListener( 'click', show, false );
	} else {
		el.attachEvent( 'onclick', show );
	}
}

window.onload = function() {
	window.sizes = new Sizes();
	showHandlers( document.getElementById( 'sizes-link' ) );
	showHandlers( document.getElementById( 'sizes-image' ) );

	var vote = document.getElementById( 'vote' )
	if( vote && vote.getElementsByTagName ) {
		var votelabel = vote.getElementsByTagName( 'label' )[0];
		if( votelabel && votelabel.getElementsByTagName  ) {
			var chbox = votelabel.getElementsByTagName( 'input' )[0];
			if( chbox ) {
				var toggleVote = function() {
					votelabel.className = ( chbox.checked ? 'checked' : '' );
				}

				if( document.addEventListener ) {
					votelabel.addEventListener( 'click', toggleVote, false );
				} else {
					votelabel.attachEvent( 'onclick', toggleVote );
				}
				toggleVote();
			}
		}
	}
	
}
