$(function(){
	
	///////////////////////////////////////////////////////
	//
	// HITAREA ANCHOR
	//
	// Mirror the hitarea of a link to another element
	// from class 'hitarea-anchor' to class 'hitarea-mirror'
	// the mirror object must have a class of the ID of the
	// anchor prepended by 'm'
	//
	// e.g.
	//
	//	<h3 class="hitarea-mirror manchor1">...</h3>
	//	<img class="hitarea-mirror manchor1" ... />
	//	<a class="hitarea-anchor" id="anchor1" href="...">...</a>
	//
	///////////////////////////////////////////////////////
	
	$('.hitarea-anchor').each(function(){
		var href = $(this).attr('href');
		$('.hitarea-mirror.m' + $(this).attr('id')).each(function(){
			$(this).addClass('faux-button').click(function(){
				window.location.href = href;
			});
		});
	});

	$('.auto-expand-hitarea').addClass('faux-button').click(function(){
		var href = '';
		if ($(this).hasClass('first')) href = $(this).find('a:first').attr('href');
		else href = $(this).find('a:last').attr('href');
		window.location.href = href;
	});

});

$(function() {
	 $('ul.icons li a').addClass('fadeIn');
});

$.fn.block = function (t) {    
    return this.each(function() {      
        var $this = $(this),                  
            $span = $(''+$(this).html()+'');
        
        //expand the span inside the element   
        $this.append($span);
        $this.css({position:'relative'});
        $span.css({position:'absolute',width:'100%',height:'100%',left:0,top:0,cursor:'pointer'});

        //rename the hover class for the new span and hide it
        ss(this.className+':hover').rename('.'+this.className+' span.hover');         $span.css({opacity: 0});

        //animate
        $this.hover(function() {   
            $span.stop().animate({opacity: 1}, t);
        }, function() { 
            $span.stop().animate({opacity: 0}, t);  
        });
    });      
};

$(function() {
    $('#welcome form fieldset.bool input').attr({ value: 'Enter a topic or keyword' }).focus(function(){
		if ($(this).val()=='Enter a topic or keyword') {
				$(this).val("");
			}
		}).blur(function(){
			if ($(this).val()=="") {
				$(this).val('Enter a topic or keyword');
			}
		});
});


$(function() {
    $('.fadein').block(250);    
});

//pagination
$(function(){
	$either_side = 4;
	$ellipsis = '&nbsp;&#8230;&nbsp;';
	$current_page = ($('#numbers li a.selected').length > 0) ? parseInt($('#numbers li a.selected').html()) : 1;
	$offset = 7 + $current_page;
	$real_num_pages = parseInt($('#numbers li').length);
	$num_pages = $real_num_pages - $offset;
	if ($current_page == 1) {
		$('#numbers li:gt('+($either_side + 1)+'):lt('+$num_pages+')').hide();
		$('#numbers li:eq('+($real_num_pages - 2)+')').prepend($ellipsis);
	} else if ($current_page == ($num_pages - 1)) {
		$('#numbers li:gt(1):lt('+($num_pages-$either_side)+')').hide();
		$('#numbers li:eq(1)').append($ellipsis);
	} else {
		$('#numbers li:gt('+($current_page + $either_side)+'):lt('+$num_pages+')').hide();
		$('#numbers li:lt('+($current_page - $either_side)+'):gt(1)').hide();
	if ($current_page < ($real_num_pages - $either_side - 3))
		$('#numbers li:eq('+($real_num_pages - 2)+')').prepend($ellipsis);
	if ($current_page > ($either_side + 2))
		$('#numbers li:eq(1)').append($ellipsis);
	}
});




