<?php $tracks = $this->getTracks() ?>
<?php $option = $this->getCurrentOption(); ?>

<?php
    if($this->getAlbum()) {
        $album = $this->getAlbum();
        $subpage = 'album_'.$album->getId();
    } else {
        $subpage = 'tracks_'.$option->getId();
    }
?>

<div id="playlists_scrollview_<?php echo $subpage ?>" class="relative">
    <ul id="playlists_list_<?php echo $subpage ?>" class="tracks_type_list_<?php echo $subpage ?>">
        <li class="presentation clearfix">
            <?php if($this->getAlbum()) : ?>
                <img class="left" src="<?php echo $album->getArtworkUrl() ?>" width="100px" height="100px"/>
            <?php endif; ?>
            <div class="metas left">
                <span class="album_name"><?php echo $album->getName() ?></span>
                <span class="artist_name"><?php echo $album->getArtistName() ?></span>
                <?php
                    $a = sizeof($tracks) == 1 ? $this->_('title') : $this->_('titles');
                ?>
                <span class="album_count"><?php echo sizeof($tracks) ?> <?php echo $a ?></span>
                <span class="read_all">
                    <a href="javascript:void(0)" class="noclickdelay" onclick="loadPlaylist($('ul#playlists_list_<?php echo $subpage ?>')); return false;"><?php echo $this->_('Read all') ?></a>
                </span>
            </div>
        </li>
        <?php foreach($tracks as $index => $track) : ?>
            <li class="<?php echo $option->getId() ?>_tracks types tracks clearfix">
                <a rel="<?php echo $index ?>" href="javascript:void(0)" onclick="loadPlaylist($('ul#playlists_list_<?php echo $subpage ?>'), this); return false;">
                    <p class="clearfix">
                        <span class="track_number"><?php echo $index++ < 10 ? '0'.$index++ : $index++ ?></span>
                        <span class="track_name"><?php echo Core_Model_Lib_String::truncate($track->getName(), 30) ?></span>
                        <?php if(!$album->getType() == 'podcast') : ?>
                            <span class="track_duration"><?php echo $track->getFormatedDuration() ?></span>
                        <?php else : ?>
                            <span class="track_duration"><?php echo $track->getFormatedDuration($track->getDuration()) ?></span>
                        <?php endif; ?>
                    </p>
                    <?php if($track->getArtistName()) : ?>
                        <p>
                            <span class="track_artist"><?php echo $track->getArtistName(); ?></span>
                        </p>
                    <?php endif; ?>
                    <span class="track_full_name" style="display:none"><?php echo $track->getName() ?></span>
                    <span class="track_url" style="display:none"><?php echo $track->getStreamUrl() ?></span>
                    <span class="track_buy_url" style="display:none"><?php echo $track->getPurchaseUrl() ?></span>
                </a>
            </li>
        <?php endforeach; ?>
    </ul>
</div>

<script type="text/javascript">
    var subpage = page.getSubpage('<?php echo $subpage ?>');
    subpage.setCallback('willappear', function() {
        this.setScrollview(new iScroll('playlists_scrollview_<?php echo $subpage ?>'))
            .setContentSize()
        ;

    });

    subpage.refreshScrollview = function() {
        var height = $(window).height() - $('#page_header_'+this.id).height();

        $('#playlists_scrollview_<?php echo $subpage ?>').css('height', height);
        $('#playlists_scrollview_<?php echo $subpage ?>').children('ul').css('min-height', height);
        this.scrollview.refresh();
        return this;
    };
</script>