// Modernizr v1.7  www.modernizr.com
window.Modernizr=function(a,b,c){function G(){e.input=function(a){for(var b=0,c=a.length;b<c;b++)t[a[b]]=!!(a[b]in l);return t}("autocomplete autofocus list placeholder max min multiple pattern required step".split(" ")),e.inputtypes=function(a){for(var d=0,e,f,h,i=a.length;d<i;d++)l.setAttribute("type",f=a[d]),e=l.type!=="text",e&&(l.value=m,l.style.cssText="position:absolute;visibility:hidden;",/^range$/.test(f)&&l.style.WebkitAppearance!==c?(g.appendChild(l),h=b.defaultView,e=h.getComputedStyle&&h.getComputedStyle(l,null).WebkitAppearance!=="textfield"&&l.offsetHeight!==0,g.removeChild(l)):/^(search|tel)$/.test(f)||(/^(url|email)$/.test(f)?e=l.checkValidity&&l.checkValidity()===!1:/^color$/.test(f)?(g.appendChild(l),g.offsetWidth,e=l.value!=m,g.removeChild(l)):e=l.value!=m)),s[a[d]]=!!e;return s}("search tel url email datetime date month week time datetime-local number range color".split(" "))}function F(a,b){var c=a.charAt(0).toUpperCase()+a.substr(1),d=(a+" "+p.join(c+" ")+c).split(" ");return!!E(d,b)}function E(a,b){for(var d in a)if(k[a[d]]!==c&&(!b||b(a[d],j)))return!0}function D(a,b){return(""+a).indexOf(b)!==-1}function C(a,b){return typeof a===b}function B(a,b){return A(o.join(a+";")+(b||""))}function A(a){k.cssText=a}var d="1.7",e={},f=!0,g=b.documentElement,h=b.head||b.getElementsByTagName("head")[0],i="modernizr",j=b.createElement(i),k=j.style,l=b.createElement("input"),m=":)",n=Object.prototype.toString,o=" -webkit- -moz- -o- -ms- -khtml- ".split(" "),p="Webkit Moz O ms Khtml".split(" "),q={svg:"http://www.w3.org/2000/svg"},r={},s={},t={},u=[],v,w=function(a){var c=b.createElement("style"),d=b.createElement("div"),e;c.textContent=a+"{#modernizr{height:3px}}",h.appendChild(c),d.id="modernizr",g.appendChild(d),e=d.offsetHeight===3,c.parentNode.removeChild(c),d.parentNode.removeChild(d);return!!e},x=function(){function d(d,e){e=e||b.createElement(a[d]||"div");var f=(d="on"+d)in e;f||(e.setAttribute||(e=b.createElement("div")),e.setAttribute&&e.removeAttribute&&(e.setAttribute(d,""),f=C(e[d],"function"),C(e[d],c)||(e[d]=c),e.removeAttribute(d))),e=null;return f}var a={select:"input",change:"input",submit:"form",reset:"form",error:"img",load:"img",abort:"img"};return d}(),y=({}).hasOwnProperty,z;C(y,c)||C(y.call,c)?z=function(a,b){return b in a&&C(a.constructor.prototype[b],c)}:z=function(a,b){return y.call(a,b)},r.flexbox=function(){function c(a,b,c,d){a.style.cssText=o.join(b+":"+c+";")+(d||"")}function a(a,b,c,d){b+=":",a.style.cssText=(b+o.join(c+";"+b)).slice(0,-b.length)+(d||"")}var d=b.createElement("div"),e=b.createElement("div");a(d,"display","box","width:42px;padding:0;"),c(e,"box-flex","1","width:10px;"),d.appendChild(e),g.appendChild(d);var f=e.offsetWidth===42;d.removeChild(e),g.removeChild(d);return f},r.canvas=function(){var a=b.createElement("canvas");return a.getContext&&a.getContext("2d")},r.canvastext=function(){return e.canvas&&C(b.createElement("canvas").getContext("2d").fillText,"function")},r.webgl=function(){return!!a.WebGLRenderingContext},r.touch=function(){return"ontouchstart"in a||w("@media ("+o.join("touch-enabled),(")+"modernizr)")},r.geolocation=function(){return!!navigator.geolocation},r.postmessage=function(){return!!a.postMessage},r.websqldatabase=function(){var b=!!a.openDatabase;return b},r.indexedDB=function(){for(var b=-1,c=p.length;++b<c;){var d=p[b].toLowerCase();if(a[d+"_indexedDB"]||a[d+"IndexedDB"])return!0}return!1},r.hashchange=function(){return x("hashchange",a)&&(b.documentMode===c||b.documentMode>7)},r.history=function(){return !!(a.history&&history.pushState)},r.draganddrop=function(){return x("dragstart")&&x("drop")},r.websockets=function(){return"WebSocket"in a},r.rgba=function(){A("background-color:rgba(150,255,150,.5)");return D(k.backgroundColor,"rgba")},r.hsla=function(){A("background-color:hsla(120,40%,100%,.5)");return D(k.backgroundColor,"rgba")||D(k.backgroundColor,"hsla")},r.multiplebgs=function(){A("background:url(//:),url(//:),red url(//:)");return(new RegExp("(url\\s*\\(.*?){3}")).test(k.background)},r.backgroundsize=function(){return F("backgroundSize")},r.borderimage=function(){return F("borderImage")},r.borderradius=function(){return F("borderRadius","",function(a){return D(a,"orderRadius")})},r.boxshadow=function(){return F("boxShadow")},r.textshadow=function(){return b.createElement("div").style.textShadow===""},r.opacity=function(){B("opacity:.55");return/^0.55$/.test(k.opacity)},r.cssanimations=function(){return F("animationName")},r.csscolumns=function(){return F("columnCount")},r.cssgradients=function(){var a="background-image:",b="gradient(linear,left top,right bottom,from(#9f9),to(white));",c="linear-gradient(left top,#9f9, white);";A((a+o.join(b+a)+o.join(c+a)).slice(0,-a.length));return D(k.backgroundImage,"gradient")},r.cssreflections=function(){return F("boxReflect")},r.csstransforms=function(){return!!E(["transformProperty","WebkitTransform","MozTransform","OTransform","msTransform"])},r.csstransforms3d=function(){var a=!!E(["perspectiveProperty","WebkitPerspective","MozPerspective","OPerspective","msPerspective"]);a&&"webkitPerspective"in g.style&&(a=w("@media ("+o.join("transform-3d),(")+"modernizr)"));return a},r.csstransitions=function(){return F("transitionProperty")},r.fontface=function(){var a,c,d=h||g,e=b.createElement("style"),f=b.implementation||{hasFeature:function(){return!1}};e.type="text/css",d.insertBefore(e,d.firstChild),a=e.sheet||e.styleSheet;var i=f.hasFeature("CSS2","")?function(b){if(!a||!b)return!1;var c=!1;try{a.insertRule(b,0),c=/src/i.test(a.cssRules[0].cssText),a.deleteRule(a.cssRules.length-1)}catch(d){}return c}:function(b){if(!a||!b)return!1;a.cssText=b;return a.cssText.length!==0&&/src/i.test(a.cssText)&&a.cssText.replace(/\r+|\n+/g,"").indexOf(b.split(" ")[0])===0};c=i('@font-face { font-family: "font"; src: url(data:,); }'),d.removeChild(e);return c},r.video=function(){var a=b.createElement("video"),c=!!a.canPlayType;if(c){c=new Boolean(c),c.ogg=a.canPlayType('video/ogg; codecs="theora"');var d='video/mp4; codecs="avc1.42E01E';c.h264=a.canPlayType(d+'"')||a.canPlayType(d+', mp4a.40.2"'),c.webm=a.canPlayType('video/webm; codecs="vp8, vorbis"')}return c},r.audio=function(){var a=b.createElement("audio"),c=!!a.canPlayType;c&&(c=new Boolean(c),c.ogg=a.canPlayType('audio/ogg; codecs="vorbis"'),c.mp3=a.canPlayType("audio/mpeg;"),c.wav=a.canPlayType('audio/wav; codecs="1"'),c.m4a=a.canPlayType("audio/x-m4a;")||a.canPlayType("audio/aac;"));return c},r.localstorage=function(){try{return!!localStorage.getItem}catch(a){return!1}},r.sessionstorage=function(){try{return!!sessionStorage.getItem}catch(a){return!1}},r.webWorkers=function(){return!!a.Worker},r.applicationcache=function(){return!!a.applicationCache},r.svg=function(){return!!b.createElementNS&&!!b.createElementNS(q.svg,"svg").createSVGRect},r.inlinesvg=function(){var a=b.createElement("div");a.innerHTML="<svg/>";return(a.firstChild&&a.firstChild.namespaceURI)==q.svg},r.smil=function(){return!!b.createElementNS&&/SVG/.test(n.call(b.createElementNS(q.svg,"animate")))},r.svgclippaths=function(){return!!b.createElementNS&&/SVG/.test(n.call(b.createElementNS(q.svg,"clipPath")))};for(var H in r)z(r,H)&&(v=H.toLowerCase(),e[v]=r[H](),u.push((e[v]?"":"no-")+v));e.input||G(),e.crosswindowmessaging=e.postmessage,e.historymanagement=e.history,e.addTest=function(a,b){a=a.toLowerCase();if(!e[a]){b=!!b(),g.className+=" "+(b?"":"no-")+a,e[a]=b;return e}},A(""),j=l=null,f&&a.attachEvent&&function(){var a=b.createElement("div");a.innerHTML="<elem></elem>";return a.childNodes.length!==1}()&&function(a,b){function p(a,b){var c=-1,d=a.length,e,f=[];while(++c<d)e=a[c],(b=e.media||b)!="screen"&&f.push(p(e.imports,b),e.cssText);return f.join("")}function o(a){var b=-1;while(++b<e)a.createElement(d[b])}var c="abbr|article|aside|audio|canvas|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",d=c.split("|"),e=d.length,f=new RegExp("(^|\\s)("+c+")","gi"),g=new RegExp("<(/*)("+c+")","gi"),h=new RegExp("(^|[^\\n]*?\\s)("+c+")([^\\n]*)({[\\n\\w\\W]*?})","gi"),i=b.createDocumentFragment(),j=b.documentElement,k=j.firstChild,l=b.createElement("body"),m=b.createElement("style"),n;o(b),o(i),k.insertBefore(m,k.firstChild),m.media="print",a.attachEvent("onbeforeprint",function(){var a=-1,c=p(b.styleSheets,"all"),k=[],o;n=n||b.body;while((o=h.exec(c))!=null)k.push((o[1]+o[2]+o[3]).replace(f,"$1.iepp_$2")+o[4]);m.styleSheet.cssText=k.join("\n");while(++a<e){var q=b.getElementsByTagName(d[a]),r=q.length,s=-1;while(++s<r)q[s].className.indexOf("iepp_")<0&&(q[s].className+=" iepp_"+d[a])}i.appendChild(n),j.appendChild(l),l.className=n.className,l.innerHTML=n.innerHTML.replace(g,"<$1font")}),a.attachEvent("onafterprint",function(){l.innerHTML="",j.removeChild(l),j.appendChild(n),m.styleSheet.cssText=""})}(a,b),e._enableHTML5=f,e._version=d,g.className=g.className.replace(/\bno-js\b/,"")+" js "+u.join(" ");return e}(this,this.document);var tscache;function topstuff_init(){$("#topjobs").topstuff(tscache,{item:"topjobs"});$("#topcars").topstuff(tscache,{item:"topcars"});$("#tophomes").topstuff(tscache,{item:"tophomes"});$("#toprentals").topstuff(tscache,{item:"toprentals"});$(".topstuff_next").click(function(){var a=$(this).parents(".topstuff_body").children(":first-child");var b=$(a).attr("id");$(a).topstuff(tscache,{item:b,position:$(this).siblings(".topstuff_current").html(),direction:1});return false});$(".topstuff_prev").click(function(){var a=$(this).parents(".topstuff_body").children(":first-child");var b=$(a).attr("id");$(a).topstuff(tscache,{item:b,position:$(this).siblings(".topstuff_current").html(),direction:0});return false})}function topstuff_cache(){var c,b,e,d=new Date(),a=d.getFullYear().toString()+d.getMonth().toString()+d.getDate().toString();e=window.location.host.replace(/((.*)\.)?thenewstribune\.com/,"$2");if(e=="blog"){b="http://blog.thenewstribune.com/wp-content/topstuff/topstuff.json?nocache="+a}else{if(e=="preview"){b="http://preview.thenewstribune.com/static/top/includes/topstuff.json?nocache="+a}else{b="http://www.thenewstribune.com/static/top/includes/topstuff.json?nocache="+a}}$.getJSON(b,function(f){tscache=f;topstuff_init()})}(function(a){a.fn.topstuff=function(c,d){var b={item:"topcars",position:"new",direction:1,max:3,amount:0};if(d){a.extend(b,d)}return this.each(function(){var e=a(this);a.fn.topstuff.processor(c,e,b)})};a.fn.topstuff.processor=function(d,c,b){if(b.item=="topjobs"){a.fn.topjobs(b,d,c)}else{if(b.item=="topcars"){b.amount=d.topcarssize}else{if(b.item=="tophomes"){b.amount=d.tophomessize}else{if(b.item=="toprentals"){b.amount=d.toprentalssize}}}if(b.position=="new"){b.position=a.fn.topstuff.rand(b.amount)}b=a.fn.topstuff.getposition(b);a.each(d,function(e,f){if(e==b.item+b.position){a(a.fn.topstuff.which(b.item,f)).appendTo(c.empty());c.next().children(".topstuff_current").empty().append(b.position+1).siblings(".topstuff_total").empty().append(b.amount)}})}};a.fn.topstuff.which=function(b,c){if(b=="topcars"){return a.fn.topstuff.topcars(c)}else{if(b=="tophomes"){return a.fn.topstuff.tophomes(c)}else{if(b=="toprentals"){return a.fn.topstuff.toprentals(c)}}}};a.fn.topstuff.rand=function(b){return Math.floor(Math.random()*b)};a.fn.topstuff.getposition=function(b){b.position=parseInt(b.position,10);if(b.direction==1){if(b.position==b.amount){b.position=0}}else{b.position-=2;if(b.position==-1){b.position=b.amount-1}}return b};a.fn.topstuff.topcars=function(b){var c='<a href="http://wwwb.thenewstribune.com/db/topcars-linker.php?d='+b.dlrid+'" id="topcars_viewall" class="topstuff_viewall">VIEW ALL &raquo;</a>';c+='<p class="topstuff_body_intro">Presented By<br /><a href="http://wwwb.thenewstribune.com/db/topcars-linker.php?d='+b.dlrid+'">'+b.dlr+"</a></p>";c+='<a href="http://wwwb.thenewstribune.com/db/topcars-linker.php?c='+b.id+'" class="topstuff_itemimg">';c+='<img src="http://media.thenewstribune.com/images/top/cars/photos/cars-'+b.dlrid+"-"+b.id+'.jpg" width="150" height="113" alt=""></a>';c+='<p class="topstuff_body_text"><a href="http://wwwb.thenewstribune.com/db/topcars-linker.php?c='+b.id+'">'+b.title+"</a>";c+="<br />"+b.desc+"</p>";return c};a.fn.topstuff.tophomes=function(c){var b='<a href="http://wwwb.thenewstribune.com/db/tophomes-linker.php?cn='+c.realtor+"&a="+c.realtorid+'" id="tophomes_viewall" class="topstuff_viewall">VIEW ALL &raquo;</a>';b+='<p class="topstuff_body_intro">Homes By<br /><a href="http://wwwb.thenewstribune.com/db/tophomes-linker.php?cn='+c.realtor+"&i="+c.realtorid+'">'+c.title+"</a></p>";b+='<p class="topstuff_body_text"><a href="http://wwwb.thenewstribune.com/db/tophomes-linker.php?cn='+c.title+"&i="+c.id+'">'+c.headline+"</a>";b+="<br />"+c.desc+"</p>";return b};a.fn.topstuff.toprentals=function(b){var c='<a href="http://www.southsoundrentals.com/toprents/viewall.php" id="toprentals_viewall" class="topstuff_viewall">VIEW ALL &raquo;</a>';c+='<p class="topstuff_body_intro"><a href="http://wwwb.thenewstribune.com/db/toprentals-linker.php?i='+b.link+'">'+b.account+"</a></p>";c+='<p class="topstuff_body_text"><a href="http://wwwb.thenewstribune.com/db/toprentals-linker.php?i='+b.link+'">'+b.title+"</a>";c+="<br />"+b.desc+"</p>";return c};a.fn.topjobs=function(b,c,f){b.amount=c.topjobssize;var e=a.fn.topjobs.allrand(b),d="";a.each(c,function(g,h){if(a.inArray(g,e)>-1){d+=a.fn.topjobs.makehtml(h)}});f.empty().append(d)};a.fn.topjobs.allrand=function(d){var b=[],e;for(e=0;e<d.max;e++){if(e===0){b[e]=a.fn.topstuff.rand(d.amount)}else{var c=a.fn.topstuff.rand(d.amount);while(a.inArray(c,b)>-1){c=a.fn.topstuff.rand(d.amount)}b[e]=c}}for(e=0;e<d.max;e++){b[e]="topjobs"+b[e]}return b};a.fn.topjobs.makehtml=function(b){var c="<dt>"+b.cat+"</dt>";c+='<dd><a href="http://www.careerbuilder.com/JobSeeker/Jobs/RedirectNewspaperJob.aspx?partnerid=Tacoma&jobid='+b.id+'&lr=cbmc_nt&siteid=cbmc_nt060">'+b.job+"</a><br />";c+=b.employer+"</dd>";return c}})(jQuery);/* Simple JavaScript Inheritance
 * By John Resig http://ejohn.org/
 * MIT Licensed.
 */
