function jsCarousel() {
	jQuery('#jscarousel').html('<ul></ul>');
	jQuery.ajax({
		type: 'GET',
	    url: xmlfeed,
	    dataType: "xml",
	    success: function(data) {
	        jQuery(data).find("item").each(function (i) {
				jQuery("#jscarousel ul").append('<li rel="' + jQuery(this).find("image").text() + '"><div class="jscarousel-tile" style="background-image:url(' + jQuery(this).find("thumbnail").text() + ');"><div class="jscarousel-border"></div></div><p class="jscarousel-title">' + jQuery(this).find("title").text() + '</p><p class="jscarousel-description">' + jQuery(this).find("description").text() + '</p><p class="jscarousel-links">' + jQuery(this).find("links").xml() + '</p><p class="jscarousel-tune-in jscarousel-tune-in-left">' + jQuery(this).find("tuneIn[position=left]").text() + '</p><p class="jscarousel-tune-in jscarousel-tune-in-right">' + jQuery(this).find("tuneIn[position=right]").text() + '</p></li>');
			});
			if (jQuery('#jscarousel ul li').size() > 5) {
				jQuery('#js-next').css({opacity: 1});
			}
			var deviceAgent = navigator.userAgent.toLowerCase();
			var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
			if (agentID) {
				jQuery('.jscarousel-links a.overlay-video').remove();
			}
			if (jQuery('body#inside-the-music').size() > 0) {
				number = 5;
			} else {
				number = 4;
			}
			jQuery('#jscarousel').jCarouselLite({
				vertical: false,
				visible: number,
				scroll: 1,
				speed: 750,
				circular: false,
				auto: 5000,
				pause: true,
				beforeStart: function(a) {					
					if (jQuery('#js-next.hover, #js-prev.hover').size() < 0) {
						if (jQuery(a[0]).is(".selected")) {
							jQuery(a[1]).click();
							jQuery('#jscarousel-image').animate({
								opacity: 1
							});
						} else if (jQuery(a[1]).is(".selected")) {
							jQuery(a[2]).click();
							jQuery('#jscarousel-image').animate({
								opacity: 1
							});
						} else if (jQuery(a[2]).is(".selected")) {
							jQuery(a[3]).click();
							jQuery('#jscarousel-image').animate({
								opacity: 1
							});
							jQuery(a[3]).mousedown();
						} else if (jQuery(a[3]).is(".selected")) {
							if (jQuery('body#inside-the-music').size() > 0) {
								jQuery(a[4]).click();
								jQuery('#jscarousel-image').animate({
									opacity: 1
								});
								jQuery(a[4]).mousedown();
							}
						}	
					}	
				},
				btnNext: "#js-next",
				btnPrev: "#js-prev"
			});
			jQuery('#jscarousel li').click(function() { 
				if (!jQuery(this).is('.selected')) {
					jQuery(this).addClass('transitioning');
					xselect = jQuery(this);
					jQuery('#jscarousel li.selected .jscarousel-border').animate({ opacity: 0 }, 500);
					jQuery('#jscarousel-image').animate({ opacity: 0 }, 500, function() {
						jQuery('#jscarousel-image').css({ backgroundImage: 'url(' + jQuery(xselect).attr('rel') + ')' });
						jQuery('#jscarousel-tune-in-left').html('' + jQuery(xselect).children(".jscarousel-tune-in-left").text() + '');
						jQuery('#jscarousel-tune-in-right').html('' + jQuery(xselect).children(".jscarousel-tune-in-right").text() + '');																				
						jQuery('#jscarousel-title').html('' + jQuery(xselect).children(".jscarousel-title").text() + '');
						jQuery('#jscarousel-blurb').html('' + jQuery(xselect).children(".jscarousel-description").text() + '');	
						jQuery('#jscarousel-links').html('' + jQuery(xselect).children(".jscarousel-links").html() + '');
						jQuery('#jscarousel li.selected').removeClass('selected');															
					});
					jQuery('#jscarousel-image').animate({ opacity: 1 }, 500);
					jQuery(xselect).find('.jscarousel-border').animate({ opacity: 1, borderTopColor: '#59b4de', borderLeftColor: '#59b4de', borderRightColor: '#59b4de', borderBottomColor: '#59b4de' }, 500, function() {					
						jQuery(xselect).addClass('selected').removeClass("transitioning");
						jQuery(xselect).siblings().find('.jscarousel-border').css({borderColor: '#FFFFFF', opacity: 0});
					});
				}
			});
			jQuery('#jscarousel ul li').hover(
				function() {
					if (jQuery(this).is(".selected") || jQuery(this).is(".transitioning")) {
						return;
					} else {
						jQuery(this).find('.jscarousel-border').animate({opacity: 1}, 500);
					}
				},
				function() {
					if (jQuery(this).is(".selected") || jQuery(this).is(".transitioning")) {
						return;
					} else {
						jQuery(this).find('.jscarousel-border').animate({opacity: 0}, 500);
					}
				}
			);
			jQuery('#jscarousel-links a').live('hover', function() {
				jQuery(this).animate({color: '#59b4de'}, 250);
			});
			jQuery('#jscarousel-links a').live('mouseout', function() {
				jQuery(this).animate({color: '#FFFFFF'}, 250);
			});
			jQuery('#jscarousel ul li:first').click();
		}
	});
}
function overlayVideo(bcid) {
	jQuery('#modal').dialog({
		width: 960,
		height: 576,
		dialogClass: 'video-overlay',
		closeTest: '',
		resizable: false,
		draggable: false,
		modal: true,
		open: function() {
			jQuery("#modal").html('<object id="myExperience" class="BrightcoveExperience"><param name="bgcolor" value="#1C1C1C" /><param name="width" value="960" /><param name="height" value="540" /><param name="playerID" value="90409831001" /><param name="publisherID" value="376817008"/><param name="isVid" value="true" /><param name="isUI" value="true" /><param name="dynamicStreaming" value="true" /><param name="@videoPlayer"  value="' + bcid + '" /></object>');
		    brightcove.createExperiences();
		},
		close: function() {
			jQuery('#modal').dialog('destroy');
		}
	});
}
function monthdays(month, year) {
    return new Date(year, month, 0).getDate();
}
function setSubnavTab() {
	if (jQuery('body').is('.show-page') && window.location.hash == "#about") {
		jQuery("#show-subnav #about-link a").click();
	}
	else if (window.location.hash == "#video") {
		jQuery("#show-subnav #video2-link a").click();
	}
	else if (window.location.hash == "#episode-guide") {
		jQuery("#show-subnav #episode-guide-link a").click();
	}
	else if (window.location.hash == "#images") {
		jQuery("#show-subnav #images-link a").click();
	}
	else if (window.location.hash == "#bios") {
		jQuery("#show-subnav #bios-link a").click();
	}
	else if (window.location.hash == "#purchase") {
		jQuery("#show-subnav #purchase-link a").click();
	}
	else if (window.location.hash == "#learn-more") {
		jQuery("#show-subnav #learn-more-link a").click();
	}
	else if (window.location.hash == "#smithsonian-connection") {
		jQuery("#show-subnav #smithsonian-connection2-link a").click();
	}
	else {
		jQuery("#show-subnav ul li:first a").click();
	}
}
function monthdays(month, year) {
    return new Date(year, month, 0).getDate();
}
jQuery(document).ready(function() {
	jQuery('a.new-window').click(function() {
		window.open(this.href);
		return false;
	});
	jQuery('body.subnav-hidden #shows-page-link').mouseenter(function() {
		jQuery('#show-pages-subnav').fadeIn();
		jQuery('#nav-bg').fadeIn();
	});
	jQuery('body.subnav-hidden #shows-page-link').mouseleave(function() {
		jQuery('#show-pages-subnav').fadeOut();
		jQuery('#nav-bg').fadeOut();
	});
	jQuery('input#searchfield').example('search');
	if (jQuery('body').is('#schedule')) {
		curr_date = new Date();
		curr_year = curr_date.getFullYear();
		curr_month = curr_date.getMonth() + 1;
		curr_day = curr_date.getDate();
		curr_monthdays = monthdays(curr_month, curr_year);
		if (curr_month == 11) {
			lim_month = 0;
			lim_year = curr_year + 1;
		} else {
			lim_month = curr_month + 1;
			lim_year = curr_year;
		}
		lim_monthdays = monthdays(lim_month, lim_year);
		calmax = curr_monthdays + lim_monthdays - curr_day;
		jQuery("input#datepicker").datepicker({
				minDate: curr_date,
				maxDate: calmax,
				showOn: 'both',
				onClose: function(dateText, inst) {
					jQuery('#the-date').html(dateText);
					jQuery('#channel-options-form').submit();
			},
			onSelect:function(){},
				buttonImage: '/site/sn/images/jquery-ui/datepicker.png',
				buttonImageOnly: true
			});
		}
	if (jQuery('body').is("#home")) {
		xmlfeed = '/site/sn/xml/home.xml';
	}	
	else if (jQuery('body').is("#air-and-space"))  {
		xmlfeed = '/site/sn/xml/air_and_space.xml';
	}
	else if (jQuery('body').is("#science-and-nature")) {
		xmlfeed = '/site/sn/xml/science_and_nature.xml';
	}
	else if (jQuery('body').is("#kids")) {
		xmlfeed = '/site/sn/xml/kids.xml';
	}
	else if (jQuery('body').is("#history")) {
		xmlfeed = '/site/sn/xml/history.xml';		
	}
	else if (jQuery('body').is("#culture")) {
		xmlfeed = '/site/sn/xml/culture.xml';
	}
	else if (jQuery('body').is("#shows-page")) {
		xmlfeed = '/site/sn/xml/shows.xml';
	}
	else if (jQuery('body').is("#inside-the-music")) {
		xmlfeed = '/site/sn/xml/inside_the_music.xml';
	}
	else {
		xmlfeed = '/site/sn/xml/home.xml';
	}
	if (jQuery('body#inside-the-music, body#home, body#shows-page, body#air-and-space, body#science-and-nature, body#history, body#culture, body#kids').size() > 0) {
		jsCarousel();
	}
	jQuery("#channel-finder-app").flashembed({ 
		src: "http://smithsonian.channelfinder.net/swf/cf_smithsonian_nav.swf", 
		height: '300',
		width: '235',
		bgcolor: "transparent", 
		quality: "high", 
		allowscriptaccess: "always",
		wmode: "transparent",
		scale: "noscale", 
		salign: "tl"
		}, { 
		lc_name: "lc_update"
	});
	jQuery("#watch-tv-widget").flashembed({ 
		src: "http://smithsonian.channelfinder.net/swf/cf_smithsonian_960x80.swf", 
		height: "100%",
		width: "100%",
		onFail: function() {
			jQuery("#watch-tv-block").remove();
		},
		bgcolor: "#1c1c1c", 
		quality: "high", 
		allowscriptaccess: "always",
		wmode: "transparent",
		scale: "noscale", 
		salign: "b"
		}, { 
		lc_name: "lc_update"
	});
	jQuery('#channel-finder-app').click(function () {
		setFlashSize_right();
	});
	if (jQuery('#vid-list ul li').size() <= 2) {
		jQuery('.next-vid').addClass('disabled');
	}
	jQuery('#show-subnav #about-link a').click(function() {
		if (jQuery(this).parent().is('.selected')) {
			return;
		} else {
			jQuery('#show-subnav .selected').toggleClass('selected');
			jQuery(this).parent().toggleClass('selected');
			jQuery('#about-content').show();
			jQuery('#episode-guide-content').hide();
			jQuery('#video-content').hide();
			jQuery('#images-content').hide();
			jQuery('#bios-content').hide();			
			jQuery('#purchase-content').hide();
			jQuery('#learn-more-content').hide();			
			jQuery('#smithsonian-connection-content').hide();						
			return;
		}
	});
	jQuery('#show-subnav #video2-link a').click(function() {
		if (jQuery(this).parent().is('.selected')) {
			return;
		} else {
			jQuery('#show-subnav .selected').toggleClass('selected');
			jQuery(this).parent().toggleClass('selected');
			jQuery('#about-content').hide();
			jQuery('#episode-guide-content').hide();
			jQuery('#video-content').show();
			jQuery('#images-content').hide();
			jQuery('#bios-content').hide();			
			jQuery('#purchase-content').hide();
			jQuery('#learn-more-content').hide();			
			jQuery('#smithsonian-connection-content').hide();
			jQuery('#related-videos ul li.vid-' + firstvid + '').click();						
			return;
		}
	});
	jQuery('#show-subnav #episode-guide-link a').click(function() {
		if (jQuery(this).parent().is('.selected')) {
			return;
		} else {
			jQuery('#show-subnav .selected').toggleClass('selected');
			jQuery(this).parent().toggleClass('selected');
			jQuery('#about-content').hide();
			jQuery('#episode-guide-content').show();
			jQuery('#video-content').hide();
			jQuery('#images-content').hide();
			jQuery('#bios-content').hide();			
			jQuery('#purchase-content').hide();
			jQuery('#learn-more-content').hide();			
			jQuery('#smithsonian-connection-content').hide();						
			return;
		}
	});
	jQuery('#show-subnav #images-link a').click(function() {
		if (jQuery(this).parent().is('.selected')) {
			return;
		} else {
			jQuery('#show-subnav .selected').toggleClass('selected');
			jQuery(this).parent().toggleClass('selected');
			jQuery('#about-content').hide();
			jQuery('#episode-guide-content').hide();
			jQuery('#video-content').hide();
			jQuery('#images-content').show();
			jQuery('#bios-content').hide();			
			jQuery('#purchase-content').hide();
			jQuery('#learn-more-content').hide();			
			jQuery('#smithsonian-connection-content').hide();						
			return;
		}
	});
	jQuery('#show-subnav #bios-link a').click(function() {
		if (jQuery(this).parent().is('.selected')) {
			return;
		} else {
			jQuery('#show-subnav .selected').toggleClass('selected');
			jQuery(this).parent().toggleClass('selected');
			jQuery('#about-content').hide();
			jQuery('#episode-guide-content').hide();
			jQuery('#video-content').hide();
			jQuery('#images-content').hide();
			jQuery('#bios-content').show();			
			jQuery('#purchase-content').hide();
			jQuery('#learn-more-content').hide();			
			jQuery('#smithsonian-connection-content').hide();						
			return;
		}
	});
	jQuery('#show-subnav #purchase-link a').click(function() {
		if (jQuery(this).parent().is('.selected')) {
			return;
		} else {
			jQuery('#show-subnav .selected').toggleClass('selected');
			jQuery(this).parent().toggleClass('selected');
			jQuery('#about-content').hide();
			jQuery('#episode-guide-content').hide();
			jQuery('#video-content').hide();
			jQuery('#images-content').hide();
			jQuery('#bios-content').hide();			
			jQuery('#purchase-content').show();
			jQuery('#learn-more-content').hide();			
			jQuery('#smithsonian-connection-content').hide();						
			return;
		}
	});
	jQuery('#show-subnav #learn-more-link a').click(function() {
		if (jQuery(this).parent().is('.selected')) {
			return;
		} else {
			jQuery('#show-subnav .selected').toggleClass('selected');
			jQuery(this).parent().toggleClass('selected');
			jQuery('#about-content').hide();
			jQuery('#episode-guide-content').hide();
			jQuery('#video-content').hide();
			jQuery('#images-content').hide();
			jQuery('#bios-content').hide();			
			jQuery('#purchase-content').hide();
			jQuery('#learn-more-content').show();			
			jQuery('#smithsonian-connection-content').hide();						
			return;
		}
	});
	jQuery('#show-subnav #smithsonian-connection2-link a').click(function() {
		if (jQuery(this).parent().is('.selected')) {
			return;
		} else {
			jQuery('#show-subnav .selected').toggleClass('selected');
			jQuery(this).parent().toggleClass('selected');
			jQuery('#about-content').hide();
			jQuery('#episode-guide-content').hide();
			jQuery('#video-content').hide();
			jQuery('#images-content').hide();
			jQuery('#bios-content').hide();			
			jQuery('#purchase-content').hide();
			jQuery('#learn-more-content').hide();			
			jQuery('#smithsonian-connection-content').show();
			return;
		}
	});
	navgo = [];
	jQuery('#related-videos ul li').each(function (i) { 
		navgo[i] = '.' + jQuery(this).attr('class').split(' ')[0] + '';
	});
	if (jQuery('body#show-page').length > 0) {
		jQuery('#vid-list').jCarouselLite({
			vertical: true,
			visible: 2,
			scroll: 1,
			speed: 750,
			circular: false,
			btnNext: ".next-vid",
			btnPrev: ".prev-vid",
			btnGo: navgo
		});
	}
	if (jQuery('body#full-episodes').size() > 0) {
		jQuery('#vid-list').jCarouselLite({
			vertical: true,
			visible: 3,
			scroll: 1,
			speed: 750,
			circular: false,
			btnNext: ".next-vid",
			btnPrev: ".prev-vid",
			btnGo: navgo
		});
	}
	jQuery('#vid-list ul li').live('click', function() {
		if (!(jQuery(this).is(".selected"))) {
			jQuery('#vid-list ul li.selected').removeClass("selected");
			vnew = '' + jQuery(this).attr('class').split(' ')[0].replace('vid-', '') + '';
			jQuery('.vid-' + vnew + '').addClass('selected');
			modCon.getMediaAsynch(vnew);
			modVP.loadVideo(vnew);
			modSocial.setLink(jQuery(this).children().attr("alt"));
			jQuery('h3.selected, p.selected').removeClass('selected');
			jQuery('h3.vid-' + vnew + ', p.vid-' + vnew + '').addClass('selected');
			if (jQuery('body#full-episodes').size() > 0) {
				window.location.hash = jQuery(this).children('p.deeplink').text();
			}
		}
		return false;
	});
	jQuery('#thumbs').jCarouselLite({
		vertical: false,
		visible: 3,
		scroll: 1,
		speed: 750,
		circular: false,
		btnNext: ".next-thumb",
		btnPrev: ".prev-thumb"
	});
	jQuery('#thumbs li img').click(function() { 
		if (!jQuery(this).parent().is('.selected')) {
			newcap = jQuery(this).attr('alt');
			newsrc = jQuery(this).attr('src');
			newsrc = newsrc.replace('thumb', 'full');
			jQuery('#main-image img').attr('src', newsrc);
			jQuery('#main-image p').html(newcap);
			jQuery('#thumbs li.selected').removeClass('selected');
			jQuery(this).parent().addClass('selected');
		}
	});
		if (jQuery('body').is('#schedule')) { 
			curr_date = new Date();
			curr_year = curr_date.getFullYear();
			curr_month = curr_date.getMonth() + 1;
			curr_day = curr_date.getDate();
			curr_monthdays = monthdays(curr_month, curr_year);
			if (curr_month == 11) {
				lim_month = 0;
				lim_year = curr_year + 1;
			} else {
				lim_month = curr_month + 1;
				lim_year = curr_year;
			}
			lim_monthdays = monthdays(lim_month, lim_year);
			calmax = curr_monthdays + lim_monthdays - curr_day;
			jQuery("input#datepicker").datepicker({
					minDate: curr_date,
					maxDate: calmax,
					showOn: 'both',
					onClose: function(dateText, inst) {
						jQuery('#the-date').html(dateText);
						jQuery('#channel-options-form').submit();
				},
				buttonImage: '/site/sn/images/jquery-ui/datepicker.png',
				buttonImageOnly: true
		});
	}
	if (jQuery('body').is('#video')) {
		jQuery('div.social ul li a').attr('addthis:url', bc_social_root);
		jQuery('div.social ul li a').attr('addthis:title',  bc_title);
		jQuery('div.social ul li a').attr('addthis:description', bc_blurb);
	}
	setSubnavTab();
	OmniVar();
	trackPage();
	if (jQuery('body.id-701').size() > 0) {
		if (jQuery.browser.msie && jQuery.browser.version < 7) {
			jQuery('#show-image').attr('src', '/site/sn/images/custom/aerial_america/logo.gif');
		} else {
			jQuery('#show-image').attr('src', '/site/sn/images/custom/aerial_america/logo.png');
		}
	}
	if (!(jQuery.browser.msie && jQuery.browser.version == 6)) {
		jQuery('#vid-list ul li').hover(function () {
			pos = jQuery(this).offset();
			vid = jQuery(this).attr('class').split(' ')[0];
			title = jQuery('h3.' + vid + '').text();
			blurb = jQuery('p.' + vid + '').text();
			jQuery('body').append('<div id="tip" style="position:absolute;top:' + (pos.top) +'px; left:' + (pos.left - 25) + 'px;"></div><div id="tooltip" style="position:absolute;left:' + (pos.left - 380) + 'px;"><p class="title">' + title + '</p><p>' + blurb + '</p></div>');
			hbr = jQuery('#tooltip').outerHeight(true);
			jQuery('#tooltip').css({top: pos.top - ((hbr-100)/2) + 'px'});
			jQuery('#tip, #tooltip').fadeIn();
		}, function() {
			jQuery('#tooltip, #tip').remove();
		});
	}
	if (jQuery('body.id-133281, body.id-133281, body.id-134778, body.id-136457, body.id-136450, body.id-136455, body.id-136456, body.id-136449, body.id-136454').size() > 0) {
		jQuery('#show-name').prependTo('#show-blurb');
		jQuery('#show-image').clone().prependTo('#show-blurb').attr('id', 'show-image2');
		if (jQuery.browser.msie && jQuery.browser.version < 7) {
			jQuery('#show-image').attr('src', '/site/sn/images/custom/aerial_america/logo.gif');
		} else {
			jQuery('#show-image').attr('src', '/site/sn/images/custom/aerial_america/logo.png');
		}
	}
	var dialogOpts = {
	    modal: true,
	    bgiframe: true,
	    autoOpen: false,
	    height: 200,
	    width: 250,
		title: "Smithsonian Folkways",
	    closeText: 'close',
	    draggable: false,
		resizable: false,
		close: function() {
			jQuery('#modal').html('');
		}
	};
	if (jQuery('body#inside-the-music').size() > 0 ) {
		jQuery("#modal").dialog(dialogOpts);
		jQuery('#itm-close').live('click', function() {
			jQuery('#modal').dialog('close');
		});
		jQuery('a.itm-player').click(function () {
			playerurl = jQuery(this).attr('href');
			jQuery("#modal").html('<iframe frameborder="0" src="' + playerurl + '" width="250" height="200" />');
			jQuery('#modal').dialog('open');
			return false;
		});
	}
	jQuery('.ui-widget-overlay').live("click", function() {
       jQuery("#modal").dialog("close");
    });
	jQuery('#itm-video-nav ul li').live('click', function() {
		if (!(jQuery(this).is(".selected"))) {
			jQuery('#itm-video-nav ul li.selected').removeClass("selected");
			vnew = '' + jQuery(this).attr('class').split(' ')[0].replace('vid-', '') + '';
			jQuery('.vid-' + vnew + '').addClass('selected');
			modCon.getMediaAsynch(vnew);
			modVP.loadVideo(vnew);
			modSocial.setLink(jQuery(this).attr("title"));
		}
	});
	if (jQuery('body#inside-the-music').size() > 0) {
		jQuery.ajax({
			type: 'GET',
		    url: '/site/sn/xml/itm_schedule.xml',
		    dataType: "xml",
		    success: function(data) {
				jQuery('#upcoming-airings').append('<ul></ul>');
				fillup = 0;
				jQuery(data).find("show").each(function (i) {
					rightnow = new Date();
					timex = 0;
					time = jQuery(this).find("time").text();
					timex = parseInt(time);
					dateObject = new Date(timex * 1000);
					if (fillup == 3) {
						return false;
					}
					else if (dateObject < rightnow) {
						return;
					} else {
						jQuery('#upcoming-airings ul').append('<li><h4>' + jQuery(this).find("title").text() + '</h4><p class="program-time">' + dateObject.format('h:MMtt') + '</p><p class="program-date">' + dateObject.format('dddd mm/dd') + '</p></li>');
						fillup++;
					}
				});
		        
			}
		});
	}
	jQuery('#js-next, #js-prev').hover(function() {
	  jQuery(this).addClass('hover');
	}, function() {
	  jQuery(this).removeClass('hover');
	});
	if (jQuery('body.id-701').size() > 0) {
		jQuery("#aerial-america-map").flashembed({ 
			src: "/site/sn/flash/aerial_america_map.swf", 
			height: '410',
			width: '570',
			quality: "high", 
			allowscriptaccess: "always",
			wmode: "window",
			bgcolor: '#95bacf'
		});
	}
	if (jQuery('body#vip-the-rivals').size() > 0) {
		jQuery('#the-rivals-player').flashembed({ 
			src: "/site/sn/flash/the_rivals.swf", 
			height: '600',
			width: '960',
			bgcolor: "#1c1c1c", 
			quality: "high", 
			allowscriptaccess: "always",
			wmode: "window"
		});
	}
});