$(document).ready(function() {
  
// Animated Scrolling for Same-Page Links
// @see http://www.learningjquery.com/2007/10/improved-animated-scrolling-script-for-same-page-links
// function filterPath(string) {
// return string
//   .replace(/^\//,'')
//   .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
//   .replace(/\/$/,'');
// }
// var locationPath = filterPath(location.pathname);
// $('a[href*=#]').each(function() {
//   var thisPath = filterPath(this.pathname) || locationPath;
//   if (  locationPath == thisPath
//   && (location.hostname == this.hostname || !this.hostname)
//   && this.hash.replace(/#/,'') ) {
//     var $target = $(this.hash), target = this.hash;
//     if (target) {
//       var targetOffset = $target.offset().top;
//       $(this).click(function(event) {
//         event.preventDefault();
//         $('html, body').animate({scrollTop: targetOffset}, 800, function() {
//           location.hash = target;
//         });
//       });
//     }
//   }
// });

$('a[rel="popup"]').click( function() {
    window.open( $(this).attr('href'),'','width=560,height=390' );
    return false;
});

// video play button
$('.multi-vid .vid').append('<img class="btn-play" src="/assets/styles/images/buttons/play-sm.png" alt="" />');

}); // document.ready

$(document).ready(function() {
  
  // Video Shadowbox
  if (typeof Shadowbox !== 'undefined') {
    $('a[href$=.mov], a[href$=.flv]').attr({
      rel: 'shadowbox;width=528;height=392', 
      title: 'click to close the video'
    });

    var sboptions = {
      assetURL:  '/assets/scripts/shadowbox/',
      loadingImage: 'styles/images/loading.gif',
      overlayBgImage: 'styles/images/overlay-85.png',      
      flvPlayer: 'flvplayer.swf', 
      keysClose:          ['c', 27]
    };
    
    // ie6 only options
    if ($.browser.msie === true && parseInt($.browser.version,10) < 7) {
      sboptions.onFinish = function() {
        $('#shadowbox_nav_close')
        .find('a').ifixpng().end()
        .css('left', '-20px');
      };
    }

    Shadowbox.init(sboptions);    
  }
  // biglinks
  $('.media-block .vid').biglinks({preventDefault: true});
	$('body.news-listing .article').biglinks();

	// add frame
	$('body.news-read .article img').addClass('framed-alt');
	
	// add top class if img is first in p
	$('body.news-read .article p').filter(function() {
		var firstKid = this.firstChild,
				firstImage = false;
		if (firstKid.nodeType == '3' && firstKid.nodeValue.replace(/\s/g,'') == '') {
			firstImage = firstKid.nextSibling && firstKid.nextSibling.nodeName == 'IMG';
		} else {
			firstImage = firstKid.nodeName == 'IMG';
		}
		return firstImage;
	}).children('img:first').addClass('top');
		
});

/** =external links
************************************************************/
$(document).ready( function() {
    $('a[rel=external]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });
});

$(document).ready(function() {
  // homepage getting started tabs
   $('div.tabs-panel').slice(1).hide();
   var $tabLinks = $('.tabs-nav a');
   $tabLinks.click(function() {
     var panel = '#' + this.href.split('#')[1];
     if ( !$(panel).is(':visible') ) {
       $tabLinks.removeClass('active');
       $(this).addClass('active');
       $('div.tabs-panel:visible').fadeOut(200, function() {
         $(panel).fadeIn();          
       });
     }
     return false;
   }).filter(':first').addClass('active');
  
});
