function jokeSwitchType(type)
{$('.type_form').hide();$('#'+type+'_form').show();};function changePictureSource(type,object)
{$(object).parent().children().removeClass('bold');$(object).addClass('bold');$(object).parent().parent().children('input').hide();$(object).parent().parent().children('input.'+type).show();};function multiplyMediaForm(object,count)
{for(var i=0;i<count;i++)
{var newo=$(object).clone(true);newo.children('div').children('.picture_url').val('');$('#filelist').append(newo);}}
function extractFormElements(form)
{var elements={};$(form.attr('elements')).each(function(){elements[$(this).attr('name')]=$(this);});return elements;}
function submitJokeForm(type)
{if((type=='joke')||(type=='aforism')||(type=='stishki')||(type=='citates')||(type=='sms'))
{var elements=extractFormElements($('#'+type+'_form'));if(!elements['text'].val())
{alert(elements['text'].attr('rel'));elements['text'].focus();}
else
{return true;}}
else if(type=='story')
{var elements=extractFormElements($('#story_form'));if(!elements['text'].val())
{alert(elements['text'].attr('rel'));elements['text'].focus();}
else
if(!elements['title'].val())
{alert(elements['title'].attr('rel'));elements['title'].focus();}
else
{return true;}}
else if(type=='picture')
{var elements=extractFormElements($('#picture_form'));var is_present_pic=false;$('.picture_file').each(function(){if($(this).val())is_present_pic=true;});$('.picture_url').each(function(){if($(this).val())is_present_pic=true;});if(!is_present_pic)
{alert($($('.picture_url').get(0)).attr('rel'));}
else if(!elements['title'].val())
{alert(elements['title'].attr('rel'));elements['title'].focus();}
else
{return true;}}
else if(type=='video')
{var elements=extractFormElements($('#video_form'));if(!elements['Filedata'].val())
{alert(elements['Filedata'].attr('rel'));}
else if(!elements['title'].val())
{alert(elements['title'].attr('rel'));elements['title'].focus();}
else
{return true;}}
else if(type=='video_ex')
{var elements=extractFormElements($('#video_ex_form'));if(!elements['text'].val())
{alert(elements['text'].attr('rel'));elements['text'].focus();}
else if(!elements['title'].val())
{alert(elements['title'].attr('rel'));elements['title'].focus();}
else
{return true;}}
return false;}
function rateJoke(positive,id)
{$('#voteblock'+id+' .voter').hide();App.track('Rate','Rate joke');$.post('/joke?vote',{id:id,positive:(positive?1:0)},function(data)
{$('#votes_for'+id).show();$('#voteblock'+id+' .no_votes').hide();if(positive)
{var new_value=parseInt($('#votes_for'+id).attr('innerHTML'))+1;$('#votes_for'+id).attr('innerHTML',new_value>0?'+'+new_value:new_value);}},'json');}
function sendJokeToFriend(form)
{$('#send_error').hide();App.track('Share','Send to friend');$.post('/send',$(form).serialize(),function(r){if(r.success)
{$('#send_pane').hide();$('#send_success').show();}
else
{$('#send_error').show();$('#send_error').html(r.content.error);}},'json');return false;}
function widgetNextJoke()
{document.getElementById('jokeBody').innerHTML=jokes[nextId++];if(jokes.length<=nextId)nextId=0;}
$(document).ready(function(){$('.personal').hover(function(){$('.personal strong').toggleClass("open");$(this).parents('div:first').find('.my').toggle();},function(){$('.personal strong').toggleClass("open");$(this).parents('div:first').find('.my').toggle();});});;$(document).ready(function()
{$('#comment_text').bind('blur',function()
{if($(this).val()=='')
{$(this).val(l_commentHintText);$(this).css({color:'silver'});}});$('#comment_text').bind('focus',function()
{if($(this).val()==l_commentHintText)
{$(this).val('');}
$(this).css({color:'black'});});$('#comment_text').blur();});function addComment(type,data)
{var commentBody=jQuery.trim($('#comment_text').val());if((commentBody=='')||(commentBody==l_commentHintText))
{return false;}
$('#comment_wait_panel').show();$('#comment_text').attr('disabled',true);$('#comment_text').css('backgroundColor','#f0f0f0');$('#add_comment_button').attr('disabled',true);data.body=commentBody;data.type=type;$.post('/comments?add',data,function(data)
{$('#comment_wait_panel').hide();$('#comment_text').attr('disabled',false);$('#comment_text').css('backgroundColor','#fff');$('#add_comment_button').attr('disabled',false);$('#comments_title').show();$('#comment_text').val('');if(data)
{$('#comments_container').append(data);return;}
loadPagedCommentsList();$('#comment_text').blur();document.location='#comments_bottom';},'plain');return false;};function deleteComment(commentId,type)
{if(confirm(l_delete_confirm))
{$.post('/comments?delete',{id:commentId,type:type},function(data)
{$('#comment_item_'+commentId).fadeOut(150);},'json');}};function replyOnComment(authorId,id)
{var replyMessage=$('#comment_item_'+id+' .body').textChildren({stringDelimiter:'',trim:true,tagMode:'include',tags:['BR']});$('#comment_text').val('<q author="'+authorId+'">'+replyMessage+'</q>'+"\n");document.location='#add_comment_title';$('#comment_text').focus();};var currentType=null;var currentQuery=null;function initCommentsList(type,query,page)
{currentType=type;currentQuery=query;pagerCurrentPage=page;};function loadCommentsList(type,query,page)
{initCommentsList(type,query,page);$('.comments_loading').show();$.post('/comments?list&type='+type+'&'+query+(typeof page!='undefined'?'&page='+page:''),{},function(response)
{$('#comments_container').html(response);$('.comments_loading').hide();});if($('#pager_left').length==1)
{keyBind.add(37,function(){eval($('#pager_left').attr('rel'))});}
if($('#pager_right').length==1)
{keyBind.add(39,function(){eval($('#pager_right').attr('rel'))});}
return false;};function loadPagedCommentsList(page)
{if(typeof page!='undefined')
{loadCommentsList(currentType,currentQuery,page);}
else
{loadCommentsList(currentType,currentQuery);}
return false;};;var Video={playerUrl:'/static/frontend/flash/uppod.swf',defaultOptions:{skin:"/static/frontend/flash/video3-1036.txt",comment:'',width:740,height:416,flashVersion:'9.0.0',poster:''},play:function(containerId,videoPath,options)
{if(swfobject.getFlashPlayerVersion().major==0)
{$('#'+containerId).html('<div style="text-align:center; padding-top:30px;">Для просмотра видео Вам необходимо установить <a href="http://www.macromedia.com/go/getflashplayer">Adobe Flash Player</a>.</div>')
return;}
if(!options)options={};for(var i in Video.defaultOptions)
{if(!options[i])options[i]=Video.defaultOptions[i];}
var flashvars={"comment":options.comment,"st":options.skin,"file":videoPath,"poster":options.poster,"uid":containerId};var params={bgcolor:"#ffffff",allowFullScreen:"true",allowScriptAccess:"always",wmode:'opaque'};new swfobject.embedSWF(Video.playerUrl,containerId,options.width,options.height,options.flashVersion,false,flashvars,params);}};var uppod_instances=new Array();var uppod_instances_id=new Array();var uppod_play_next=0;function uppodStartsReport(playerID){uppodStartsReportVideo(playerID);}
function uppodErrorReport(playerID){}
function uppodTheEnd(playerID){if(uppod_play_next==1){if(uppod_instances_id[playerID]<uppod_instances.length-1){document.getElementById(uppod_instances[uppod_instances_id[playerID]+1]).sendToUppod('play');}
else{document.getElementById(uppod_instances[0]).sendToUppod('play');}}}
function uppodOnEnd(playerID){}
function uppodOnLoad(playerID){}
function uppodOnDownload(playerID){}
function uppodOnQuality(playerID){}
function uppodOnSeek(playerID){}
function uppodStopAll(playerID){for(var i=0;i<uppod_instances.length;i++){try{if(uppod_instances[i]!=playerID){document.getElementById(uppod_instances[i]).sendToUppod("stop");}}
catch(errorObject){}}}
function uppodSend(playerID,com,callback){document.getElementById(playerID).sendToUppod(com,(callback?callback:''));}
function uppodGet(playerID,com,callback){return document.getElementById(playerID).getUppod(com,(callback?callback:''));}
function uppodGetNpl(n,playerID){}
function uppodGetVolume(n,playerID){}
function uppodGetTime(n,playerID){}
function uppodGetTimeDuration(n,playerID){}
function uppodGetStatus(n,playerID){}
function uppodGetBytesTotal(n,playerID){}
function uppodGetBytesLoaded(n,playerID){}
function uppodGetProcent(n,playerID){}
function uppodGetFullScreen(n,playerID){}
function testCallback(n){}
function uppodPlayers(){var objectID;var objectTags=document.getElementsByTagName("object");for(var i=0;i<objectTags.length;i++){objectID=objectTags[i].id;if(objectID.indexOf("player")>-1&uppod_instances.indexOf(objectID)==-1){uppod_instances[i]=objectID;uppod_instances_id[objectID]=i;}}}
function uppodPL(playerID){}
function uppodPreloader(playerID){document.getElementById(playerID+"Preloader")?document.getElementById(playerID+"Preloader").style.display="none":'';document.getElementById(playerID+"Box")?document.getElementById(playerID+"Box").style.position="static":'';}
if(!Array.indexOf){Array.prototype.indexOf=function(obj){for(var i=0;i<this.length;i++){if(this[i]==obj){return i;}}
return-1;}}
var ap_uppodID=setInterval(uppodPlayers,1000);;(function($){var RETURN=13;var TAB=9;var ESC=27;var ARRLEFT=37;var ARRUP=38;var ARRRIGHT=39;var ARRDOWN=40;var BACKSPACE=8;var DELETE=46;function debug(s){$('#info').append(htmlspecialchars(s)+'<br>');}
function getCaretPosition(obj){var start=-1;var end=-1;if(typeof obj.selectionStart!="undefined"){start=obj.selectionStart;end=obj.selectionEnd;}
else if(document.selection&&document.selection.createRange){var M=document.selection.createRange();var Lp;try{Lp=M.duplicate();Lp.moveToElementText(obj);}catch(e){Lp=obj.createTextRange();}
Lp.setEndPoint("EndToStart",M);start=Lp.text.length;if(start>obj.value.length)
start=-1;Lp.setEndPoint("EndToStart",M);end=Lp.text.length;if(end>obj.value.length)
end=-1;}
return{'start':start,'end':end};}
function setCaret(obj,l){obj.focus();if(obj.setSelectionRange){obj.setSelectionRange(l,l);}
else if(obj.createTextRange){m=obj.createTextRange();m.moveStart('character',l);m.collapse();m.select();}}
function prepareArray(jsondata){var new_arr=[];for(var i=0;i<jsondata.length;i++){if(jsondata[i].id!=undefined&&jsondata[i].value!=undefined){jsondata[i].id=jsondata[i].id+"";jsondata[i].value=jsondata[i].value+"";if(jsondata[i].info!=undefined)
jsondata[i].info=jsondata[i].info+"";new_arr.push(jsondata[i]);}}
return new_arr;}
function escapearg(s){if(s==undefined||!s)return'';return s.replace('\\','\\\\').replace('*','\\*').replace('.','\\.').replace('/','\\/');}
function htmlspecialchars(s){if(s==undefined||!s)return'';return s.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;');}
function ltrim(s){if(s==undefined||!s)return'';return s.replace(/^\s+/g,'');}
$.fn.jqac=function(options){return this.each(function(){var me=$(this);var me_this=$(this).get(0);if(!me.is('input:text,input:password,textarea'))
return;if(!options&&(!$.isFunction(options.get)||!options.ajax_get)){return;}
if(me.attr('jqac')=='on')return;me.attr('jqac','on');me.attr('autocomplete','off');options=$.extend({delay:200,timeout:5000,minchars:3,multi:false,cache:true,height:150,autowidth:false,noresults:'-',default_list:0},options);if(options.default_list){me.focus(function(ev){if((getUserInput()=='')&&!suggestions_menu)getSuggestions(getUserInput());});}
me.keydown(function(ev){switch(ev.which){case RETURN:if(!suggestions_menu)return true;else setHighlightedValue();return false;case ESC:clearSuggestions();return false;}
return true;});me.keypress(function(ev){switch(ev.keyCode){case RETURN:case ESC:return false;case ARRUP:changeHighlight(ev.keyCode);return false;case ARRDOWN:if(!suggestions_menu)getSuggestions(getUserInput());else changeHighlight(ev.keyCode);return false;}
return true;});me.keyup(function(ev){switch(ev.which){case RETURN:case ESC:case ARRLEFT:case ARRRIGHT:case ARRUP:case ARRDOWN:return false;default:getSuggestions(getUserInput());}
return true;});var user_input="";var input_chars_size=0;var suggestions=[];var current_highlight=0;var suggestions_menu=false;var suggestions_list=false;var loading_indicator=false;var clearSuggestionsTimer=false;var getSuggestionsTimer=false;var showLoadingTimer=false;var zIndex=me.css('z-index');function getUserInput(){var val=me.val();if(options.multi){var pos=getCaretPosition(me_this);var start=pos.start;for(;start>0&&val.charAt(start-1)!=',';start--){}
var end=pos.start;for(;end<val.length&&val.charAt(end)!=',';end++){}
var val=val.substr(start,end-start);}
return ltrim(val);}
function setSuggestion(val){user_input=val;if(options.multi){var orig=me.val();var pos=getCaretPosition(me_this);var start=pos.start;for(;start>0&&orig.charAt(start-1)!=',';start--){}
var end=pos.start;for(;end<orig.length&&orig.charAt(end)!=',';end++){}
var new_val=orig.substr(0,start)+(start>0?' ':'')+val+orig.substr(end);me.val(new_val);setCaret(me_this,start+val.length+(start>0?1:0));}
else{me_this.focus();me.val(val);}}
function getSuggestions(val){if(options.default_list&&(val.length==0)){suggestions=prepareArray(options.get_default());createList(suggestions);return false;}
if(val.length<options.minchars){clearSuggestions();return false;}
if(options.cache&&val.length>input_chars_size&&suggestions.length){var arr=[];for(var i=0;i<suggestions.length;i++){var re=new RegExp("("+escapearg(val)+")",'ig');if(re.exec(suggestions[i].value))
arr.push(suggestions[i]);}
user_input=val;input_chars_size=val.length;suggestions=arr;createList(suggestions);return false;}
else{clearTimeout(getSuggestionsTimer);user_input=val;input_chars_size=val.length;getSuggestionsTimer=setTimeout(function(){suggestions=[];if($.isFunction(options.pre_callback))
options.pre_callback();if($.isFunction(options.get)){suggestions=prepareArray(options.get(val));createList(suggestions);}
else if($.isFunction(options.ajax_get)){clearSuggestions();showLoadingTimer=setTimeout(show_loading,options.delay);options.ajax_get(val,ajax_continuation);}},options.delay);}
return false;};function ajax_continuation(jsondata){hide_loading();suggestions=prepareArray(jsondata);createList(suggestions);}
function show_loading(){if(!loading_indicator){loading_indicator=$('<div class="jqac-menu"><div class="jqac-loading">Loading</div></div>').get(0);$(loading_indicator).css('position','absolute');var pos=me.offset();$(loading_indicator).css('left',pos.left+"px");$(loading_indicator).css('top',(pos.top+me.height()+2)+"px");if(!options.autowidth)
$(loading_indicator).width(me.width());$('body').append(loading_indicator);}
$(loading_indicator).show();setTimeout(hide_loading,10000);}
function hide_loading(){if(loading_indicator)
$(loading_indicator).hide();clearTimeout(showLoadingTimer);}
function createList(arr){if(suggestions_menu)
$(suggestions_menu).remove();hide_loading();killTimeout();suggestions_menu=$('<div class="jqac-menu"></div>').get(0);$(suggestions_menu).css({'position':'absolute','z-index':1000000,'max-height':options.height+'px','overflow-y':'auto'});suggestions_list=$('<ul></ul>').get(0);$(suggestions_list).css('list-style','none').css('margin','0px').css('padding','0px').css('overflow','hidden');var re=new RegExp("("+escapearg(htmlspecialchars(user_input))+")",'ig');for(var i=0;i<arr.length;i++){var val=new String(arr[i].value);var output=htmlspecialchars(val).replace(re,'<em>$1</em>');var span=$('<span class="jqac-link">'+output+'</span>').get(0);if(arr[i].info!=undefined&&arr[i].info!=""){$(span).append($('<div class="jqac-info">'+arr[i].info+'</div>'));}
$(span).attr('name',i+1);$(span).click(function(){setHighlightedValue();});$(span).mouseover(function(){setHighlight($(this).attr('name'),true);});var li=$('<li></li>').get(0);$(li).append(span);$(suggestions_list).append(li);}
if(arr.length==0){$(suggestions_list).append('<li class="jqac-warning">'+options.noresults+'</li>');}
$(suggestions_menu).append(suggestions_list);var pos=me.offset();$(suggestions_menu).css('left',pos.left+"px");$(suggestions_menu).css('top',(pos.top+me.height()+2)+"px");if(!options.autowidth)
$(suggestions_menu).width(me.width());$(suggestions_menu).mouseover(function(){killTimeout()});$(suggestions_menu).mouseout(function(){resetTimeout()});$('body').append(suggestions_menu);if($.fn.bgiframe)
$(suggestions_menu).bgiframe({height:suggestions_menu.scrollHeight});if(suggestions_menu.scrollHeight>options.height){$(suggestions_menu).height(options.height);$(suggestions_menu).width($(suggestions_menu).width()+20);}
current_highlight=0;clearSuggestionsTimer=setTimeout(function(){clearSuggestions()},options.timeout);};function setHighlightedValue(){if(current_highlight&&suggestions[current_highlight-1]){var sugg=suggestions[current_highlight-1];if(sugg.affected_value!=undefined&&sugg.affected_value!='')
setSuggestion(sugg.affected_value);else
setSuggestion(sugg.value);if($.isFunction(options.callback))
options.callback(suggestions[current_highlight-1]);clearSuggestions();}};function changeHighlight(key){if(!suggestions_list||suggestions.length==0)return false;var n;if(key==ARRDOWN)
n=current_highlight+1;else if(key==ARRUP)
n=current_highlight-1;if(n>$(suggestions_list).children().size())
n=1;if(n<1)
n=$(suggestions_list).children().size();setHighlight(n);};function setHighlight(n,mouse_mode){if(!suggestions_list)return false;if(current_highlight>0)clearHighlight();current_highlight=Number(n);var li=$(suggestions_list).children().get(current_highlight-1);li.className='jqac-highlight';if(!mouse_mode)adjustScroll(li);killTimeout();};function clearHighlight(){if(!suggestions_list)return false;if(current_highlight>0){$(suggestions_list).children().get(current_highlight-1).className='';current_highlight=0;}};function clearSuggestions(){killTimeout();if(suggestions_menu){$(suggestions_menu).remove();suggestions_menu=false;suggestions_list=false;current_highlight=0;}};function adjustScroll(el){if(!suggestions_menu)return false;var viewportHeight=suggestions_menu.clientHeight;var wholeHeight=suggestions_menu.scrollHeight;var scrolled=suggestions_menu.scrollTop;var elTop=el.offsetTop;var elBottom=elTop+el.offsetHeight;if(elBottom>scrolled+viewportHeight){suggestions_menu.scrollTop=elBottom-viewportHeight;}
else if(elTop<scrolled){suggestions_menu.scrollTop=elTop;}
return true;}
function killTimeout(){clearTimeout(clearSuggestionsTimer);};function resetTimeout(){clearTimeout(clearSuggestionsTimer);clearSuggestionsTimer=setTimeout(function(){clearSuggestions()},500);};})};})($);