$(document).ready(function() {
	
	$("div.videoControl").click(function(){
		if ( $(this).hasClass("closedControl") ) {
			$("p.videoDesc").hide();
			$("div.videoControl").removeClass("openControl");
			$("div.videoControl").addClass("closedControl");
			$(this).parent().find("p.videoDesc").fadeIn("fast");
			$(this).addClass("openControl");
			$(this).removeClass("closedControl");
			return
		}
		if ( $(this).hasClass("openControl") ) {
			$("p.videoDesc").hide();
			$(this).addClass("closedControl");
			$(this).removeClass("openControl");
			return
		}
	});
	
	
	/*
	$(function () {
        $('.videoList li').each(function () {
            var distance = 5;
            var time = 50;
            var hideDelay = 50;
            var hideDelayTimer = null;
            var beingShown = false;
            var shown = false;
            var info = $('.popup').css('opacity', 0); //dob object handle to the popup

			$('div.videoControl').mouseover(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown || shown) {
                    // don't trigger the animation again
                    return;
                } else {
                    // reset position of info box
                    beingShown = true;
					
					//showing the popup
                    info.css({
                        top: 3,
                        left: 270,
                        display: 'block'
                    }).animate({
						//enable a vertical slide by uncommenting this
                        //top: '-=' + distance + 'px',
                        opacity: 1
                    }, time, 'swing', function() {
                        beingShown = false;
                        shown = true;
                    });
                }
                return false;
				
            }).mouseout(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function () {
                    hideDelayTimer = null;
					
					//hiding the popup
                    info.animate({
						//enable a vertical slide by uncommenting this
                        //top: '-=' + distance + 'px',
                        opacity: 0
                    }, time, 'swing', function () {
                        shown = false;
                        info.css('display', 'none');
                    });

                }, hideDelay);
                return false;
				
            });
        });
    });
	
	*/
	
	
	function selectTab(category) {
		current_list = 'ul#VideoList' + category;
		current_tab = 'div#video-tab-' + category;
		$("ul.videoList").css("visibility", "hidden");
		$("ul.videoList").css("display", "none");
		$(current_list).css("visibility", "visible");
		$(current_list).css("display", "block");
		$("div.video-tab").removeClass("video-tab-on");
		$("div.video-tab").addClass("video-tab-off");
		$(current_tab).removeClass("video-tab-off");
		$(current_tab).addClass("video-tab-on");
	}
	
	/*
		current_category should be set by php on the page that uses this script
	*/
	
	selectTab(current_category);
	
	$("div#video-tab-1").click(function(){
		if ( $(this).hasClass("video-tab-off") ) {
			selectTab(1);
			return
		}
	});
	
	$("div#video-tab-2").click(function(){
	
		if ( $(this).hasClass("video-tab-off") ) {
			selectTab(2);
			return
		}
	});
	
	$("div#video-tab-3").click(function(){
		if ( $(this).hasClass("video-tab-off") ) {
			selectTab(3);
			return
		}
	});
	
});