//MOBILE DETECTION
(function(a){jQuery.browser.mobile=/android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))})(navigator.userAgent||navigator.vendor||window.opera);


function mainmenu(){
	$('ul#nav li ul').css({display: "none"}); // Opera Fix
	$('ul#nav li').hover(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
		},function(){
		$(this).find('ul:first').css({visibility: "hidden"});
	});
}

$(document).ready(function(){
	mainmenu();
	activate_mobile();
});
// 0 default
// 1 full
// 2 mobile
var display_type=0;

function activate_mobile(){

	
	if(jQuery.browser.mobile){
		//add class for mobile styles
		$('#container').addClass('mobile');
		//change viewport to mobile
		/*$('<meta>', {
		 name: 'viewport',
		 content: 'width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0'
		}).appendTo('head');*/
		
		$('meta[name=viewport]').attr('content', 'width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0');
		
		if(display_type==0){
			display_type=2;
		}

		//add links in footer
		if(display_type==1){
			$('#footer').prepend('<a class="mobile_site display_type" href="javascript:void(\'0\');">Mobile Site</a>&nbsp;&nbsp;|&nbsp;&nbsp;');
		}else if(display_type==2){
			$('#footer').prepend('<a class="full_site display_type" href="javascript:void(\'0\');">Full Site</a>&nbsp;&nbsp;|&nbsp;&nbsp;');
		}
		
		activate_mobile_buttons();
	}
		
	
	
	
}

function activate_mobile_buttons(){
	$('.full_site').unbind();
	$('.mobile_site').unbind();
	$('.full_site').click(function(){
		display_type=1;
		$('#handheld').remove();
		$('#footer .display_type').addClass('mobile_site');
		$('#footer .display_type').removeClass('full_site');
		$('#footer .display_type').html('Mobile Site');
		$('meta[name=viewport]').attr('content', 'width=device-width, initial-scale=1.0, user-scalable=1');
		activate_mobile_buttons();
	});
	$('.mobile_site').click(function(){
		display_type=2;
		$('head').append('<link id="handheld" rel="stylesheet" href="/assets/styles/mobile.css" type="text/css" />');
		$('#footer .display_type').addClass('full_site');
		$('#footer .display_type').removeClass('mobile_site');
		$('#footer .display_type').html('Full Site');
		$('meta[name=viewport]').attr('content', 'width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0');
		activate_mobile_buttons();
	});	
}

//shows the RSS content in the browser
function showRSS(RSS,num_items){		
	//default values for html tags used
	//var imageTag = "<img id='chan_image'";
	//var startItemTag = "<li>";
	//var startTitle = "<div id='item_title'>";
	//var startLink = "<div id='item_link'>";
	//var startDescription = "<div id='item_description'>";
	//var endTag = "</li>";
	
	
	//populate channel data
	//var properties = new Array("title","link","description","pubDate","copyright");
	var properties = new Array("description");
	for (var i=0; i<properties.length; i++)	{
		eval("document.getElementById('more_from_author_name').innerHTML = ''");
		curProp = eval("RSS."+properties[i]);
		if (curProp != null){
			eval("document.getElementById('more_from_author_name').innerHTML = curProp");
		}
	}

	//show the image
	/*
	document.getElementById("chan_image_link").innerHTML = "";
	if (RSS.image.src != null){
		document.getElementById("chan_image_link").href = RSS.image.link;
		document.getElementById("chan_image_link").innerHTML = imageTag
			+" alt='"+RSS.image.description
			+"' width='"+RSS.image.width
			+"' height='"+RSS.image.height
			+"' src='"+RSS.image.url
			+"' "+"/>";
	} */

	//populate the items
	document.getElementById("author_items").innerHTML = "";
	item_html = "";
	var results = num_items.split("|");
	low = results[0]; //city
	high = parseInt(results[1]) + 1; //temp
	
	//GETS THE CURRENT ARTICLES TITLE
	var articleTitle = document.getElementById('article-title').innerHTML;
	
	for (var i=0; i<RSS.items.length; i++){						
		//MAKES SURE WE ONLY GET HIGH LIMIT AMOUNT AND ALSO CHECKS WE ARE NOT ADDING THE CURRENT ARTICLE TO THE LIST
		if(  (i<high && RSS.items[i].title!=articleTitle) && (i<high && html_entity_decode(RSS.items[i].title,"ENT_QUOTES")!=articleTitle)  ){
		//if(i<high && RSS.items[i].title!=articleTitle){							
			item_html += "<li>";
			item_html += (RSS.items[i].title == null && RSS.items[i].link == null) ? "" : "<a href=\""+RSS.items[i].link+"\">" + RSS.items[i].title + "</a>";
			//item_html += (RSS.items[i].link == null) ? "" : startLink + RSS.items[i].link + endTag;
			// item_html += (RSS.items[i].description == null) ? "" : startDescription + RSS.items[i].description + endTag;
			item_html += "</li>";	
		}
	}
	if(i>=low){
		document.getElementById("author_items").innerHTML += item_html; /*D1*/	
		document.getElementById("more_from_author_mod").style.display = "block";
	}

	//we're done
	
	return true;
}



