/* site/tv.js */
$(function(){var tv_content=$('#tv_content');$('.menu_element.menu_favorite_empty a',tv_content).click(function(e){confirmDialog(320,170,'Сохранить текущую конфигурацию программы телепередач?\nВнимание, предыдущая сохраненная конфигурация станет недоступна.',function(){});});$('.menu_element.menu_favorite a',tv_content).click(function(e){confirmDialog(320,170,'Вы пытаетесь загрузить конфигурацию программы телепередач, сохраненную Вами ранее.\nВнимание! Текущая конфигурация станет недоступна.',function(){});});var blockType=$('#tv_content_block_type',tv_content).length;var listType=$('#tv_content_list_type',tv_content).length;var sortable=$("#sortable",tv_content);sortable.sortable({revert:true,placeholder:'sortable_blank_place',handle:'.logo',opacity:0.6,tolerance:'pointer',containment:'#tv_content',update:function(event,ui){$.ajax({url:'/tv/setorder/?'+sortable.sortable('serialize')});},deactivate:function(event,ui){if($.browser.opera){ui.item.css({top:0,left:0});}}});$('.tv_object .object_slider_down',tv_content).click(function(){var li=$(this).closest('.tv_object');loadListings(li,'append');$(this).hide();});$('.tv_object .object_slider_up',tv_content).click(function(){var li=$(this).closest('.tv_object');loadListings(li,'prepend');$(this).hide();});$('#draggable > li .add_object_types',tv_content).click(function(){if($(this).hasClass('add_object_types_down')){$(this).removeClass('add_object_types_down').addClass('add_object_types_up');$(this).children().not('.top').hide();}else{$(this).addClass('add_object_types_down').removeClass('add_object_types_up');$(this).children().show();}});$('#draggable > li .add_object_types .add_object_type',tv_content).click(function(event){$(this).siblings('.add_object_type').removeClass('top').addClass('bottom');$(this).removeClass('bottom').addClass('top');});var add_objects=$('#add_objects',tv_content);$('#draggable > li .add_object_plus',tv_content).click(function(){var object_type=$('#draggable .tv_object .add_object_type.top',tv_content).attr('id').match(/add_object_type_(.*?)$/i)[1];$('.block_name',add_objects).removeClass('active');$('.add_objects_content',add_objects).hide();$('#add_objects_'+object_type,add_objects).addClass('active');var current_content=$('#'+$('.header .block_name.active',add_objects).attr('id')+'_content',tv_content);current_content.show();add_objects.show();var newTop=Math.max((window.innerHeight-add_objects.height())/2,0);var newLeft=Math.max((window.innerWidth-add_objects.width())/2,0);add_objects.css('top',newTop+window.scrollY);add_objects.css('left',newLeft);makeVerticalScroller(current_content);});add_objects.draggable({addClasses:false,appendTo:'body',handle:'.pult'});$('.close',add_objects).click(function(){add_objects.hide();});$('.block_name',add_objects).click(function(){$('.block_name.active',add_objects).removeClass('active');$(this).addClass('active');$('.add_objects_content',tv_content).hide();var current_content=$('#'+$(this).attr('id')+'_content',add_objects);current_content.show();makeVerticalScroller(current_content);});$('.submit .button',add_objects).click(function(){add_objects.hide();});$('.add_objects_content .add_object',add_objects).click(function(){var object=$(this);var object_params=object.attr('object').match(/^(\w*)_(\d*)$/i);var object_type=object_params[1];var object_id=object_params[2];var siblingInputs=$('.add_objects_content .add_object[object="'+object_type+'_'+object_id+'"]',add_objects);if(!object.hasClass('checked')){object.addClass('checked');siblingInputs.addClass('checked');$.ajax({data:{id:object_id,date:$('#date',tv_content).val(),toDate:$('#toDate',tv_content).val(),block_type:blockType},url:'/tv/subscribe/'+object_type,beforeSend:function(){if(blockType){var li=$('<li id="object_'+object_type+object_id+'" class="drag_object tv_object tv_object_'+object_type+'"></li>');li.append('<div style="text-align: center; "><img src="http://static.weburg.ru/img/js//thickbox/thickbox-ico-loading.gif" /></div>');li.appendTo(sortable);}},success:function(data,textStatus){var li=$('#object_'+object_type+object_id,tv_content);if(data!='error'){if(blockType){li.html('');li.append(data);sortable.sortable('refresh');li.find('.close').click(function(){var tv_object=$(this).parent('.tv_object');tv_object.find('.object_schedule').html('<div style="text-align: center; "><img src="http://static.weburg.ru/img/js//thickbox/thickbox-ico-loading.gif" /></div>');var objectParams=tv_object.attr('id').match(/^object_(\w*?)(\d*)$/i);var object_type=objectParams[1];var object_id=objectParams[2];$('.add_objects_content .add_object[object="'+object_type+'_'+object_id+'"]:first',add_objects).click();});li.find('.object_slider_down').click(function(){loadListings(li,'append');$(this).hide();});li.find('.object_slider_up').click(function(){loadListings(li,'prepend');$(this).hide();});li.find('.listings .listing .listing_name').click(function(){var listing_id=$(this).attr('id').match(/^listing_(\d+)$/i)[1];show_info(listing_id);});}}
else{object.removeClass('checked');siblingInputs.removeClass('checked');alertDialog(320,170,'Не удалось подписаться');if(blockType){li.remove();}}},error:function(){object.removeClass('checked');siblingInputs.removeClass('checked');$('#tv_content #object_'+object_type+object_id).remove();alertDialog(320,170,'Не удалось подписаться');}});}
else{object.removeClass('checked');siblingInputs.removeClass('checked');$.ajax({data:{id:object_id},url:'/tv/unsubscribe/'+object_type,success:function(data,textStatus){if(data=='ok'){if(blockType){$('#object_'+object_type+object_id,tv_content).remove();}}else{object.addClass('checked');siblingInputs.addClass('checked');alertDialog(320,170,'Не удалось отписаться');}}});}});$('.object_info .favorite, .channels_list .channel .favorite',tv_content).click(function(event){event.preventDefault();var object=$(this);var object_params=object.attr('object').match(/^(\w*)_(\d*)$/i);var object_type=object_params[1];var object_id=object_params[2];if(!object.hasClass('checked')){$.ajax({data:{id:object_id,object_type:object_type},url:'/tv/timetable/mytv/add',success:function(data,textStatus){if(data!='error'){object.addClass('checked');object.attr('href','/tv/timetable/mytv/remove?object_type='+object_type+'&id='+object_id);object.children('img').attr('src','http://static.weburg.ru/img/css//design/tv/favorite_big.png');}
else{alertDialog(320,170,'Не удалось добавить в МоёТВ');}},error:function(){alertDialog(320,170,'Не удалось добавить в МоёТВ');}});}
else{$.ajax({data:{id:object_id,object_type:object_type},url:'/tv/timetable/mytv/remove',success:function(data,textStatus){if(data=='ok'){object.removeClass('checked');object.attr('href','/tv/timetable/mytv/add?object_type='+object_type+'&id='+object_id);object.children('img').attr('src','http://static.weburg.ru/img/css//design/tv/favorite_big_empty.png');}else{alertDialog(320,170,'Не удалось удалить из избранного');}}});}}).focus(function(){$(this).blur();});$('.tv_object .close',sortable).click(function(){var tv_object=$(this).parent('.tv_object');tv_object.find('.object_schedule').html('<div style="text-align: center; "><img src="http://static.weburg.ru/img/js//thickbox/thickbox-ico-loading.gif" /></div>');var objectParams=tv_object.attr('id').match(/^object_(\w*?)(\d*)$/i);var object_type=objectParams[1];var object_id=objectParams[2];$('#tv_content #add_objects .add_objects_content .content .add_object[object="'+object_type+'_'+object_id+'"]:first').click();});$('#tv_content .header .pult .add_object_type').click(function(){var object_type=$(this).attr('id').match(/^pult_add_object_type_(.*?)$/i)[1];var add_objects=$('#tv_content #add_objects');$('.block_name',add_objects).removeClass('active');$('#add_objects_'+object_type,add_objects).addClass('active');$('.add_objects_content',add_objects).hide();var current_content=$('#tv_content #'+$('.header .block_name.active',add_objects).attr('id')+'_content');current_content.show();add_objects.show();var newTop=Math.max((window.innerHeight-add_objects.height())/2,0);var newLeft=Math.max((window.innerWidth-add_objects.width())/2,0);add_objects.css('top',newTop+window.scrollY);add_objects.css('left',newLeft);makeVerticalScroller(current_content);});$('#tv_content .header .menu #menu_slide_up_objects').click(function(){if(blockType){}else{$('#tv_content .tv_content .tv_list_schedule tbody:has(.object_name) .listing').hide();$('#tv_content .tv_content .tv_list_schedule tbody:has(.object_name)').addClass('hidden_listings');}
$(this).hide();$('#tv_content .header .menu #menu_slide_down_objects').show();});$('#tv_content .header .menu #menu_slide_down_objects').click(function(){if(blockType){}else{$('#tv_content .tv_content .tv_list_schedule .object_name').each(function(){var tbody=$(this).parent();if(tbody.hasClass('show_expired')){tbody.children('.listing').show();}else{tbody.children('.listing:not(.listing_expire)').show();}
tbody.removeClass('hidden_listings');});}
$(this).hide();$('#tv_content .header .menu #menu_slide_up_objects').show();});$('#tv_content .header .current_date .time_selector').click(function(){$('#tv_content .header .current_date #time_selector').css('top',$(this).offset().top+$(this).height()+3).css('left',$(this).offset().left-$('#container').offset().left-2);$('#tv_content .header .current_date #time_selector').toggle();});$('#tv_content .header .current_date #time_selector .time').click(function(){var selector=$('#tv_content .header .current_date #time_selector');var parent=$(this).parent('.time_select');$('#tv_content .header .current_date .time_selector .current_time').text($(this).text());selector.hide();$('.time_select',selector).removeClass('time_select_selected');parent.addClass('time_select_selected');var dayTime=parent.attr('id');$('.tv_object',sortable).each(function(){var scrollbar=$(this).find('.scrollbar-slider');var tr=$(this).find('.content_'+dayTime+':not(.listing_expire):first');if($.defined(scrollbar.slider('option','max'))&&$.defined(tr.position())){var scrollValue=Math.min(tr.position().top,scrollbar.slider('option','max'));scrollbar.slider('value',scrollbar.slider('option','max')-scrollValue);}});});$('#tv_content .tv_content .toggle_expired_listings').toggle(function(){$(this).attr('title','Показать в списке прошедшие передачи');$(this).text('Показать прошедшие').addClass('hidden_expired');$('#tv_content .tv_content .listing_expire').hide();$('#tv_content .tv_content .tv_list_schedule .listings').each(function(){$(this).removeClass('show_expired');var listings=$(this).children('.listing:not(.listing_expire)');if(!listings.length){$(this).hide();}});},function(){$(this).attr('title','Не показывать в списке прошедшие передачи');$(this).text('Скрыть прошедшие').removeClass('hidden_expired');$('#tv_content .tv_content .tv_list_schedule .listings').show().addClass('show_expired');$('#tv_content .tv_content .listings:not(.hidden_listings) .listing_expire').show();if($('#tv_content .tv_content .pages').length){$('#tv_content .tv_content .pages .page').removeClass('expire_page');}});$('#tv_content .tv_content .tv_list_schedule .object_name').click(function(){var tbody=$(this).parent();if(tbody.hasClass('hidden_listings')){if(tbody.hasClass('show_expired')){tbody.children('.listing').show();}else{tbody.children('.listing:not(.listing_expire)').show();}
tbody.removeClass('hidden_listings');}else{tbody.children('.listing').hide();tbody.addClass('hidden_listings');}});$('#tv_content .tv_content .listings .listing .listing_name, #tv_content .live .listings .listing .listing_name').click(function(){var listing_id=$(this).attr('id').match(/^listing_(\d+)$/i)[1];show_info(listing_id);});$('#show_info .close').click(function(){var show_info_block=$('#show_info');show_info_block.hide();show_info_block.children('.show').html('');});if($('#tv_content .tv_content .listing:not(.listing_expire)').length){$('#tv_content .tv_content .toggle_expired_listings').click();}
if($('#tv_calendar_selector').length){var calendar=$('#tv_calendar');var calendar_slider=$('#tv_calendar_selector');var dates_count=$('#tv_calendar .date').length-1;var one_width=$('#tv_calendar .date:first').outerWidth();var handle_right=calendar_slider.find('.selector-handler-right');var handle_width=handle_right.width()-4;var real_handle_width=handle_right.width();var calendar_width=calendar_slider.find('.tv_calendar_selector_handler_parent').width();var max_width=one_width*dates_count+handle_width;var date_from_index=$('.date.date_from',calendar).prevAll('.date').length*one_width;var date_to_index=($('.date.date_to',calendar).prevAll('.date').length)*one_width+handle_width;var slider=calendar_slider.slider({range:true,min:0,max:max_width,step:1,distance:0,values:[date_from_index,date_to_index],slide:function(event,ui){var index=($(ui.handle).hasClass('.selector-handler-right')?1:0);var coef=parseInt(ui.value/one_width);var value=0;if((ui.value-coef*one_width)>((coef+1)*one_width-ui.value)){coef+=1;}
value=coef*one_width;slider.slider('values',index,value);var link=$('.date:eq('+coef+') > a',calendar);var date=link.attr('id').match(/^calendar_date_(.+)$/i)[1];if(index){$('#calendar_date_to',calendar).val(date);}else{$('#calendar_date_from',calendar).val(date);}
$('#tv_content .submit_calendar_range').attr('href',$('#calendar_page_link',calendar).val()+'?date='+$('#calendar_date_from',calendar).val()+'&to_date='+$('#calendar_date_to',calendar).val())
if($(ui.handle).hasClass('selector-handler-right')){slider.slider('values',1,slider.slider('values',1)+handle_width);var right_left=parseInt(parseFloat($('.selector-handler-right',calendar_slider).css('left'))*calendar_width/100);var left_left=parseInt(parseFloat($('.selector-handler-left',calendar_slider).css('left'))*calendar_width/100);if(right_left-left_left-real_handle_width<0)right_left+=1;$('.ui-slider-range',calendar_slider).css('left',left_left+real_handle_width+5).width(right_left-left_left-real_handle_width);return false;}
if(ui.values[0]==ui.values[1]){var val=parseInt(ui.values[0]/one_width)*one_width;slider.slider('values',0,val);var right_left=parseInt(parseFloat($('.selector-handler-right',calendar_slider).css('left'))*calendar_width/100);var left_left=parseInt(parseFloat($('.selector-handler-left',calendar_slider).css('left'))*calendar_width/100);$('.ui-slider-range',calendar_slider).css('left',left_left+real_handle_width+5).width(0);return false;}
var right_left=parseInt(parseFloat($('.selector-handler-right',calendar_slider).css('left'))*calendar_width/100);var left_left=parseInt(parseFloat($('.selector-handler-left',calendar_slider).css('left'))*calendar_width/100);if(right_left-left_left-real_handle_width<0)right_left+=1;$('.ui-slider-range',calendar_slider).css('left',left_left+real_handle_width+5).width(right_left-left_left-real_handle_width);return false;}});handle_right.bind("mouseenter mouseleave",function(){$(this).toggleClass('handle-mouseenter');});var right_left=parseInt(parseFloat($('.selector-handler-right',calendar_slider).css('left'))*calendar_width/100);var left_left=parseInt(parseFloat($('.selector-handler-left',calendar_slider).css('left'))*calendar_width/100);if(right_left-left_left-real_handle_width<0)right_left+=1;$('.ui-slider-range',calendar_slider).css('left',left_left+real_handle_width+5).width(right_left-left_left-real_handle_width);}
if($('.live').length){var live_widget=$('.live');var listings=$('.listings',live_widget);live_width=$('#information').width()-113;live_widget.width(live_width);var listings_width=0;var listing_width=$('.listing:first',listings).outerWidth(true);listings_width=$('.listing',listings).length*(listing_width);if(listings_width>live_width){listings.width(listings_width);$('.listings_right',live_widget).click(function(){if(Math.abs(listings.position().left)<(listings_width-live_width)){listings.css('left',listings.position().left-listing_width);}});$('.listings_left',live_widget).click(function(){if(listings.position().left<0){listings.css('left',listings.position().left+listing_width);}});}else{$('.listings_left, .listings_right',live_widget).hide();}}
if($('.channels_widget').length){var channels_widget=$('.channels_widget');var channels=$('.channels',channels_widget);channels_widget_width=$('#information').width()-113;channels_widget.width(channels_widget_width);var channels_width=0;var channel_width=$('.channel:first',channels).outerWidth(true);channels_width=$('.channel',channels).length*(channel_width+4);channels.width(channels_width);$('.channels_right',channels_widget).click(function(){if(Math.abs(channels.position().left)<(channels_width-channels_widget_width)){channels.css('left',channels.position().left-channel_width*3);}});$('.channels_left',channels_widget).click(function(){if(channels.position().left<0){channels.css('left',channels.position().left+channel_width*3);}});}
if(getCookie('hidden_tv_logo')){$('#tv_content .tv_logo, #tv_content .tv_present_description .title').hide();$('#tv_content .hide_logo').html('Показывать заставку').addClass('show_logo');}
$('#tv_content .hide_logo').click(function(){if($(this).hasClass('show_logo')){deleteCookie('hidden_tv_logo','/tv/');$('#tv_content .tv_logo, #tv_content .tv_present_description .title').slideDown('slow');$('#tv_content .hide_logo').html('Больше не показывать заставку').removeClass('show_logo');}else{setCookie('hidden_tv_logo','1',666,'/tv/');$('#tv_content .tv_logo, #tv_content .tv_present_description .title').slideUp('slow');$('#tv_content .hide_logo').html('Показывать заставку').addClass('show_logo');}});$('#tv_content .watch_online').click(function(e){e.preventDefault();var newWin=window.open($(this).attr('href'),"tv_online","statusbar=no,menubar=no,toolbar=no,scrollbars=no,resizable=no,width=660,height=600");newWin.focus();});});function slideObject(object,slideHeight){var div=object.children('.content');var scrollbar=object.children('.scrollbar');var scheduleHeight=div.children('.object_schedule').outerHeight();divHeight=slideHeight;div.animate({height:divHeight},1500);var scrollbarHeight=divHeight+22;scrollbar.animate({height:scrollbarHeight},1500);var scrollbarSliderHeight=scrollbarHeight-109;scrollbar.find('.scrollbar-slider').animate({height:scrollbarSliderHeight},1500);scrollbar.find('.scrollbar-handler-parent').animate({height:scrollbarSliderHeight},1500,"swing",function(){var slider=scrollbar.find('.scrollbar-slider');slider.slider('destroy');if(divHeight>scheduleHeight){scrollbar.hide();div.find('.vertical_scroll_content').css('top',0);}else{slider.find('.scrollbar-handler-parent').html('<div class="scrollbar-handler ui-slider-handle"></div>');makeVerticalScroller(object);}});}
function loadListings(object,type){var tv_content=$('#tv_content');var objectParams=object.attr('id').match(/^object_(\w*?)(\d*)$/i);var object_type=objectParams[1];var object_id=objectParams[2];var table=object.find('.object_schedule_table');var starttime=table.attr('first_listing');var endtime=table.attr('last_listing');switch(type){case'append':starttime=endtime;endtime=0;break;case'prepend':endtime=starttime;starttime=0;break;default:starttime=endtime;endtime=0;break;}
$.ajax({data:{starttime:starttime,endtime:endtime},url:'/tv/load/'+object_type+'/'+object_id,beforeSend:function(){var loading='<div style="text-align: center;" id="loading'+object_type+object_id+'"><img src="http://static.weburg.ru/img/js//thickbox/thickbox-ico-loading.gif" /></div>';switch(type){case'append':table.after(loading);break;case'prepend':table.before(loading);break;default:table.after(loading);break;}},success:function(data,textStatus){object.find('#loading'+object_type+object_id).remove();if(data&&!data.match(/^error/)){var new_listings=$(data);switch(type){case'append':new_listings.appendTo(table);break;case'prepend':new_listings.prependTo(table);break;default:new_listings.appendTo(table);break;}
$("#sortable",tv_content).sortable('refresh');new_listings.find('.listing .listing_name').click(function(){var listing_id=$(this).attr('id').match(/^listing_(\d+)$/i)[1];show_info(listing_id);});}
slideObject(object,492);},error:function(){object.find('#loading'+object_type+object_id).remove();alertDialog(320,170,'Не удалось получить программу');}});}
function show_info(listing_id){var tv_content=$('#tv_content');var show_info_block=$('#show_info');$.ajax({url:'/tv/listings/'+listing_id+'/show_info',beforeSend:function(){show_info_block.children('.show').html('<div style="text-align: center; "><img src="http://static.weburg.ru/img/js//thickbox/thickbox-ico-loading.gif" /></div>');var newTop=Math.max((window.innerHeight-show_info_block.height())/2,0);var newLeft=Math.max((window.innerWidth-show_info_block.width())/2,0);show_info_block.css('top',newTop+window.scrollY);show_info_block.css('left',newLeft);show_info_block.show();},success:function(data,textStatus){show_info_block.children('.show').html('');if(data){show_info_block.children('.show').append(data);var newTop=Math.max((window.innerHeight-show_info_block.height())/2,0);var newLeft=Math.max((window.innerWidth-show_info_block.width())/2,0);show_info_block.css('top',newTop+window.scrollY);show_info_block.css('left',newLeft);}},error:function(){show_info_block.children('.show').html('');}});}
$(window).load(function(){if(document.location.hash.match(/wegg/)){window.setInterval("$('#tv_content .tv_logo, #tv_content .tv_present_description .title').slideUp('slow');",3000);window.setInterval("$('#tv_content .tv_logo, #tv_content .tv_present_description .title').slideDown('slow');",4100);}
if($('#tv_content .tv_logo:visible').length){document.location.hash='content';if(!getCookie('hidden_tv_logo')){window.setTimeout("$('#tv_content .tv_logo, #tv_content .tv_present_description .title').slideUp('slow');",1500);}}});
/* site/socialization_panel.js */
$(function(){var width=620;var height=450;var left=(screen.width-width)/2;var top=(screen.height-height)/3;var url=this._base_domain+'share.php';var popupParams='scrollbars=1, resizable=1, menubar=0, left='+left+', top='+top+', width='+width+', height='+height+', toolbar=0, status=0';$(".socnet_url").click(function(){window.open($(this).attr('href'),'Weburg.ru | '+$(this).attr('title'),popupParams);return false;});});
