<!-- HIDE SCRIPT
//NAVIGATION 
function adorder(url) {
	if (url == '')
		url = 'http://tacomanewstribune.adperfect.com/';

	var adWindow;
	if (adWindow = window.open(url,'weboe', 'width=1024,toolbar=yes,location=yes,menubar=yes,scrollbars=yes,resizable=yes')) {
		adWindow.focus();
	} else {
		alert('You must allow popups from this site in order to place an ad.');
	}
	return false;
}

// GENERIC COOKIE SCRIPT (Next 3 functions)
function getCookieVal(offset) {
	var endstr=document.cookie.indexOf(";",offset);

	if (endstr==-1)
	endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset,endstr));
}

function GetCookie(cname) {
	var arg=cname+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;

	while (i<clen) {
		var j=i+alen;
		if (document.cookie.substring(i,j)==arg) return getCookieVal (j);                 i=document.cookie.indexOf(" ",i)+ 1;
		if (i==0) break;
	} return null;
}

function SaveCookie(cname,cvalue,cdays,cpath) {
	ex = new Date;
	ex.setTime(ex.getTime() + (cdays*86400000));

	if (cpath == null) { cpath = "/" };
	cpath = "; path=" + cpath;
	if (cdays == null) { cdays = "" } else { cdays = "; expires=" + ex.toGMTString() }
	document.cookie = cname + '=' + cvalue + cdays + cpath + ";domain=" + location.host.replace(/.*\.(.*\.com)/,"$1") + ";";
}

function readCookie(name) {
	var cookieValue = "";
	var search = name + "=";
	if(document.cookie.length > 0) { 
		offset = document.cookie.indexOf(search);
		if (offset != -1) { 
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
			cookieValue = unescape(document.cookie.substring(offset, end))
		}
	}
	return cookieValue;
}

function parseCookie(cookie, key) {
	var valArray = cookie.split("|");
	for (i = 0; i < valArray.length; i++) {
		if (valArray[i].match(key)) {var value = valArray[i].split("="); return value[1];}
	}
	return null;
}

// GENERIC WINDOW OPENER (pass window options to function)
function openWin(url,name,options) {
	win = window.open(url,name,options);
	self.name = "main";
	win.focus();
}

// PHOTO GALLERY POPUP (preset window options)
function photoGallery(url) {
	galleryWindow = window.open(url,'gallerypopup','status=yes,width=660,height=600,scrollbars=auto,resizable=yes');
	galleryWindow.focus();
}

// PHOTO GALLERY POPUP2 (preset window options)
function photoGallery2(url) {
	galleryWindow = window.open(url,'gallerypopup','status=yes,width=800,height=550,scrollbars=auto,resizable=yes');
	galleryWindow.focus();
}

// 24 HOUR PHOTO GALLERY POPUP (preset window options)
function goGallery(url) {
        var hackedUrl = "/24hour" + url;
	galleryWindow = window.open(hackedUrl,'gallerypopup','status=yes,width=660,height=600,scrollbars=auto,resizable=yes');
	galleryWindow.focus();
}

// VIDEO GALLERY POPUP (preset window options)
function videoGallery(url) {
	videoWindow = window.open(url,'videopopup','status=yes,width=485,height=400,scrollbars=auto,resizable=yes');
	videoWindow.focus();
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,width=600,height=300');");
}

// VIDEO 2 GALLERY POPUP -- FOR LONGER DESCRIPTIONS (preset window options)
function video2Gallery(url) {
	videoWindow = window.open(url,'videopopup2','status=yes,width=485,height=550,scrollbars=auto,resizable=yes');
	videoWindow.focus();
}

// FLASHVIDEO GALLERY POPUP (preset window options)
function flashvideo(url) {
	videoWindow = window.open(url,'flashvideo','status=yes,width=400,height=480,scrollbars=auto,resizable=yes');
	videoWindow.focus();
}


// AUDIO POPUP (preset window options)
function audioGallery(url) {
	videoWindow = window.open(url,'videopopup','status=yes,width=435,height=200,scrollbars=auto,resizable=yes');
	videoWindow.focus();
}

// AUDIO2 POPUP - boxier longer descriptions (preset window options)
function audio2Gallery(url) {
	//videoWindow = window.open(url,'videopopup','status=yes,width=410,height=360,scrollbars=auto,resizable=yes');
	videoWindow = window.open(url,'videopopup','status=yes,width=410,height=460,scrollbars=auto,resizable=yes');
	videoWindow.focus();
}

// SLIDESHOW POPUP - (preset window options)
function slideshowGallery(url) {
	slideshowWindow = window.open(url,'slideshowpopup','status=yes,width=800,height=630,scrollbars=auto,resizable=yes');
	slideshowWindow.focus();
}

