
$(document).ready(function(){
	
	/*adjust_text($('.pane-front-featured-panel-pane-1 .views-field-title .field-content a').height(), 1);
	adjust_text($('.pane-front-featured-panel-pane-2 .views-field-title .field-content a').height(), 2);
	adjust_text($('.pane-front-featured-panel-pane-3 .views-field-title .field-content a').height(), 3);
	adjust_text($('.pane-front-featured-panel-pane-4 .views-field-title .field-content a').height(), 4, $('.pane-front-featured-panel-pane-4 .views-field-field-body-value .field-content').height());
	adjust_text($('.pane-front-featured-panel-pane-5 .views-field-title .field-content a').height(), 5);
	adjust_text($('.pane-front-featured-panel-pane-5 .views-field-title .field-content a').height(), 6);


	adjust_related();
	
	adjust_title($('.pane-front-featured-panel-pane-4 .views-field-title .field-content a').height(), 4);
	adjust_title($('.pane-front-featured-panel-pane-6 .views-field-title .field-content a').height(), 6);
	
	
	function adjust_title(title_height, block){
		switch(block){
			case 4:
				if(title_height >= 82){
					$('.pane-front-featured-panel-pane-4 .views-field-title .field-content a').truncate(50);
				}
				break;
			case 6:
				if(title_height >= 72){
					$('.pane-front-featured-panel-pane-6 .views-field-title .field-content a').truncate(43);
				}
				break;
		}
	
	}
	
	
	function adjust_related(){
		$('.related-front').siblings().children().children('li').each(function(){
			if($(this).height() >= 20){
				$(this).children('a').truncate(50);
				//$(this).children().children('.truncate_less').replaceWith($(this).children().children('.truncate_less').html());
			}
		});
	}
	
	function adjust_text(title_height, block, text_height){
		var num_lines = 0;
		switch(block){
			case 1:
				if(title_height >= 60){
					num_lines = 6.5;
				} else if(title_height >= 43 && title_height <= 55){
					num_lines =8.5;
				} else if(title_height <= 30){
					num_lines= 10.5;
				}
				$('.pane-front-featured-panel-pane-1 .views-field-field-body-value .field-content').truncate(num_lines*40);
				break;
			case 2:
				if(title_height >= 53){
					num_lines = 1;
				} else if(title_height >= 36 && title_height <= 50){
					num_lines = 2;
				} else if(title_height <= 30 ){
					num_lines = 3.5 ;
				}
				$('.pane-front-featured-panel-pane-2 .views-field-field-body-value .field-content').truncate(num_lines*40);
				break;
			case 3:
				if(title_height >= 53){
					num_lines = 1.3;
				} else if(title_height >= 36 && title_height <= 50){
					num_lines = 2.3;
				} else if(title_height <= 30 ){
					num_lines = 3.3 ;
				}
				$('.pane-front-featured-panel-pane-3 .views-field-field-body-value .field-content').truncate(num_lines*40);
				break;
			case 4:
				if(text_height >= 90){
					$('.pane-front-featured-panel-pane-4 .views-field-field-body-value .field-content').truncate(190);
				}
				break;
			case 5:
				if(title_height >= 53){
					num_lines = 1;
				} else if(title_height >= 36 && title_height <= 50){
					num_lines = 2;
				} else if(title_height <= 30 ){
					num_lines = 3 ;
				}
				$('.pane-front-featured-panel-pane-5 .views-field-field-body-value .field-content').truncate(num_lines*40);
				break;
			case 6:
				if(title_height >= 53){
					num_lines = 5;
				} else if(title_height >= 36 && title_height <= 50){
					num_lines = 2;
				} else if(title_height <= 30 ){
					num_lines = 3 ;
				}
				$('.view-front-blogs-featured .views-field-field-body-value .field-content').truncate(num_lines*40);
				break;
		
		}
	}*/
});




/* NOW PLAYING BLOCK */

$(document).ready( function() {
	
	scheduleTime();
});


function scheduleTime() {
	
	var cpHeight = 0;
	var currentTime = parseInt( $('#date').html().match(/[0-9]+:[0-9]+/)[0].replace(':', '') );
	if ( $('#date').html().match(/(PM|pm)/) && currentTime < 1200) currentTime = currentTime + 1200;
	if ( $('#date').html().match(/(AM|am)/) && currentTime >= 1200) currentTime = currentTime - 1200;

  
	$('.view-radio-schedule div.item-list > ul li').each( function() {
		
			var showTime = parseInt( $(this).find('.date-display-single').html().replace(':', '').match(/[0-9]+/) );
			
			if ($(this).find('.date-display-single').html().match(/(PM|pm)/) && showTime < 1200) showTime = showTime + 1200;
			if ($(this).find('.date-display-single').html().match(/(AM|am)/) && showTime >= 1200) showTime = showTime - 1200;

			
			if ( showTime > currentTime && typeof(currentlyPlaying) == 'undefined' ) {
				currentlyPlaying = $(this).prev();
				$(currentlyPlaying).find('.date-display-single').addClass('date-selected');
				cpHeight -= $(currentlyPlaying).outerHeight();
				cpHeight -= ($(this).prev().outerHeight() * 2 );

			} else if (typeof(currentlyPlaying) == 'undefined') {
				cpHeight += $(this).outerHeight();
			} 
		
	});

    currentlyPlaying = $('#currently_playing').parent().parent().parent();
    if(currentlyPlaying != "") {
      $(currentlyPlaying).find('.views-field-field-schedule-item-time-value > span').prepend('►');
      $(currentlyPlaying).css('background', '#fff');
      $(currentlyPlaying).css('color', '#A91E22');
      $(currentlyPlaying).css('padding', '14px 8px');
      
      $(currentlyPlaying).prev().css('background', '#FFE5E6');
      $(currentlyPlaying).next().css('background', '#FFE5E6');
      
      var divTop = ( cpHeight );
    }
	
	
	/* slider stuff */
	
	$('#upcoming-events .view-content').jScrollPane({
			showArrows: true,
			scrollbarWidth: 20		
		}
	);
	
	if($('.view-radio-schedule .item-list')[0]){
		$('.view-radio-schedule .item-list')
			.jScrollPane({
				showArrows: true,
				scrollbarWidth: 20		
			}
		)[0].scrollTo(divTop);
	}

}


