window.slideshowSpeed = 12000;

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

    //$( '#logo, #home_featured li:not(div.content), #home_sub div.bg, #page_banner div.fade, #sidebars li.widget_gallery_previews ').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
    //	});
    //}
	
	featured_slideshow($);
	
	// content_equal_height($);
	
	sub_page_menu_hide($);

});

function sub_page_menu_hide($) {
	$('#sub-page-menu > ul > li:has(ul) > a').each(function() {
		$(this).html( '&raquo; '+$(this).html() );
	});
	
	$('#sub-page-menu > ul > li')
		.not('.current_page_ancestor, .current_page_item')
			.find('>ul')
				.hide()
				.end()
			.end();
		//.find('ul')
		//	.prev('a')
		//		.click( function() {
		//			$(this).next('ul').slideToggle();
		//			return false;
		//		});
}

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);
}

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);
}

