function filter_river(tag) {
	if (parent.location != window.location) {
		window.parent.filterRiver(tag.replace(/-/g, ' '));
	} else {
		window.location = "/content/tag/" + tag;
	}
}

// redirect ASAP
redirectBrowsersToAppropriateVersionOfPage();

$(document).ready(function() {
	var showCount = $('.slideshow > ul > li').size();
	var hasSlideShow = showCount > 1;
	if (hasSlideShow) {
		doSlideShow();
	} else {
		$('.slideshow ul').addClass('singleSlideShow');
		$('.slideshow').css('height', '505px');
	};
});


function rewriteInternalLinksForSwfAddress() {
  var links = $('a[href*=/content/]');
  var hashContentRegex = /#\/content\//;
  var contentRegex = /.*\/content\//;
  var generateClickHandler = function(url){ 
                               return function(event){ 
                                 if( top && top.SWFAddress ) {
                                   top.SWFAddress.setValue(url); 
                                   event.preventDefault();
                                 } 
                               }; 
                             };
  links.each( function( array, link, index ) {
    if( !link.href || link.href.match(hashContentRegex)) return;
    $(link).click( generateClickHandler(link.href.replace(contentRegex, '/content/')));
    //link.href = link.href.replace(contentRegex, '#/content/');
  });
}

function doSlideShow() {
	$('.slideshow ul').css('display', 'block');
	$('.slideshow ul').galleryView({
		gallery_width: 900,
		gallery_height: 555,
		panel_width: 900,
		panel_height: 505,
		frame_height: 50,
		frame_width: 90,
		gallery_padding: 0,
		scale_panel_images: false,
		pause_on_hover: true,
		show_filmstrip: true
	});
};

function redirectBrowsersToAppropriateVersionOfPage() {
	var isNotMobileBrowser = (navigator.userAgent.match(/iPhone|android|IEMobile/i) == null);
	var isNotInFrame  = top.location.href == document.location.href;
	if (isNotInFrame && isNotMobileBrowser) {
		var blogBase = '/';
		var index = blogBase;
		var newUrl = index + (document.location.pathname != blogBase ? "#" + 
			document.location.pathname : '');
		
		// save the referrer for use after loading the newUrl
		document.cookie = "savedreferrer="+encodeURIComponent(document.referrer)+"; path=/";
		document.location.replace(newUrl);
	}
}


