﻿/* News feed animations */
// feedTickerInterval comes from the host page

$(document).ready(function(){    

    if ($('.feed-list').length > 0) {
    	

        $(".facebookfeeds").ndSocial({
            service: 'facebook',
            account: 'nationalsportsmuseum',
            messagesPerPage: 4,
            totalPages: 3,
            firstMessageMarkerClass: 'active',
            loadingText: "Loading Facebook feeds..."

        }, function () {
            var $feedlist = $(this);
            var $listitems = $feedlist.find('UL.items > LI');
            $listitems.filter(':first').addClass('active');
            $listitems.live('hover', function () {
                if ($(this) == true) {
                    return;
                } else {
                    $listitems.removeClass('active');
                    $(this).addClass('active');
                }
            });

        });
        $(".twitterfeeds").ndSocial({
            service: 'twitter',
            account: 'NSMNews',
            messagesPerPage: 4,
            totalPages: 3,
            firstMessageMarkerClass: 'active',
            perPage: 4,
            loadingText: "Loading twitter feeds..."
        }, function () {
            var $feedlist = $(this);
            var $listitems = $feedlist.find('UL.items > LI');
            $listitems.filter(':first').addClass('active');
            $listitems.live('hover', function () {
                if ($(this) == true) {
                    return;
                } else {
                    $listitems.removeClass('active');
                    $(this).addClass('active');
                }
            });

        });


    }


	var maxHeight = 0;
	var current = $("#newsfeed div:first");
	do
	{
		if(current.height() > maxHeight)
			maxHeight = current.height();
		current = current.next();
	}
	while(current.length>0)
	
    $("#newsfeed").css("height",maxHeight);
    //alert(maxHeight);
    
	$("#newsfeed > div").hide();
	//$("#newsfeed > div:first").slideDown(700);
	$("#newsfeed > div:first").fadeIn(700);
	//$("#newsfeed>div.first").animate({opacity: 0},700);
	setTimeout(newsfeedtick, feedTickerInterval);

	if ($('.video-gallery').length > 0) {


	    $('DIV.video-gallery DIV.media-album DIV.item A').click(function (e) {
	        e.preventDefault();
	        var mediaDescription = $(this).parent().parent().find('div.description').html();
	        $('DIV.video-gallery DIV.media-intro').html(mediaDescription);

	    })

	}

    if ($('input.date-pick').length > 0) {
        $("input.date-pick").datePicker();
    }

    if ($(".image-listing li").length > 0) {
        $(".image-listing li").vjustify();

    } 
 

function setVideoURL1(path, playOnLoad) {

     if ($.browser.msie) {
         document["VideoPlayer1"].setVideoURL(path, 'true');
     }
     else if ($.browser.mozilla) {
       
         document["VideoPlayer2"].setVideoURL(path, 'true');

     }
     else {
         window["VideoPlayer2"].setVideoURL(path, 'true');
     }

 }


    //start play video

    if ($('input#mediaUrl').length > 0 ) {
        var videoUrl = $('input#mediaUrl').val();

	setTimeout(function() {setVideoURL1(videoUrl, 'true'); }, 1000);

        
    }




});


