var scroller;

$(document).ready(function() {
	
	$(".menu").children("li").hover(
		function() {
			$(this).children(".link_over").toggle(true);
			$(this).children(".children").toggle(true);
		},
		function() {
			if(!$(this).is(".current_page_item, .current_page_ancestor")) $(this).children(".link_over").toggle(false);
			$(this).children(".children").toggle(false);
		}
	);
	
	$(".fade").hover(
		function() { $(this).stop(true,true).fadeTo("fast",0.6); },
		function() { $(this).stop(true,true).fadeTo("fast",1); }
	);
	
	var link_over = $("#link_over_placeholder").html();
	var the_link;
	$("#header_menu").find("li").each(function() {
		the_link = $('<div>').append($(this).children("a:first").clone()).html();
		$(this).append($(link_over));
		$(this).children(".link_over").append($(the_link));
	});
	
	$("#header_menu>li:first>.children").remove();
	
	$(".children li").each(function() { $(this).width($(this).parent().width()); });
	
	$("#header_menu .current_page_item .link_over").toggle(true);
	$("#header_menu .current_page_ancestor .link_over").toggle(true);
	
});

$(window).load(
	function() {
		main_pic = $("#main_image_holder > .wp-post-image");
		main_pic.height(main_pic.parent().width()/main_pic.width() * main_pic.parent().height());
		main_pic.width(main_pic.parent().width());
		main_pic.css("margin-top",(0-(main_pic.height()-main_pic.parent().height())/2) + "px");
		
		scroller = $("#image_scroller_images");
		if(scroller.length == 0) return;
		images = $("#image_scroller_images img");
		scroller.width((images.length + 1) * 800);
		images.eq(0).clone().appendTo("#image_scroller_images");
		imageSlide();
	}
);

function imageSlide() {
	if(scroller.css("left") == (800-scroller.width() + "px")) scroller.css("left","0px");
	scroller.delay(2500).animate({ left: '-=800' },500,imageSlide);
}

function limitText(limitField,limitNum) {
	if(limitField.value.length > limitNum) limitField.value = limitField.value.substring(0,limitNum);
}
