$(document).ready(function(){	
	$("a[href^='#']").click(function(e){ e.preventDefault(); }); //for links that only have a hash, don't add the hash to the url
	$("a.email").nospam();
	
	$("#About .employment li").hover(
		function(){
			var c = $(this).attr("class").split(' ')[0];
			$("#bio span."+c+", #bio span."+c+" a").animate({color:"#ff4500"});
		},
		function(){
			var c = $(this).attr("class").split(' ')[0];
			$("#bio span."+c+", #bio span."+c+" a").animate({color:"#222"});			
		}
	);
	$("#featured ol li a").click(function(){
		$(this).parents("ol").find(".active").removeClass("active");
		$(this).addClass("active");
	});

	$('#slider').cycle({
        timeout: 0000,
		next: "#next_featured",
		prev: "#prev_featured",
        pager:"#featured_nav",
		before: function(current_slide, next_slide, options){
			if($("#featured_desc li:visible").length == options.slideCount){ //need this for page load
				$("#featured_desc li").hide();
				$("#featured_desc li").eq(0).show();
			} else {
				$("#featured_desc li:visible").hide();
				$("#featured_desc li").eq(options.nextSlide).show();
			}
			$("#view").attr("href",$(this).attr("href"));
		},
	    pagerAnchorBuilder: function(idx, slide) { 
	        return '<li><a href="#">' + (idx+1) + '</a>'; 
	    }
    });

var fix = function(){
	$('.pic_cycle').cycle({
        timeout: 10000000,
		before: function(current_slide, next_slide, options){
			if(options.loaded == undefined){
				$(this).parents(".pic_wrapper").find(".pic_nav li:contains('Next')").click(function(){
						$(this).cycle.next(options);
						return false;
				});
				$(this).parents(".pic_wrapper").find(".pic_nav li:contains('Prev')").click(function(){
						$(this).cycle.prev(options);
						return false;
				});
				options.loaded = true;
			}
			$(this).parents(".pic_wrapper").find(".pic_nav li:first a").attr("href",$(this).attr("href"));
		}
    });
}
fix();
setTimeout(fix, 1000);
setTimeout(fix, 5000);
setTimeout(fix, 10000);
setTimeout(fix, 20000);


	$('#featured .wrapper').hover(
		function(){
			$('#view').css('color','#0FF');
		},
		function(){
			$('#view').css('color','#FFF');
		}
	);
	
	//HACK ALERT. TODO - remove this ugliness
	$("a[href^='http://"+window.location.hostname+"/ideas/sundries']")
	.add("a[href^='http://"+window.location.hostname+"/ephemera/sundries']").each(function(){
		$(this).attr('href','/sundries'+$(this).attr('href').split('/sundries')[1]);
	});
	
	$("a.show_more").click(function(){
		$(this).html(
			$(this).text()=="more »" ? "less &laquo;" : "more &raquo;"
		);
		$(this).parent().find(".more").slideToggle();
	});
	
	$(".mini_nav").hover(
		function(){
			$(this).find("ul").show();
		},
		function(){
			$(this).find("ul").hide();
	});
	
	$(".mini_nav li, a.bio, a.physcl, a.code, a.gui, a.graphic, a.music, a.fine_art, a.wku, a.innography, a.gotee, a.graffiti, a.passalong, a.hatch, a.quietinc").click(function(){
		var c = $(this).attr("class");
		var offset = (c=="bio" ? 0 : $("#"+c).offset().top - 100);
		$.scrollTo(offset,{duration:1000, easing:'swing'});
	});
		
	$("a:contains('Dokkoise House')").click(function(){
		$("#dont_kid").css('visibility','hidden');
		$("#dokkoise").css('visibility','visible');
	});
	$("a:contains('Kid Yourself')").click(function(){
		$("#dokkoise").css('visibility','hidden');
		$("#dont_kid").css('visibility','visible');
	});
	
	/*
	$("#status_1").click(function(){
		triggerAudio('1','http://formasfunction.dev/wp-content/themes/formasfunction/media/forgiving_monarch.mp3','mp3');
	});
	$("#status_2").click(function(){
		triggerAudio('2','http://formasfunction.dev/wp-content/themes/formasfunction/media/after_the_walk.mp3','mp3');
	});
	*/
	
});

function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
};

function triggerAudio(id, path, type) {
	getFlashMovie("audio_player").triggerAudio(id, path, type);
};

function changeText(id, text) {
	elem = getElement(id);
	elem.innerHTML = text;
};

function toggleClass(id, class_name){
	$("#"+id).toggleClass(class_name);
};