//*****************************************************************************
// Copyright 2007 Starscale Inc.

var listTextLookup=[['Current Top Things','/list/top'],['Current Bottom Things','/list/bottom'],['Recently Added Things','/list/new'],['Recently Voted-on Things','/list/votes'],['All Time Top Things','/list/highest'],['All Time Bottom Things','/list/lowest']];ibi.YupNope.thingListLoader=null;function doSearch(element,value){assertThingListLoader();hideFilterTagText();if(ibi.YupNope.thingListLoader.doSearch(value)){hideAddThingDivs();hidePopups();$('thingListHeaderText').update(ibi.YupNope.Strings.Search.Results+"'"+
value.escapeHTML()+"'");$('thingListHeaderText').href='/search/'+encodeURIComponent(value);$('thingListHeaderText').title=value;}}
function clearSearch(){if(ibi.YupNope.thingListLoader&&$('addThingContent')){ibi.YupNope.thingListLoader.denySearch();$('addThingContent').value="";setTimeout(function(){ibi.YupNope.thingListLoader.allowSearch()},1000);}}
function hidePopups(){hideOtherListsPopup();hideTagPopup();}
function loadListInternal(index,tagId){if(index>=0&&index<listTextLookup.length){assertThingListLoader();$('thingListHeaderText').update(listTextLookup[index][0]);$('thingListHeaderText').href=listTextLookup[index][1];clearSearch();if(tagId!=null&(tagId!=undefined)){setFilterTagText(tagId);ibi.YupNope.thingListLoader.setTagFilter(tagId);}
setListCookie(index);return ibi.YupNope.thingListLoader.loadExtremeList(index);}
return false;}
function loadList(index,tagId){loadListInternal(index,tagId);}
function loadDefaultList(tagId){loadList(ibi.YupNope.Const.ExtremeQueryType.CurrentMaxScore,tagId);}
function loadLastList(tag){var cookie=new ibi.Web.Cookie('ynlist');var val=cookie.getValue();var func=function(tagId){try{if(!val||!loadListInternal(val,tagId)){loadDefaultList(tagId);}}catch(e){loadDefaultList(tagId);}}
if(tag){lookupTagId(tag,func);}else{func();}}
function setListCookie(listIndex){var cookie=new ibi.Web.Cookie('ynlist',listIndex,{path:"/",isSession:false,periodType:'days',periodUnit:2});cookie.write();}
function addThing(vote,checkLength){if($F('addThingContent')==""){$('addThingError').update(ibi.YupNope.Strings.Add.EmptyError);if(!$('addThingError').visible()){new Effect.BlindDown('addThingError',{duration:0.5});}}
else{if($F('addThingContent').length>ibi.YupNope.Const.MaxThingLength){if(checkLength){$('voteToConfirmTrim').value=vote;$('thingLength').innerHTML=$F('addThingContent').length;if(!$('addThingTrimConfirm').visible()){new Effect.BlindDown('addThingTrimConfirm',{duration:0.5});}
return;}
else{$('addThingContent').value=$F('addThingContent').substring(0,ibi.YupNope.Const.MaxThingLength);}}
hideAddThingDivs();toggleAddButtons();var consts=ibi.Phix.YupNope.Things.Const.AddOrVote;new ibi.Ajax.Request(consts.uriPath,{parameters:consts.Arg.Content+"="
+encodeURIComponent($F('addThingContent'))
+"&"+consts.Arg.Vote+"="+vote,onFailure:function(){showGlobalError(ibi.YupNope.Strings.GeneralError);toggleAddButtons();},onSuccess:function(transport){var json=transport.responseText.evalJSON();if(json.Status==consts.Status.Success){doSearch(null,$F('addThingContent'));}else if(json.Status==consts.Status.ContentInvalid){showGlobalError(ibi.YupNope.Strings.Add.Invalid);}else{showGlobalError(ibi.YupNope.Strings.Add.Error);}
toggleAddButtons();},on403:function(){setTimeout(function(){showGlobalError(ibi.YupNope.Strings.Add.LoggedIn);toggleAddButtons();if(!$('loginFormDiv')){setTimeout(function(){window.location.reload();},2000);}else{showLoginForm();}},10);}});}}
function toggleAddButtons(){if($('addThingYupButton').visible()){$('addThingNopeButton').hide();$('addThingYupButton').hide();$('addThingYupProgress').show();}
else{$('addThingNopeButton').show();$('addThingYupButton').show();$('addThingYupProgress').hide();}}
function hideAddThingDivs(){if($('addThingError').visible()){new Effect.BlindUp('addThingError',{duration:0.5});}
if($('addThingTrimConfirm').visible()){new Effect.BlindUp('addThingTrimConfirm',{duration:0.5});}
$('addThingContent').onChange="";}
function hideConfirm(){if($('addThingTrimConfirm').visible()){new Effect.BlindUp('addThingTrimConfirm',{duration:0.5});}}
function assertThingListLoader(){if(!ibi.YupNope.thingListLoader){ibi.YupNope.thingListLoader=new
ibi.YupNope.ThingListLoader($('mainThingList'),ibi.YupNope.ExtremeCallbacks,ibi.YupNope.SearchCallbacks);}}
