function showPopup(id) 
{
    //Get the A tag
    var id = '#'+id;

    //Get the screen height and width
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    //Set heigth and width to mask to fill up the whole screen
    $('#divMask').css({'width':maskWidth,'height':maskHeight});

    //transition effect  
    $('#divMask').css('opacity', 0);           
    $('#divMask').css('display', 'block');           
    $('#divMask').animate({opacity: 0.5}, 500);           
    //$('#mask').fadeIn(1000);        
    //$('#mask').fadeTo("slow",0.8);  

    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();

    //Set the popup window to center
    $(id).css('top',  winH/2-$(id).height()/2);
    $(id).css('left', winW/2-$(id).width()/2);

    //transition effect
    $(id).fadeIn(1000); 
}
function redirectPage(url)
{
	document.location = url;
}
$(function()
{
	$('img.toothpaste').click(function()
	{
		popup = 'censored';
		showPopup('divCensoredPopup');
	});
	$('.result .resultTitle').click(function(e)
	{
		popup = 'loading';
		e.preventDefault();
		showPopup('divLoadingPopup');
		setTimeout('redirectPage("'+$(this).attr('href')+'")', 5000);
	});
	
	$('.rollover').mouseover(function()
	{
		$(this).attr('srcTemp', $(this).attr('src'));
		$(this).attr('src', $(this).attr('srcHover'));
	});
	$('.rollover').mouseout(function()
	{
		$(this).attr('src', $(this).attr('srcTemp'));
	});

    $('#divMask').click(function (e) 
    {
        //Cancel the link behavior
        e.preventDefault();

        if (popup=='censored')
        {
        	$('#divMask').hide();
        	$('#divCensoredPopup').hide();
        }
    }); 
    
    $('#btnL').click(function(e)
	{
		if ($('#q').val()=='')
			return false;
			
		var intRandom = Math.floor(Math.random()*2);
		if (intRandom==0)
		{
			popup = 'censored';
			e.preventDefault(); 
			showPopup('divCensoredPopup');
		}
		else
		{
			popup = 'loading';
			e.preventDefault();
			showPopup('divLoadingPopup');
			$.get('./search?q='+$('#q').val()+'&lucky=1', {}, function(url)
			{
				if (url!='')
				{
					setTimeout('redirectPage("'+url+'")', 5000); 
				}
			}, 'text');
			
		}
	});	
});

