var metaPaneExpanded = true;
var widgetBarExpanded = true;
var debug_mode = false;
function toggleLogin() {
	//$('header-login-form').toggleClassName('login-form-closed');
	//alert($('header-right').getStyle('right'));
	if ($('header-right').getStyle('right') == '0px') {
		$('header-right').morph('right:-350px;', { duration: 0.3 });
	} else {
		$('header-right').morph('right:0px;', { duration: 0.3 });
	}
	
	
	
	//$('UserUsername').focus();
	return false;

}
function openPopup(href) {

	window.open(href,'_blank','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=350,height=470,top=100,left=200');
	return false;
}
function openAddSub() {
	$('addSubPopup').toggleClassName('hidden');
}
function expandReader(btn) {
	//$().morph('left:300px;');//right:' + $('content-right'). + 'px;');
	$('readerPane').setStyle('width: auto');  
	new Effect.Morph('content-right', {
		style: { left: '300px' },
		afterFinish: function() {
			$$('.rack_right_border').each(function(div){ div.setStyle('left: 298px')});
			resizePanes();
		}
	});
	
	btn.style.display = 'none'; 
	$('panel-right').style.display = 'block'; 
	
	$('feedblock').removeClassName('feedblock_wide');
	$('feedblock').addClassName('feedblock_narrow');
	
	return false;
}

function showMetaPane() {
	$('hideMetaPaneControl').show();
	$('showMetaPaneControl').hide();
	new Effect.Morph('readerPane', {
		style: { bottom: '228px' },
		afterFinish: resizePanes,
	});
	new Effect.Morph('metaPane', {
		style: { height: '220px' },
		afterFinish: resizePanes,
	});
	metaPaneExpanded = true;
}

function hideMetaPane() {
	new Effect.Morph('readerPane', {
		style: { bottom: '26px' },
		afterFinish: resizePanes,
	});
	new Effect.Morph('metaPane', {
		style: { height: '18px' },
		afterFinish: resizePanes,
	});

	$('hideMetaPaneControl').hide();
	$('showMetaPaneControl').show();
	metaPaneExpanded = false;
}

function resizePanes() {
	clh = $('content-left').style.height = ($('footer').offsetTop - $('content-left').offsetTop + 4) + "px";
	$('content-right').style.height = ($('content').offsetHeight - 5) + "px"; // for scroll bar
	$('reader').style.height = ($('content-right').offsetHeight - $('footer').offsetHeight ) + "px"; // for scroll bar

	rack_height = ($('content-left').getHeight() / 3) - 40;
	rack_inner_height = ($('content-left').getHeight() / 3) - 50;
	
	$$('div.rack').each(function (div) { div.setStyle({'height': rack_height + 'px'})}); 
	$$('div.rack_feeds').each(function (div) { div.setStyle({'height': rack_inner_height + 'px'})}); 
	
	scrollbar_content.recalculateLayout();
	updateScrollbar();
}

function updateScrollbar() {
	$('reader_scrollbar_container').setStyle('width: ' + ($('readerPane').offsetWidth) + 'px');
	$('article_description').setStyle('height: ' + ($('readerPane').offsetHeight - 120) + 'px');
	
	scrollbar_content.recalculateLayout();
	scrollbar_content.recalculateLayout();
}

function shrinkReader(btn) {
	$('readerPane').setStyle('width: auto');
	$$('.rack_right_border').each(function(div){ div.setStyle('left: 498px')});
	new Effect.Morph('content-right', {
		style: { left: '500px' },
		afterFinish: function() {
			resizePanes();
			$('feedblock').removeClassName('feedblock_narrow');
			$('feedblock').addClassName('feedblock_wide');

		}
	});

	btn.style.display = 'none'; 
	$('panel-left').style.display = 'block'; 
	
	resizePanes();
	return false;
}

function hideShelf(btn) {

	widgetBarExpanded = false;
	
	new Effect.Morph('shelf', {
		style: { width: '0px' },
			});
	$('content-right').morph('right:10px;');
		
	btn.style.display = 'none'; 
	$('shelf-left').style.display = 'block'; 
	updateScrollbar();
	return false;
}
function showShelf(btn) {

	widgetBarExpanded = true;
	
	
	$('content-right').morph('right:150px;');  
	
	new Effect.Morph('shelf', {
		style: { width: '150px' },

	});
	btn.style.display = 'none'; 
	$('shelf-right').style.display = 'block'; 
	
	$('shelf-controls').style.backgroundColor = '#F6F6F6';
	updateScrollbar();
	return false;
}
function swapLoginForm() {
	var openid = 'openidLoginForm';
	var regformid = 'regLoginForm';
	
	if (!$(openid).visible()) {
		appear_id = openid
		hide_id = regformid;
	} else {
		appear_id = regformid;
		hide_id = openid;
	}
	
	//new Effect.Parallel([
	//	Effect.toggle(hide_id, 'appear', { queue: 'end' });
	//	Effect.toggle(appear_id, 'appear', { queue: 'end' });
		
	//]);
	
	Effect.Fade(hide_id, { duration: 0.3 });
	Effect.Appear(appear_id, { queue: 'end' });

	return false;
}


function setupScrollbars() {
	scrollbar_content = new Control.ScrollBar('article_scroll_frame','reader_scrollbar_track');
	scrollbar_playlist = new Control.ScrollBar('playlist','playlist_scrollbar_track'); 
}

function refreshScrollbar() {
	
	scrollbar_content.recalculateLayout();	
	resizePanes();
	setTimeout('refreshScrollbar2()', 800);
}

function refreshScrollbar2() {
	scrollbar_content.recalculateLayout();
	scrollbar_content.recalculateLayout();
}
		
		
	
