$(document).ready(function(){
	
	//When page loads...
	$(".tab").children(":not(.tab-nav)").hide(); //Hide all content
	$(".tab:first").children().show(); //Hide all content
	$(".tab:first").find(".tab-nav").addClass("selected");
	
	//On Click Event
	$(".tab-nav").click(function() {
		$(".tab").children(":not(.tab-nav)").hide(); //Hide all content
		$("#tabs").find(".tab-nav").removeClass("selected");
		$(this).addClass("selected");
		$(this).parent().children().fadeIn();
		return false;
	});
	
	// Home feature add buffer to right col
	$("#content-inner").find(".column-2").find(".col:even").addClass("col-buffer");
	
	// add a "rel" attrib if Opera 7+
	if(window.opera) {
		if ($("a.jqbookmark").attr("rel") != ""){ // don't overwrite the rel attrib if already set
			$("a.jqbookmark").attr("rel","sidebar");
		}
	}

	$("a.bookmark").click(function(event){
		event.preventDefault(); // prevent the anchor tag from sending the user off to the link
		var url = this.href;
		var title = this.title;

		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
		} else if( window.external ) { // IE Favorite
			window.external.AddFavorite( url, title);
		} else if(window.opera) { // Opera 7+
			return false; // do nothing - the rel="sidebar" should do the trick
		} else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
			 alert('Unfortunately, this browser does not support the requested action,'
			 + ' please bookmark this page manually.');
		}

	});
	
    // Toggle Search...
    $('input#s').each(function() {
        var default_value = 'Search...';
        this.value = default_value;
        $(this).focus(function() {
            if(this.value == default_value) {
                this.value = '';
            }
        });
        $(this).blur(function() {
            if(this.value == '') {
                this.value = default_value;
            }
        });
    });
	
	// Cycle through comments in tabbed sidebar
	$('#tabs').find('.tab:eq(0) ul').cycle({
		timeout:	5000,
		pause:		true
	});
	
	// Respond form toggle
	/*
	$("#respond").find("form").hide();
	$("#respond").find("h3").click(function(){
		$(this).parent().find("form").toggleFade( {speedIn : 800, speedOut : 150} );
		
	});
	*/
	
/*
	$(".tab ul.tabs_menu li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs_menu li").click(function() {

		$("ul.tabs_menu li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});
*/
});

(function($) {
  $.fn.toggleFade = function(settings)
  {
  	settings = jQuery.extend(
  		{
        speedIn: "normal",
        speedOut: settings.speedIn
  		}, settings
  	);
  	return this.each(function()
  	{
  	  var isHidden = jQuery(this).is(":hidden");
      jQuery(this)[ isHidden ? "fadeIn" : "fadeOut" ]( isHidden ? settings.speedIn : settings.speedOut);
    });
  };
})(jQuery);
