jQuery(document).ready(function () {
    jQuery('.showhideinfo').click(function () {
        var $this = jQuery(this);
        var detailWrapper = jQuery($this.attr('href'));
        var detailWrapperPointer = jQuery(".edit-row-notch", detailWrapper)
        detailWrapper.slideToggle('fast');
        detailWrapperPointer.css(
        { "left": ($this.offset().left - detailWrapper.offset().left) + 20 + "px" });
        if ($this.text() == 'Show Details')
        { $this.text('Hide Details'); }
        else { $this.text('Show Details'); }
        return false;
    });
	
	jQuery('.showhideprograminfo').click(function () {
        var $this = jQuery(this);
        var detailWrapper = jQuery($this.attr('href'));
        var detailWrapperPointer = jQuery(".edit-row-notch", detailWrapper)
        detailWrapper.slideToggle('fast');
        detailWrapperPointer.css(
        { "left": ($this.offset().left - detailWrapper.offset().left) + 20 + "px" });
        if ($this.text() == 'Details')
        { $this.text('Hide Details'); }
        else { $this.text('Details'); }
        return false;
    });
	
	jQuery('.showmoredetails').click(function () {
		var $this = jQuery(this);
        var detailWrapper = jQuery($this.attr('href'));
		
		if($this.text()=='Show More')
		{
			if($this.siblings().closest("#ProgramDetails").find('#emptyDiv').length==0)
			{
				$this.siblings().closest("#ProgramDetails").append("<div id='emptyDiv'></div>");
			}
			$this.siblings().closest("#ProgramDetails").removeAttr("style");
			$this.text('Hide');
		}
		else
		{
			$this.siblings().closest("#ProgramDetails").find('#emptyDiv').remove();
			$this.text("Show More");
			$this.siblings().closest("#ProgramDetails").attr("style","overflow: hidden;text-overflow: ellipsis;display: -webkit-box;-webkit-line-clamp: 3;line-clamp: 3;-webkit-box-orient: vertical;");
		}
        return false;
    });

    jQuery('[data-countdown]').each(function () {
        var $this = jQuery(this), finalDate = jQuery(this).data('countdown');
        if (finalDate < 0) {
            $this.html('1000+ days');
        }
        else {
            $this.countdown(moment.unix(finalDate).toDate())
            .on('update.countdown', function (event) {
                if (event.offset.totalDays >= 1000) {
                    $this.html('1000+ days');
                }
                else {
                    if (event.offset.totalDays >= 1) {
                        $this.html(event.strftime('%-Dd %-Hh %-Mm'));
                    }
                    else {
                        if (event.offset.hours >= 1)
                            $this.html(event.strftime('%-Hh %-Mm %-Ss'));
                        else if (event.offset.minutes >= 1)
                            $this.html(event.strftime('%-Mm %-Ss'));
                        else
                            $this.html(event.strftime('%-Ss'));
                    }
                }
            })
            .on('finish.countdown', function (event) {
                var _id = jQuery(this).attr("id");
                jQuery("#future-program-" + _id).hide();
                jQuery("#active-program-" + _id).show();
                jQuery("#future-program-text-" + _id).hide();
                jQuery("#active-program-text-" + _id).show();
            });
        }
    });
});
