_qoptions = {
    qacct:"p-11lnUuPOz_qQQ"
};
document.write('<' + 'script language="javascript" type="text/javascript" src="http://edge.quantserve.com/quant.js" ' + '>' +'</' + 'script'+ '>');

var rotatingList = function(el) {
	this.list = null;
	this.items = null;
	this.active = null;
	this.timer = null;
	this.init(el);
};

rotatingList.prototype.init = function(el) {
	this.list = el;
	this.items = $(this.list).children('li');
	this.showItem(0);
	this.startTimer();
	var self = this;
	$(this.list).hover(function(){clearTimeout(self.timer);self.showList();},function(){self.hideList();self.showItem(0);self.startTimer();});
};

rotatingList.prototype.showItem = function(idx) {
	this.active = idx;
	$(this.items).each(function(i,el){(i==idx)?$(el).show():$(el).hide();});
};

rotatingList.prototype.showList = function() {
	$(this.list).addClass('active');
	$(this.items).each(function(i,el){$(el).show();});
};

rotatingList.prototype.hideList = function() {
	$(this.list).removeClass('active');
};

rotatingList.prototype.startTimer = function() {
	var self = this;
	i = (this.active+1==this.items.length)?0:this.active+1;
	this.timer = setTimeout(function(){self.showItem(i);self.startTimer();},5000);
};



$(document).ready(function(){
	// initRotatingList();
	var rl = new rotatingList( $('#superNav .list') );
	var dr = new DetectReferrer( $('#WelcomePlaceHolder'));
	
	$("li.fav_item a").hover(function() {
		$('> em', this).stop().fadeIn("fast");
	}, function() {
		$('> em', this).stop().css({opacity:1}).fadeOut("fast");
	});
	
	$(".view div#view_toggle").hover(function() {
		$('> ul', this).stop().addClass('active');
	}, function() {
		$('> ul', this).stop().removeClass('active');
	});
	
	$(".view_choice li").click(function() {
	    window.location=$(this).find("a").attr("href");return false;
	});

	$('#comment-text').one("focus", function() {
		$('#comment-text').parent().after('<div id="preview-box"><div class="comment-by">Preview</div><div id="live-preview">Your preview will show up below. Start Typing!</div><div id="live-author"></div><p>*Tags allowed: a href, b, i, br/, p, strong, em, ul, ol, li, blockquote, pre</p></div>');
	});
	
    // var $userCookie = getCommenterName();
	var $comment = ''; 
	$('#comment-text').keyup(function() {
		$comment = $(this).val();
		$comment = $comment.replace(/\n/g, "<br />")
		.replace(/\n\n+/g, '<br /><br />');
		$('#live-preview').html( $comment );
		//$('#live-author').html('posted by ' + $userCookie);
	});
	$(".tag-slide").click(function(){
		$(this).parents("div").next(".entry-tags").slideToggle("slow");
		$(this).toggleClass("active"); return false;
	});
	
	$('#share-dropdown li.share-links').hover(
		function() { $('ul', this).css('display', 'block'); },
		function() { $('ul', this).css('display', 'none'); }
	);
    
    $("body.nycgo.gothamist #container").click(function(event){
        event.stopPropagation();
        pageTracker._trackPageview('/outgoing/nycgo_101909');
        window.open('http://ads.pointroll.com/PortalServe/?pid=872424E84320090930165217&pos=c&r=[RANDOM]');
    });
    
    $('body.nycgo #container-inner').click(function(event){
        event.stopPropagation();
    });

	$("body.virgin.sfist #container").click(function(event){
        event.stopPropagation();
        pageTracker._trackPageview('/outgoing/virgin_110209');
        window.open('http://ad.doubleclick.net/clk;218607575;41691468;t');
    });

    $('body.virgin #container-inner').click(function(event){
        event.stopPropagation();
    });
    $("body.pirate.gothamist #container").click(function(event){
        event.stopPropagation();
        pageTracker._trackPageview('/outgoing/pirate_110809');
        window.open('http://clk.atdmt.com/481/go/182340399/direct/01/');
    });
	$("body.pirate.dcist #container").click(function(event){
        event.stopPropagation();
        pageTracker._trackPageview('/outgoing/pirate_110809');
        window.open('http://clk.atdmt.com/481/go/182355959/direct/01/');
    });
	$("body.pirate.laist #container").click(function(event){
        event.stopPropagation();
        pageTracker._trackPageview('/outgoing/pirate_110809');
        window.open('http://clk.atdmt.com/481/go/182353845/direct/01/');
    });

    $('body.pirate #container-inner').click(function(event){
        event.stopPropagation();
    });
    $("body.zipcar.bostonist #container").click(function(event){
        event.stopPropagation();
        pageTracker._trackPageview('/outgoing/zipcar_110909');
        window.open('http://clk.atdmt.com/DEU/go/165519999/direct/01/');
    });

    $('body.zipcar #container-inner').click(function(event){
        event.stopPropagation();
    });

    $('#mobilesitevisit').click(function(){
    	$.cookie('mobilepreference',null,{path: '/', domain: hostname});
    });
    
    
	$("#postMore").click(function(){
		var toLoad = $(this).attr('href');
		$('#moreEntries').hide('slow',loadContent);
		// window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
		function loadContent() {
			$('#moreEntries').load(toLoad,'',showNewContent())
		}
		function showNewContent() {
			$('#moreEntries').show('slow');
			$('#postMore').addClass("active");
		}
		return false;
	});

    // $(".widget-skyscraper.widget .widget-inner div").append('<p><a href="http://www.gothamistllc.com/mediakit/">Advertise with us</a></p>');
});

