﻿var flashPlayerVersion = "10.0.0";

// hide tables in article body
$("div#articleBody table").remove();

// set up author display
$("div.articleAuthor a").hover(function() {
	var IEoffset = 0;
	if ($.browser.msie && $.browser.version.substring(0, 1) == "7") IEoffset = 10; ;
	var newPos = $("div#articleDetails").position();
	$("div#authorDetails").css({ "left": newPos.left + IEoffset, "top": 0 });
	$("div#authorDetails").fadeIn("slow");
});
$("div#authorDetails").hover(null, function() {
	$("div#authorDetails").fadeOut();
});

// article tools
$(".articleTools:first").prepend("").css({ 'padding-left': '10px', 'text-align': 'left' });

var videoWidth = 320;

if (typeof imageName == 'undefined')
	imageName = "";

if (typeof wmvExists == 'undefined')
	wmvExists = false;

if (typeof flashVideoExists == 'undefined')
	flashVideoExists = false;

$("#articleBody div.articleText > *").addClass("adjusted");
$(".articleExtras").addClass("adjusted");
$(".articleTools").addClass("adjusted");
$("div.articleText").append($("div.articleTools"));

// add image if there is one.
if (imageName == "" && wmvExists == false && flashVideoExists == false) {
	$("div.articleImage").hide();
} else if (wmvExists) {
	$("#flashPlayerBlock").hide();
	$("#flashEmbed").hide();
} else if (flashVideoExists) {
	if (swfobject.hasFlashPlayerVersion(flashPlayerVersion)) {

		var path = "/media/player/player.swf?url=" + sConnection + "&img=" + imageName + "&control_url=controls_news.swf&isLive=" + isLive + "&buffer=" + iBuffer + "&in=" + inPoint + "&out=" + outPoint + "&autoPlay=" + autoPlay + "&origin=CBN_NEWS&aid=" + articleId + "&ts=" + (new Date).getTime();

		var fn = function() {
			var att = { data: path, width: "100%", height: "100%" };
			var par = { wmode: "opaque", scr: "fullscreen", allowfullscreen: "true", bgcolor: "#000000" };
			var id = "flashVideo";

			var obj = swfobject.createSWF(att, par, id);

		};
		swfobject.addDomLoadEvent(fn);

		$("#flashVideo").show();
		$("#flashError").hide();
	}
	else {
		$("#flashVideo").hide();
		$("#flashError").show();
	}
}
else {
	if (imageName != "") { $("div.articleImage").html("<img src='" + imageName + "' width='320' />"); }
	$("#flashPlayerBlock").hide();
	$("#flashEmbed").hide();
}

// check for older video content and adjust size as needed
if ($("img#videoImage").length > 0) {
	$("span.articleImage").css({ 'height': 'auto', 'overflow': 'hidden' });
}

function stretchMe() {
	if ($("div.articleImage").width() < 615) {
	    if (navigator.userAgent.indexOf("Firefox") != -1) {
	        $("div.articleImage").height("480px").width("615px");
	        $("span#flashPlayerBlock").height("450px").width("615px");
	        $("span#flashEmbed input").width("80%");
	    } else if (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) {
	        // do nothing
	    } else {
	    $("div.articleImage").animate({ width: "615px", height: "480px" }, 1000);
	    $("span#flashPlayerBlock").animate({ width: "615px", height: "450px" }, 1000);
	    $("span#flashEmbed input").width("80%");
	    }
	}
	else {
		if (navigator.userAgent.indexOf("Firefox") != -1)
		{
			$("div.articleImage").height("270px").width("320px");
	        $("span#flashPlayerBlock").height("240px").width("320px");
	        $("span#flashEmbed input").width("250px");
		} else {
		    $("div.articleImage").animate({ width: "320px", height: "270px" }, 1000);
		    $("span#flashPlayerBlock").animate({ width: "320px", height: "240px" }, 1000);
		    $("span#flashEmbed input").width("80%");
		}
	}
}
