$(document).ready(function() {

// Layout options feature
$('a#options').click(function (){
	if (($('.layout_options')).is(':hidden')) {
	$('#wrapper').fadeTo('fast', 0.33);
	$('.layout_options').fadeIn('normal');
	} else {
	$('#wrapper').fadeTo('fast', 1.0);
	$('.layout_options').fadeOut('normal');
	}
});

$('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()});
$('.layout_options').fadeOut('normal');
$('#wrapper').fadeTo('fast', 1.0);
});
// done.

// Drop Down Menu (2 Levels)
$('#menu ul ul').hide(0.000000000000000000000000000000000000001);
$('#menu ul li a').addClass('nav_parent');
$('#menu ul ul a').removeClass('nav_parent');
$('#menu ul ul a').addClass('nav_child');

$('.nav_parent').bind('mouseenter', function() {
	if (($(this).next().is('ul')) && ($(this).next().is(':visible'))) {
	return false;
	} else if (($(this).next().is('ul')) && ($(this).next().is(':hidden'))) {
	$(this).next().show();
	return false;
	}
});

$('.nav_parent').parent().bind('mouseleave', function() {
	$('#menu ul ul:visible').hide();
});
// End of Menu

/* 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).hide();
});

$('.box_a').each( function() {
	var box_ID = $(this).attr('id');
	if ($.cookie(box_ID) == 'closed') $(this).hide();
});

$('.widgets li').each (function() {
	var sidebar_ID = $(this).attr('id');
	if ($.cookie(sidebar_ID) == 'closed') $(this).hide();
});

/* control visible stories */
$('ul.more_stories').each(function(index) {
$(this).children('li').slice(3).hide();
});

$('.minus').click(function() {
$(this).parent().next('ul').children('li:visible:last').hide();
});

$('.plus').click(function() {
$(this).parent().next('ul').children('li:hidden:first').show();
});

/* clear form */
clearInput('#feedemail');

});