//This will not allow other libraries that Wordpress might try to use override jquery
jQuery.noConflict();

var smallH = 630;
var largeH = 750;
var smallW = 1000;

// Initialize a variable to track if the footer is opened or closed
var isShown = false;

jQuery(document).ready(function(){
		
	// Get the window dimensions at load time
	var windowHeight = jQuery(window).height();
	var windowWidth = jQuery(window).width();	
		
	//Show the toggle link if JS is on
	jQuery("#footer-link").show();
	
	//Hide Trackbacks
	jQuery("#trackbacks-list").hide();
	
	//Initialize footer widgets
	jQuery("#blog").show();
	jQuery("#author").hide();
	jQuery("#other").hide();
	jQuery("#footer-nav-blog").addClass("active");
			
	//Change some things around based on window size
	if(windowHeight < smallH) {
		jQuery('#logo').addClass("up");
	}
	
	if(windowHeight > largeH) {
		jQuery(".entry-extra").css("display","block");
	}
	
	if(windowWidth < smallW) {
		jQuery("#left-col2-widgets").hide();
		jQuery("#content").css("margin-left","250px");	
		jQuery("#logo").addClass("small");
	} else {
		jQuery("#left-col2-widgets").show();
		jQuery("#content").css("margin-left","450px");
	}

	
	// Collapsable footer with dynamic image
	jQuery(function()
	{
		jQuery("#toggle").click(function(event) {
			event.preventDefault();
			jQuery("#footer-widgets").slideToggle();

			isShown = (isShown ? false : true);
			
			var windowHeight = jQuery(window).height();
			var windowWidth = jQuery(window).width();
			if (windowHeight > smallH && windowWidth > smallW) {
				if (!isShown) {
					jQuery('#logo').fadeOut(function () {
						jQuery("#logo").removeClass("up");
					});	
					jQuery('#logo').fadeIn();
				} else {
					jQuery('#logo').fadeOut(function () {
						jQuery("#logo").addClass("up");
					});	
					jQuery('#logo').fadeIn();
				}
			}
		});
				
		jQuery("#comments-link").click(function(event) {
			event.preventDefault();
			jQuery("#trackbacks-list").slideUp("fast",function () {
				jQuery("#comments-list").slideDown("fast");
			});
		});
		
		jQuery("#trackbacks-link").click(function(event) {
			event.preventDefault();
			jQuery("#comments-list").slideUp("fast",function () {
				jQuery("#trackbacks-list").slideDown("fast");
			});
		});

		jQuery("#footer-nav-blog").click(function(event) {
			jQuery("#footer-nav-author").removeClass("active");
			jQuery("#footer-nav-other").removeClass("active");
			jQuery("#footer-nav-blog").addClass("active");
			jQuery("#author").slideUp("fast", function () {
				jQuery("#other").slideUp("fast", function () {
					jQuery("#blog").slideDown("fast");
				});
			});
		});

		jQuery("#footer-nav-author").click(function(event) {
			jQuery("#footer-nav-blog").removeClass("active");
			jQuery("#footer-nav-other").removeClass("active");
			jQuery("#footer-nav-author").toggleClass("active");
			jQuery("#blog").slideUp("fast", function () {
				jQuery("#other").slideUp("fast", function () {
					jQuery("#author").slideDown("fast");
				});
			});
		});

		jQuery("#footer-nav-other").click(function(event) {
			jQuery("#footer-nav-author").removeClass("active");
			jQuery("#footer-nav-blog").removeClass("active");
			jQuery("#footer-nav-other").toggleClass("active");
			jQuery("#author").slideUp("fast", function () {
				jQuery("#blog").slideUp("fast", function () {
					jQuery("#other").slideDown("fast");
				});
			});
		});
		
	});        
});

// On resize handler for all browsers to allow the logo image to correct itself if the browser gets larger
jQuery(window).resize(function(){
	var windowHeight = jQuery(window).height();
	var windowWidth = jQuery(window).width();
	
	if(!isShown) {
		if(windowHeight > smallH) {
			jQuery('#logo').removeClass("up");
		} else {
			jQuery('#logo').addClass("up");
		}
	}
	
	if(windowHeight > largeH) {
		jQuery(".entry-extra").css("display","block");
	} else {
		jQuery(".entry-extra").css("display","none");
	}
	
	if(windowWidth < smallW) {
		jQuery("#left-col2-widgets").hide();
		jQuery("#content").css("margin-left","250px");
		jQuery("#logo").addClass("small");
	} else {
		jQuery("#left-col2-widgets").show();
		jQuery("#content").css("margin-left","450px");
		jQuery("#logo").removeClass("small");
	}

});

