var newsPageClass = 'page-item-26';
var newsParentClass = 'page-item-92';

var hpPhotos  = {
	index: 0,
	count: 0,
	path: '/wp-content/uploads/'
};

// equal column height function
function equalHeight(group) {
    tallest = 0;
    group.each(function() {
        thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}

$(document).ready(function() {

	/* Accessible input values */
	$("input.propagate").each(function(){
	var $this = $(this);
	var val = $('label[for=' + $this.attr('id') + ']').html();
	if($this.val() == '') $this.val(val);
	$this.focus(function(){
	  if($this.val() == val) $this.val('');
	}).blur(function(){
	  if($this.val() == '') $this.val(val);
	});
	});

//	if (($('li.current_page_item').length == 0)&&($('h1#home-header').length == 0)) {
//			$('li.'+newsPageClass+',li.'+newsParentClass).addClass('current_page_item');
//	}
	// add .after class to list item that follows the .current list item
	/*
	$("#navigation .current_page_item").next().addClass("after");
	$("#navigation .current_page_item").prev().addClass("before");
	$("#navigation .current_page_parent").next().addClass("after");
	$("#navigation .current_page_parent").prev().addClass("before");
	$("#navigation .current_page_ancestor").next().addClass("after");
	$("#navigation .current_page_ancestor").prev().addClass("before");
	$("#navigation ul li:first-child").addClass("first");
	$("#navigation ul li:last-child").addClass("last");*/

// check if it's a blog post, if so update 

	if ($('div#nav ul').attr('rel')) {
		var p = $('div#nav ul').attr('rel');
		var pLi = $('.page-item-'+p);
	
		pLi.parent().parent().addClass('current_page_ancestor current_page_parent');
		pLi.addClass('current_page_item');
	}
	
	
	$('div#nav > ul > li.current_page_parent,div#nav > ul > li.current_page_item').next().addClass('after');
	$('div#nav > ul > li.current_page_parent,div#nav > ul > li.current_page_item').prev().addClass('before');
	$('div#nav > ul > li:first-child').addClass('first');
	$('div#nav > ul > li:last-child').addClass('last');





	// last class for subnav
	$(".subnav ul li:last-child").addClass("last");


	if ($('#home-masthead').length > 0) {
		// get homepage images
		homePhotos ? hpImages = homePhotos.split(',') : Array();

		hpPhotos.count = hpImages.length;
		for (var i=0; i<hpPhotos.count; i++) {
			$('#home-masthead').prepend('<img src="'+hpPhotos.path+hpImages[i]+'" class="hp" alt="" style="display: none" />');
		}
		r = Math.floor(Math.random()*hpPhotos.count);
		hpPhotos.index = r;
		swapPhoto();
		setInterval(swapPhoto, 3000);
	}

	$('.posts-per-page').change(function() {
		var loc = location.href.split('?')[0];
		location.href = loc+'?posts='+this.options[this.selectedIndex].value;
	});

	/*
	if ($('#sidebar').height() < 300) {
		alert($('#sidebar').height());
		$('#sidebar').css('padding-bottom','120px');
	}
	else {
		alert($('#sidebar').height());
	}*/
});

$(window).load(function() {
	// equal heights
	equalHeight($(".column"));
	$('#sidebar').css('padding-bottom','120px');
});
function swapPhoto() {
	if (hpPhotos.index == hpPhotos.count) {
		hpPhotos.index = 0;
	}
	$('.hp:visible').fadeOut(1000);
	$('.hp:nth-child('+(parseInt(hpPhotos.index)+1)+')').fadeIn(1000);
	hpPhotos.index++;
}

