(function($){
	$(document).ready(function (){
		
	});
	
	//  Extending jQuery
    $.fn.extend({
		/*!
         *  Loads element with blockUI
         *  While loading shows loading message
         */
        indexNews: function(data){
			var sel = 0;
			var _this = this;
			
			//	Insertin span element
			$(_this).html('<span></span>');
			var span= $(_this).find('span');
			span.css('cursor', 'pointer');
			
			//	Selecting first one
			$(span).html(data[sel].title).truncate(100);
			sel++;

			//	Binding index news
			$(this).everyTime(10000, 'indexNews', function(i) {
				if (!empty(data[sel])){
					$(span).html(data[sel].title).truncate(100);
				}
				
				sel++;
				if (empty(data[sel])){
					sel = 0;
				}
			});
			
			//	Click event
			span.click(function(){
				var msg = '';
				
				$.each(data, function(i, item){
					msg = msg + '<p>' + item.title + '</p><br /><br />';
				});
				
				$.blockUI({
					message: '<table><tr><td class="ar p8"><img id="closeBlockUI" src="/img/b-close.gif" alt="" title="" style="cursor:pointer"/></td></tr><tr><td style="text-align: center; vertical-align:middle; height: 300px">' +  msg + '</td></tr></table>',
					css: {
					//	backgroundColor: '#fff',
						background: '#DEDBD3',
						cursor: 'default',
						border: 0,
						width: '300px',
						height: '320px',
						top: '15%',
						left: '38%',
						color: '#968f7d'
					},
					overlayCSS:{
						cursor: 'default',
						opacity: 0.1
					},
				});
			//	$('.blockOverlay, .blockMsg').unbind().click($.unblockUI);
				$('#closeBlockUI').unbind().click($.unblockUI);
			});
        }
	});
})(jQuery);
