
$(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;
		}
	);
	// reveal interior players with "reveal" link
	$("#center a.reveal").click(function(){
		// find the hidden
		$hidden = $(this).parents().find(".hidden");
		$hidden.slideDown();
		
		return false;
	});
	$("object").each(function() {
			if ($(this).find("param[value^='http://www.youtube.com']").length > 0) {
				var parent = $(this).parent();
				var youtubeCode = parent.html();
				var params = "";
				if (youtubeCode.toLowerCase().indexOf("<param") == -1) {
					$("param", this).each(function() {
						params += $(this).get(0).outerHTML;
					});
				}
				var oldOpts = /rel=0/g;
				var newOpts = "rel=0&amp;color1=0xFFFFFF&amp;color2=0xFFFFFF&showinfo=0";
				youtubeCode = youtubeCode.replace(oldOpts, newOpts);
				if (params != "") {
					params = params.replace(oldOpts, newOpts);
					youtubeCode = youtubeCode.replace(/<embed/i, params + "<embed");
				}
				parent.html(youtubeCode);
			}
		});

	oneBit = new OneBit('/wp-content/themes/wott/_swf/1bit.swf');
	oneBit.ready(function() {
	oneBit.specify('color', '#DC9A06');
	oneBit.specify('background', '#FFFFFF');
	oneBit.specify('playerSize', '10');
	oneBit.specify('position', 'after');
	oneBit.specify('analytics', false);
	oneBit.apply('#center a');
	}); 
	
});


/* 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;
}


