﻿jQuery.fn.viewMore = function(options)
{
    var settings = 
    {
        linkText: 'Read more',
        linkTextExt: 'Show less'
    };
    
    if (options)
    {
        jQuery.extend(settings, options);
    }
    
    if ($(this).children("br").length >= 2)
    {
         var fullText = $(this).html();
         var firstLocation=0;
         if(fullText.indexOf("<BR")==-1)
         {
            firstLocation=fullText.indexOf("<br")
         }
         else
         {
             firstLocation=fullText.indexOf("<BR");
         }
         
        // var secondLocation=fullText.indexOf(">",firstLocation);
       
         //var hiddenText = fullText.substring(0,firstLocation+(secondLocation-firstLocation));
         var hiddenText = fullText.substring(firstLocation);
          $(this).html(fullText.replace(hiddenText,'<div class="hiddenTags" style="display:none;">'+hiddenText+'</div>'))
          
         $(this).append('<span class="quotes_close">&nbsp;</span><br /><a href="javascript:;" class="read_more">' + settings.linkText + '</a>');
         
        $('a.read_more').click(function()
        {
            if ($('.hiddenTags').css('display') == 'none')
            {
                 $('.hiddenTags').slideDown();
                 $('a.read_more').text(settings.linkTextExt);
            }
            else
            {
                $('.hiddenTags').slideUp();
                $('a.read_more').text(settings.linkText);
            }
        });
    }
}