//shows the RSS content in the browser
function showRSS_pubs(RSS,num_items){		
	//default values for html tags used
	//var imageTag = "<img id='chan_image'";
	//var startItemTag = "<li>";
	//var startTitle = "<div id='item_title'>";
	//var startLink = "<div id='item_link'>";
	//var startDescription = "<div id='item_description'>";
	//var endTag = "</li>";
	
	
	//populate channel data
	//var properties = new Array("title","link","description","pubDate","copyright");
	var properties = new Array("description");
	for (var i=0; i<properties.length; i++)	{
		eval("document.getElementById('more_from_pub_name').innerHTML = ''");
		curProp = eval("RSS."+properties[i]);
		if (curProp != null){
			eval("document.getElementById('more_from_pub_name').innerHTML = curProp");			
		}
	}

	//show the image
	/*
	document.getElementById("chan_image_link").innerHTML = "";
	if (RSS.image.src != null){
		document.getElementById("chan_image_link").href = RSS.image.link;
		document.getElementById("chan_image_link").innerHTML = imageTag
			+" alt='"+RSS.image.description
			+"' width='"+RSS.image.width
			+"' height='"+RSS.image.height
			+"' src='"+RSS.image.url
			+"' "+"/>";
	} */

	//populate the items
	document.getElementById("pub_items").innerHTML = "";
	item_html = "";
	var results = num_items.split("|");
	low = results[0]; //city
	high = parseInt(results[1]) + 1; //temp
	
	//GETS THE CURRENT ARTICLES TITLE
	var articleTitle = document.getElementById('article-title').innerHTML;
	
	for (var i=0; i<RSS.items.length; i++){						
		//MAKES SURE WE ONLY GET HIGH LIMIT AMOUNT AND ALSO CHECKS WE ARE NOT ADDING THE CURRENT ARTICLE TO THE LIST
		//if(i<high && RSS.items[i].title!=articleTitle){						
		if(  (i<high && RSS.items[i].title!=articleTitle) && (i<high && html_entity_decode(RSS.items[i].title,"ENT_QUOTES")!=articleTitle)  ){
			item_html += "<li>";			
			item_html += (RSS.items[i].title == null && RSS.items[i].link == null) ? "" : "<a href=\""+RSS.items[i].link+"\">" + RSS.items[i].title + "</a>";
			//item_html += (RSS.items[i].link == null) ? "" : startLink + RSS.items[i].link + endTag;
			// item_html += (RSS.items[i].description == null) ? "" : startDescription + RSS.items[i].description + endTag;
			item_html += "</li>";				
		}
	}
	if(i>=low){
		document.getElementById("pub_items").innerHTML += item_html; /*D1*/	
		document.getElementById("more_from_pub_mod").style.display = "block";
	}

	//we're done
	
	return true;
}


