//for safari
$(window).bind("load", function() {
	if(!$.fontAvailable('Pointy')) {
       Cufon.replace('.sidebar_pets h3, #homepage_stuff .homepage_stuff_inside h2, .entry h2:not(.pet_info h2), .entry h2 a:not(.pet_info h2 a), .entry div.pet_content h3');
    }

});
$(document).ready(function() {
	if(!$.fontAvailable('Pointy')) {
       Cufon.replace('.sidebar_pets h3, #homepage_stuff .homepage_stuff_inside h2, .entry h2:not(.pet_info h2), .entry h2 a:not(.pet_info h2 a), .entry div.pet_content h3');
    }

	$("ul.news-links li a").click(function() {
		$("ul.news-links li").removeClass('current');
		$(this).parent().addClass('current');
		$("div.homepage_news_panel:visible").stop().hide();
		var eyeD = $(this).attr("href");
		$("div"+eyeD).stop().fadeIn("fast");
		return false;
	});
	$(".pet_info a.photo").click(function() {
		var photoEyeD = $(this).attr("href");
		$(".pet_info a").removeClass('current');
		$(".pet_info a[href="+photoEyeD+"]").addClass('current');
		$(".pet_image img").removeClass('current');
		$(".pet_image img[id="+photoEyeD+"]").addClass('current');
		return false;
	});
	var nextPost = $(".next_post");
	$.each(nextPost, function() {
		var nextImg = "";
		if($(this).parent().parent().is(":last-child")) {
			nextImg = $(".animal:first").find(".pet_info .pet_photies a.photo:first").html();
		} else {
			nextImg = $(this).parent().parent().next().find(".pet_info .pet_photies a.photo:first").html();
		}
		$(this).append("<span>next</span>");
		$(this).append(nextImg);
		
	});
	$(".next_post").click(function() {
		if ($(this).parent().parent().is(":last-child")) {
			$(".animal:first").addClass("current_animal");
			$(this).parent().parent().removeClass("current_animal");
			$(".current_animal").find(".pet_image img:first").addClass('current');
			$(".current_animal").find(".pet_info a:first").addClass('current');
		} else {
			$(this).parent().parent().next(".animal").addClass("current_animal");
			$(this).parent().parent().removeClass("current_animal");
			$(".current_animal").find(".pet_image img:first").addClass('current');
			$(".current_animal").find(".pet_info a:first").addClass('current');
		}
		return false;
	});
	var prevPost = $(".prev_post");
	$.each(prevPost, function() {
		var prevImg = "";
		if($(this).parent().parent().is(":first-child")) {
			prevImg = $(".animal:last").find(".pet_info .pet_photies a.photo:first").html();
		} else {
			prevImg = $(this).parent().parent().prev().find(".pet_info .pet_photies a.photo:first").html();
		}
		$(this).append("<span>previous</span>");
		$(this).append(prevImg);
	});
	
	$(".prev_post").click(function() {
		if ($(this).parent().parent().is(":first-child")) {
			$(".animal:last").addClass("current_animal");
			$(this).parent().parent().removeClass("current_animal");
			$(".pet_image img").removeClass('current');
			$(".pet_info a").removeClass('current');
			$(".current_animal").find(".pet_image img:first").addClass('current');
			$(".current_animal").find(".pet_info a:first").addClass('current');
		} else {
			$(this).parent().parent().prev(".animal").addClass("current_animal");
			$(this).parent().parent().removeClass("current_animal");
			$(".pet_image img").removeClass('current');
			$(".pet_info a").removeClass('current');
			$(".current_animal").find(".pet_image img:first").addClass('current');
			$(".current_animal").find(".pet_info a:first").addClass('current');
		}
		return false;
	});
	$("#s").focus(function() {
		$(this).val("");
	});
	$('body').upUpDownDown({
        watchFor: [38,38,40,40,37,39,37,39,66,65],
        callback: function(){
            $('body').append("<div style='position:absolute;top:100px;left:100px;z-index:599999;'><img src='/wp-content/themes/kindnessranch/images/bacon.png' width='698' height='382' alt='' /></div>");
        }
    });

});

(function(jQuery) {
    jQuery.fn.upUpDownDown = function(o){
        var options = jQuery.extend({
                                        watchFor : [38,38,40,40,37,39,37,39,66,65],
                                        callback : function() { }
                                    }, o);
        
        var key_accum = [];
        var match = options.watchFor;
 
        $(document).keyup(function(e){
            len = key_accum.push(e.keyCode ? e.keyCode : e.charCode);
            
            if(len > match.length) key_accum.shift();
            
            if (key_accum.join('-') == match.join('-'))
            {
                key_accum = [];
                if (options.callback)
                {
                    options.callback($(this));
                }
            }
        });
    }
})(jQuery);