// vAlign plugin, vertically centers things. Just call .vAlign() after selector.
(function ($) {
	$.fn.vAlign = function() {
		return this.each(function(i){
		var ah = $(this).height();
		var ph = $(this).parent().height();
		var mh = (ph - ah) / 2;
		$(this).css('margin-top', mh);
		});
	};
})(jQuery);

$(function(){

var max_size = 600;
$("#postContent .wp-caption img").each(function(i) {
  if ($(this).width() > max_size) {
    //var h = max_size;
    var w = max_size;
  }
 // } else {
 //   var w = max_size;
 //   var h = Math.ceil($(this).height() / $(this).width() * max_size);
 // }
  $(this).css({ width: w, height: "auto" });
});
	
	// Center image once it's loaded. Cures weird bug where images would center, the load, cutting half off.
	//$("#sidebarAuthor #authorArt a img").vAlign();
	//$("#sidebarAuthor #authorArt a img, .blogHomeItemImage img").vAlign();
	
	//Add odd & even classes to comments, if not IE6
	$("#commentList li:odd").addClass("odd");
	$("#commentList li:even").addClass("even");
	
	// Drop down menus - intial hover
	$('#nav li').mouseover(function(){
		$("ul", this).stop(true, true).css("display","inline");
	});
	$('#nav li').mouseleave(function(){
		$("ul", this).stop(true, true).css("display","none");
	});

	// Drop down menus - stay open
	$('#nav li ul').mouseover(function(){
		$(this).stop(true, true).css("display","inline");
	});
	$('#nav li ul').mouseleave(function(){
		$(this).stop(true, true).css("display","none");
	});
	
	// Slide 'Discover New Art Online' box, & append bottom fade image
	$("#discoverNewArtOnline").append('<a href="#" class="discoverNewArtOnlineTriggerOff">More...</a>');
	$("#discoverNewArtOnline").find('p').slice(4,10).hide().css("opacity","0");
	$("#discoverNewArtOnline a").toggle(function() {
		$("#discoverNewArtOnline").find('p').slice(4,10).slideDown().animate({opacity: 1});
		$(this).removeClass("discoverNewArtOnlineTriggerOff");
		$(this).addClass("discoverNewArtOnlineTriggerOn");
		$(this).html('Less...');
	},function() {
		$("#discoverNewArtOnline").find('p').slice(4,10).animate({opacity: 0}).slideUp();
		$(this).removeClass("discoverNewArtOnlineTriggerOn");
		$(this).addClass("discoverNewArtOnlineTriggerOff");
		$(this).html('More...');
	});
	
	// Get width of sidebarAuthor text, and set it
	$("#sidebarAuthor .author").load(function(){
		var imageWidth = $("#sidebarAuthor img").width();
		textWidth = 310 - imageWidth;
		$("#sidebarAuthor p").css({"width":textWidth,"float":"right"});
	});
	
	if (window.XMLHttpRequest) {
		var zIndexNumber = 400;
		//console.log("is not IE 6");
	} else {
		var zIndexNumber = 300;
		//console.log("is IE 6");
	}
	$(function() {
		$("#header div").each(function() {
			$(this).css('zIndex', zIndexNumber);
			zIndexNumber -= 1;
		});
	});
	
});

jQuery.fn.center = function () {  
    this.css("position","absolute");  
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");  
    return this;  
}
$(function(){
    $("#headerIn").center();
});
$(window).resize(function(){
    $("#headerIn").center();
});