//OBJECTS

//objects inside the RSS2Item object
function RSS2Enclosure(encElement)
{
	if (encElement == null)
	{
		this.url = null;
		this.length = null;
		this.type = null;
	}
	else
	{
		this.url = encElement.getAttribute("url");
		this.length = encElement.getAttribute("length");
		this.type = encElement.getAttribute("type");
	}
}

function RSS2Guid(guidElement)
{
	if (guidElement == null)
	{
		this.isPermaLink = null;
		this.value = null;
	}
	else
	{
		this.isPermaLink = guidElement.getAttribute("isPermaLink");
		this.value = guidElement.childNodes[0].nodeValue;
	}
}

function RSS2Source(souElement)
{
	if (souElement == null)
	{
		this.url = null;
		this.value = null;
	}
	else
	{
		this.url = souElement.getAttribute("url");
		this.value = souElement.childNodes[0].nodeValue;
	}
}

//object containing the RSS 2.0 item
function RSS2Item(itemxml)
{
	//required
	this.title;
	this.link;
	this.description;

	//optional vars
	this.author;
	this.comments;
	this.pubDate;

	//optional objects
	this.category;
	this.enclosure;
	this.guid;
	this.source;

	var properties = new Array("title", "link", "description", "author", "comments", "pubDate");
	var tmpElement = null;
	for (var i=0; i<properties.length; i++)
	{
		tmpElement = itemxml.getElementsByTagName(properties[i])[0];
		if (tmpElement != null)
			eval("this."+properties[i]+"=tmpElement.childNodes[0].nodeValue");
	}

	this.category = new RSS2Category(itemxml.getElementsByTagName("category")[0]);
	this.enclosure = new RSS2Enclosure(itemxml.getElementsByTagName("enclosure")[0]);
	this.guid = new RSS2Guid(itemxml.getElementsByTagName("guid")[0]);
	this.source = new RSS2Source(itemxml.getElementsByTagName("source")[0]);
}

//objects inside the RSS2Channel object
function RSS2Category(catElement)
{
	if (catElement == null)
	{
		this.domain = null;
		this.value = null;
	}
	else
	{
		this.domain = catElement.getAttribute("domain");
		this.value = catElement.childNodes[0].nodeValue;
	}
}

//object containing RSS image tag info
function RSS2Image(imgElement)
{
	if (imgElement == null)
	{
	this.url = null;
	this.link = null;
	this.width = null;
	this.height = null;
	this.description = null;
	}
	else
	{
		imgAttribs = new Array("url","title","link","width","height","description");
		for (var i=0; i<imgAttribs.length; i++)
			if (imgElement.getAttribute(imgAttribs[i]) != null)
				eval("this."+imgAttribs[i]+"=imgElement.getAttribute("+imgAttribs[i]+")");
	}
}

//object containing the parsed RSS 2.0 channel
function RSS2Channel(rssxml)
{
	//required
	this.title;
	this.link;
	this.description;

	//array of RSS2Item objects
	this.items = new Array();

	//optional vars
	this.language;
	this.copyright;
	this.managingEditor;
	this.webMaster;
	this.pubDate;
	this.lastBuildDate;
	this.generator;
	this.docs;
	this.ttl;
	this.rating;

	//optional objects
	this.category;
	this.image;

	var chanElement = rssxml.getElementsByTagName("channel")[0];
	var itemElements = rssxml.getElementsByTagName("item");

	for (var i=0; i<itemElements.length; i++)
	{
		Item = new RSS2Item(itemElements[i]);
		this.items.push(Item);
		//chanElement.removeChild(itemElements[i]);
	}

	var properties = new Array("title", "link", "description", "language", "copyright", "managingEditor", "webMaster", "pubDate", "lastBuildDate", "generator", "docs", "ttl", "rating");
	var tmpElement = null;
	for (var i=0; i<properties.length; i++)
	{
		tmpElement = chanElement.getElementsByTagName(properties[i])[0];
		if (tmpElement!= null)
			eval("this."+properties[i]+"=tmpElement.childNodes[0].nodeValue");
	}

	this.category = new RSS2Category(chanElement.getElementsByTagName("category")[0]);
	this.image = new RSS2Image(chanElement.getElementsByTagName("image")[0]);
}

