// Sitewide scripts using jquery
//place this at the bottom of other script includes to activate jquery plugins

$(document).ready(function(){ 
	var load_video = function(href) {
		$("#videos").flash(
			{ 
			  src: 'movie_player.swf',
			  width: 320,
			  height: 285,
			  wmode: "transparent",
			  flashvars: { streamName: 'video/' + href }
			},
			{ version: 8 },
			function(htmlOptions) {
				$this = $(this);
				$this.html($.fn.flash.transform(htmlOptions));						
			}
		);
	};
	
	var gallery = function() {
		$(".thumbbox").mouseover(function() {
			$(this).addClass("hover")
				.siblings().removeClass("hover");
		})
			.click(function() {
				var $box = $(this);
				var href = $box.children("a").attr("href");
				var title = $box.children("a").attr("title");
				load_video(href); //load the video
				$("#playing span#title").text(title);//update now playing title
				return false;
			});
	}
	var get_videos = function(id) {
		$.getJSON("chamber_json.php", {id: id}, function(data) {
			$("#thumbnails").empty();
			$.each(data.video, function(i,item){
				var $div = $("<div class='thumbbox'></div>");
				var $img = $("<img />").attr("src", "images/thumbs/" + item.thumb);
				$("<a></a>").attr("href", item.href).attr("title", item.title).html($img).appendTo($div);
				$("<h1></h1>").text(item.title).appendTo($div);
				$div.append(item.description);
				$div.appendTo("#thumbnails");
			});
			gallery();
			//load in a&w rootbeer ad
			//$('<div class="thumbbox"><a href="http://awrootbeer.com/90_anniversary.php" target="_blank"><img src="images/aw_win.jpg" alt="Win a Trip to Lodi - home of A&amp;W Rootbeer" width="316" height="72" border="0"></a></div>').appendTo("#thumbnails");
		});
	};
	$("#category").change(function() {
		var id = $(this).val();
		get_videos(id);
	});
	//load first set of videos on page load
	get_videos(1);
	load_video("PatPatrick_F8_300K-97299.flv");
});