// RYAN MOORE POPUP (preset window options)
function specialGallery(url) {
	galleryWindow = window.open(url,'gallerypopup','status=yes,width=640,height=500');
	galleryWindow.focus();
}

// FIX MAIL LINKS (part of obscuring e-mail addresses, puts address back together)
function fixMail(to,domain,tld) {
	if (tld == undefined) {tld = "com";}
	if (domain == undefined) {domain = "mail.tribnet";}
	document.location="ma"+"ilto:"+to+"\@"+domain+"\."+tld;
} 

// PULLDOWN MENU SCRIPT
function formHandler(pulldownform){
var URL = document.pulldownform.site.options[document.pulldownform.site.selectedIndex].value;
window.location.href = URL;
}
function formHandler2(pulldownform2){
var URL = document.pulldownform2.site2.options[document.pulldownform2.site2.selectedIndex].value;
window.location.href = URL;
}

// UPDATE COOKIES
var insitecookie="tacoma_user_auth";
var threshold=0;
var daystokeep=1;

if (GetCookie(insitecookie) && !GetCookie(insitecookie).match("threshold")) {
    if (!GetCookie('seentoday')) {
         document.write('<img width="1" height="1" border="0" ');
		 document.write("src='http://www.thenewstribune.com/static/secure/log.gif?pg="+escape(document.location)+"'>");
         SaveCookie('seentoday',1,.9,'/')
    }
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=660,left = 340,top = 212');");
}

function wallpaperWindow(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=660,height=620,left = 340,top = 212');");
}

function tntLongDate() {
	var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
	var today = new Date();
	var wday   = days[today.getDay()];
	var lmonth = months[today.getMonth()];
	var date = today.getDate();
	var fyear = today.getFullYear();
	
	return (wday +", " + lmonth + " " + date + ", " + fyear);
}

// END HIDING -->


// IMAGE ROLLOVER

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/*
JQUERY IMPLEMENTATIONS - 02.22.2010
by Ian Swenson

Controls front daypart and searchbar
*/

$(document).ready(function(){
	
	/*** FRONT DAYPART: Change label, sidebar & contnet ***/
	$('#front_daypart_label a').click(function(){
		
		// Variable with corresponding sidebar ul id
		var sb = '#fdsb_' + $(this).attr('name');
		
		// Variable with corresponding content div id
		var ct = '#fd_' + $(sb + ' li.topli a').attr('name');
		
		// Change active in label
		$(this).parent().addClass('active').siblings().removeClass('active');
		
		// Change active in sidebar and remove active from its li's
		$(sb).addClass('active').removeClass('disabled')
			.siblings().addClass('disabled').removeClass('active')
			.children('li').addClass('disabled').removeClass('active');
			
		// Add active to first li of new sidebar
		$(sb + ' li.topli').addClass('active');
		
		// Move styling div to active li
		$('#front_daypart_sidebar_styling').appendTo($(sb + ' li.topli'));
		
		// Change active in content
		$(ct).addClass('active').removeClass('disabled')
			.siblings().addClass('disabled').removeClass('active');
			
		// Don't follow link
		return false;
	}) ;

	/*** FRONT DAYPART: Change active li & content ***/
	$('#front_daypart_box ul a').click(function(){
		
		// Variable with corresponding content div id
		var ts = '#fd_' + $(this).attr('name');
		
		// Move styling div to active li
		$('#front_daypart_sidebar_styling').appendTo($(this).parent());
		
		// Change active li
		$(this).parent().addClass('active').siblings().removeClass('active');
		
		// Change active in content
		$(ts).addClass('active').removeClass('disabled')
			.siblings().addClass('disabled').removeClass('active');
			
		// Don't follow link
		return false;
	}) ;
	
	
	/*** SEARCH BAR: Create drop down and send to appropriate place ***/
	$('#search_field').focus(function() {
		$('#search_controller').css('display', 'block');
	})
	.blur(function() {
		if ($(this).val()) { $(this).css('background-position', '0 -32px'); }
	});
	
	$('#search_close').click(function() {
		$('#search_controller').fadeOut(250);
	});
	
	$('#search_form').submit(function() {
		if ( $('#search_field').val() == '' ) { 
			alert('Please type in your search terms');
			return false;
		}
		else {
			if ( $('#search_controller input:radio:checked').val() == 'web_search') {
				var encoded_keywords = encodeURIComponent( $('#search_field').val() );
				var section_num = '702';
				var url_version = 'osr';
				var params = 
					'product=Yahoo,Overture&' + 'collection=WEB&' + 
					'preview_template=http%3A%2F%2Fpreview.thenewstribune.com%2F' + 
					section_num + 
					'%2Fv-' + url_version + '%2Findex.html&' +
					'live_template=http%3A%2F%2Fwww.thenewstribune.com%2F' + 
					section_num + 
					'%2Fv-' + 
					url_version + 
					'%2Findex.html&' + 
					'error_template=http%3A%2F%2Fwww.thenewstribune.com%2F' + 
					section_num + 
					'%2Fv-err%2Findex.html&' +
					'results_per_page=10&preview=1&'  +
					'prop_related=1&prop_dym=1';
				window.location = 'http://search2.thenewstribune.com/search-bin/search.pl.cgi?sf_Keywords=' + encoded_keywords + '&' + params;
				return false;
			}
		}
	});
	
});


