/**
 * Travel JavaScripts
 * This file should be used to store all site-wide scripts.
 */ 

$(document).ready(function () {

	// Thumbnail navigation for the Featured gallery widget

  $("a#nextgallery").bind("click", function(e) {
		e.preventDefault();
		var thumb = $("div.gallnav ul.thumbs li.active");
		thumb.removeClass("active");
		if (thumb.next().is("li")) thumb.next().addClass("active");
		else $("div.gallnav ul.thumbs li:first").addClass("active");
	});

	$("a#prevgallery").bind("click", function(e) {
		e.preventDefault();
		var thumb = $("div.gallnav ul.thumbs li.active");
		thumb.removeClass("active");
		if (thumb.prev().is("li")) thumb.prev().addClass("active");
		else $("div.gallnav ul.thumbs li:last").addClass("active");
	});

	/**
	 * Flash Info Popup
	 * Requires jQuery 1.3.2+.
	 */ 
	$("div#flashInfoStoryEmbed a").bind("click", function(e) {
		var flashInfoURL = $(this).attr("href");
		
		if (flashInfoURL != '') {
			window.open(flashInfoURL, "flashInfo", "width=950,height=670,left=0,top=0");
		}
		
		return false;
	});
	
	/**
	 * Video Widget
	 * Requires jQuery 1.3.1+.
	 */
	if ($('#videoPlayer').length > 0) _canoevideo();
    
});

/* This function is no longer the same as the one that appears on other channels, to account
 * for requirements as per request 41918 (June 25, 2009). Most important, the tabs have been
 * removed and the playlist is hardcoded, so the anchor param is ignored. (mhogg)
 */

function _canoevideo(anchor)
{

	jQuery.getJSON('http://en.video.canoe.tv/api/playlist/' + '1896809980' + '?format=json&limit=2&callback=?', function(data) {
		$('#videoPlayer .content').empty();
		$.each(data.videos, function(i, video) {
			if (i == 0) {
				$('#videoPlayer .content').append('<a href="http://travel.canoe.ca/Travel/Video/home.html?vid=' + video.id + '" title="' + video.name + '" target="_blank"><img class="featured" src="' + video.thumbnail_url + '" alt="pic for ' + video.name + '" width="170" /></a>');
			}
			$('#videoPlayer .content').append('<div class="video"><a href="http://travel.canoe.ca/Travel/Video/home.html?vid=' + video.id + '" title="' + video.name + '" target="_blank"><img src="' + video.thumbnail_url + '" width="40" height="30" /></a><p><a href="http://travel.canoe.ca/Travel/Video/home.html?vid=' + video.id + '" title="' + video.name + '" target="_blank">' + video.name + '</a></p></div>');
		});
	});

  return false;
}
