window.slideshowSpeed = 10000;

/*jQuery(document).ready(function($){

    $( '#header div, #home_featured li:not(div.content)').pngFix();
    
	expand_footer();
	var resizeTimer = null;
	jQuery(window).bind('resize', function() {
	    if (resizeTimer) clearTimeout(resizeTimer);
	    resizeTimer = setTimeout(expand_footer, 100);
	});

   
}); */

jQuery(document).ready(function($){

    $( '#header div, #home_featured li:not(div.content)').pngFix();
    
	expand_footer();
	//	var resizeTimer = null;
	//	jQuery(window).bind('resize', function() {
	//	    if (resizeTimer) clearTimeout(resizeTimer);
	//	    resizeTimer = setTimeout(expand_footer, 100);
	//	});
	
	if ( $('body').hasClass('home') == true ) {
		featured_slideshow($);
	}
	
	// Remove bottom margin from paragraphs followed by a list
	$('ul,ol', '#content').not('.cth-grid').prev('p').css('margin-bottom', '0');
   
});

function expand_footer() {
	var $ = jQuery;
	
	var win = windimension();
	var missing_height = win[1] - $('body').height();
	if ( missing_height < 0 ) {
		return;
	}
    var fheight = $('#footer').height();

	$('#footer').height( fheight + missing_height );
}
function windimension(){
	if(window.innerHeight !==undefined)A= [window.innerWidth,window.innerHeight]; // most browsers
	else{ // IE varieties
		var D= (document.body.clientWidth)? document.body: document.documentElement;
		A= [D.clientWidth,D.clientHeight];
	}
	return A;
}
function featured_slideshow($) {
	window.featured = $('#home_featured');
	
	var ani_opts = {};
	ani_opts.over = { paddingLeft: '1.8em' };
	ani_opts.out = { paddingLeft: '1.2em' };
	if (!$.browser.msie && !$.browser.safari) {
		ani_opts.over = { paddingLeft: '1.8em', letterSpacing: '1.2px' };
		ani_opts.out = { paddingLeft: '1.2em', letterSpacing: '0px' };
	}
	
	$('a', featured).hover(
		function(){ $(this).find('h2').stop().animate(ani_opts.over, 750 );	},
		function(){ $(this).find('h2').stop().animate(ani_opts.out, 750 );	}
	);
	
	$('img', featured).attr('title', '');
	
	$('> ul.items > li', featured)
	    .not(':first')
	        .hide()
            .end()
        .css({
            'position': 'absolute',
            'top': '0px',
            'left': '0px'
        });
        
	
	$('> ul.nav a', featured)
	    .eq(0)
	        .addClass('active')
	        .end()
	    .click(function(){
            var id = $(this).attr('href');
            if (!$(this).hasClass('active')) {
                $('> ul.items > li:visible', featured).fadeOut(1000);
                $(id).fadeIn(1000);
                
                $('> ul.nav a', featured).removeClass('active');
                $(this).addClass('active');
            }
            
            window.slideshowStop = true;
            
            return false;
	    });
	
	setTimeout(slideshow, slideshowSpeed);
}

function slideshow() {
	var $ = jQuery;
	
    if (window.slideshowStop == true) {
        return;
    }
    
    var next = $('> ul.items > li:visible', featured).fadeOut(1000).next();
    if (next.length == 0) {
        next = $('> ul.items > li:eq(0)', featured);
    }
    var id = $(next).attr('id');

    next.fadeIn(1000);
    $('> ul.nav a', featured).removeClass('active');
    $('a[href=#'+id+']', featured).addClass('active');
    
    setTimeout(slideshow, slideshowSpeed);
}