(function(){var a=false,b=/xyz/.test(function(){xyz})?/\b_super\b/:/.*/;this.Class=function(){};Class.extend=function(g){var f=this.prototype;a=true;var e=new this();a=false;for(var d in g){e[d]=typeof g[d]=="function"&&typeof f[d]=="function"&&b.test(g[d])?(function(h,i){return function(){var k=this._super;this._super=f[h];var j=i.apply(this,arguments);this._super=k;return j}})(d,g[d]):g[d]}function c(){if(!a&&this.init){this.init.apply(this,arguments)}}c.prototype=e;c.constructor=c;c.extend=arguments.callee;return c}})();
/** 

  JUITTER 3.0
  BY RODRIGO FANTE @link http://rodrigofante.com
  Class instance changes by @link http://burninglogic.net

  Juitter is distributed under the MIT License
  Read more about the MIT License --> http://www.opensource.org/licenses/mit-license.php
*/
var Juitter=Class.extend({registerVar:function(a){this.numMSG=20;this.containerDiv="juitterContainer";this.loadMSG="Loading messages...";this.imgName="loader.gif";this.readMore="Read it on Twitter";this.nameUser="image";this.mode=a.mode;this.search=a.search;this.fresh=a.fresh?a.fresh:43200000;this.lang=a.lang?a.lang:"";this.contDiv=a.placeHolder?a.placeHolder:this.containerDiv;this.loadMSG=a.loadMSG?a.loadMSG:this.loadMSG;this.gifName=a.imgName?a.imgName:this.imgName;this.numMSG=a.total?a.total:this.numMSG;this.readMore=a.readMore!==undefined?a.readMore:this.readMore;this.fromID=a.nameUser?a.nameUser:this.nameUser;this.openLink=a.openExternalLinks?'target="_blank"':"";this.url=this.url()},init:function(a){this.ultID=0;if($("#"+this.contDiv)){this.registerVar(a);this.loading();this.conectaTwitter(1)}},url:function(){var a="http://search.twitter.com/search.json?",b=this.lang.length>0?"&lang="+this.lang:b="";param=this.search;mult=param.search(/,/);if(mult>0){param="&ors="+param.replace(/,/g,"+")}if(this.mode=="fromUser"||this.mode=="from"){a+=(mult<=0)?"q=from%3A":"from%3A"}if(this.mode=="toUser"||this.mode=="to"){a+=(mult<=0)?"q=to%3A":"to%3A"}if(this.mode=="search"){param=param.replace(/#/,"%23");a+="q="+param+b+"&rpp="+this.numMSG}else{a+=param+"&rpp="+this.numMSG}return a},update:function(){this.conectaTwitter()},loading:function(){if(this.loadMSG=="image/gif"){$("<img></img>").attr("src",this.gifName).appendTo("#"+this.contDiv)}else{$("#"+this.contDiv).html(this.loadMSG)}},makelinks:function(a){var d,c,b;d=/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[\-A-Z0-9+&@#\/%=~_|])/ig;a=a.replace(d,'<a href="$1" class="extLink" '+this.openLink+">$1</a>");d=/[\@]+([A-Za-z0-9-_]+)/ig;a=a.replace(d,'<a href="http://twitter.com/$1" class="profileLink">@$1</a>');d=/[\#]+([A-Za-z0-9-_]+)/ig;a=a.replace(d,'<a href="http://juitter.com/#$1" class="hashLink">#$1</a>');return a},conectaTwitter:function(){var a,b;a=this;b=new Date();$.ajax({url:a.url,type:"GET",dataType:"jsonp",timeout:1000,error:function(){$("#"+a.contDiv).html("")},success:function(c){$("#"+a.contDiv).html("").hide();$.each(c.results,function(g,j){var f,d,h,k,e;if(g==0){$("<ul></ul>").attr("id",a.contDiv+"twittList").attr("class","twittList").prependTo("#"+a.contDiv)}if(j.text!="undefined"){f=new Date(j.created_at);d=b.getTime()-f.getTime();h="http://twitter.com/"+j.from_user+"/status/"+j.id_str;k=j.text;if(a.fromID=="image"){e='<a href="http://twitter.com/'+j.from_user+'"><div class="juitterAvatarContainer"><img src="'+j.profile_image_url+'" alt="'+j.from_user+'" class="juitterAvatar" /></a></div><div class="juitterTweetContainer"> '+a.makelinks(k)+' <span class="time"> &middot; '+f.toLocaleString()+"</span>"}else{e='<a href="http://twitter.com/'+j.from_user+'">@'+j.from_user+":</a> "+a.textFormat(k)+' <span class="time"> &middot;'+f.toLocaleString()+"</span>"}if(a.readMore){e+=' &middot; <a href="'+h+'" '+a.openLink+">"+a.readMore+"</a>"}if(d<a.fresh){$("<li></li>").attr("class","twittLI clearfix fresh").html(e).appendTo("#"+a.contDiv+"twittList")}else{$("<li></li>").attr("class","twittLI clearfix").html(e).appendTo("#"+a.contDiv+"twittList")}}});$("#"+a.contDiv).show("slow")}})},});/* @minify true */
$(document).ready(function(){
	
	$('#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;
			}
		}
	});
	
});/* @minify true */
jQuery(document).ready(function($) {
  
  /* Tabs used in Most Popular, Video */
  $(".tnt_tabs li.tnt_tab_disabled").removeClass("tnt_tab_disabled");
  $(".tnt_tabs li").click(function() {
    var el = $(this).children("a").attr("href");
    $(el).show().siblings(".tnt_tab_content").hide();    
    $(this).addClass("tnt_tab_active").siblings("li").removeClass("tnt_tab_active");
    return false;
  });

});/* @minify true */

/* 
  Intended for use with files written by this script:

  /cgi-bin/zvents/zvents_includes.php 
*/

(function($) {
  
  $.fn.zvents_includes = function( settings ) 
  {
    /* Defaults */
    var cfg = {
      site: 'tnt',
      days: 5,
      target: '#zvents_listings'
    };

    /* Allow overridding of defaults */
    if ( settings ) { $.extend(cfg, settings); }

    return this.each(function() {

      /* Catch this for error handling */
      var $this = $(this);
      
      var tabs = [], today = new Date(), day_names = [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ];

      /* Run through loop for each day */
      for( var i = 0; i < cfg.days; i++ ) {

        var date    = today.getDate();
        var day     = today.getDay();
        var dayName = day_names[ day ];
        var weekend = ( day === 0  ||  day == 6 );

        /* Add tab content details to array */
        tabs.push({
          html: date + '<span>' + dayName.slice( 0, 3 ) + '</span>',
          file: '/static/includes/zvents/' + cfg.site + '/' + i + '.3.html',
          weekend: weekend
        });

        today.setDate( date + 1 );
      }

      /* Create tabs */
      $.fn.zvents_includes.tabs( $this, cfg.target, tabs );
    
    });    
  };


  /**
   * Creates tabs and controls AJAX clicks
   *
   * @param object el
   * @param string target
   * @param object tabs
   */
  $.fn.zvents_includes.tabs = function( el, target, tabs )
  {
    var list = el.html('<ul />').find('ul').addClass('clearfix');
    var size = tabs.length;

    for ( var i = 0; i < size; i++ ) {
      var li = list.append('<li />').find('li:last-child').html( tabs[i].html );

      /* First, last, and weekend classes */
      if ( i === 0 ) { li.addClass('first selected'); }
      else if ( i == size - 1 ) { li.addClass('last'); }
      if ( tabs[i].weekend) { li.addClass('weekend'); }

      /* Bind click function */
      li.bind( 'click', {file: tabs[i].file}, function(event) {

        /* Loading div */
        var h = Math.round( $(target)[0].offsetHeight / 2 );
        var loading = '<div class="loading" style="height:' + h + 'px;padding-top:' + h + 'px;text-align:center;">Loading &hellip;</div>'
        $(target).html(loading);

        /* AJAX file contents in */
        $.get( event.data.file, function(data) {
          $(target).html(data);
        });

        /* Change possessor of selected class */
        list.children(".selected").removeClass('selected');
        $(this).addClass('selected');

      });
    }

  };

})(jQuery);/* @minify true */

$(document).ready(function(){



  /* Top Stuff */

  topstuff_cache();

  
  /* Login */
  $('#login_link').click(function(e) {
    e.preventDefault();
    $(this).siblings('.loginbox').show();
  });
  $('.loginclose').click(function() {
    $(this).parent().fadeOut(500);
  });
  if ( document.login !== undefined ) {
    document.login.rurl.value = document.location.href;
  }

  


  /* Zvents */

  $("#zvents_calendar_tnt").zvents_includes({target:"#zvents_listings"});

  

});function getCookieVal(b){var a=document.cookie.indexOf(";",b);if(a==-1){a=document.cookie.length}return unescape(document.cookie.substring(b,a))}function GetCookie(d){var b=d+"=";var f=b.length;var a=document.cookie.length;var e=0;while(e<a){var c=e+f;if(document.cookie.substring(e,c)==b){return getCookieVal(c)}e=document.cookie.indexOf(" ",e)+1;if(e===0){break}}return null}function SaveCookie(a,d,e,c){var b=new Date();b.setTime(b.getTime()+(e*86400000));if(c===null){c="/"}c="; path="+c;if(e===null){e=""}else{e="; expires="+b.toGMTString()}document.cookie=a+"="+d+e+c+";domain="+location.host.replace(/.*\.(.*\.com)/,"$1")+";"}function readCookie(b){var e="";var c=b+"=";if(document.cookie.length>0){var d=document.cookie.indexOf(c);if(d!=-1){d+=c.length;var a=document.cookie.indexOf(";",d);if(a==-1){a=document.cookie.length}e=unescape(document.cookie.substring(d,a))}}return e}function parseCookie(d,c){var f=d.split("|");var b,a=f.length;for(b=0;b<a;b++){if(f[b].match(c)){var e=f[b].split("=");return e[1]}}return null}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,0.9,"/")}}function tntLongDate(){var a=["January","February","March","April","May","June","July","August","September","October","November","December"];var g=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];var d=new Date();var f=g[d.getDay()];var c=a[d.getMonth()];var e=d.getDate();var b=d.getFullYear();return(f+", "+c+" "+e+", "+b)}Array.prototype.remove=function(c,b){var a=this.slice((b||c)+1||this.length);this.length=c<0?this.length+c:c;return this.push.apply(this,a)};function supports_html5_storage(){try{return"localStorage" in window&&window.localStorage!==null}catch(a){return false}}function get_storage_array(a){var b=localStorage.getItem(a);if(b!==null){b=b.split("|||")}return b}function set_storage_array(a,b){if(b.length===0){delete localStorage[a]}else{localStorage.setItem(a,b.join("|||"))}}$(document).ready(function(){$(".local_dropdown").change(function(){window.location.href=$(this).children("option:selected").val()});var d=supports_html5_storage();var j="tntstory_fontsize";var e=$("#storyBody");var h=18,a=9;if($(e).length!==0){function g(k){$(e).css("font-size",k+"px");if(d){localStorage.setItem(j,k)}}function b(m){var o,k=m.length;var n=m[k-1];if(n!="%"){o=2}else{o=3}return m.slice(0,-o)}function i(k){k=b(k);k++;if(k>h){k=h}g(k)}function c(k){k=b(k);k--;if(k<a){k=a}g(k)}if(d){var f=localStorage.getItem(j);if(f!==null){g(f)}}$(".bigger_font").click(function(){i($(e).css("font-size"));return false});$(".smaller_font").click(function(){c($(e).css("font-size"));return false})}});/* 
This is an object oriented version of the poll javascript
This script does everything our ajax polls implementation needs, including:

1. showing appropriate html depending on if the person has voted or not
2. handle submission of the form
3. get results
etc
*/

