﻿jQuery.noConflict();
jQuery(function() {

   //accordion functions
   // if (jQuery("#accordion .accordion-trigger").length > 0) {
    var accordion_block = false;
        jQuery("#accordion .accordion-trigger").click(function() {
            if(!accordion_block)
            {
                close_accordion(jQuery(this));
            }
            return false;
        });
   // }
    function close_accordion(target) {
        if (!jQuery(target).parent().hasClass('accordion-slide-active')) {
            accordion_block = true;
            jQuery("#accordion .accordion-trigger").css("cursor", "default");
            jQuery('.accordion-slide-active').animate(
                                { width: '36px' }
                                , 750
                                , 'swing'
                                , function() {
                                    jQuery(this).toggleClass('accordion-slide-active');
                                }
                        );
            open_accordion(target);
        }
    }
    function open_accordion(newTarget) {
        jQuery(newTarget).parent().animate(
                        { width: '798px' }
                        , 790
                        , 'swing'
                        , function() {
                            jQuery(this).toggleClass('accordion-slide-active');
                jQuery("#accordion .accordion-trigger").css("cursor", "pointer");
                accordion_block = false;
                        }
                );
    }
	
	
    /*Анимация видеогайда*/
    jQuery('#videogaidclose').click(function() {
    
    if (jQuery('#accordionWrap').is(':hidden')) {
        
            jQuery('#accordionWrap').slideDown('slow', function() {
            if (jQuery('#onairex').is(':hidden')) { jQuery('#header').removeClass('headerbotshort').addClass('headerbot'); }
            else { jQuery('#header').removeClass('headerbot').addClass('headercen'); }    
            });
            jQuery('#videogaidclose').attr('src', '/images/design/close-guide.png');
            jQuery.ajax({type: "POST",url: "/videogaid.php",data: {state: '1'}});
            
        }
        else {
            
            jQuery('#accordionWrap').slideUp('slow', function() {
            
            });
            jQuery('#videogaidclose').attr('src', '/images/design/open-guide.png');
            if (jQuery('#onairex').is(':hidden')) { jQuery('#header').removeClass('headerbot').addClass('headerbotshort'); }
            else { jQuery('#header').removeClass('headercen').addClass('headerbot'); }

            jQuery.ajax({type: "POST",url: "/videogaid.php",data: {state: '0'}});
            
        }
    });

    /*Меню тест*/
    
    
    
    /*Анимация прямого эфира*/ 
    jQuery('#onairclose').click(function() { 
     
    if (jQuery('#onairex').is(':hidden')) { 
            jQuery.ajax({type: "POST",url: "/onair.php",data: {user: '1'}});
            jQuery('#onairex').slideDown('slow', function() { 
            if (jQuery('#accordionWrap').is(':hidden')) { jQuery('#header').removeClass('headerbotshort').addClass('headerbot'); } 
            else { jQuery('#header').removeClass('headerbot').addClass('headercen'); } 
        }); 
        jQuery('#onairclose').attr('src', '/images/design/close-onair.png'); 
             
        } 
        else { 
            jQuery.ajax({type: "POST",url: "/onair.php",data: {user: '0'}});
            jQuery('#onairex').slideUp('slow', function() { 

        }); 
        jQuery('#onairclose').attr('src', '/images/design/open-onair.png'); 
            if (jQuery('#accordionWrap').is(':hidden')) { jQuery('#header').removeClass('headerbot').addClass('headerbotshort'); } 
            else { jQuery('#header').removeClass('headercen').addClass('headerbot'); } 
        } 
    });


    jQuery('#onairon').click(function() {
	jQuery('#onairoff').removeClass('active');
	jQuery('#onairon').css("cursor", "default"); jQuery('#onairoff').css('cursor', 'pointer');
	jQuery('#onairon').addClass('active');
        jQuery.ajax({type: "POST",url: "/onair.php",data: {onair: '1'}});
    });
    jQuery('#onairoff').click(function() {
	jQuery('#onairon').removeClass('active');
	jQuery('#onairoff').css('cursor', 'default'); jQuery('#onairon').css('cursor', 'pointer');
	jQuery('#onairoff').addClass('active');	
        jQuery.ajax({type: "POST",url: "/onair.php",data: {onair: '0'}});
    });

/*форма вопроса*/
    jQuery('#ask_question').click(function() {
	jQuery("#ask_question").css("display", "none");
	jQuery('#ask_div').slideDown('slow', function() {});	 
    });
    jQuery('#ask_question_close').click(function() {
	jQuery('#ask_div').slideUp('slow', function() {});
	jQuery("#ask_question").css("display", "block");	 
    });

    function cptRefresh() { 
	var countOfexec = 0;
	var code = jQuery("#sid").val();
	return function() { 
          if(countOfexec < 5) { 
           var timestamp = new Date(); 
           jQuery('#captcha').attr("src", "/bitrix/tools/captcha.php?captcha_sid="+code+"&timestamp="+timestamp.getTime()); 
          } else { 
           jQuery.get("/recap.php", function(data) { 
              jQuery("#sid").val(data); 
              jQuery('#captcha').attr("src", "/bitrix/tools/captcha.php?captcha_sid="+data); 
              code = data;
           }); 
           countOfexec = 0;
          } 
          return ++countOfexec; 
	};
    } 
    var refresh = cptRefresh();
    jQuery('#recap').click(refresh);

/*вкладки в редактировании ЛК*/

   jQuery('#bx_sonet_subtitle_PERSONAL').click(function() {
	jQuery('#bx_sonet_fieldset_PERSONAL').slideDown('slow', function() {});
	jQuery('#bx_sonet_subtitle_PERSONAL').removeClass('subtitle').addClass('subtitleor');
	if (!jQuery('#bx_sonet_fieldset_CONTACT').is(':hidden')) {
		jQuery('#bx_sonet_subtitle_CONTACT').removeClass('subtitleor').addClass('subtitle');
		jQuery('#bx_sonet_fieldset_CONTACT').hide();
	}
	if (!jQuery('#bx_sonet_fieldset_AUTH').is(':hidden')) {
		jQuery('#bx_sonet_subtitle_AUTH').removeClass('subtitleor').addClass('subtitle');
		jQuery('#bx_sonet_fieldset_AUTH').hide();
	}
   });

   jQuery('#bx_sonet_subtitle_CONTACT').click(function() {
	jQuery('#bx_sonet_fieldset_CONTACT').slideDown('slow', function() {});
	jQuery('#bx_sonet_subtitle_CONTACT').removeClass('subtitle').addClass('subtitleor');
	if (!jQuery('#bx_sonet_fieldset_PERSONAL').is(':hidden')) {
		jQuery('#bx_sonet_subtitle_PERSONAL').removeClass('subtitleor').addClass('subtitle');
		jQuery('#bx_sonet_fieldset_PERSONAL').hide();
	}
	if (!jQuery('#bx_sonet_fieldset_AUTH').is(':hidden')) {
		jQuery('#bx_sonet_subtitle_AUTH').removeClass('subtitleor').addClass('subtitle');
		jQuery('#bx_sonet_fieldset_AUTH').hide();
	}
   });

   jQuery('#bx_sonet_subtitle_AUTH').click(function() {
	jQuery('#bx_sonet_fieldset_AUTH').slideDown('slow', function() {});
	jQuery('#bx_sonet_subtitle_AUTH').removeClass('subtitle').addClass('subtitleor');
	if (!jQuery('#bx_sonet_fieldset_CONTACT').is(':hidden')) {
		jQuery('#bx_sonet_subtitle_CONTACT').removeClass('subtitleor').addClass('subtitle');
		jQuery('#bx_sonet_fieldset_CONTACT').hide();
	}
	if (!jQuery('#bx_sonet_fieldset_PERSONAL').is(':hidden')) {
		jQuery('#bx_sonet_subtitle_PERSONAL').removeClass('subtitleor').addClass('subtitle');
		jQuery('#bx_sonet_fieldset_PERSONAL').hide();
	}
   });
}); 

/*rate menu*/
jQuery(document).ready(function(){
    jQuery("ul.subnav").parent().append("<span id='switch_span'></span>");
    jQuery("ul.topnav li span").click(function() {
        jQuery(this).parent().find("ul.subnav").slideDown('fast').show();
	jQuery('#switch_span').addClass("switch_act");
        jQuery(this).parent().hover(function() {
        }, function(){
            jQuery(this).parent().find("ul.subnav").slideUp('slow'); jQuery('#switch_span').removeClass("switch_act");
        }); jQuery('#last_corner').corner("bottom");
        }).hover(function() {
            jQuery(this).addClass("subhover"); jQuery('#switch_span').addClass("switch_act");
        }, function(){
            jQuery(this).removeClass("subhover");
	if (jQuery(this).parent().find("ul.subnav").isHidden()) jQuery('#switch_span').removeClass("switch_act");
    });
});  
