$.fn.togglePopup = function(){
	//detect whether popup is visible or not
	if($('#popup_votes').hasClass('hidden')){
		//hidden - then display
		if($.browser.msie){
			//when IE - fade immediately
		 	$('#opaque').height($(document).height()).toggleClass('hidden').click(function(){$(this).togglePopup();});
		 	if($.browser.version == 6){
		 		$('#layout').css('position','absolute').css('top','0px');
			}
		}else{
/*			if($.browser.opera){
			     $('.top_line, .bottom_line').css('width','94%');
			}
*/			//in all the rest browsers - fade slowly
			$('#opaque').height($(document).height()).toggleClass('hidden').fadeTo('slow', 0.8).click(function(){$(this).togglePopup();});
			$('#close_vote').click(function(){$(this).togglePopup();});
    }
		$('#popup_votes').alignCenter().toggleClass('hidden');
	}else{
			//visible - then hide
			$('#opaque').toggleClass('hidden').removeAttr('style').unbind('click');
			$('#popup_votes').toggleClass('hidden');
			$('#close_vote').unbind('click');

	}
};

$(document).ready(function(){
	$('#get_vote').click(function(){
		$('#popup_votes').togglePopup();
	});
	//align element in the middle of the screen
	$.fn.alignCenter = function() {
		//get margin left
		var marginLeft = - $(this).width()/2 + 'px';
		//get margin top
		var marginTop = - $(this).height()/1.8 + 'px';
		//return updated element
		return $(this).css({'margin-left':marginLeft, 'margin-top':marginTop});
	};
	
	$('#get_vote').hover(
		function(){
			$(this).addClass("hover");
		},
		function(){
			$(this).removeClass("hover");
		}
	);
});


