﻿(function($) {
	$.fn.astdNews = function(options){
	  	  var  
            defaults = {   
            take: 5,   
            categories: 'News',
            maxLength: 45
            },   
          settings = $.extend({}, defaults, options);   
          
          
            this.each(function() {   
                var $this = $(this);  
                $.ajax({  
                     type: "POST",  
                     contentType: "application/json; charset=utf-8", 
                     url: "/ASTD/NewsService.asmx/GetNews",  
                     data: '{ categories: "' + settings.categories + '" , take:' + settings.take + '}',  
                     dataType: "json",  
                     success: function(msg) {  
                                    var c = eval(msg);  
                                    for (var i in c) { 
                                    var title = c[i][0].length > settings.maxLength ? c[i][0].substring(0,settings.maxLength) + '...' : c[i][0];
                                    $('<li><a href="' + c[i][1] + '" target="_blank" title="' + c[i][0] + '">' + title + '</a></li>').appendTo($this);
                                     }
                              }
                });   
            });
            return this;   
        }  
})(jQuery);