//PROCESSES

//uses xmlhttpreq to get the raw rss xml
function getRSS(rssurl,displayFunction,num_items){
	//call the right constructor for the browser being used
	if (window.ActiveXObject)
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest)
		xhr = new XMLHttpRequest();
	else
		alert("not supported");

	//prepare the xmlhttprequest object
	xhr.open("GET",rssurl,false);
	xhr.send(null); 
	
	
	
	/*
	var xhr = false;
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		xhr = new XMLHttpRequest();
	else if (window.ActiveXObject){ // if IE	
		try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } 
		catch (e){
			try{ xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
			catch (e){}
		}
	}else
		return false;
		
	
	xhr.open('GET', rssurl, false); //get page synchronously 		
	xhr.send(null); 
	*/
	
	
	
	//xhr.setRequestHeader("Cache-Control", "no-cache");
	//xhr.setRequestHeader("Pragma", "no-cache");
	//xhr.onreadystatechange = function() {
		
		//if (xhr.readyState == 4){
		//	if (xhr.status == 200){
				
				if (xhr.responseText != null){
					//alert(xhr.responseXML);
					processRSS(xhr.responseXML,displayFunction,num_items);
				}else{
					alert("Failed to receive RSS file from the server - file not found.");
					return false;
				}
		//	}
		//	else
		//		alert("Error code " + xhr.status + " received: " + xhr.statusText);
		//}
	//}

	//send the request
	//xhr.send(null);
}

//processes the received rss xml
function processRSS(rssxml,displayFunction,num_items){
	RSS = new RSS2Channel(rssxml);
	eval(displayFunction)(RSS,num_items);
	//showRSS(RSS);
}


var xhr;

function html_entity_decode( string, quote_style ) {
    // http://kevin.vanzonneveld.net
    // +   original by: john (http://www.jd-tech.net)
    // +      input by: ger
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +   improved by: marc andreu
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: get_html_translation_table
    // *     example 1: html_entity_decode('Kevin &amp; van Zonneveld');
    // *     returns 1: 'Kevin & van Zonneveld'
    // *     example 2: html_entity_decode('&amp;lt;');
    // *     returns 2: '&lt;'
 
    var histogram = {}, symbol = '', tmp_str = '', entity = '';
    tmp_str = string.toString();
    
    if (false === (histogram = get_html_translation_table('HTML_ENTITIES', quote_style))) {
        return false;
    }
 
    // &amp; must be the last character when decoding!
    delete(histogram['&']);
    histogram['&'] = '&amp;';
 
    for (symbol in histogram) {
        entity = histogram[symbol];
        tmp_str = tmp_str.split(entity).join(symbol);
    }
    
    return tmp_str;
}

