var loader = { 
  imgs: [],
  load: function(src) {img=this.imgs; var ct=img.length; img[ct]=new Image();img[ct].src=src;}
};
$(function() {

  /* roll over */
  $("a.ro").each(function() { loader.load($(this).children('img').attr('src').replace(/(\.[a-z]{3})$/i,"-on$1"));});
  $("a.ro").mouseover(function() {
    var src=$(this).children('img').attr('src');
    $(this).children('img').attr('src', src.replace(/(\.[a-z]{3})$/i,"-on$1"));
  });
  $("a.ro").mouseout(function() {
    var src=$(this).children('img').attr('src');
    $(this).children('img').attr('src', src.replace(/-on\./,"."));
  });
	
	if (/*@cc_on!@*/false) { t=0;} else { t=200;}
	$("a.over").hover(function(){ $(this).children('img').animate({opacity:0.7,filter:"alpha(opacity=70)"},t);}, function(){ $(this).children('img').animate({opacity:1,filter:"alpha(opacity=100)"},t);});
  
});

/**
 * Produce Live video
 */
var producelive = {
	params: { allowScriptAccess: "always" },
	atts:   { id: "side-movie" },
	movieID:	"",
	
	init:	function(movieID) {
		this.movieID = movieID;
		swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&version=3&playerapiid=side", "inner", "250", "177", "8", null, null, this.params, this.atts);
	},
	process:	function() {
		sidemovie = document.getElementById("side-movie");
		sidemovie.loadVideoById(this.movieID, 0);
		sidemovie.mute();
		sidemovie.addEventListener("onStateChange", "producelive.ytStatusChange");
	},
	ytStatusChange: function(newState) {
   if (newState == 0) {
		 sidemovie.playVideo();
	 }
  }	
	
};
function onYouTubePlayerReady(playerId) {
	if (playerId == "side") {
		producelive.process();
	}
}


/**
 * records
 */
var records = {
	params: { allowScriptAccess: "always" },
	
	init:	function(movieID, domID) {
		swfobject.embedSWF("http://www.youtube.com/v/"+movieID+"?enablejsapi=1&playerapiid="+domID, domID, "200", "110", "8", null, null, this.params, {id: domID});
	}
};


/**
 * popup
 */
var popup = {
	params:	[],
	domID:	"inner",
	movieparams: { allowScriptAccess: "always"},

	view:	function(type, fileID) {
		window.open("../popup.html?type="+type+"&fileID="+fileID, "popup", "width=580,height=400,scrollbars=no,location=no");
		return false;
	},
	
	init:	function() {
		this.parser();
		if (this.params["type"] == "movie") {
			this.showMovie();
		} else if (this.params["type"] == "audio") {
			this.playAudio();
		} else {
			return false;
		}
	},
	
	parser:	function() {
		// get query string
		if (location.search.length > 1) {
			var params = [];
			var q = location.search.substr(1).split("&");
			for (var i in q) {
				var buf = q[i].split("=");
				this.params[buf[0]] = buf[1];
			}
		}
	},
	
	showMovie:	function() {
		swfobject.embedSWF("http://www.youtube.com/v/"+this.params["fileID"]+"?enablejsapi=1&playerapiid="+this.domID, this.domID, "560", "345", "8", null, null, this.movieparams, {id: this.domID});
	},
	
	playAudio:	function() {
		this.movieparams["flashvars"] = "file=wp-content/uploads/"+this.params["fileID"]+"&autoplay=true";
		swfobject.embedSWF("flaver.swf", this.domID, "500", "200", "9", null, null, this.movieparams, {id: this.domID});
	}
};