function viewToggle(view){
	var expdate = new Date(); 
	expdate.setTime(expdate.getTime() + 1000 * 60 * 60 * 24 * 30);
	if (view == 'summary') {
		mtSetCookie("HomepageView","Summary",expdate, '/');
	} else if (view == 'full'){
		mtSetCookie("HomepageView","Full",expdate, '/');
	}
	window.location.reload();
}

function addBookmark(url, title) {
	if (window.sidebar) {
    		window.sidebar.addPanel(title, url, ""); 
    	} else if (window.external) { 
    		window.external.AddFavorite(url, title); 
    	}
}
jQuery.url=function(){var segments={};var parsed={};var options={url:window.location,strictMode:false,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}};var parseUri=function(){str=decodeURI(options.url);var m=options.parser[options.strictMode?"strict":"loose"].exec(str);var uri={};var i=14;while(i--){uri[options.key[i]]=m[i]||""}uri[options.q.name]={};uri[options.key[12]].replace(options.q.parser,function($0,$1,$2){if($1){uri[options.q.name][$1]=$2}});return uri};var key=function(key){if(!parsed.length){setUp()}if(key=="base"){if(parsed.port!==null&&parsed.port!==""){return parsed.protocol+"://"+parsed.host+":"+parsed.port+"/"}else{return parsed.protocol+"://"+parsed.host+"/"}}return(parsed[key]==="")?null:parsed[key]};var param=function(item){if(!parsed.length){setUp()}return(parsed.queryKey[item]===null)?null:parsed.queryKey[item]};var setUp=function(){parsed=parseUri();getSegments()};var getSegments=function(){var p=parsed.path;segments=[];segments=parsed.path.length==1?{}:(p.charAt(p.length-1)=="/"?p.substring(1,p.length-1):path=p.substring(1)).split("/")};return{setMode:function(mode){strictMode=mode=="strict"?true:false;return this},setUrl:function(newUri){options.url=newUri===undefined?window.location:newUri;setUp();return this},segment:function(pos){if(!parsed.length){setUp()}if(pos===undefined){return segments.length}return(segments[pos]===""||segments[pos]===undefined)?null:segments[pos]},attr:key,param:param}}();

var hostname = jQuery.url.attr("host");

if(jQuery.url.attr("host") == 'gothamist.com'){ 
      var sitename = 'It seems you\'ve come to Gothamist via a web search. Please consider <a href="#" onclick="addBookmark(\'http://'+hostname+'\', \''+hostname+'\'); return false;">bookmarking us</a>, <a href="/index.rdf">subscribing to our RSS feed</a>, or checking out <a href="/popular">this week\'s most popular stories</a>.</div><div style="border-top:0px solid #FFF;padding:0px 10px 10px;font-size:14px;line-height:18px"><table><tr><td width="340"><p style="margin:0;padding:0 20px 0 0">Want to know about the best events and deals in New York every day? Subscribe to our newsletter:</p></td><td><form action="http://gothamist.list-manage.com/subscribe/post" method="POST"><input type="hidden" name="u" value="1ff83f6bd9b5621949725cf98"><input class="refer_label" type="hidden" name="id" value="b4f8dc6148"><label for="MERGE0a" style="font-size:11px"><strong>EMAIL</strong> <em> (required)</em></label><br /><input class="refer_input" type="text" name="MERGE0" id="MERGE0a" size="25" value="" style="vertical-align:top;height:17px;"><input class="gothamlistSubscribe" type="image" value="subscribe" src="http://assets.gothamistllc.com/images/spacer.gif"/></form></td></tr></table>';} else { var sitename = 'It seems you\'ve come to us via a web search. Please consider <a href="#" onclick="addBookmark(\'http://'+hostname+'\', \''+hostname+'\'); return false;">bookmarking us</a>, <a href="/index.rdf">subscribing to our RSS feed</a>, or checking out <a href="/popular">this week\'s most popular stories</a>.';} 


var msgs = [
{'url':null,                           'msg':null}
,{'url':/^http:\/\/(\w+\.)?google\.com\/search/,      'msg':sitename}
,{'url':/^http:\/\/(\w+\.)?yahoo\.com/,      'msg':sitename}
,{'url':/^http:\/\/(\w+\.)?msn\.com/,      'msg':sitename}
,{'url':/^http:\/\/(\w+\.)?search.live\.com/,      'msg':sitename}
,{'url':/^http:\/\/(\w+\.)?ask\.com/,      'msg':sitename}
,{'url':/^http:\/\/(\w+\.)?aol\.com/,      'msg':sitename}
];

function DetectReferrer(){            
   var div = $('#WelcomePlaceHolder');
   //if Div was not placed means , not to show message
   if (!div.length) return;
   var ref = document.referrer.toLowerCase();
   var msg = findMatch(ref);
   // if not null msg found
   if(msg) {
      //Add Close Button and Show up message
      div.html('<div style="background:#FFFF99;margin-bottom:15px;"><a style="position:absolute;top:16px;right:20px;font-weight:bold;text-decoration:none;color:white;" href="javascript:void(0)" class="CloseButton">X</a><div style="padding:10px;font-size:14px;line-height:18px"><h1 style="text-transform:uppercase;font-weight:bold;font-size:13px;margin-bottom:2px">Welcome, friend!</h1>' + msg + '</div>').show('slow',function(){
         //Hide On click close Button
         $('.CloseButton',div).click(function(){ div.hide() })
      });
   }
}
function findMatch(ref) {
   for(var i=0; i<msgs.length; i++)
      if( ( ref=='' && msgs[i].url==null) || (ref>'' && ref.match(msgs[i].url) ) )
         return msgs[i].msg;
   return null;
}
