$(document).ready(function() {

// Layout options feature
$('a#options').click(function (){
	$('#popupsHolder').css('display', 'block');
});

$('#popupsHolder').children('#flyBox').children('h3').children('.closefly').click(function(){
	$('#popupsHolder').css('display', 'none');
})

$('a#reset').click(function() {
	$('.cat-widget').each( function() {$.cookie($(this).attr('id'), null, { path: '/', expires: 100 }); $(this).show()});
	$('.box_a').each( function() {$.cookie($(this).attr('id'), null, { path: '/', expires: 100 }); $(this).show()});
	$('.widgets li').each (function() {$.cookie($(this).attr('id'), null, { path: '/', expires: 100 }); $(this).show()});
	$('.cat-widget').each(function(index) {
		$.cookie($(this).attr('id')+'-v', null, { path: '/', expires: 100 });
		$(this).children('ul.more_stories').children('li').slice(1).show();
	});
	location.reload(true);
	$('.layout_options').fadeOut('normal');
	$('#wrapper').fadeTo('fast', 1.0);
	

	
});
// done.

/* various widget actions */
$('.minimize').click(function() {
	$(this).parent('h3').next('.container').toggle();
});

$('.Sminimize').click(function() {
	$(this).parent('h2').next().toggle();
});

$('.Wminimize').click(function() {
	$(this).parent('h2').next().toggle();
});

$('.close').click(function() {
	$(this).parent('h3').parent('.cat-widget').fadeOut('slow');
	$.cookie($(this).parent('h3').parent('.cat-widget').attr('id'), 'closed', { path: '/', expires: 100 });
	return false;
});

$('.Sclose').click(function() {
	$(this).parent('h2').parent().fadeOut('slow');
	$.cookie($(this).parent('h2').parent('.box_a').attr('id'), 'closed', { path: '/', expires: 100 });
	return false;
});

$('.Wclose').click(function() {
	$(this).parent('h2').parent().fadeOut('slow');
	$.cookie($(this).parent('h2').parent('li').attr('id'), 'closed', { path: '/', expires: 100 });
	return false;
});

$('.cat-widget').each( function() {
	var cat_ID = $(this).attr('id');
	if ($.cookie(cat_ID) == 'closed'){ $(this).css('display', 'none'); };
});

$('.box_a').each( function() {
	var box_ID = $(this).attr('id');
	if ($.cookie(box_ID) != 'closed') $(this).show();
});

$('.widgets li').each (function() {
	var sidebar_ID = $(this).attr('id');
	if ($.cookie(sidebar_ID) != 'closed') $(this).show();
});

/* control visible stories */
$('ul.more_stories').each(function(index) {
	var num = $.cookie( $(this).parent().parent().parent().attr('id')+'-v' );
	if (num){
		$(this).children('li').slice(num).hide();
	}else{
		$(this).children('li').slice(10).hide();
	}
});

$('.minus').click(function() {
	$(this).parent().parent().children('ul').children('li:visible:last').hide();
	vis =  $(this).parent().parent().children('ul').children('li:visible').size();
	$.cookie($(this).parent('h3').parent().parent().parent().attr('id')+'-v', vis, { path: '/', expires: 100 });
});

$('.plus').click(function() {
	$(this).parent().parent().children('ul').children('li:hidden:first').show();
	vis =  $(this).parent().parent().children('ul').children('li:visible').size();
	$.cookie($(this).parent('h3').parent().parent().parent().attr('id')+'-v', vis, { path: '/', expires: 100 });
});

/* clear form */
clearInput('#feedemail');

});