﻿$(document).ready(function(){

    $('.TalkBack h6').click(function(){
       $(this).parent().parent().toggleClass('active').find('.commentBody').slideToggle(200);

    });
      $('.TalkBack .hd a.ShowAllComments').click(function(){
       $('.TalkBack li').addClass('active').find('.commentBody').show();
       $('.TalkBack .hd a.HideAllComments').css("display","block");
       $(this).css("display","none");
    });
        
    $('.TalkBack .hd a.HideAllComments').click(function(){
       $('.TalkBack li').removeClass('active').find('.commentBody').hide();
       $(this).css("display","none");
       $('.TalkBack .hd a.ShowAllComments').css("display","block");
       
    });
    $('.TalkBack .hd a').mouseover(function (){
      $(this ).addClass('active1');
    }).mouseout(function (){
        $(this ).removeClass('active1');
    });
      
     //התמונות המקושרות
     $('.image_box').each(function() {
         var image = $(this).find('img');
         //הוספת הטקסט האלטרטיבי תחת התמונה
     
         var link = $(this).find('a.link_image');
         if(link && isUrl(image.attr('alt')))
         {
            var url = GetUrl(image.attr('alt'));
            $(link).attr('href',url).html(image.attr('alt').replace(url,""));
            image.attr("alt",image.attr('alt').replace(url,""));
         }
         else
         {
            $(link).html(image.attr('alt'));
         }
         
       
      });
      
      //
      $('.bottom_related .related_box').each(function(i){
        if(i==0) $(this).addClass('first');
        $(this).click(function(){
            location.href=$(this).find("a").attr("href");
        });
      });
      //הוספת כתובת URL לטקסט
      $('.commentBody').each(function(){$(this).html(string_create_urls($(this).html()))});

});



//function string_create_urls(input)
//{
//     return input.replace(/(ftp|http|https|file):\/\/[\S]+(\b|$)/gim,'<a href="$&">$&</a>').replace(/([^\/])(www[\S]+(\b|$))/gim,'$1<a href="http://$2" class="my_link" target="_blank">$2</a>');
//} 
function string_create_urls(input)
{
  return input.replace(/<br>/gim, '\n').replace(/(ftp|http|https|file):\/\/[\S]+(\b|$)/gim,'<a href="$&" class="my_link" target="_blank">$&</a>').replace(/([^\/])(www[\S]+(\b|$))/gim,'$1<a href="http://$2" class="my_link" target="_blank">$2</a>').replace(/\n/gim, '<br>');
}