function get_html_translation_table(table, quote_style) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: noname
    // +   bugfixed by: Alex
    // +   bugfixed by: Marco
    // +   bugfixed by: madipta
    // %          note: It has been decided that we're not going to add global
    // %          note: dependencies to php.js. Meaning the constants are not
    // %          note: real constants, but strings instead. integers are also supported if someone
    // %          note: chooses to create the constants themselves.
    // %          note: Table from http://www.the-art-of-web.com/html/character-codes/
    // *     example 1: get_html_translation_table('HTML_SPECIALCHARS');
    // *     returns 1: {'"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;'}
    
    var entities = {}, histogram = {}, decimal = 0, symbol = '';
    var constMappingTable = {}, constMappingQuoteStyle = {};
    var useTable = {}, useQuoteStyle = {};
    
    useTable      = (table ? table.toUpperCase() : 'HTML_SPECIALCHARS');
    useQuoteStyle = (quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT');
    
    // Translate arguments
    constMappingTable[0]      = 'HTML_SPECIALCHARS';
    constMappingTable[1]      = 'HTML_ENTITIES';
    constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
    constMappingQuoteStyle[2] = 'ENT_COMPAT';
    constMappingQuoteStyle[3] = 'ENT_QUOTES';
    
    // Map numbers to strings for compatibilty with PHP constants
    if (!isNaN(useTable)) {
        useTable = constMappingTable[useTable];
    }
    if (!isNaN(useQuoteStyle)) {
        useQuoteStyle = constMappingQuoteStyle[useQuoteStyle];
    }
 
    if (useTable == 'HTML_SPECIALCHARS') {
        // ascii decimals for better compatibility
        entities['38'] = '&amp;';
        if (useQuoteStyle != 'ENT_NOQUOTES') {
            entities['34'] = '&quot;';
        }
        if (useQuoteStyle == 'ENT_QUOTES') {
            entities['39'] = '&#039;';
        }
        entities['60'] = '&lt;';
        entities['62'] = '&gt;';
    } else if (useTable == 'HTML_ENTITIES') {
        // ascii decimals for better compatibility
      entities['38']  = '&amp;';
        if (useQuoteStyle != 'ENT_NOQUOTES') {
            entities['34'] = '&quot;';
        }
        if (useQuoteStyle == 'ENT_QUOTES') {
            entities['39'] = '&#039;';
        }
      entities['60']  = '&lt;';
      entities['62']  = '&gt;';
      entities['160'] = '&nbsp;';
      entities['161'] = '&iexcl;';
      entities['162'] = '&cent;';
      entities['163'] = '&pound;';
      entities['164'] = '&curren;';
      entities['165'] = '&yen;';
      entities['166'] = '&brvbar;';
      entities['167'] = '&sect;';
      entities['168'] = '&uml;';
      entities['169'] = '&copy;';
      entities['170'] = '&ordf;';
      entities['171'] = '&laquo;';
      entities['172'] = '&not;';
      entities['173'] = '&shy;';
      entities['174'] = '&reg;';
      entities['175'] = '&macr;';
      entities['176'] = '&deg;';
      entities['177'] = '&plusmn;';
      entities['178'] = '&sup2;';
      entities['179'] = '&sup3;';
      entities['180'] = '&acute;';
      entities['181'] = '&micro;';
      entities['182'] = '&para;';
      entities['183'] = '&middot;';
      entities['184'] = '&cedil;';
      entities['185'] = '&sup1;';
      entities['186'] = '&ordm;';
      entities['187'] = '&raquo;';
      entities['188'] = '&frac14;';
      entities['189'] = '&frac12;';
      entities['190'] = '&frac34;';
      entities['191'] = '&iquest;';
      entities['192'] = '&Agrave;';
      entities['193'] = '&Aacute;';
      entities['194'] = '&Acirc;';
      entities['195'] = '&Atilde;';
      entities['196'] = '&Auml;';
      entities['197'] = '&Aring;';
      entities['198'] = '&AElig;';
      entities['199'] = '&Ccedil;';
      entities['200'] = '&Egrave;';
      entities['201'] = '&Eacute;';
      entities['202'] = '&Ecirc;';
      entities['203'] = '&Euml;';
      entities['204'] = '&Igrave;';
      entities['205'] = '&Iacute;';
      entities['206'] = '&Icirc;';
      entities['207'] = '&Iuml;';
      entities['208'] = '&ETH;';
      entities['209'] = '&Ntilde;';
      entities['210'] = '&Ograve;';
      entities['211'] = '&Oacute;';
      entities['212'] = '&Ocirc;';
      entities['213'] = '&Otilde;';
      entities['214'] = '&Ouml;';
      entities['215'] = '&times;';
      entities['216'] = '&Oslash;';
      entities['217'] = '&Ugrave;';
      entities['218'] = '&Uacute;';
      entities['219'] = '&Ucirc;';
      entities['220'] = '&Uuml;';
      entities['221'] = '&Yacute;';
      entities['222'] = '&THORN;';
      entities['223'] = '&szlig;';
      entities['224'] = '&agrave;';
      entities['225'] = '&aacute;';
      entities['226'] = '&acirc;';
      entities['227'] = '&atilde;';
      entities['228'] = '&auml;';
      entities['229'] = '&aring;';
      entities['230'] = '&aelig;';
      entities['231'] = '&ccedil;';
      entities['232'] = '&egrave;';
      entities['233'] = '&eacute;';
      entities['234'] = '&ecirc;';
      entities['235'] = '&euml;';
      entities['236'] = '&igrave;';
      entities['237'] = '&iacute;';
      entities['238'] = '&icirc;';
      entities['239'] = '&iuml;';
      entities['240'] = '&eth;';
      entities['241'] = '&ntilde;';
      entities['242'] = '&ograve;';
      entities['243'] = '&oacute;';
      entities['244'] = '&ocirc;';
      entities['245'] = '&otilde;';
      entities['246'] = '&ouml;';
      entities['247'] = '&divide;';
      entities['248'] = '&oslash;';
      entities['249'] = '&ugrave;';
      entities['250'] = '&uacute;';
      entities['251'] = '&ucirc;';
      entities['252'] = '&uuml;';
      entities['253'] = '&yacute;';
      entities['254'] = '&thorn;';
      entities['255'] = '&yuml;';
    } else {
        throw Error("Table: "+useTable+' not supported');
        return false;
    }
    
    // ascii decimals to real symbols
    for (decimal in entities) {
        symbol = String.fromCharCode(decimal);
        histogram[symbol] = entities[decimal];
    }
    
    return histogram;
}

