
$(document).ready(function(){
	
	// resizes thumbs
	
	/*
	$('div.thumb img').load().each(function(){
		
		if ($(this).width() > 195){
			
			$(this).animate({ width : 195 }, .1);
		}
	});
	*/

	$("a[href^='http']").attr('target','_blank');

	$('#side-narrow .s-block a[href$=".pdf"]').addClass('pdf');
	

	// news scroller
	
	if ($('#news-list').length > 0){
	
		$('#news-list').cycle({ 
			fx:     'scrollHorz', 
			prev:   '#news-list-prev', 
			next:   '#news-list-next',
			speed:  500, 
			timeout: 0 
		});
	}

	
	// photos scroller 

	if ($('#photos').length > 0){
	
		var curr_photo = 0;
		var n_photos = $('#photos div').length;

		$('#next').click(function(){
			
			curr_photo = curr_photo < n_photos - 1 ? curr_photo + 1 : 0;
			$('#photos div:visible').hide();
			$('#photo-' + curr_photo).show();
		});

		$('#prev').click(function(){
			
			curr_photo = curr_photo > 0 ? curr_photo - 1 : n_photos - 1;
			$('#photos div:visible').hide();
			$('#photo-' + curr_photo).show();
		});
	}


	// eletter subscriber

	$('#eletter').data('init', $('#eletter').val());

	$('#eletter').focus(function(){
		$('#eletter').val($('#eletter').val() == $('#eletter').data('init') ? '' : $('#eletter').val()); 
	});

	$('#eletter').blur(function(){
		$('#eletter').val($('#eletter').val() == '' ? $('#eletter').data('init') : $('#eletter').val()); 
	});

	$('form#email-subscribe').submit(function(){

		$('form#email-subscribe').ajaxSubmit({ url: '/subscribers/add_email/', type: 'POST', dataType: 'json', success: function(e){
			
			$('#eletter').val(e.message);
			$('#eletter').css('color', e.status > 0 ? '#05931C' : '#FF0000');
		} });

		return false; 
	});



	// audio player
	
	if ($('.jplayer').length > 0){
	
		$('#hokie-g-player').jPlayer( {

			ready: function () {
				
				$(this).setFile($(this).parent().find('a.play-button').attr('href'));
			},

			swfPath: "/_ui/js/jplayer",
			oggSupport: false
		} );
		
		$('#hokie-g-player').jPlayerId( "play", 'pb-1');
		$('#hokie-g-player').jPlayerId( "pause", 'pz-1');

		$('#buddy-d-player').jPlayer( {

			ready: function () {
				
				$(this).setFile($(this).parent().find('a.play-button').attr('href'));
			},

			swfPath: "/_ui/js/jplayer",
			oggSupport: false
		} );
		
		$('#buddy-d-player').jPlayerId( "play", 'pb-2');
		$('#buddy-d-player').jPlayerId( "pause", 'pz-2');

		$('.jplayer').onProgressChange( function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {

		});
	}

});