﻿$(function(){
	$('li.filter').hover(function(){
		$(this).children('div.dropdown').toggle();
	});
	
	$('ul.filterItems').each(function(){
		$this = $(this);
		if ( $this.children('li').length > 10 )
			makelist($this);
	});
	
	$('div.tab').click(function(){
		var section = $(this).attr('data-section');
		$('div.tab').removeClass('current');
		$(this).addClass('current');
		$('div.contentContainer').hide();
		$('div.contentContainer[data-section="' + section + '"]').show();
	});
	
	// BUTTON ICONS
	
	var icons = {
	    mail: 'images/icons/mail.png',
	    feed: 'images/icons/feed.png'
	}
	
	$('.mButton[data-icon]').each(function () {
	    $(this).css({paddingLeft: 25}).append(
	        $('<div>').css({
	            position: 'absolute',
	            width: 16,
	            height: 16,
	            left: 5,
	            top: 2,
	            backgroundImage: 'url(' + icons[$(this).attr('data-icon')] + ')'
	        })
	    );
	});
	// END BUTTON ICONS
});

AudioPlayer.setup("/Pages/Sermons/flash/player.swf", {  
	width: 560,
	transparentpagebg: "yes",
	autostart: "no"
});

$(document).ready(function(){
    $('.emailTrigger').fancybox({
        "type": "iframe",
        "width": 360,
        "height": 500
    });
});

var audioPlayer;
function togglePlayer(playerID)
{
    $div = $("#mp3Player" + playerID);
    audioPlayer = "audioplayer_" + playerID;
    if($div.is(":hidden"))
    {
        $div.slideDown(function()
        {
            setTimeout('openPlayer(true);', 400);
        });
    }
    else
    {
        AudioPlayer.getPlayer("audioplayer_" + playerID).close();
        setTimeout('openPlayer(false);', 400);
    }
}

function openPlayer(b)
{
    if(b == true)
        AudioPlayer.getPlayer(audioPlayer).open();
    else
        $div.slideUp();
}

function toggleNotes(playerID, videoURL)
{
    var vWidth = 548;
    var vHeight = 340;
    $notes = $("#notes" + playerID);
    $video = $("#video" + playerID);
    if($notes.is(":visible")){
        $notes.slideUp("slow", function(){
            $video.html("");
        });
    }else{
        if(videoURL != ""){
            $video.show();
            $video.html('<iframe style="margin-bottom: 10px;" width="' + vWidth.toString() + '" height="' + vHeight.toString() + '" src="' + videoURL + '" frameborder="0" allowfullscreen></iframe>');
        }
        else{
            $video.html("");
            $video.hide();
        }
            
        $notes.slideDown();
    }
}
