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

    $( '#header div, #home_featured li:not(div.content)').pngFix();
    
    //if ( !($.browser.msie && parseInt($.browser.version) < 7) ) {
    //    $.Lightbox.construct({
    //		show_linkback:	false,
    //		show_info: true,
    //		show_extended_info: true,
    //		ie6_upgrade: false,
    //		opacity: 0.8,
    //		auto_relify: true,
    //		download_link: false
    //	});
    //}
	
	// Add fancybox
	$('a[href$=.jpg],[href$=.gif],[href$=.png],[href$=.jpeg]:has(>img)', '#content')
		.attr('rel', 'gallery')
		.each(function() {
			$(this).attr('title', $(this).find('>img').attr('alt') );
		})
		.fancybox({
			'titlePosition': 'inside'
		});
	
	featured_slideshow($);
	
	content_equal_height($);
   
});


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;
	    });
	    
	var slideshowSpeed = 7000;
	
	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');

    var slideshowSpeed = 7000;

    setTimeout(slideshow, slideshowSpeed);
}

function content_equal_height($) {
	// Set sidebars and content to be of equal height     
    if ( $('body > div.home').length == 0 ) {
		// Compare to #content_box for ie6 to work
		equalHeight( $('#content_box, #sidebars'), $);   
		equalHeight( $('#content_box, #content'), $);   
    }

	// Expand post_box if there is only one and it's shorter than the sidebar
    //  var postbox = $('#content div.post_box');
    //  if (postbox.length == 1 && postbox.height() < $('#sidebars').height() ) {
    //      var cols = postbox.add('#sidebars');
    //      equalHeight(cols);
    //  }
}

function equalHeight(group, $) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}


