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
    	});
    }
	
	var featured = $('#home_featured');
	$('> 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;
	    });

	// Featured Click Proxy
	$('div.content, div.bg, img.fade', featured).click(function() {
		var href = $(this).parents('li:first').find('a.more-link').attr('href');
		window.location = href;
	});
	
	
	// Functions
	var slideshowSpeed = 15000;
	
	function slideshow() {
	    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);
	}
	
	setTimeout(slideshow, slideshowSpeed);
	
	
	// Set sidebars and content to be of equal height 
	// if ( ! $(body).hasClass('order-sign-service') ) {
	    equalHeight($('#sidebars, #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);
    }
   
});


