
Shadowbox.loadSkin('classic', 'http://www.elon.edu/campaign/Scripts/shadowbox/skin');
Shadowbox.loadLanguage('en', 'http://www.elon.edu/campaign/Scripts/shadowbox/lang');
Shadowbox.loadPlayer(['flv', 'iframe'], 'http://www.elon.edu/campaign/Scripts/shadowbox/player');

function getPlayer(gid) {
	if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[gid];
	} else {
		return document[gid];
	}
};

$(document).ready(function() {

    var options = {
        flvPlayer:     'http://www.elon.edu/campaign/Scripts/player.swf'
    };
    
    Shadowbox.init(options);
    
    var width = parseInt($("#videos_container").css("width").replace("px",""));
    
    loadVideos();
    
    checkNextPrev();
    
    /*
    $("#shadowbox_container").css("display","none");
    
    $("#shadowbox_overlay, #shadowbox_nav_close").click(function(){
        $("#shadowbox_container").css("display","none");
    });*/
    
    $("#prev").click(function(){
        var amount = parseInt($("#videos").css("margin-left").replace("px","")) + width;
        $("#videos").animate({marginLeft: amount + "px"}, 700, null, function(){
            $("#videos").css("margin-left",amount + "px");
            checkNextPrev(width);
        });
        return false;
    });
    
    $("#next").click(function(){
        var amount = parseInt($("#videos").css("margin-left").replace("px","")) - width;
        $("#videos").animate({marginLeft: amount + "px"}, 700, null, function(){
            $("#videos").css("margin-left",amount + "px");
            checkNextPrev(width);
        });
        return false;
    });
    
});

function loadVideos(category)
{
    var totalCount = 0;
    
    var categoryS = ((category) ? "?c=" + category : "");
    $("#videos").css("margin-left","0px");
    checkNextPrev();
    $.ajax({
        type: "GET",
        url: "http://www.elon.edu/shell/ignite/ignitevideos.xml",
        dataType: "xml",
        success: function(xml) {
            $("#videos").html("");
            
            $(xml).find('videos').each(function() {
                $(this).find('video').each(function() {
                
                    var id = $(this).attr('id');
                    var category = $(this).attr('category');
                    var name = $(this).find('name').text();
                    var video_url = $(this).find('video_url').text();
                    var thumb_url = $(this).find('thumb_url').text();
                    
                    var div = '<a class="sb_link" rel="shadowbox;width=640;height=480" href="' + video_url + '"><img src="' + thumb_url + '"/>' + '<br />' + name + '</a>';
                    $('<li></li>').html(div).appendTo('#videos');
                    totalCount++;
                });
                Shadowbox.setup($("li > a[rel^=shadowbox]"));
                $(".sb_link, #submit_story_link").click(function(){
                    $("#shadowbox_container").css("display","block");
                });
                
                if(totalCount < 6)
                {
                    $('#next').hide();
                }
            });
        },
        error: function(xhr, message, ex) {
            alert("Please try again. Error: " + message);
        }
    });
}

function checkNextPrev(width)
{
    var nextVis = false;
    var prevVis = false;
    var marginLeft = parseInt($("#videos").css("margin-left").replace("px",""));
    var numElements = $("#videos > li").size();

    if ((numElements / 4) * width < ((marginLeft * -1) + width))
    {
        nextVis = false;
    }
    else
    {
        nextVis = true;
    }
    
    if (marginLeft == 0)
    {
        prevVis = false;
        nextVis = true;
    }
    else
    {
        prevVis = true;
    }
    
    if (prevVis)
    {
        $("#prev").show("fast");
    }
    else
    {
        $("#prev").hide("fast");
    }
    
    if (nextVis)
    {
        $("#next").show("fast");
    }
    else
    {
        $("#next").hide("fast");
    }
}

                                $(document).ready(function(){
                                

var flashvars = false;
    var params = {menu: "false",flashvars: "overstretch=false&displayheight=320&controlbar=none&autostart=false&image=http://www.elon.edu/images/e-web/giving/ignite/csagevideo.jpg"};
    var attributes = {id: "realvideo",name: "realvideo"};
    swfobject.embedSWF("http://www.elon.edu/campaign/Scripts/player.swf?file=http://stream.elon.edu/stream/ur/2009/6_09/carolinesageignite_6_22_09.flv", "realvideo", "240", "157", "9.0.0","http://www.elon.edu/campaign/Scripts/expressInstall.swf", flashvars, params, attributes);

                                });


