
(function($){$.fn.yDialogTrigger=function(dialog,active){return this.each(function(){var $this=$(this);$(this).bind("click",function(e){if(dialog.is(":visible")){dialog.trigger("hide",[$this]);}else{dialog.trigger("show",[$this]);}
e.preventDefault();});if(active){$this.bind("active",function(){$this.addClass(active);});$this.bind("inactive",function(){$this.removeClass(active);});}});}
$.fn.yDialog=function(){return this.each(function(){var $this=$(this);var src;$this.bind("show",onShow).bind("hide",onHide);$this.find("input.cancel").bind("click",function(){$this.trigger("hide");});var hClick;if(!hClick)hClick=function(e){if($(e.target).parents().andSelf().index($this)==-1){$this.trigger("hide");}};var hKey;if(!hKey)hKey=function(e){if(e.keyCode==27){$this.trigger("hide");};}
function onShow(e,obj){src=$(obj).trigger("active");setTimeout(function(){$(document).bind("click",hClick).bind("keyup",hKey);},50);$this.trigger("beforeshow",[obj]);$this.show();if($.browser.msie){document.body.className+='';}
$this.trigger("aftershow",[obj]);return false;}
function onHide(e,obj){if(src)src.trigger("inactive");$(document).unbind("click",hClick).unbind("keyup",hKey);$this.trigger("beforehide",[obj]);$this.hide();$this.trigger("afterhide",[obj]);return false;}});}})(jQuery);(function($){$.fn.ySerpTrigger=function(films,params){var popup=$(".b-movie-popup").yDialog().serpPopup(films,params);if(params.openFilmIndex>-1){setTimeout(function(){popup.trigger("show",[$(".b-search-result-video").find("td.s"+params.openFilmIndex+":first .show-player")]);},200);}
return this.each(function(){var link=$(this);link.bind("click",function(e){popup.trigger("show",[link]);return false;});});}
$.fn.serpPopup=function(films,params){return this.each(function(){var popup=$(this);$("body").append(popup)
var host=window.location.host;host=host.replace(/\.ru$/,".net");var w=$(window);var iframe=popup.find("iframe");popup.find("a.close").bind("click",function(){popup.trigger("hide");return false;});var select=popup.find("select");var newCollection=popup.find(".l-add .l-add-t");var titleNewCollection=newCollection.find("input[name='title']");var voting=popup.find(".b-rating-stars").voting().trigger('voting:disable');select.bind("change",function(){var $this=$(this);var id=$this.find(":selected").val();if(id<0){newCollection.show();newCollection.find("input").focus();}
else{newCollection.hide();}});var film;var playing;var added=popup.find(".added");var note=popup.find(".popup-note");var external=popup.find(".external-service");var complaintDialog=popup.find(".complaint-body").yDialog();popup.find(".complaint .b-inplace-action-dot").yDialogTrigger(complaintDialog);popup.find(".cancel-complaint").bind("click",function(){complaintDialog.trigger("hide")});var ok=complaintDialog.find('.ok');complaintDialog.find('form :radio').bind('click',function(){ok.attr('disabled',false);});yAjax.postForm(popup.find(".complaint-body form"),{dataType:'json',beforeSubmit:function(){return confirm('Вы действительно хотите пожаловаться на этот ролик?');},success:function(){complaintDialog.trigger("hide");popup.find(".complaint").hide();popup.find(".complaint-ok").show();}});function updateCollections(data){if(!film){return false;}
if(!film.collections){film.collections=new Array();}
var c=film.collections;var l=c.length;if(data){var uniq=true;for(var i=0;i<l;i++){if(c[i].id==data.id){uniq=false;break;}}
if(uniq){film.collections.push({id:data.id,title:data.title,login:data.login});l++;}}
if(l>0){var r='';for(var i=0;i<l;i++){if(i){r+=', '}
r+='<a href="/users/'+c[i].login+'/collection/'+c[i].id+'/">'+c[i].title+'</a>';}
if(l==1){r='Ролик добавлен в коллекцию: '+r;}else{r='Ролик добавлен в коллекции: '+r;}
added.html(r).show();}
else{added.html('').hide();}}
var submit=popup.find(".panel-body input[type=submit]");var updateSubmit=false;function onchange(){submit.attr('disabled',updateSubmit?!$.trim(titleNewCollection.val()):false);}
onchange();titleNewCollection.keyup(onchange).blur(onchange).change(onchange);select.change(function(){updateSubmit=select.find(":selected").val()<0;onchange();});submit.bind("click",function(){var sel=select.find(":selected");var id=sel.val();var title=sel.text();if(!film){return false;}
if(id==0){alert('Выберите коллекцию');return false;}
else if(id<0){if(titleNewCollection.val()){yAjax.post("/actions/ajax/album-add.xml",{title:titleNewCollection.val(),mode:'select'},function(data){if(data.error){return processError(data.error);}
title=data.title.length>params.maxAlbumTitleLength?data.title.substr(0,params.maxAlbumTitleLength)+'&#8230;':data.title;var o=$("<option value='"+data.id+"'>"+title+"</option>");select.find("option:first-child").after(o);select[0].selectedIndex=1;select.get(0).className+='';titleNewCollection.val('');newCollection.hide();id=data.id;movie2Album();},null,"json");}
return false;}
function processError(type){if(type=='album_already_exists'){alert('Такая коллекция уже есть');return titleNewCollection.focus();}
alert('Ошибка');}
function movie2Album(){var dataMovie={album:id,title:title,mode:'serp'};if(film.hosting){dataMovie.url=film.link;}else{dataMovie.author=film.author;dataMovie.video=film.video;}
yAjax.post("/actions/ajax/movie2album-add.xml",dataMovie,function(data){updateCollections(data);},null,'json');};movie2Album();});popup.bind("beforeshow",function(e,obj){popup.find(".complaint-ok").hide();popup.find(".complaint").show();complaintDialog.find('form :radio').removeAttr('checked');ok.attr('disabled',true);var n=/s(\d+)/.exec(obj.parents("td:first").attr("class"))[1];film=films[n];if(playing){playing.removeClass("b-frame-play-now");}
playing=obj.parents("i.b-frame:first").addClass("b-frame-play-now");updateCollections();var left=Math.floor((w.width()-(film.width+30))/2);var top=w.scrollTop()+Math.floor((w.height()-film.height)/2);var filmLink;if(film.hosting){var hosting=hostings[film.hosting];var a=external.show().find("a");a.attr("href",film.link).html('Страница ролика на&nbsp;'+hosting.title);a.get(0).onclick=film.redir?function(){redirect(a.get(0),film.redir);}:function(){};iframe.attr("src","http://"+host+"/embed.xml?link="+encodeURIComponent(film.link)+"&params="+encodeURIComponent(film.params)+"&width="+film.width+"&height="+film.height);note.show();filmLink=film.link;}else{iframe.attr("src","http://"+host+"/embed.xml?player="+encodeURIComponent(film.player)+"&flashvars="+encodeURIComponent(film.flashvars));filmLink="http://video.yandex.ru/users/"+film.author+"/view/"+film.video+"/";external.show().find("a").attr("href",filmLink).text(filmLink);note.hide();}
voting.trigger('voting:disable').trigger('voting:params',{filmUrl:filmLink,url:'/actions/ajax/vote-search.xml'}).trigger('voting:set',film.rating);yAjax.post('/actions/ajax/get-vote-search.xml',{url:filmLink},function(data){if(filmLink==data.url){voting.trigger(data.status=='ok'?'voting:enable':'voting:disable');}},null,'json');popup.find(".complaint input[name='url']").val(film.link);iframe.css({width:film.width,height:film.height});popup.css({position:"absolute",left:left,top:top,width:film.width+30});});popup.bind("afterhide",function(){iframe.attr("src","/embed.xml");film=null;playing.removeClass("b-frame-play-now");playing=null;});});};})(jQuery);(function($){$.fn.newalbum2select=function(params){return this.each(function(){var $this=$(this);var newCollection=$this.parents('form:first').find('.b-collection-new');var newCollectionTitle=newCollection.find('input.title');var submit=newCollection.find('input.ok');function onchange(){submit.attr('disabled',!$.trim(newCollectionTitle.val()));}
onchange();newCollectionTitle.keyup(onchange).blur(onchange).change(onchange);$(this).bind("change",function(){var id=$this.find(":selected").val();if(id<0){newCollection.show();newCollectionTitle.focus();}
else{newCollection.hide();}});newCollection.find('.ok').click(function(){var title=jQuery.trim(newCollectionTitle.val());if(title){yAjax.post("/actions/ajax/album-add.xml",{title:title,mode:'select'},function(data){if(data.error){return processError(data.error);}
var title=data.title.length>params.maxAlbumTitleLength?data.title.substr(0,params.maxAlbumTitleLength)+'&#8230;':data.title;var o=$("<option value='"+data.id+"'>"+title+"</option>");$this.find("option:first-child").after(o);$this[0].selectedIndex=1;$this.get(0).className+='';newCollectionTitle.val('');newCollection.hide();},null,'json');}
else{alert('Введите название коллекции');newCollectionTitle.focus();}});newCollection.find('.cancel').click(function(){newCollection.hide();$this[0].selectedIndex=1;});function processError(type){if(type=='album_already_exists'){alert('Такая коллекция уже есть');return newCollectionTitle.focus();}
alert('Ошибка');}});}})(jQuery);(function($){$(function(){$(".b-top-tizer .close").bind("click",function(){$(".b-top-tizer").hide();var expire=new Date();expire.setTime(expire.getTime()+30*86400*1000);var c=[];c.push('showlocal=false');c.push('domain='+window.location.hostname);c.push('path=/');c.push('expires='+expire.toGMTString());document.cookie=c.join(';');return false;});});})(jQuery);var yAjax={post:function(sUrl,oData,fCallBackSuccess,fCallBackError,sType){$.post(sUrl,oData,function(mData,sTextStatus){yAjax.processCallbackSuccess(fCallBackSuccess,fCallBackError,mData,sTextStatus);},sType);},postForm:function(oForm,oOptions){var fCallBackSuccess=oOptions.success;if(oOptions.success){oOptions.success=function(mData,sTextStatus){yAjax.processCallbackSuccess(fCallBackSuccess,null,mData,sTextStatus);}}
oForm.ajaxForm(oOptions);},processCallbackSuccess:function(fCallBackSuccess,fCallBackError,mData,sTextStatus){if(this.Debug.processErrors(mData)){if(fCallBackSuccess){fCallBackSuccess(mData,sTextStatus);}}
else if(fCallBackError){fCallBackError(mData,sTextStatus);}},Debug:{oElementDebug:null,bShowed:false,ID_ELEMENT_DEBUG:'debug',CLASS_NAME_SHOWED:'showed',CLASS_NAME_ERROR:'system-error',init:function(){this.oElementDebug=$('#'+this.ID_ELEMENT_DEBUG);if(!this.isEnabled()){return;}
this.bShowed=this.oElementDebug.hasClass(this.CLASS_NAME_SHOWED);$(document).bind('click',function(oEvent){if($(oEvent.target).parents().andSelf().index(yAjax.Debug.oElementDebug)==-1){yAjax.Debug.hide();}});},isEnabled:function(){return this.oElementDebug.length>0;},processErrors:function(mData){if(!mData||(typeof(mData)!='string'&&!mData.error)){return true;}
var aErrors=$(document.createElement('div')).html(typeof(mData)=='string'?mData:mData.error).find('.'+this.CLASS_NAME_ERROR);if(aErrors.length>0){if(this.isEnabled()){this.oElementDebug.text('');aErrors.each(function(i,oError){yAjax.Debug.oElementDebug.append($(oError).html());});this.show();}
return false;}
return true;},hide:function(){if(!this.isEnabled()||!this.bShowed){return;}
this.oElementDebug.removeClass(this.CLASS_NAME_SHOWED);this.bShowed=false;},show:function(){if(!this.isEnabled()||this.bShowed){return;}
this.oElementDebug.addClass(this.CLASS_NAME_SHOWED);this.bShowed=true;}}};$(document).ready(function(){yAjax.Debug.init();});(function($){$.fn.voting=function(params){return this.each(function(){var
$this=$(this),matches=$this.attr('class').match(/b\-rating\-stars\-(\d)/),ratingMain=matches?matches[1]:0,ratingUser=1,allowVote=true;$this.bind('voting:params',function(e,data){params=data;}).bind('voting:disable',disable).bind('voting:enable',enable).bind('voting:set',function(e,data){setRating(data);});$this.find('a').mouseover(function(){if(!allowVote){return;}
ratingUser=$(this).attr('class').match(/r(\d)/)[1];setRating(ratingUser,true);}).mouseout(function(){setRating(ratingMain);}).click(function(){if(!allowVote){return;}
vote(ratingUser);});function setRating(value,onlyShow){$this.attr('class',$this.attr('class').replace(/b\-rating\-stars\-\d/,'')).addClass('b-rating-stars-'+value);if(!onlyShow){ratingMain=value;}}
function vote(rating){disable();yAjax.post(params.url?params.url:'/actions/ajax/vote.xml',params.filmUrl?{'url':params.filmUrl,'vote':rating}:{'film-id':params.filmId,'author':params.author,'vote':rating},function(data){if(params.opinions&&data.count){params.opinions.html(data.count);}
if(data.votes){ratingMain=data.votes;}
setRating(ratingMain);$this.attr('title','Вы уже проголосовали за этот ролик');},null,'json');}
function disable(){allowVote=false;$this.removeClass('b-rating-stars_live');}
function enable(){allowVote=true;$this.addClass('b-rating-stars_live');}});};})(jQuery);