//java script

/**
*includes a file
*/
function include(filename)
{
	var head = document.getElementsByTagName('head')[0];
	
	script = document.createElement('script');
	script.src = filename;
	script.type = 'text/javascript';
	
	head.appendChild(script);
}

//storage for properties files
var properties = new Array();

//include company specific config
include(ntkn_branded_assets_directory + "config.js");


//the window to view the story
var win;
//the browser window for external links
var browserWin;

//size of font in story window 
var bodyFontSize = 10;

//story content
var title;
var author;
var body;
var categories;
var date;

window.onbeforeunload = confirmExit;



/**
onClose calls client to close socket
*/
function onClose()
{
	//todo call flex object
}
/**
*Calls a callback which has been registered by flash
*/
function confirmExit()
{
	onClose();
}

/**
*opens a link in the browser window'
*/
function openLink(address)
{
	browserWin = window.open(address,'browserWin','');
}

/**
*Sets body size of font
*/
function setBodyFontSize(s)
{
	bodyFontSize = s;
	reload();
}

/**
*Brings up the story display
*/
function displayStory(t,a,b,d,c)
{
	//set data
	title = t;
	author = a;
	body = b;
	categories = c;
	date = d;
	
	//write html
  	writeOutput();
  	//focus window
	
	win.focus();
}


/**
*Writes the html output to win
*/
function writeOutput()
{
	win = window.open('','win','toolbar=no,addressbar=no,menubar=no,scrollbars=1,resizable=1,width=500,height=400');
	win.document.open();
	win.document.clear();
	
	win.document.write('<head><title>NTKN News Stories</title>');
	win.document.write('<style type="text/css">p.body {font-size: ' + bodyFontSize + 'px}</style>');
	win.document.write('</head>');
	
	win.document.write('<body bgcolor="#E7E7E7">');
	win.document.write('<font size="2" face="Verdana">');
	win.document.write('<div style="z-index: 1; border-color: #798C95; border-width: 1px; border-style: solid; height: 99%;  margin-left:0.2%; margin-right:0.2%;margin-top:0.2%;margin-bottom:0.2%;padding-left:3%; padding-right:3%;padding-top:3%;padding-bottom:3%;background-color:#f8f8f8; layer-background-color:#f8f8f8; visibility: visible"');
	win.document.write('<div style="z-index: 2; left: 20px; top: 50px; margin-left: 20px; background-color:#fefefe; layer-background-color:#fefefe; visibility: visible"');
	win.document.write('<p>');
	win.document.write('<font size="5">' + title+ '</font>');
	win.document.write('</p>');
	
	win.document.write('<p class="body">');
	win.document.write(body);
	win.document.write('</p>');
	
	
	win.document.write('<p>');
	win.document.write('<font color="#888888">' +date+'</font>');
	win.document.write('</p>');
	
	win.document.write('<p>');
	win.document.write('<font color="#888888">' +categories+'</font>');
	win.document.write('</p>');
	
	win.document.write('<p>');
	win.document.write('<em><font color="#888888">' + author+'</font></em>');
	win.document.write('</p>');
	
	win.document.write('</div>');
	win.document.write('</div>');
	win.document.write('</font>');
	win.document.write('</body>');
	
	//make all links open in new window
	var links = win.document.getElementsByTagName('a');
	for (var i=0; i<links.length; ++i) 
	{
		links[i].setAttribute('target','_blank');
	}

	//close output
	win.document.close();
}

/**
*If the story window is open, the output is rewritten, else nothing.
*/
function reload()
{
	if (win != undefined && !win.closed)
	{
		writeOutput();
	}
}

/**
*Closes the story window
*/
function closeStoryWindow()
{
	if (win != undefined && !win.closed)
		win.close();
}

/**
*Writes a cookie to this browser
*/
function createCookie(name,value,days) 
{
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires;
}

/**
*Reads a cookie from browser
*/
function readCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

/**
*Gets a config property
*/
function getProperty(name)
{
	return properties[name];
}

