$(document).ready(function() {

// external links
$('a[rel="external"]').click( function() {
    window.open( $(this).attr('href') );
    return false;
});
$('a[rel="popup"]').click( function() {
    window.open( $(this).attr('href'),'','width=772,height=390,resizable=0,scrollbars=1,location=0,toolbar=0,menubar=0' );
    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: function() {
        if (this.href.indexOf('top-5') > -1) {
          return 'shadowbox;width=732;height=252';
        } else {
          return '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');
		
});

$(document).ready(function() {
	$('.home-vids a').append('<img class="video-play-btn" src="/assets/styles/images/buttons/play-sm.png" alt="" />');
});

$(document).ready(function() {
	if (typeof $.fn.cycle !== 'undefined') {
	  $('.landing-ads .ad-1').cycle({ 
	    timeout:  6000 
	  });
	  $('.landing-ads .ad-2').cycle({
	    delay: 3000,
	    timeout:  6000 
	  });
	}
});

// programs list
$(document).ready(function() {
  if ( (/^(professional|certificates|associate|bachelor)/i).test($('#nav_cat_archive > li > strong').text()) ) {
    $('#nav_cat_archive').addClass('col').after('<ul id="nav_cat_archive2" class="col programs-list last"></ul>')
      .children().each(function() {
        var cat = $('strong:first', this).text();
        if ( !(/^(professional|certificates|associate|bachelor)/i).test(cat) ) {
          $(this).appendTo('#nav_cat_archive2');
        }
    });
  }
});

$(document).ready(function() {
	// prettier headings with js
	$('body.audience h3').addClass('group').wrapInner('<span></span>');
});

/** =request info form
************************************************************/
$(document).ready(function() {
	$('#degree').change(function() {
		var selectedDegree = $(this).val(),
				selectedProgram = '';				
	
		$('#program')
			.children('optgroup').each(function(index) {
				if (this.label == selectedDegree) {
					$(this).show();
					selectedProgram = $(this).children(':first').text();
				} else {
					$(this).hide();
				}
			})
		.end()
		.val(selectedProgram)
		.trigger('change');
			
	}).trigger('change');
		
	$('#program').change(function() {
		$('div.program.active').removeClass('active');
		$('div.program').filter(function() {
		  return $(this).children('h3').text() == $('#program').val();
		}).addClass('active');
	}).trigger('change');
});

$(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');
  
});
