@extends('layouts/sidebar')

@section('title') 
  Fragment gemist
@endsection

@section('breadcrumb')
	<ul class="bread_crumb">
		@if(isset($program))
		<li><a title="Fragment gemist" href="{{url('radio/gemist')}}">Fragment gemist</a></li>
		<li class="separator icon_small_arrow right_gray">&nbsp;</li>
		<li>{{$program->name}}</li>
		@endif
	</ul>
@endsection 

@section('content')
  @parent

  @if(isset($program)) 
    <h2>{{$program->name}}</h2>
    <p class="align-right">
      <a href="{{url('radio/gemist')}}" title="Alle programma's" class="btn btn-info">&larr; Toon alles</a>
      <a href="{{url('radio/programma' . $program->url)}}" title="{{$program->name}}" class="btn btn-info">Programmainfo</a>
    </p>
  @else
    <p>Hele uitzendingen kunt u binnen twee weken terugluisteren door het betreffende programma op te zoeken via de <a href="{{url('radio/gids')}}">programmagids</a>.
  @endif

  @if($podcasts)

  <div class="page_layout clearfix">
	<div class="row grid" id="items">
	@include('podcastitems', ['podcasts' => $podcasts])
	</div><!--/.row-->
  </div>
  
  <div id="loading" style="display: none">
    <div class="progress progress-striped active">
      <div class="progress-bar"  role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
        <b>Meer podcasts aan het ophalen...</b>
      </div>
    </div>
  </div>

  @push('scripts')
  <script>
    var page = 1;
    var isLoading = 0;
    var $items = $('#items');  
    var $isLoading = $('#loading');  
    $(function() {
      $(window).scroll(function () {
        var $this = $(this);       
        var tweak = 10;
        
        if(!isLoading && (page > 0) && ($this.scrollTop() >= $items.height() - $this.height() - tweak))
        {
          isLoading = 1; 
          $isLoading.show();
          $.ajax({ url: document.location.pathname + '?pagina=' + (++page) })
            .always(function() { isLoading = 0; $isLoading.hide(); })
            .done(function(data) { 
              if(!data) { 
                if(page > 1) $items.append("<hr /><p>Er zijn geen podcasts (meer).</p>"); 
                page = -1; 
                return;
              }
              $newPage = $("<div />").append(data); 
              $items.append($newPage);
              $newPage.find("audio, video").mediaelementplayer({ stretching: 'responsive' }); 
            });
        }
      });
    });
  </script>
  @endpush
  @else
  
  <p>Er zijn geen fragmenten beschikbaar.</p>
 
  @endif
 
@endsection

