﻿$(function(){
	$('a[rel*=external]').click( function() {
		window.open(this.href);
		return false;
	});
	$('#shadow, #voice, #contest').click(
		function(){
			$("#shadow").addClass('hidden');
			$("#contest").addClass('hidden');
			$("#voice").addClass('hidden');
		}
	);
	$('#contests').click(
		function(){
			$("#shadow").css({height:$(document).height()+'px'});			
			$("#shadow").removeClass('hidden');
			$("#contest").removeClass('hidden');
			center($("#contest").width(),$("#contest").height(),'contest');	
		}
	);
	$('#voices').click(
		function(){
			$("#shadow").css({height:$(document).height()+'px'});			
			$("#shadow").removeClass('hidden');
			$("#voice").removeClass('hidden');
			center($("#voice").width(),$("#voice").height(),'voice');	
		}
	);
	$(window).resize(function(){center($("#voice").width(),$("#voice").height(),'voice');});
});
function center(viewerW,viewerH,id){
	var clientH, offset, top; 		
	clientH = this.document.body.clientHeight;	
	offset = (viewerH>clientH)? 0 : Math.floor((clientH-viewerH)/2);
	top = scrollTop()+offset;
	$("#"+id).css({top: top+'px',marginLeft: '-'+Math.floor(viewerW/2)+'px'});
}
function scrollTop(){
	var top = 0;
	if( typeof(window.pageYOffset) == 'number'){
		top = window.pageYOffset;
	}else if(document.body&&(document.body.scrollLeft||document.body.scrollTop)){
		top = document.body.scrollTop;
	}else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop)){
		top = document.documentElement.scrollTop;
	}
	return top;
}
