function clearInput(field_id, term_to_clear) {
	
	// Clear input if it matches default value
	if (document.getElementById(field_id).value == term_to_clear ) {
		document.getElementById(field_id).value = '';
	}
	
	// If the value is blank, then put back term
	else if (document.getElementById(field_id).value == '' ) {
		document.getElementById(field_id).value = term_to_clear;
	}
} // end clearSearch()

function toggleDisplayBlock(idOf,idArrow) {
	var element = document.getElementById(idOf);
	if (element != undefined)
	{
		if (element.style.display == 'none')
			element.style.display = 'block'; 
		else
			element.style.display = 'none';  
		var arrow = document.getElementById(idArrow);
		if (arrow != undefined)
			if (element.style.display == 'none')
				arrow.innerHTML = '&#x25ba;';
			else
				arrow.innerHTML = '&#x25bc;';
		var toggle = document.getElementById('toggle');
		if (toggle != undefined)
			if (toggle.value == 'NaN')
				toggle.value = '';
			if (element.style.display == 'none')
				toggle.value += ('' + idOf + ' ');
			else
				toggle.value -= ('' + idOf);
	}
}

function showTabContents(tab_id, tab_content_id) {
  $("#" + tab_id).siblings().removeClass('active');
  $("#" + tab_id).addClass('active');
  $("#" + tab_content_id).siblings().addClass('hide');
  $("#" + tab_content_id).removeClass('hide');
    
  return false;
}

(function($) {
	$.fn.equalHeights = function(minHeight, maxHeight) {
		tallest = (minHeight) ? minHeight : 0;
		this.each(function() {
			if($(this).height() > tallest) {
				tallest = $(this).height();
			}
		});
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
		return this.each(function() {
			$(this).height(tallest).css("overflow","auto");
		});
	}
})(jQuery);

$(document).ready(function(){
	
	$(".image-button img").hover(
	 function()
	 {
	  this.src = this.src.replace("_off","_over");
	 },
	 function()
	 {
	  this.src = this.src.replace("_over","_off");
	 }
	);
	
	//Full Super Tab Sliding (Hidden to Visible)
	$('.inactive .tab-inner').hover(function(){
		$(".cover", this).stop().animate({top:'0'},{queue:false,duration:190});
	}, function() {
		$(".cover", this).stop().animate({top:'32px'},{queue:false,duration:190});
	});	
	
	$(".equal").equalHeights();
	$(".equalize").equalHeights();
	$(".equal_footerPull").equalHeights(210);
	$('#slidebar-menu-on').click( 
		function ( ) {
			$('#aside').addClass('hide');
			$('#atop').removeClass('hide');
			$('#docbody').animate({width:"98%"}, 190);
			
		}
		
	);
	
	$('#slidebar-menu-off').click(    
		function ( ) {
			$('#aside').removeClass('hide');
			$('#atop').addClass('hide');
			$('#docbody').animate({width:"79.25%"}, 190);
			
		}
	);
	
	
	$('#slidebar-handle').toggle( 
		function ( ) {
			$('.inside');
			$('#docbody').animate({width:"79.25%"}, 190);
		},
		function ( ) {
			$('.inside').slideUp();
			$('#docbody').animate({width:"98%"}, 190);

		}
	);
	
	
	$('#thread_opener').click(    
		function ( ) {
			$('[id^=thread_ID]').removeClass('hide');
			$('[id^=dummy_ID]').addClass('hide');
			$('#thread_opener').css('display', 'none');
			$('#thread_closer').css('display', 'block');
			$('#thread_closer').addClass('last');
		}
	);
	
	$('#thread_closer').click(    
		function ( ) {
			$('[id^=dummy_ID]').removeClass('hide');
			$('[id^=thread_ID]').addClass('hide');
			$('#thread_closer').css('display', 'none');
			$('#thread_opener').css('display', 'block');
			$('#thread_opener').addClass('last');
		}
	);

	$('.plus').click(function () {
      $(this).toggleClass('plus');
      $(this).toggleClass('minus');
    });
    
    
    
	
	$('#option-toggle').toggle( 
		function ( ) {
			$('#advanced_options').slideDown({duration:190});
			$('#atop').animate({top:'195px'},{queue:false,duration:190});
			return false;
			
		},
    
		function ( ) {
			$('#advanced_options').slideUp({duration:190});
			$('#atop').animate({top:'159px'},{queue:false,duration:190});
			return false;
			
		}
	);

        
	// toggle download options
	$(".open_download_options").click(function(){
	
	if( $(".download_options").css('display') == "none"){
	  $(".download_options").slideDown("fast");
	  $(".download_options").addClass("selstate");
	  customizedDownload = true;
	}else{
	  $(".download_options").slideUp("fast");
	  $(".open_download_options").removeClass("selstate");
	  customizedDownload = false;
	}
	return false;
	});
	
	// generate TOC if it is requested!
	if($('.generatetoc').text().length > 0 && $('.thistoc').length > 0) buildTOC();

});

function buildTOC(){
	var buildtoc = '';
	buildtoc += '<h6><a href="#headline">'+$('.generatetoc h1').text()+'</a></h6>';
	buildtoc += '<ul class="nav">';
	$('.generatetoc h2, .generatetoc h3, .generatetoc h4, .generatetoc h5').each(function(index) {
		var levelw = 0;
		if($(this).attr('tagName') == 'H3') levelw = 10;
		if($(this).attr('tagName') == 'H4') levelw = 20;
		if($(this).attr('tagName') == 'H5') levelw = 30;
		buildtoc += '<li style="padding-left: '+levelw+'px;"><a href="#heading'+index+'">'+$(this).text()+'</a></li>';
		if($(this).children('a').length > 0) {
			$(this).children('a').attr('name','heading'+index)
		} else {
			$(this).html('<a name="heading'+index+'">'+$(this).text()+'</a>')			
		}
	});
	buildtoc += '</ul>';
	$('.thistoc').html(buildtoc);
}

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};
jQuery(document).ready(function(){
    $('.accordion a.haskids').click(function(event) {
        $(this).next().slideToggle('normal');
        event.preventDefault();
    });
    
    $('.accordion a.active').parents('ul').show();  

    $('.showall ul').show();    
    
});