function htmlentities (string, quote_style) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: nobbler
    // +    tweaked by: Jack
    // +   bugfixed by: Onno Marsman
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: get_html_translation_table
    // *     example 1: htmlentities('Kevin & van Zonneveld');
    // *     returns 1: 'Kevin &amp; van Zonneveld'
    // *     example 2: htmlentities("foo'bar","ENT_QUOTES");
    // *     returns 2: 'foo&#039;bar'
 
    var histogram = {}, symbol = '', tmp_str = '', entity = '';
    tmp_str = string.toString();
    
    if (false === (histogram = get_html_translation_table('HTML_ENTITIES', quote_style))) {
        return false;
    }
    
    for (symbol in histogram) {
        entity = histogram[symbol];
        tmp_str = tmp_str.split(symbol).join(entity);
    }
    
    return tmp_str;
}





function locateKeywords(data, container)
{	
	var el = $(container);
	
	if(el.length>1){
		$.each(data.keywords, function(i,keyword){
			el.each(function(){
				var me=$(this);
				var pattern = new RegExp("(\\b"+keyword.word+"\\b)", ["i"]);
				//var rs = "<a href='"+keyword.url+"' class='external_link'>$1 <span>["+keyword.term+" <img src='/img/external.gif' />]</span></a>";
				var rs = "<a href='"+keyword.url+"' class='external_link'>$1</span></a>";
				me.html(me.html().replace(pattern, rs));
				
				if(me.html().match(pattern)!=null){
					return false;
				}
			});
		});
	}else{
		$.each(data.keywords, function(i,keyword){
			var pattern = new RegExp("(\\b"+keyword.word+"\\b)", ["i"]);
			//var rs = "$1 <a href='"+keyword.url+"' class='external_link'>["+keyword.term+" <img src='/img/external.gif' />]</a>";
			var rs = "<a href='"+keyword.url+"' class='external_link'>$1</span></a>";
			el.html(el.html().replace(pattern, rs));
			
			if(el.html().match(pattern)!=null){
				return false;
			}
		});
	}
} 

function getQueryVariable(variable) {
				var query = window.location.search.substring(1);
				var vars = query.split("&");
				for (var i=0;i<vars.length;i++) {
					var pair = vars[i].split("=");
					if (pair[0] == variable) {
						return pair[1]; 
					}
				}  
			}


