
$(document).ready(function() {
	// setup fancyzoom
	setupZoom();
	
	// setup right column links to hover "properly" on top child
	$("#right ul li ul li:not(.active) a").hover(
		 function () {
        	//$(this).parent("ul").slideUp();
			var $parent 		= $(this).parents('ul');
			var $son			= $(this).parents('li');
			var $num 			= $parent.children().index($son);
			var $grandparent 	= $parent.parents('ul li');
			var $date			= $grandparent.find(".thedate");
			if ($num<1){
				$date.css("backgroundColor","#eeeedf");
			}
     	 }, 
      	function () {
       		var $parent 		= $(this).parents('ul');
			var $son			= $(this).parents('li');
			var $num 			= $parent.children().index($son);
			var $grandparent 	= $parent.parents('ul li');
			var $date			= $grandparent.find(".thedate");
			if ($num<1){
				$date.css("backgroundColor","#ffffff");
			}
      	}
								
	);
	// check right column for active state
	if ($("#right ul li ul li.active").exists()){
		var $targ				= $("#right ul li ul li.active a");
		var $parent 		= $targ.parents('ul');
		var $son			= $targ.parents('li');
		var $num 			= $parent.children().index($son);
		var $grandparent 	= $parent.parents('ul li');
		var $date			= $grandparent.find(".thedate");
		$date.css("backgroundColor","#eeeedf");
	}
	
	// setup SWF for audio playing
	var so = new SWFObject("/wp-content/themes/wott/_swf/preview.swf", "previewer", "10", "10", "9", "#000");
	so.addParam("wmode","transparent");
	so.addParam("allowscriptaccess","always");
	so.write("audio_preview");
	
	// setup podcast STREAM link to play mp3
	nowPlaying = false;
	$("#podcastStreamLink").click(
		function(){
			if (nowPlaying){
				jsStopAudio();
				$(this).removeClass("active");
				$(this).html("Play Episode");
			} else {
				jsSendAudio($(this).attr("href"));	
				$(this).addClass("active");
				$(this).html("Stop Episode");
			}
			return false;
		}
	);
	
});


/* WE OWN THIS TOWN  */
var wott = {};

wott.calHover = function(bodyID, mask, container, iteration){
	var width = $("body#"+bodyID+" ."+mask).width();
	var dest = parseInt(width * iteration) * -1;

	var margin = (iteration) * 10;
	var dest = dest - margin;
	
	$("body#"+bodyID+" ."+container).animate({ 
			marginLeft: dest
		  }, 700 );
	
}

/* jQUERY */
/*	******************************
		PLUGIN - Utility Functions 
		Author: Jack Lukic - KNI (all plugins)
		Notes: Used to extend jQuery functionality and shorten code
	******************************	*/

jQuery.fn.extend({
	// test if el exists
	exists: function() {
		if(this.size() > 0) {
			return true;
		}
		else {
			return false;	
		}
	}
});

function $$(id) {
	 if ($.browser.msie) {
		return window[id];
	 }
	 else {
		return document[id];
	 }
}
function jsSendAudio(mp3) {
	if (nowPlaying){
		jsStopAudio();
	}
	$$('previewer').sendAudio(mp3);
	nowPlaying = true;
}
function jsStopAudio(){
	$$('previewer').stopAudio();
	nowPlaying = false;
}

