
$(document).ready(function() {  
	stupidLinkFixer();
	fadeSocialMedia();
	alignArticleImages();
	setTableBg();
	unavailableCheckbox();
}); //End document.ready


function stupidLinkFixer() {
	if (top.location != location) {top.location.href = document.location.href;}
	$('#csi, .bigger, div.announcement, div.article-single, #cfimark').biggerlink({otherstriggermaster:false}); 	//make entire elements clickable
	$('#sidebar ul.subnav li.inactive, #sidebar li.active, #cfimark').biggerlink();
}


function fadeSocialMedia() {
	$('div#socialMedia').fadeTo(1, .4).hover(function() {
		$(this).fadeTo(400, 1);
	}, function() {
		$(this).fadeTo(400, .4);
	});
}


function alignArticleImages() {
	$("div#content").find("div.image").each(function() {
		var imageWidth = $("img", this).outerWidth();
		$(this).width(imageWidth);
	}).end().find("div.right, div.left").addClass("js_float");
}


function setTableBg() {
	$("table.hash tr td:even").css("background", "#7fc5d4");
	$("table.hash tr td:odd").css("background", "#cbf6ff");
	$("table.zebra tr:odd").css("background", "#7fc5d4");
}


function unavailableCheckbox(){
	var unavailable = $('.unavailable');
	if (unavailable.size() != 0) {
		$('div.showall').show().attr("checked", true);
	}; // if unavailable...
	$('input#showallarticles:checkbox').bind('click', function() { //Hide articles on archive pages
	  if ($(this).attr("checked") == false){
		unavailable.slideUp();
		$(this).attr("checked", false);
	  }
	  else {
		unavailable.slideDown();
		$(this).attr("checked", true);
	  };
	});
};

// function ajaxify(selector){
// 	$(selector).each(function(){
// 		var url = $(this).attr('href')
//         if (url.match('archive')) {
//             url = url.replace("/archive", "/ajaxarchive");
//             url = url.replace(/.*org/, "");
//             }
//         else if(url.split('/')[3].match(/P\d+/gi)) {
//             url = '/whatsnew/' + url.split('/')[3]
//             };
// 		$(this).bind('click', function(){
// 				fetchPage(url)
// 			});
//         
//         $('#csi, .bigger, div.announcement, div.article-single, #cfimark').biggerlink({otherstriggermaster:false}); 	//make entire elements clickable
// 		$(this).attr('href', '#top');
// 
// 	});
// };


// function fetchPage(url){
// $.ajax({
//   type: "GET",
//   url: url,
//   success: function(data){
//         //scroll(0,200);
// 	  $('#ajaxReload').fadeOut(200, function(){
// 		  $('#ajaxReload').html(data);
// 	  }).fadeIn(200, function(){
// 		ajaxify('#pagination a');
// 		$('body').hide().show();
// 		fixcolumns();
// 	 });
//   }
// });
// };


// function fixcolumns(){
//   var content       = $("#content") 
//   var sidebar       = $('#sidebar')       // Cache a bunch of selectors and bludgeon all the heights into compliance
//   var wrapper       = $('#wrapper')	
//   var sidebarHeight	= sidebar.height(); 	// Equalize #sidebar, #content, and #content_wrapper
//   var bodyHeight	= content.height(); 	// get #body's height
//   var bio           = $("#bio");
//   var bioHeight     = bio.height();
//   var fudgeFactor   = 0;
// 
//   if ( bioHeight ){
//     fudgeFactor   = 30;
//     if (navigator.appName == "Microsoft Internet Explorer"){ wrapper.css("paddingBottom", 20); }; // ( IE vs. CSS ) == Fail
//     };
// 
//   if ( sidebarHeight > (bodyHeight + bioHeight) ) { // Balance Columns
//     content.height(sidebarHeight - bioHeight - fudgeFactor);
//     wrapper.hide().show()
//     };
// };


// $(document).ready(function() {
	// If you don't sanitize first, the biggerlink() function breaks when its targets are parsed
	  // if (top.location != location) {top.location.href = document.location.href;} // Get your own website, Digg and Facebook

	  // $('#moreoptions a').click(function () {
	  //   $('#footer').fadeTo("slow", .2).fadeTo("slow", 1);
	  // });
    
	// $('ul.kwicks').kwicks({max: 250, spacing: 5});	//Kwicks functionality for Primary Nav 
	// $("a[rel='external']").append('<span class="external-link">&nbsp;&rarr;</span>');

	// var orgLinks = $('')
	// 	orgLinks.fadeTo(1, .15); 	//fade out the CFI and CSH buttons
	// 
	// 	var activeLi = $('')
	// 	var inactiveLi = 

	// $('#csi, .bigger, div.announcement, div.article-single, #cfimark').biggerlink({otherstriggermaster:false}); 	//make entire elements clickable
	// $('#sidebar ul.subnav li.inactive, #sidebar li.active, #cfimark').biggerlink();
	// $("#sidebar input.nuke").click(function () { 
	//   $(this).attr({value: ""});
	// });
	

	

	// orgLinks.hover( 		//fade them in and out on hover
	// 	function() {
	//       $(this).fadeTo('fast', .9);
	// 		},
	// 	function() {
	//       $(this).fadeTo('slow', .15);
	// 		});
	// 
	// inactiveLi.fadeTo(1, .6);	//Fade out sidebar subnav links
	// inactiveLi.hover(
	// 	function() {
	// 		$(this).fadeTo(400, 1);
	// 		activeLi.fadeTo(400, .6);
	// 		},
	// 	function() {
	// 		$(this).fadeTo(400, .6);
	// 		activeLi.fadeTo(400, 1);
	// 		});

	// ajaxify('#pagination a');



	//if (navigator.appName == "Microsoft Internet Explorer"){ // Hate
			// if (navigator.appVersion == '4.0 (compatible; MSIE 6.0; Windows NT 5.1)') {
			// 	$('.kwicks li').css({backgroundImage: 'url(/img/ie6sprite1.png)'}).hide().show(); //added with js for accessibility
			// }; // end ie6 test
	//	}; // end ie test
// });
