$(document).ready(function(){
	// quick rules
	$("#toggle").show();
	$("tr:even").addClass("even");
	$("tr:odd").addClass("odd");
	
	//MICROFORMAT STUFF
	$("#feature a[href^=http://]:not(a[href*=teachmetheweb.org])").attr("rel","external");
	$("#page_content a[href^=http://]:not(a[href*=teachmetheweb.org])").attr("rel","external");
	$("#footer a[href^=http://]:not(a[href*=teachmetheweb.org])").attr("rel","external");
	$("#sidebar a[rel*=met]").addClass("friend-met");
	
	//ALTERNATING RIGHT AND LEFT PICTURES
	//$("#main_content img:even").addClass("jsright");
	//$("#main_content img:odd").addClass("jsleft");
	
	// ^= equals begins with, $= equals ends with, *= equals contains
	$("a[@href$=.doc]").addClass("word").parent().append(" [doc]");
	$("a[@href$=.pdf]").addClass("pdf").parent().append(" [pdf]");
	$("a[@href$=.xls]").addClass("excel").parent().append(" [xls");
	$("a[@href$=.ppt]").addClass("ppt").parent().append(" [ppt]");
	$("a[@href$=.gif]").addClass("pic").parent().append(" [gif]");
	$("a[@href$=.cpp]").addClass("cpp").parent().append(" [cpp]");
	$("a[@href$=.fla]").addClass("flash").parent().append(" [fla]");
	$("a[@href$=.swf]").addClass("flash").parent().append(" [swf]");
	$("a[@href$=.zip]").addClass("zip").parent().append(" [zip]");

	$("img.me").hover(
      function () {
        $(this).attr("alt","Mr. Brown as a pirate with a jacked up parrot");
        $(this).attr("src","http://teachmetheweb.org/support/gr/uploads/c024b.jpg");
      }, 
      function () {
        $(this).attr("src","http://teachmetheweb.org/support/gr/uploads/c024.jpg");
      }
    );


    //causing errors
    /*
	$("a").hover(
		function() {$("[href="+$(this).attr("href")+"]").addClass("hover").filter(this).css("background-color","none");},
		function() {$("[href="+$(this).attr("href")+"]").removeClass("hover");}
	);*/

	$("#searchField input[type=text]").focus(function(){
           var field=$("#searchField input[type=text]").val();
           if(field=="Search for it"){
               $("#searchField input[type=text]").val("");
           }
        });
	$("#searchField input[type=text]").blur(function(){
           var field=$("#searchField input[type=text]").val();
           if(field==""){
              $("#searchField input[type=text]").val("Search for it");
           }
        });
    
    //tabs ON blog page
	var tabContainersCourse = $('div.fields > div');	
	//TOP SET OF TABS ON blog page
	
	$('#tab-nav a').click(function () {
		tabContainersCourse.hide().filter(this.hash).show();
		$('#tab-nav a').removeClass('current');
		$('#tab-nav a[href="'+this.hash+'"]').addClass('current');				
		return false;
	});//.filter(':first').click();

	var tempHash = jQuery.url.attr("anchor");
	if(tempHash != null){
		tabContainersCourse.hide().filter('#'+tempHash).show();
		$('#tab-nav a').removeClass('current');
		$('#tab-nav a[href="#'+tempHash+'"]').addClass('current');				
	}
    
	var tabContainersTabs = $('#feature div.wrapper > div');
    var DivCount = tabContainersTabs.size();
	if(DivCount>1){ //testing to make sure more than one div before showing next button
        $("#feature a.next").show();
    }
	tabContainersTabs.hide().filter(':first').show();
	var placeHolder=1;
	$('#feature a.next').click(function () {
		var sizeOf = tabContainersTabs.size();
		placeHolder++;
		if(placeHolder>sizeOf){
			placeHolder=1;
		}
		tabContainersTabs.hide().filter('#article'+placeHolder).fadeIn('slow');
		return false;
	});
	
	var c = $.cookie('toggle');
	var ALLofFeature = $('div.home #feature > div');
	if(c=='hide'){
		ALLofFeature.hide();
		$('#toggleFeature img.hide').hide();
		$('#toggleFeature img.show').show();		
		$.cookie('toggle', 'hide', {expires: 365});
	}
	else{
		ALLofFeature.show();
		$('#toggleFeature img.hide').show();
		$('#toggleFeature img.show').hide();		
		$.cookie('toggle', 'show', {expires: 365});
	}
	$('#toggleFeature').click(function () {
		var NowC = $.cookie('toggle');
		ALLofFeature.slideToggle("slow");
		$('#toggleFeature img.hide').toggle();
		$('#toggleFeature img.show').toggle();		
		if(NowC=='hide'){
			$.cookie('toggle', 'show', {expires: 365});
		}
		else{
			$.cookie('toggle', 'hide', {expires: 365});
		}
		return false;
	});
});