var live  = {};
live.video_format = 152;
live.still_format = 160;
live.thumb_format = 162;
//djplayer.players.first_id //First video_id loaded

live.home = function(incoming){
    if (incoming.videos.length){
	var first = incoming.videos[0];
	live.create({
		video : first["url_"+live.video_format],
		    image : first["url_"+live.still_format],
		    video_id : first.video_id
		    });
	if (typeof(djplayer.players["djvideo_campaign_1"]) == "undefined")
	    djplayer.players["djvideo_campaign_1"] = {};
	    
	djplayer.players["djvideo_campaign_1"].first_id = first.video_id;
	$("#djplayer_sidebar_title").html(first.title);

	var fill = "";
	for (var i in incoming.videos){
	    v = incoming.videos[i];
	    djplayer.videos[v.video_id] = {
		url_video : v["url_"+live.video_format],
		url_still : v["url_"+live.still_format],
		url_thumb : v["url_"+live.thumb_format],
		title : v.title,
		description: v.description,
		viewed : 0
	    };
	    fill += "<a class='side_video' href='javascript:live.homePlay("+v.video_id+");'>";
	    fill += "<div class='side_video_left'><img src='"+v["url_"+live.thumb_format]+"' /></div>";
	    fill += "<div class='side_video_right'><span>"+v.title+"</span><div>"+v.description+"</div></div>";
	    fill += "</a>";
	}
	$("#djplayer_sidebar_nav").html(fill);
    }
};

live.create = function(opt){
    var flashvars = {
        file: opt.video,
	image: opt.image,
        autostart:(opt.autostart ? "true" : "false"),
        controlbar: "over",
        skin: dj_require_base + "/includes/javascript/video/dangdang.swf",
        abouttext: "DrJays.com",
        aboutlink: dj_require_base,
        id: "djvideo_campaign_1"
    };
    var params = {
        allowfullscreen:"true",
        allowscriptaccess:"always"
    };
    var attributes = {
        id: "djvideo_campaign_1",
        name: "djvideo_campaign_1"
    };

    var width  = 300;
    var height = 169;
    swfobject.embedSWF(dj_require_base + "/includes/javascript/video/player.swf", "djvideo_campaign_1", width, height, "9.0.115", false, flashvars, params, attributes);
}

live.homePlay = function(video_id){
  
    var v = djplayer.videos[video_id];

    djplayer.players["djvideo_campaign_1"].player.sendEvent("LOAD",{
	    author:"DrJays.com",
		description: v.description,
		file: v.url_video,
		link: "http://live.drjays.com/",
		image: v.url_still,
		title: v.title,
		type: "video"
		});
    
    setTimeout("djplayer.players['djvideo_campaign_1'].player.sendEvent('PLAY', 'true')", 0);
    $("#djplayer_sidebar_title").html(v.title);
    djplayer.videoView(video_id);
};

live.subnav = function(subnav){

    fill = "";
    if (subnav == "style"){
	fill += "<a href='/index.php/category/style/trend-alert/?cm_re=SubHeader-_-Style%20-%20Trend%20Alert-_-60209'>Trend Alert</a>";
	fill += "<a href='/index.php/category/style/brand-alert/?cm_re=SubHeader-_-Style%20-%20Brand%20Alert-_-60209'>Brand Alert</a>";
	fill += "<a href='/index.php/category/style/celebrity-style/?cm_re=SubHeader-_-Style%20-%20Celebrity%20Style-_-60209'>Celebrity Style</a>";
	fill += "<a href='/index.php/category/style/street-style/?cm_re=SubHeader-_-Style%20-%20Street%20Style-_-60209'>Street Style</a>";
	fill += "<a href='/index.php/category/style/inside-style/?cm_re=SubHeader-_-Style%20-%20Inside%20Style-_-60209'>Inside Style</a>";
    }
    else if (subnav == "society"){
	fill += "<a href='/index.php/category/society/drjayscom-debate/?cm_re=SubHeader-_-Society%20-%20DrJays.com%20Debate-_-60209'>DrJays.com Debate</a>";
    }
    else if (subnav == "sounds"){
	fill += "<a href='/index.php/category/sounds/artist-spotlight/?cm_re=SubHeader-_-Sounds%20-%20Artist%20Spotlight-_-60209'>Artist Spotlight</a>";
    }
    else if (subnav == "screen"){

    }
    else if (subnav == "sneakers"){

    }
    else if (subnav == "silly"){

    }
    else if (subnav == "sports"){
	
    }
    $("#blog_subnav").html(fill);
};

live.sendCMElement = function(eid,cat){
    cmCreatePageElementTag(eid,cat);
};

$(document).ready(function(){
	$("#blog_nav a").mouseover(function(){
		var match = $(this).attr("id").match(/^blog_nav_(\S+)/);
		if (match)
		    live.subnav(match[1]);
	    }).mouseout(function(){
		    //live.subnav("");
		});
    });