/*
JUITTER 1.0.0 - 22/07/2009 - http://juitter.com
BY RODRIGO FANTE - http://rodrigofante.com

** jQuery 1.2.* or higher required

Juitter is distributed under the MIT License
Read more about the MIT License --> http://www.opensource.org/licenses/mit-license.php

This script is just a beta test version, download and use it at your own risk.
The Juitter developer shall have no responsability for data loss or damage of any kind by using this script.
*/
(function($) {
	var conf = {},
		// JUITTER DEFAULT CONFIGURATION ========================
		// YOU CAN CHANGE THE DYNAMIC VARS ON CALLING THE start method, see the system.js for more information about it.

		numMSG = 20; // set the number of messages to be show
		containerDiv="juitterContainer", // //Set a place holder DIV which will receive the list of tweets example <div id="juitterContainer"></div>
		loadMSG="Loading messages...", // Loading message, if you want to show an image, fill it with "image/gif" and go to the next variable to set which image you want to use on 
		imgName="loader.gif", // Loading image, to enable it, go to the loadMSG var above and change it to "image/gif"
		readMore="Read it on Twitter", // read more message to be show after the tweet content
		// IAN EDIT: add option
		rt="off", // change to anything else to include retweets
		nameUser="image" // insert "image" to show avatar of "text" to show the name of the user that sent the tweet 
		live:"live-20", //optional, disabled by default, the number after "live-" indicates the time in seconds to wait before request the Twitter API for updates, I do not recommend to use less than 60 seconds.
		// end of configuration
		
	
		// some global vars
		aURL="";msgNb=1;
		var mode,param,time,lang,contDiv,loadMSG,gifName,numMSG,readMore,rt,fromID,ultID,filterWords;
		var running=false;
		// Twitter API Urls
		apifMultipleUSER = "http://search.twitter.com/search.json?from%3A";
		apifUSER = "http://search.twitter.com/search.json?q=from%3A";
		apitMultipleUSER = "http://search.twitter.com/search.json?to%3A";
		apitUSER = "http://search.twitter.com/search.json?q=to%3A";
		apiSEARCH = "http://search.twitter.com/search.json?q=";
	$.Juitter = {
		registerVar: function(opt){
			mode=opt.searchType;
			param=opt.searchObject;
			timer=opt.live;
			lang=opt.lang?opt.lang:"";
			contDiv=opt.placeHolder?opt.placeHolder:containerDiv;
			loadMSG=opt.loadMSG?opt.loadMSG:loadMSG;
			gifName=opt.imgName?opt.imgName:imgName;
			numMSG=opt.total?opt.total:numMSG;
			readMore=opt.readMore?opt.readMore:readMore;
			// IAN EDIT: add option
			rt=opt.rt?opt.rt:rt;
			fromID=opt.nameUser?opt.nameUser:nameUser;
			filterWords=opt.filter;
			openLink=opt.openExternalLinks?"target='_blank'":"";
		},
		start: function(opt) {		
			ultID=0;
			if($("#"+contDiv)){	
				this.registerVar(opt);
				// show the load message
				this.loading();
				// create the URL  to be request at the Twitter API
				aURL = this.createURL();
				// query the twitter API and create the tweets list
				this.conectaTwitter(1);		
				// if live mode is enabled, schedule the next twitter API query
				if(timer!=undefined&&!running) this.temporizador();
			}   
		},
		update: function(){
			this.conectaTwitter(2);		
			if(timer!=undefined) this.temporizador();
		},
		loading: function(){
			if(loadMSG=="image/gif"){
				$("<img></img>")
					.attr('src', gifName)
					.appendTo("#"+contDiv); 
			} else $("#"+contDiv).html(loadMSG);
		},
		createURL: function(){
			var url = "";
			jlg=lang.length>0?"&lang="+lang:jlg=""; 
			var seachMult = param.search(/,/);
			if(seachMult>0) param = "&ors="+param.replace(/,/g,"+");
			if(mode=="fromUser" && seachMult<=0) url=apifUSER+param;
			else if(mode=="fromUser" && seachMult>=0) url=apifMultipleUSER+param;
			else if(mode=="toUser" && seachMult<=0) url=apitUSER+param;
			else if(mode=="toUser" && seachMult>=0) url=apitMultipleUSER+param;
			else if(mode=="searchWord") url=apiSEARCH+param+jlg;
			// IAN EDIT: double message number to keep retweets in check
			url += "&rpp="+(numMSG*2);		
			return url;
		},
		delRegister: function(){
			// remove the oldest entry on the tweets list
			if(msgNb>=numMSG){
				$(".twittLI").each(
					function(o,elemLI){
						if(o>=numMSG) $(this).hide("fast");													  
					}
				);
			}	
		},
		conectaTwitter: function(e){
			// query the twitter api and create the tweets list
			$.ajax({
				url: aURL,
				type: 'GET',
				dataType: 'jsonp',
				timeout: 1000,
				error: function(){ $("#"+contDiv).html("fail#"); },
				success: function(json){
					if(e==1) $("#"+contDiv).html("");			
					$.each(json.results,function(i,item) {
						if(e==1 || (i<numMSG && item.id>ultID)){
							if(i==0){
								tultID = item.id;
								$("<ul></ul>")
									.attr('id', 'twittList'+ultID)
									.attr('class','twittList')
									.prependTo("#"+contDiv);  
							}
							
							// IAN EDIT: added next line, changed 2nd
							if (rt == "off") var match = /^RT\s|\sRT\s/i.exec(item.text);
							if (item.text != "undefined" && !match) {
								var link =  "http://twitter.com/"+item.from_user+"/status/"+item.id;  
								
								var tweet = $.Juitter.filter(item.text);
								
								// IAN EDIT: changed next three lines: item.created_at BECOMES time
								var time = parseTwitterDate(item.created_at);								
								if(fromID=="image") mHTML="<a href=\"http://www.twitter.com/"+item.from_user+"\"><img src=\""+item.profile_image_url+"\" width=\"48\" height=\"48\" alt=\""+item.from_user+"\" class=\"juitterAvatar\" /></a> "+$.Juitter.textFormat(tweet)+" <span class=\"time\"> &middot; "+time+"</span>";
								else mHTML="<a href=\"http://www.twitter.com/"+item.from_user+"\">@"+item.from_user+":</a> "+$.Juitter.textFormat(tweet)+" -| <span class=\"time\"> &middot; "+time+"</span>";
								
								$("<li></li>") 
									.html(mHTML)  
									.attr('id', 'twittLI'+msgNb)
									.attr('class', 'twittLI clearfix')
									.appendTo("#twittList"+ultID);

								$('#twittLI'+msgNb).hide();
								$('#twittLI'+msgNb).show("slow");
								
								// remove old entries
								$.Juitter.delRegister();
								msgNb++;								
							}
						}
					});	
					ultID=tultID;
				}
			});
		},	
		filter: function(s){
			if(filterWords){
				searchWords = filterWords.split(",");				
				if(searchWords.length>0){
					cleanHTML=s;
					$.each(searchWords,function(i,item){	
						sW = item.split("->").length>0 ? item.split("->")[0] : item;
						rW = item.split("->").length>0 ? item.split("->")[1] : "";					
						regExp=eval('/'+sW+'/gi');					
						cleanHTML = cleanHTML.replace(regExp, rW);							
					});
				} else cleanHTML = s;			
				return cleanHTML;
			} else return s;
		},
		textFormat: function(texto){
			//make links
			var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
			texto = texto.replace(exp,"<a href='$1' class='extLink' "+openLink+">$1</a>"); 
			var exp = /[\@]+([A-Za-z0-9-_]+)/ig;
			texto = texto.replace(exp,"<a href='http://twitter.com/$1' class='profileLink'>@$1</a>"); 
			var exp = /[\#]+([A-Za-z0-9-_]+)/ig;
			texto = texto.replace(exp,"<a href='http://juitter.com/#$1' onclick='$.Juitter.start({searchType:\"searchWord\",searchObject:\"$1\"});return false;' class='hashLink'>#$1</a>"); 
			// make it bold
			if(mode=="searchWord"){
				tempParam = param.replace(/&ors=/,"");
				arrParam = tempParam.split("+");
				$.each(arrParam,function(i,item){					
					regExp=eval('/'+item+'/gi');
					newString = new String(' <b>'+item+'</b> ');
					texto = texto.replace(regExp, newString);					  
				});				
			}
			return texto;
		},
		temporizador: function(){
			// live mode timer
			running=true;
			aTim = timer.split("-");
			if(aTim[0]=="live" && aTim[1].length>0){
				tempo = aTim[1]*1000;
				setTimeout("$.Juitter.update()",tempo);
			}
		}
	};
	
	
	// IAN EDIT: added function
	function parseTwitterDate(text) {
		var newtext = text.replace(/(\+\S+) (.*)/, '$2 $1')
		var date = new Date(Date.parse(newtext)).toLocaleDateString();
		var time = new Date(Date.parse(newtext)).toLocaleTimeString();
		return date + ' ' + time;
	}
	
})(jQuery);
