// JavaScript Document



function doStuff(child,action) {

  if (child.attr('class') == 'toggleme') {
	if (action == 'expand') { child.css('display','block'); }  
	if (action == 'close') { child.css('display','none'); }  
  }
  if ( (child.attr('class').indexOf('expand') >= 0) && (action.indexOf('close') >= 0)  ) {
	child.removeClass('off');	
	child.css('background-position','0px -2px');
  }
  if ( (child.attr('class').indexOf('close') >= 0) && (action.indexOf('close') >= 0)  ) {
	child.addClass('off')
	child.css('background-position','0px -80px');
  }
  if ( (child.attr('class').indexOf('expand') >= 0) && (action.indexOf('expand') >= 0)  ) {
	child.addClass('off');
	child.css('background-position','0px -54px');
  }
  if ( (child.attr('class').indexOf('close') >= 0) && (action.indexOf('expand') >= 0)  ) {
	child.removeClass('off')
	child.css('background-position','0px -28px');
  }
  
}

function walk(children, action) {

  if (typeof children == "undefined" || children.size() === 0) {
    return;
  }
  children.each(function(){
    var child = jQuery(this);
    if (child.children().size() > 0) {
      walk(child.children(), action);
    }
    doStuff(child, action);
  });
}

/* Removes Text from Search OnFocus */		
jQuery(document).ready(function(){ 				  
	jQuery(".toolbar a").click(function(){ 
		switch( jQuery(this).attr('id') ) {
			case 'expand':
				walk(jQuery(".title").parent().parent(), 'expand');
				jQuery(this).css('background-position','0px -52px');
				jQuery(this).css('cursor','default');
				jQuery("a#close").css('background-position','0px -26px');
				jQuery("a#close").css('cursor','pointer');
				return false;
				break;
			case 'close':
				walk(jQuery(".title").parent().parent(), 'close');
				jQuery(this).css('background-position','0px -78px');
				jQuery(this).css('cursor','default');
				jQuery("a#expand").css('background-position','0px 0px');
				jQuery("a#expand").css('cursor','pointer');
				return false;
				break;
			default:
				break;
		}

	});	
	
	jQuery(".options a").click(function() {
		var action = jQuery(this).attr('class');
		if (action == "expand") {
			walk(jQuery(this).parent().parent().parent(), 'expand');
			
			jQuery(this).addClass('off');
			jQuery(this).css('background-position','0px -54px');
			jQuery(this).parent().children("a.close").removeClass('off');
			jQuery(this).parent().children("a.close").css('background-position','0px -28px');
			jQuery("a#close").css('background-position','0px -26px');
			jQuery("a#close").css('cursor','pointer');
		} else if (action == "close") {
			
			walk(jQuery(this).parent().parent().parent(), 'close');
			jQuery(this).addClass('off');
			jQuery(this).css('background-position','0px -80px');
			jQuery(this).parent().children("a.expand").removeClass('off');
			jQuery(this).parent().children("a.expand").css('background-position','0px -2px');
			jQuery("a#expand").css('background-position','0px 0px');
			jQuery("a#expand").css('cursor','pointer');
		}
		return false;
	});
});



