function toggle_sidebars(){
	if ($j.cookie('sidebars_hidden')=='true'){
		show_sidebar(true);
	} else {
		hide_sidebar(true);
	}
}

function show_sidebar(animated){
	if (animated=='undefined') animated=true;
	$j.cookie('sidebars_hidden','false', { path: '/'});
	if (animated){
		$j('.center-widget-title, .center-widget, .footer').animate({
			marginLeft:sidebarMarginLeft,
			marginRight:sidebarMarginRight
		},500,function(){
			$j('ul.left-sidebar, ul.right-sidebar').fadeIn();	
		});		
	} else {
		$j('.center-widget-title, .center-widget, .footer').css({
			marginLeft:sidebarMarginLeft,
			marginRight:sidebarMarginRight
		});
		$j('ul.left-sidebar, ul.right-sidebar').css({
			display: 'block'
		});
	}
}

function hide_sidebar(animated){
	if (animated=='undefined') animated=true;
	$j.cookie('sidebars_hidden','true', { path: '/'});

	if (animated){
		$j('ul.left-sidebar, ul.right-sidebar').fadeOut(function(){
			$j('.center-widget-title, .center-widget, .footer').animate({
				marginLeft:0,
				marginRight:0
			});	
		});
	} else {
		$j('.center-widget-title, .center-widget, .footer').css({
			marginLeft:0,
			marginRight:0
		});
		$j('ul.left-sidebar, ul.right-sidebar').css({
			display: 'none'
		});
	}

}

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

	if ($j.cookie('sidebars_hidden')=='true'){
		hide_sidebar(false);
	}
	
	// $j('a[rel=lightbox]').fancybox({
		// 'speedIn'		:	600, 
		// 'speedOut'		:	200, 
		// 'overlayShow'	:	false
	// });
	//$j('a[rel=lightbox]').lightBox();
	
	Shadowbox.init();

	$j('.tooltip_top').each( function(i){
		$j(this).tipsy({gravity: 's'});
	});
	$j('.tooltip_left').each( function(i){
		$j(this).tipsy({gravity: 'e'});
	});
	$j('.tooltip_bottom').each( function(i){
		$j(this).tipsy({gravity: 'n'});
	});
	$j('.tooltip_right').each( function(i){
		$j(this).tipsy({gravity: 'w'});
	});
	
	$j('.social_bookmarks').mouseover(function() {
		$j(this).css({
			marginTop: '-8px'
		})
	});	
	$j('.social_bookmarks').mouseout(function() {
		$j(this).css({
			marginTop: '0'
		})
	});	
});

function skss_share(service) {
    // Get href and title
    // PDS URL correction, remove when going live
    var url = location.href;
    url = url.replace(/^http:\/\/[a-z]+\.u\./i,'http://www.');
    encodedurl = encodeURIComponent(url);
    var encodedtitle = encodeURIComponent(document.title);

    var serviceUrl = null;
    if (service == 'delicious') {
        serviceURL = 'http://del.icio.us/post?v=4&noui&jump=close'
            + '&url='      + encodedurl
            + '&title='    + encodedtitle;
    } else if (service == 'digg') {
        serviceURL = 'http://digg.com/submit?phase=2'
            + '&url='      + encodedurl
            + '&title='    + encodedtitle;
    } else if (service == 'facebook') {
        serviceURL = 'http://www.facebook.com/sharer.php'
            + '?u=' + encodedurl
            + '&t=' + encodedtitle;
    } else if (service == 'fark') {
        serviceURL = 'http://www.fark.com/cgi/fark/submit.pl'
            + '?new_url='     + encodedurl
            + '&new_comment=' + encodedtitle;
    } else if (service == 'google') {
        serviceURL = 'http://www.google.com/bookmarks/mark?op=add'
            + '&bkmk='       + encodedurl
            + '&title='      + encodedtitle
            + '&labels='     + ''
            + '&annotation=' + '';
    } else if (service == 'newsvine') {
        serviceURL = 'http://www.newsvine.com/_tools/seed&save'
            + '?u='      + encodedurl;
    } else if (service == 'reddit') {
        serviceURL = 'http://reddit.com/submit'
            + '?url='      + encodedurl
            + '&title='    + encodedtitle;
    } else if (service == 'slashdot') {
        serviceURL = 'http://slashdot.org/bookmark.pl'
            + '?url='   + encodedurl
            + '&title=' + encodedtitle;
    } else if (service == 'technorati') {
        serviceURL = 'http://technorati.com/faves?sub=favthis'
            + '&add=' + encodedurl;
    } else if (service == 'twitter') {
        serviceURL = 'http://twitter.com/home?status='+encodedtitle+': '+encodedurl;
    } else if (service == 'stumbleupon') {
        serviceURL = 'http://www.stumbleupon.com/submit?url='+encodedurl+'&title='+encodedtitle;
    } else if (service == 'svejonet') {
        serviceURL = 'http://svejo.net/story/submit_by_url?url='+encodedurl;
    } else if (service == 'identica') {
		serviceURL = 'http://identi.ca/?action=newnotice&status_textarea='+encodedtitle+' '+encodedurl
    } else if (service == 'netvibes') {
		serviceURL = 'http://www.netvibes.com/share?title='+encodedtitle+'&url='+encodedurl
    }
    
    if ( serviceURL != null ) {
        var theNewWin = window.open(serviceURL,'sfgateshare','width=900,height=640,resizable=yes,toolbar=no,location=no,scrollbars=yes');
        if ( typeof theNewWin != "undefined" &&
             theNewWin != null ) {
            theNewWin.focus();
        }
    }
}