/* object constructor */
function miPollAjax() {
    this.poll_id;
    this.story_id;
    this.section_id;
    this.stretched = false;
    this.vote_casted = false;
    this.base_url = document.location.protocol + "//" + document.location.host

    // When you click to cast your vote this get's called
    this.submitPoll = function()
    {
        var poll_value = this.getPollValue();

        // Test if they chose a radio button to vote on
        if (poll_value != -1)
        {
            // vote_casted gets set in the beginning if they have already voted and set to true after voting.
            // That allows us to pop up an alert if they've already voted. 
            if ( this.vote_casted == true )
            {
                alert( "Limit 1 vote per user, you have already voted." );
            }
            else
            {
                // Build a url with the form data to send the iframe to to exec the perl script
                url = "http://www.thenewstribune.com/survey-bin/tabulate_poll.cgi?mi_pb_cache=1&expire_days=5&path=/&already_voted_error=You%20have%20already%20voted.%20Limit%201%20vote%20per%20user.&save=Cast%20Vote&value=Cast%20Vote";
                url = url + "&poll_id=" + this.poll_id;
                url = url + "&section_id=" + this.section_id;
                url = url + "&story_id=" + this.story_id;
                url = url + "&poll_response=" + poll_value;

		$("#poll_result").load(url); 
		this.hidePollForm();
            	this.fetchPollResults();
            	this.showPollResults();
                this.vote_casted = true;
            }
        }
        else
        {
            alert( "Please choose an option to vote for" )
        }
    }

    // This will retrieve poll results without casting a vote, by calling in the cgi results via jquery's 
    // AJAX support
    // Note: not passing "save" or "value" like the submitPoll function does prevents this call
    // from casing a vote. 
    this.fetchPollResults = function()
    {
        // Build a url with the form data to send the iframe to to exec the perl script
        url = "http://www.thenewstribune.com/survey-bin/tabulate_poll.cgi?mi_pb_cache=1&expire_days=5&path=/&already_voted_error=You%20have%20already%20voted.%20Limit%201%20vote%20per%20user.";
        url = url + "&poll_id=" + this.poll_id;
        url = url + "&section_id=" + this.section_id;
        url = url + "&story_id=" + this.story_id;

	$("#poll_result").load(url); 
    }

    this.register_response = function( element )
    {
        this.tempElement = element;
        //this.handleResponse( 1, this.tempElement );
        this.stretch_graphs();
    }


    // This helper function looks at the list of poll responses and returns the index of the one selected
    this.getPollValue = function()
    {
        var radios = document.forms.poll_responses.poll_response;
        for ( var i=0; i < radios.length; i++ )
        {
            if ( radios[i].checked ) return ( radios[i].value );
        }
        return -1;
    }

    // Onload, hide either the poll form or the poll results based on the cookie
    this.visibilityCheck = function()
    {
        if ( this.alreadyVoted() )
        {
            //alert( "You have already voted." );
            this.hidePollForm();
            this.fetchPollResults();
            this.showPollResults();
            //this.showAlreadyVotedMessage();
            this.vote_casted = true;
        }
        else  // Otherwise show the form so they can vote
        {
            this.showPollForm();
        }
    }

    //checks to see if the user has voted already
    this.alreadyVoted = function()
    {
        // Get the cookie and parse it to see if this poll ID has been submitted before
        content = this.getPollCookie('mi_polls');
        //alert( "poll cookie => '" + this.getPollCookie('mi_polls') + "'" );
    
        // No cookie, do nothing
        if ( content == null )
        {
            return;
        }
    
        // Parse the cookie so we can see if they voted on this particular poll id
        sval = content.split ( ";" );
        num_cookies = sval.length;
        key = new Array();
        for ( x = 0; x < num_cookies / 2 + 1; x++ )
        {
            qval = sval[x].split("=");
            id = qval[0];
            poll_submitted = qval[1];
            key[id] = poll_submitted;
            //alert( "id => '" + id + "', value => '" + poll_submitted + "'" );
        }

        // If they already voted, hide the form, and show a message saying they already voted
        if ( key[this.poll_id] == 1 )
        {
            //alert( "You have already voted" );
            return true;
        }
        else
        {
            return false;
        }
    }

    // Grab the cookie so we can check if they've already submitted or not
    this.getPollCookie = function(cookie_name)
    {
        dc = document.cookie;
        cname = cookie_name + "=";
        clen = dc.length;
        cbegin = 0;
    
        while ( cbegin < clen )
        {
            vbegin = cbegin + cname.length;
    
            if ( dc.substring ( cbegin, vbegin ) == cname )
            {
                vend = dc.indexOf ( ";", vbegin );
                if ( vend == -1 ) vend = clen;
    
                return unescape ( dc.substring ( vbegin, vend ) );
            }
    
            cbegin = dc.indexOf ( " ", cbegin ) + 1;
    
            if ( cbegin == 0 ) break;
        }
        
        return null;
    }

    // The size of the box this stuff is going into can vary quite a bit so
    // This will scale up the size of those bars on the bar graph so they take up
    // More of the box.. If your graphs are running off the edge, bring .9 down to .8
    this.stretch_graphs = function()
    {
        this.stretched = true;
        var element_poll_result = document.getElementById("poll_result");
        var element_poll_form = document.getElementById("poll_form");
   
        // Detect how much room the box has that the results are going into 
        if ( element_poll_result.offsetWidth > 0 )
            div_width = element_poll_result.offsetWidth;
        else
            div_width = element_poll_form.offsetWidth;

        // Magical formula or deciding how much to increase the bar width    
        multiplier = (div_width * .9 - 20)/100;

        // Get each of those bars, and expand or shrink each one of them       
        var element_bar_result = document.getElementsByName("bar_result");

        for ( count = 0; count < element_bar_result.length; count++ )
        {
            pixels = element_bar_result[count].width;
            if ( pixels > 0 )
                element_bar_result[count].width = pixels * multiplier;
        }
    
    }

    // Hide/Show the poll form and poll results  
    this.hidePollForm = function()
    {
        //alert( "hide poll form" );
        var element = document.getElementById("poll_form");
        if (element) element.style.display= "none";
    }

    this.showPollForm = function()
    {
        var element = document.getElementById("poll_form");
        if (element) element.style.display= "block";
    }

    this.hidePollResult = function()
    {
        var element = document.getElementById("poll_result");
        if (element) element.style.display= "none";
    }

    this.hideAlreadyVotedMessage = function()
    {
        var element = document.getElementById("poll_already_voted");
        if (element) element.style.display="none";
    }

    this.showPollResults = function()
    {
        this.fetchPollResults();
        var element = document.getElementById("poll_result");
        if (element) element.style.display = "block";

        if (this.stretched == false)
        {
            this.stretch_graphs();
        }
    }

    this.showAlreadyVotedMessage = function()
    {
        element = document.getElementById("poll_already_voted");
        if (element) element.style.display = "block";
    }

} /* end object */

