PageSourceSearch

https://mcallen.net/Sitefinity/WebsiteTemplates/McAllen/App_Themes/McAllen/js/swift-box.js

js mcallen.net collected 2026-10-02 04:15:00 UTC 129,521 bytes, 3,436 lines download raw bytes

1/* ------------------------------------------------------------------------
2	* Swift Box - jQuery news slider and viewer
3	*
4	* @version: 	1.451
5	* @requires:	jQuery v1.5 or later (v1.7 to use lightbox)
6	* @author:		Luca Montanari aka LCweb (https://lcweb.it)
7------------------------------------------------------------------------- */
8
9(function ($) {
10	var lc_SwiftBox = function(element, lcnb_settings) {
11		
12		var settings = $.extend({
13			src: [], 				// news sources - array of objects
14			theme: 'light',			// swiftbox theme to use - CSS file name
15			layout: 'horizontal', 	// news layout - horizontal/vertical
16			
17			height: 300,			// box height 
18			width: '100%',			// box width - percentage - integer number
19			min_news_h: 100,		// minimum news height for vertical layout - integer number
20			min_news_w: 150,		// minimum news width for horizontal layout - integer number
21			min_horiz_w: 400,		// minimum width of the horizontal layout for responsive websites - integer number
22	
23			horiz_img_h: false,		// image height for horizontal layout, false to use the CSS one - integer number
24			vert_img_w: false,		// image width for vertical layout, false to use the CSS one - integer number
25			
26			read_more_txt: '..',	// text to put at the end of shortened news description
27			boxed_news: false,		// display each news into a separated box
28			horiz_img_mode: false,	// full-height image and no description in horizontal layout (only if there's an image) - bool 
29			buttons_position: 'bottom', // link and socials position - bottom, top, side (only for vertical and boxed layout) 
30			btn_over_img: false,	// if the news image exists, puts side buttons over it - bool
31			
32			max_news: 6, 			// maximum news number to fetch - integer
33			news_per_time: 3, 		// news visible in the box - integer
34			cache_news: false,		// if use the AJAX caching option - bool
35			social_share: true,		// shows the social share buttons - bool 
36			hide_elements: '',		// list of elements to hide - date, title, image, link, btn_bar
37			show_src_logo: false,	// Show the news source's logo in the box - bool (only for vertical layout)
38			
39			script_basepath: false, // basepath to the plugin folder
40			touchswipe: true,		// enable the touchswipe support for mobile devices - bool
41			lightbox: true,			// enable the lightbox for big images and youtube videos
42
43			title_behavior: 'expand',	// set title behavior on click - none, expand, link
44			img_behavior: 'lightbox', 	// set image behavior on click - none, expand, link, lightbox
45			
46			date_format: "d mmmm yyyy",	// date format shown - SS, MM, H, HH, HHH, d, dd, ddd, dddd, m, mm, mmm, mmmm, yy, yyyy
47			elapsed_time: false,	// shows the elapsed time instead of the news date - bool
48			
49			read_more_btn: false,	// replace date box with a read more button - bool
50			read_more_btn_txt: 'Read more', // text displayed in the read more button
51			
52			nav_arrows: false,		// shows the navigation arrows and their position - false / side / top_l / top_c / top_r / bottom_l / bottom_c / bottom_r 
53			autoplay: false,		// start the slideshow - bool
54			animation_time: 700, 	// animation timing in millisecods / 1000 = 1sec
55			slideshow_time: 6000, 	// interval time of the slideshow in milliseconds / 1000 = 1sec	
56			carousel: false,		// use the infinite carousel mode - bool
57			slide_all: false,		// slide all visible elements per time (only in slideshow) - bool
58			pause_on_hover: true,	// pause and restart the autoplay on box hover - bool
59			
60			expandable_news: true,	// add the button to expand news and see full contents - bool
61			scroll_exp_elem: true,	// keep image and close button always visible on high expanded news - bool
62			exp_main_img_pos: 'inside', // set news main image position in expanded mode - inside, side, hidden
63			manage_exp_images: true,	// manage news images to become sizable and add lightbox support - bool 
64			exp_img_w: '1_2',		// images container width for expanded layout - 1_1, 1_2, 1_3, 1_4  
65			exp_img_h: 225,			// images container width for expanded layout in pixels - integer / auto
66			autop_after_exp: false, // resume autoplay after expanded news closing - bool 
67			
68			// date strings - for internationalization
69			short_d_names: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
70			full_d_names : ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
71			short_m_names: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
72			full_m_names : ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
73			elapsed_names: ["ago", "seconds", "minute", "minutes", "hour", "hours", "day", "days", "week", "weeks", "month", "months"]
74				 
75		}, lcnb_settings);
76
77	
78		// Global variables accessible only by the plugin
79		var vars = { 
80			lcnb_news_array : [],
81			lcnb_ordered_news : [],
82			lcnb_done_fetches : 0,
83			lcnb_news_number : 0,
84			lcnb_inline_news_count : 0,
85			lcnb_orig_texts: [],
86			lcnb_excerpts: [],
87			
88			lcnb_news_w : 0,
89			lcnb_news_h : 0,
90			lcnb_news_to_show : 0,
91			lcnb_show_offset : 0,
92			
93			lcnb_is_shown : false,
94			lcnb_is_playing : false,
95			lcnb_is_moving : false,
96			lcnb_is_waiting_for_anim : false,
97			lcnb_paused_on_h : false,
98			lcnb_is_expanded : false,
99			lcnb_lightbox_ready : false,
100			lcnb_carousel_obj : false,
101			lcnb_resizing_timeout : false,
102			lcnb_event_type : 'click',
103			lcnb_wrap_width : 0,
104			lcnb_css3_browser : false
105		};	
106		
107		
108		// .data() system to avoid issues on multi instances
109		var $lcnb_wrap_obj = $(element);
110		$lcnb_wrap_obj.data('lcnb_vars', vars);
111		$lcnb_wrap_obj.data('lcnb_settings', settings);		
112			
113		/////////////////////////////////////////////////////////////////	
114
115		// parse inline news
116		var parse_inline_news = function() {
117			if( $lcnb_wrap_obj.find('.nb_news_wrap').length) {
118	
119				$lcnb_wrap_obj.find('.nb_news_wrap').each(function() {
120					var $wrap = $(this);
121					var img_max_w = parseInt( $(this).attr('img_max_w') );
122					var img_max_h = parseInt( $(this).attr('img_max_h') );
123					var link_target = (typeof($(this).attr('link_target')) != 'undefined') ? $(this).attr('link_target') : false; 
124					var strip_tags = (typeof($(this).attr('strip_tags')) != 'undefined') ? $(this).attr('strip_tags') : false; 
125					var remove_tags = (typeof($(this).attr('remove_tags')) != 'undefined') ? $(this).attr('remove_tags') : false; 
126					
127					$(this).find('article').each(function(i, v) {
128                    	
129						// img size checker
130						if(img_max_w && img_max_h) {
131							$(this).find('section img').each(function() {
132								var src = (typeof( $(this).attr('lazy-src') ) != 'undefined') ? $(this).attr('lazy-src') : $(this).attr('src'); 
133								var new_url = lcnb_script_basepath + 'php_assets/img_size_check.php?src='+ encodeURIComponent(src) +'&max_w='+ img_max_w +'&max_h='+ img_max_h;
134								$(this).attr('src', new_url);
135							});
136						}
137							
138						var date = $(this).attr('datetime');
139						var title = $(this).find('header').text();
140						var txt = $(this).find('section').lcnb_unselfclose_iframes().html();
141						var exc = ($(this).children('blockquote').length) ? $(this).children('blockquote').html() : '';
142						var link = $(this).find('.lcnb_inline_link').attr('href'); /* delete it */ $(this).find('.lcnb_inline_link').remove();
143						var video = $(this).find('.lcnb_video').attr('src');
144						
145						// safe featured image check
146						$main_img = ($(this).find('img.lcnb_main_img').length) ? $(this).find('img.lcnb_main_img') : $(this).children('img');
147						
148						// lazy img loading
149						var main_img_src = (typeof( $main_img.attr('lazy-src')) != 'undefined') ? $main_img.attr('lazy-src') : $main_img.attr('src');
150						var img = ($main_img.length) ? img_size_check_url(main_img_src, img_max_w, img_max_h) : '';
151						
152						// if want to strip or remove something
153						if(strip_tags || remove_tags) {
154							var txt_data = man_feed_descr(txt, false, false, strip_tags, remove_tags);
155							txt = txt_data.txt;	
156						}
157						
158					    if( typeof(date) != 'undefined' && typeof(txt) != 'undefined' && $.trim(txt) != '' ) {
159							
160							var d = new Date(date);
161							var news_obj = {
162								type	: 'inline', 
163								time	: d.getTime(),
164								date 	: date,
165								title	: title,
166								txt		: txt,
167								excerpt : exc,
168								link	: link,
169								s_link	: link,
170								img		: img,
171								video	: video,
172								link_target	: link_target,
173								exp_img_pos	: (typeof($wrap.attr('exp_img_pos')) != 'undefined') ? $wrap.attr('exp_img_pos') : false,
174								exp_img_w	: (typeof($wrap.attr('exp_img_w')) != 'undefined') ? $wrap.attr('exp_img_w') : false,
175								exp_img_h	: (typeof($wrap.attr('exp_img_h')) != 'undefined') ? $wrap.attr('exp_img_h') : false
176							};
177							
178							// exclude chosen parameters
179							if(settings.hide_elements.indexOf('title') != -1) {news_obj.title = '';}
180							if(settings.hide_elements.indexOf('link') != -1) {news_obj.link = '';}
181							if(settings.hide_elements.indexOf('image') != -1) {news_obj.img = '';} 
182
183							vars.lcnb_news_array.push(news_obj);
184							vars.lcnb_inline_news_count = vars.lcnb_inline_news_count + 1;
185							
186							if(i == (settings.max_news - 1)) {return false;}
187						}
188                    });
189				});  
190			}	
191		};
192			
193			
194		// handle the sources
195		var handle_sources = function() {
196			// if no external sources - initialize with the local ones
197			if(settings.src.length == 0) {news_date_sort($lcnb_wrap_obj);}
198
199			$.each(settings.src, function(index, v) {
200				var src_obj = this;
201				var params = '';
202				var to_call = '';
203				
204				// find the url to call to get the data
205				switch(this.type) {
206					case 'facebook' : 
207						to_call = 'https://graph.facebook.com/v2.7/'+ src_obj.id +'/posts?fields=name,message,picture,description,created_time,link,attachments{media},type,object_id&limit='+ settings.max_news +'&access_token=477200255765895|W7ApsUH35SJ-t4TupZVqKAIKDLY';						
208						break;
209						
210					case 'twitter' : 
211						var rts = (typeof(src_obj.include_retweet) == 'undefined' || src_obj.include_retweet === true) ? 'true' : 'false';
212						to_call = lcnb_script_basepath + 'php_assets/twitter_oauth.php';
213						params = { url : 'statuses/user_timeline.json?screen_name='+ src_obj.id +'&exclude_replies=true&tweet_mode=extended&include_rts='+ rts +'&count='+ (settings.max_news + 2)};
214						break;	
215						
216					case 'google' : 
217						// get the user ID
218						if(src_obj.id.indexOf('/') > -1) {
219							var pos = src_obj.id.indexOf('?');
220							if(pos > -1) {
221								src_obj.id = src_obj.id.substring(0, pos);
222							}
223							if(src_obj.id.indexOf('/posts') === -1) { // august 2017 - profiles don't have /posts - force it to be retrocompatible
224								src_obj.id += '/posts'; 	
225							}
226							var arr = src_obj.id.split('/');
227							var clean_id = arr[ (arr.length - 2) ];
228						}
229						else {var clean_id = src_obj.id;}
230						
231						to_call = 'https://www.googleapis.com/plus/v1/people/'+ clean_id +'/activities/public?key=AIzaSyCalvBYOVexkTeFT5aIELfgpTVlyGCIvvA';
232						params = { 
233							maxResults: settings.max_news,
234							prettyprint: false,
235							fields: 'items(actor(image), annotation, object(content, attachments(content,fullImage,image,thumbnails,objectType)), published, url, verb)'
236						};
237						break;	
238						
239					case 'youtube' : 
240						var yt_max_res = (settings.max_news > 50) ? 50 : settings.max_news;
241
242						// API v3 - get channel ID
243						$.ajax({
244							url: 'https://www.googleapis.com/youtube/v3/channels?part=snippet&forUsername='+ src_obj.id +'&maxResults=1&key=AIzaSyCalvBYOVexkTeFT5aIELfgpTVlyGCIvvA',
245							dataType: 'jsonp',
246							success: function(resp) {
247								
248								// user is found
249								if(resp.items.length) {
250									var ch_id = (resp.items.length == 0) ? '' : resp.items[0].id;
251
252									to_call = 'https://www.googleapis.com/youtube/v3/activities?part=snippet&channelId='+ ch_id +'&maxResults='+ yt_max_res +'&fields=items(contentDetails%2Csnippet)&key=AIzaSyCalvBYOVexkTeFT5aIELfgpTVlyGCIvvA';
253								}
254								
255								// is a channel
256								else {
257									to_call = 'https://www.googleapis.com/youtube/v3/search?channelId='+ encodeURIComponent(src_obj.id) +'&key=AIzaSyCalvBYOVexkTeFT5aIELfgpTVlyGCIvvA&part=snippet&order=date&maxResults='+ yt_max_res;
258								}
259								
260								var is_yt_chann = (resp.items.length) ? false : true;
261								fetch_news(index, 'youtube', to_call, params, src_obj, {is_yt_channel : is_yt_chann});
262							}
263						});
264						break;
265						
266					case 'pinterest' : 
267						var raw_url = src_obj.url;
268						if( raw_url.substr(raw_url.length - 1) == '/' ) {raw_url = raw_url.substr(0, (raw_url.length - 1));}
269					
270						to_call = raw_url.toLowerCase().replace('http://', 'https://') + '.rss';
271						break;	
272						
273					case 'soundcloud' : 
274						var raw_url = src_obj.url;
275						if( raw_url.substr(raw_url.length - 1) == '/' ) {raw_url = raw_url.slice(0, -1);}
276						
277						var arr = raw_url.split('/');
278						var username = arr[arr.length-1];
279						
280						// NEW API - get user ID
281						$.ajax({
282							url: 'https://api.soundcloud.com/resolve?url='+ encodeURIComponent('https://soundcloud.com/'+username) +'&client_id=4bc0297066dd5e45babd36ce10075160',
283							dataType: 'jsonp',
284							success: function(resp) {
285								
286								if( typeof(resp) == 'object' && resp.id) {
287									to_call = 'https://api.soundcloud.com/users/'+ resp.id +'/tracks?client_id=4bc0297066dd5e45babd36ce10075160';
288									fetch_news(index, 'soundcloud', to_call, params, src_obj);
289								}
290								else {
291									console.log('swiftbox - failed to get soudcloud user ID for '+username);
292								}
293							}
294						});
295						
296						
297						to_call = 'https://api.soundcloud.com/users/'+ username +'/tracks?client_id=4bc0297066dd5e45babd36ce10075160';
298						break;			
299					
300					case 'tumblr' : 
301						var raw_url = src_obj.url;
302						var url_arr = raw_url.toLowerCase().replace('http://', '').replace('https://', '').split('/');
303						var blog_id = url_arr[0];
304
305						to_call = 'https://api.tumblr.com/v2/blog/'+blog_id+'/posts?api_key=pcCK9NCjhSoA0Yv9TGoXI0vH6YzLRiqKPul9iC6OQ6Pr69l2MV&filter=text&limit='+settings.max_news;
306						break;	
307						
308					default:
309						to_call = src_obj.url;
310						break;		 	
311				}
312				
313				// remote feed - use YQL
314				if(this.type == 'rss' || this.type == 'pinterest') {
315					to_call = 'https://query.yahooapis.com/v1/public/yql?q='+ 
316						encodeURIComponent("SELECT * FROM feed WHERE url = '"+ to_call +"' LIMIT "+ settings.max_news ) +
317						'&format=json&diagnostics=false&callback=';
318				} 
319				
320				if(this.type != 'youtube' && this.type != 'soundcloud') {
321					fetch_news(index, this.type, to_call, params, src_obj); 
322				}
323			});
324		}
325			
326		
327		// fetch news from the sources	
328		var fetch_news = function(index, type, src, params, src_opts, custom_opts) {
329
330			// data to exclude 
331			var exclude = (typeof(settings.hide_elements) == 'undefined') ? '' : settings.hide_elements;
332			if(typeof(src_opts.hide_elements) == 'string') {exclude = exclude + ',' + src_opts.hide_elements.replace('date.', '');}
333			
334			// fixed image
335			var fixed_img = (src_opts.img == undefined) ? false : src_opts.img; 
336			
337			// images max sizes
338			var max_img_size = (typeof(src_opts.max_img_size) == 'object') ? src_opts.max_img_size : false; 
339			
340			// regular expression to link textual URLs
341			var url_exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
342			
343			// fetch
344			var dataType = ( jQuery.inArray(type, ['facebook', 'twitter', 'rss', 'pinterest']) != -1) ? "json" : "jsonp";
345			$.ajax({
346				url: src,
347				data: params,
348				dataType: dataType,
349				cache: settings.cache_news,
350				success: function(resp) {
351					var error = false;
352					
353					switch(type) {
354						case 'facebook' : 
355							if (typeof(resp.error) != 'undefined')  {error = resp.errors.error_message;}
356							else {resp = resp.data;}
357							
358							break;	
359						
360						case 'twitter' : 
361							if(typeof(resp.errors) != 'undefined') {error = resp.errors;}
362							break;	
363						
364						case 'google' :
365							resp = resp.items;
366							if(typeof(resp.error) != 'undefined') {error = resp.error;}
367							break;	
368						
369						case 'youtube': 
370							if (typeof(resp.error) != 'undefined')  {error = resp.error.message;}
371							else {resp = resp.items;}
372							
373							break;
374						
375						case 'soundcloud': 
376							if (typeof(resp.errors) != 'undefined')  {error = resp.errors.error_message;}
377							else {resp = resp;}
378
379							break;
380							
381						case 'tumblr': 
382							if (resp.meta.status == 200)  {resp = resp.response.posts;}
383							else {error = resp.response;}
384
385							break;
386
387						default: // rss and pinterest
388							if (resp.query.count)  {resp = (typeof(resp.query.results.entry) == 'undefined') ? resp.query.results.item : resp.query.results.entry;}
389							else {error = 'no news or invalid URL';}
390							break;		 	
391					}
392					
393					if(!error && typeof(resp) != 'undefined') {
394						$.each(resp, function(i, news) {
395							switch(type) {
396								case 'facebook' : 
397									console.log(news);
398									
399									var fix_time = news.created_time.replace('+0000', '+00:00');
400									
401									var d = new Date(fix_time);
402									var txt = (!news.message) ? news.description : news.message;
403									
404									// fix for elements not having texts
405									if(txt) {
406										var managed_data = man_feed_descr(txt, fixed_img, max_img_size, '', '', true);
407									} else {
408										var managed_data = {txt : '' , img : ''};
409									}
410									
411									// search post image
412									if(!fixed_img) {
413										if((news.type == 'photo' || news.type == 'video' || news.type == 'link') && typeof(news.attachments) != 'undefined') {
414											managed_data.img = news.attachments.data[0].media.image.src;
415										}
416										else if(news.type == 'photo'&& typeof(news.attachments) == 'undefined') {
417											managed_data.img = 'https://graph.facebook.com/'+ news.object_id +'/picture?type=normal&width=9999&height=9999';	
418										}
419										else if((news.type == 'link' || news.type == 'event') && typeof(news.picture) != 'undefined') {
420											managed_data.img = news.picture;	
421										}
422										
423										// check against facebook safe-image small picures
424										if(typeof(managed_data.img) == 'string' && managed_data.img.indexOf('safe_image.php') != -1) {
425											managed_data.img = managed_data.img.replace(/130/g, 1000);
426										}
427									}
428									
429									var news_obj = {
430										time	: d.getTime(),
431										date 	: fix_time,
432										title	: (typeof(news.name) == 'undefined') ? '' : news.name,
433										txt		: managed_data.txt.replace(url_exp, '<a href="$1">$1</a>'),
434										link	: news.link,
435										s_link	: news.link,
436										img		: managed_data.img 
437									};
438									break;
439									
440								case 'twitter' :
441									// IE fix	
442									var fixed_date = normalize_date_str(news.created_at).replace(/^... (...) (..) (........) (...)(..) (....)$/, function(match, month, date, time, tz1, tz2, year) {
443									  return year + "-" + {
444										Jan: "01",
445										Feb: "02",
446										Mar: "03",
447										Apr: "04",
448										May: "05",
449										Jun: "06",
450										Jul: "07",
451										Aug: "08",
452										Sep: "09",
453										Oct: "10",
454										Nov: "11",
455										Dec: "12"
456									  }[month] + "-" + date + "T" + time + tz1 + ":" + tz2;
457									});	
458										
459									var d = new Date(fixed_date);
460									if(max_img_size) {img = img_loading_fix(img, max_img_size.w, max_img_size.h);}
461									
462									// image
463									if(typeof(news.entities.media) != 'undefined' && typeof(news.entities.media[0]) != 'undefined' && news.entities.media[0].type == 'photo' && !fixed_img) {
464										var img = news.entities.media[0].media_url_https;
465									} else {
466										if(fixed_img) {var img = fixed_img;}
467										else {
468											var img = (typeof(src_opts.use_avatar) != 'undefined' && src_opts.use_avatar) ? news.user.profile_image_url : '';	
469										}	
470									}
471									
472									// link 
473									if(typeof(news.entities.urls) != 'undefined' && typeof(news.entities.urls[0]) != 'undefined') {
474										var link = news.entities.urls[0].expanded_url;	
475										var s_link = link;
476									} else {
477										// use tweek direct link - structure https://twitter.com/USERNAME/status/TWEET-ID
478										var link = 'https://twitter.com/' + news.user.screen_name +'/status/'+ news.id_str;	
479										var s_link = '';
480									}
481	
482									var news_obj = {
483										time	: d.getTime(),
484										date 	: fixed_date,
485										title	: '',
486										txt		: news.full_text.replace(url_exp, '<a href="$1">$1</a>'),
487										link	: link,
488										s_link  : s_link,
489										img		: img.replace('_normal', ''),
490										user_id	: settings.src[index].id,
491										tweet_id: news.id_str
492									}; 
493									break;	
494									
495								case 'google' : 
496									var fixed_date = normalize_date_str(news.published);
497									var d = new Date(fixed_date);
498									var img = (exclude.indexOf('image') != -1) ? '' : get_google_img(news, fixed_img);
499									if(max_img_size) {img = img_loading_fix(img, max_img_size.w, max_img_size.h);}
500									
501									// get text
502									var txt = (news.verb == 'share') ? news.annotation : news.object.content;
503									var news_obj = {
504										time	: d.getTime(),
505										date 	: fixed_date,
506										title	: '',
507										txt		: txt,
508										link	: news.url,
509										s_link	: news.url,
510										img		: img
511									};
512									break;	
513									
514									
515								case 'youtube' : 
516									if(news.snippet.type == 'upload' || custom_opts.is_yt_channel) {
517										var fixed_date = normalize_date_str(news.snippet.publishedAt);
518										var d = new Date(fixed_date);
519										
520										// find biggest image available
521										var video_thumb = (typeof(news.snippet.thumbnails.maxres) != 'undefined') ? news.snippet.thumbnails.maxres.url : news.snippet.thumbnails.high.url;
522										var img = (fixed_img) ? fixed_img : video_thumb;
523										if(max_img_size) {img = img_loading_fix(img, max_img_size.w, max_img_size.h);}
524										
525										// get video ID from thumbnail
526										var thumb_url = video_thumb.replace('/maxresdefault.jpg', '').replace('/hqdefault.jpg', '');
527										var thumb_arr = thumb_url.split('/');
528										var link = 'https://www.youtube.com/watch?v='+ thumb_arr[thumb_arr.length-1];
529										
530										var news_obj = {
531											time	: d.getTime(),
532											date 	: fixed_date,
533											title	: news.snippet.title,
534											txt		: news.snippet.description.replace(/\n/g, '<br/>').replace(url_exp, '<a href="$1">$1</a>'),
535											link	: link,
536											s_link	: link,
537											img		: img
538										};
539									}
540									else {var news_obj = {};}
541									
542									break;
543									
544									
545								case 'pinterest' : 
546									var d = new Date(news.pubDate);
547									var managed_data = man_feed_descr(news.description, fixed_img, max_img_size, '', 'a:first-child', true);
548
549									var news_obj = {
550										time	: d.getTime(),
551										date 	: news.pubDate,
552										title	: '',
553										txt		: managed_data.txt,
554										link	: news.link,
555										s_link	: news.link,
556										img		: managed_data.img.replace('/192x/', '/550x/').replace('/236x/', '/550x/')
557									};
558									break;	
559								
560								case 'soundcloud' : 
561									var d = new Date(news.created_at);
562
563									// iframe URL to embed
564									var embed_url = 'https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/'+ news.id +'&auto_play=true&hide_related=true&visual=true';
565									
566									// image
567									if(news.artwork_url) {var img = news.artwork_url.replace('-large.', '-t500x500.');}
568									else if (news.user.avatar_url) {var img = news.user.avatar_url.replace('-large.', '-t500x500.');}
569									else {var img = '';}
570
571									var news_obj = {
572										time	: d.getTime(),
573										date 	: news.created_at,
574										title	: news.title,
575										txt		: news.description.replace(/\n/g, '<br/>').replace(url_exp, '<a href="$1">$1</a>'),
576										link	: embed_url,
577										s_link	: news.permalink_url,
578										img		: img
579									};
580									break;	
581									
582								case 'tumblr' : 
583									if(news.type != 'photo' && news.type != 'link' && news.type != 'text') {
584										var news_obj = {};	
585									}
586									else {
587										if(news.type == 'photo') {
588											var title = '';
589											var link = news.short_url;
590											
591											var n_data = man_feed_descr( $.trim(news.caption), 'foo', max_img_size, settings.src[index].strip_tags, settings.src[index].remove_tags, true);
592											var descr = n_data.txt;
593											var img = (fixed_img) ? fixed_img : news.photos[0].original_size.url;
594											if(max_img_size) {img = img_loading_fix(img, max_img_size.w, max_img_size.h);}
595										} 
596										else if(news.type == 'link') {
597											var title = news.title;
598											var link = news.url;
599
600											var txt_subj = ($.trim(news.description)) ? $.trim(news.description) : $.trim(news.excerpt);
601											var n_data = man_feed_descr(txt_subj, fixed_img, max_img_size, settings.src[index].strip_tags, settings.src[index].remove_tags, true);
602											var descr = n_data.txt;
603											var img = n_data.img
604											
605											// get link photo
606											if(typeof(news.photos) != 'undefined') {
607												img = news.photos[0].original_size.url;		
608											}
609										}
610										else { // text type
611											var title = news.title;
612											var link = news.short_url;
613											
614											var n_data = man_feed_descr( $.trim(news.body), fixed_img, max_img_size, settings.src[index].strip_tags, settings.src[index].remove_tags, true);
615											var descr = n_data.txt;
616											var img = n_data.img
617										}
618
619										var js_timestamp = news.timestamp * 1000;
620										var news_obj = {
621											time	: js_timestamp,
622											date 	: new Date(js_timestamp),
623											title	: title,
624											txt		: descr,
625											link	: link,
626											s_link	: (news.type == 'link') ? news.short_url : link,
627											img		: img
628										};
629									}
630									break;	
631									
632								default: // rss
633
634									// switch between atom and rss feeds
635									if(typeof(news.pubDate) == 'undefined') { // atom
636										
637										var fixed_date = normalize_date_str(news.updated);
638										var d = new Date(fixed_date);
639										
640										var managed_data = man_feed_descr( $.trim(news.content.content), fixed_img, max_img_size, settings.src[index].strip_tags, settings.src[index].remove_tags, true);
641										
642										// find right link
643										if(typeof(news.link) == 'object') {
644											var true_link = '';
645											
646											if(typeof(news.link.rel) != 'undefined' && news.link.rel == 'alternate') {
647												true_link = news.link.href;
648											}
649										}
650										else if(typeof(news.link) != 'undefined') {
651											var true_link = news.link;
652										}
653										else {
654											var true_link = '';	
655										}
656										
657										// find out title
658										var true_tit = (typeof(news.title) == 'string') ? news.title : news.title.content;
659	
660										var news_obj = {
661											time	: d.getTime(),
662											date 	: fixed_date,
663											title	: true_tit,
664											txt		: managed_data.txt,
665											link	: true_link,
666											s_link	: true_link,
667											img		: (fixed_img) ? fixed_img : managed_data.img
668										};
669									}
670									
671									else {
672										
673										// if an image is specified in mediaGroup - override main one
674										if(!fixed_img) {
675											if(typeof(news.thumbnail) != 'undefined') {
676												fixed_img = news.thumbnail.url;
677												var forced_fixed_img = true;	
678											}
679											else if(typeof(news.enclosure) != 'undefined' && typeof(news.enclosure) == 'object') {
680												fixed_img = news.enclosure.url;
681												var forced_fixed_img = true;
682											}
683											else if(typeof(news.enclosure) != 'undefined' && typeof(news.enclosure[0]) != 'undefined') {
684												fixed_img = news.enclosure[0].url;
685												var forced_fixed_img = true;
686											}
687											else if(typeof(news.content) != 'undefined' && typeof(news.content.medium) != 'undefined' && news.content.medium == 'image') {
688												fixed_img = news.content.url;
689												var forced_fixed_img = true;	
690											}
691											else if(typeof(news.content) != 'undefined' && typeof(news.content.type) != 'undefined' && news.content.type.indexOf('image') !== -1) {
692												fixed_img = news.content.url;
693												var forced_fixed_img = true;	
694											}
695											else if(typeof(news.content) == 'object' && typeof(news.content[0]) != 'undefined' && typeof(news.content[0].url) != 'undefined') {
696												fixed_img = news.content[0].url;
697												var forced_fixed_img = true;	
698											}
699										}
700										
701										var true_txt = (typeof(news.encoded) != 'undefined') ? news.encoded : news.description;
702										
703										var fixed_date = normalize_date_str(news.pubDate);
704										var d = new Date(fixed_date);
705										var managed_data = man_feed_descr( $.trim(true_txt), fixed_img, max_img_size, settings.src[index].strip_tags, settings.src[index].remove_tags, true);
706										
707										var news_obj = {
708											time	: d.getTime(),
709											date 	: fixed_date,
710											title	: news.title,
711											txt		: managed_data.txt,
712											link	: news.link,
713											s_link	: news.link,
714											img		: managed_data.img
715										};
716										
717										if(typeof(forced_fixed_img) != 'undefined') {
718											fixed_img = false;	
719										}
720									}
721									break;		 	
722							}
723							
724							// exclude chosen parameters
725							if(exclude.indexOf('title') != -1 || settings.hide_elements.indexOf('title') != -1) {news_obj.title = '';}
726							if(exclude.indexOf('link') != -1) {news_obj.link = '';}
727							if(exclude.indexOf('image') != -1) {news_obj.img = '';} 
728							
729							// common parameters
730							news_obj.type = type;
731							news_obj.link_target = src_opts.link_target;
732							//news_obj.color = (typeof(color) == 'undefined') ? 'none' : color;
733							news_obj.author = (typeof(src_opts.author) == 'undefined') ? false : src_opts.author
734							
735							// expanded mode images - custom setup
736							var eim = (typeof(src_opts.exp_img_manag) != 'undefined') ? src_opts.exp_img_manag : {};
737							news_obj.exp_img_pos= (typeof(eim.pos) != 'undefined') ? eim.pos : false;
738							news_obj.exp_img_w	= (typeof(eim.w) != 'undefined') ? eim.w : false;
739							news_obj.exp_img_h	= (typeof(eim.h) != 'undefined') ? eim.h : false;
740							
741							// check if page URL needs to be used as sharing link
742							if(typeof(src_opts.self_s_link) != 'undefined' && src_opts.self_s_link) {
743								news_obj.s_link = location.href;
744							}
745							
746							// if has text - add as proper news
747							if(typeof(news_obj.txt) != 'undefined' && news_obj.txt != '') {
748								vars.lcnb_news_array.push(news_obj);
749							}
750
751							// having reached news limit - stop loop
752							if( (vars.lcnb_news_array.length - vars.lcnb_inline_news_count) == (settings.max_news * (vars.lcnb_done_fetches + 1) )) {
753								return false;
754							}
755						});
756					}
757					
758					// once fetches are ended - process the final array
759					vars.lcnb_done_fetches = vars.lcnb_done_fetches + 1;
760					if(vars.lcnb_done_fetches == settings.src.length) {
761						news_date_sort($lcnb_wrap_obj);	
762					}
763				}
764			});
765		}
766		
767		
768		// manage the RSS description to get the clean news and the image
769		var man_feed_descr = function(raw_txt, fix_img, max_img_size, to_strip, to_remove, br_ify) {
770
771			// image management before append - to avoid useless loading
772			if(raw_txt.indexOf('<img') != -1) {
773				if(typeof(to_remove) != 'undefined' && to_remove.indexOf("img") !== -1 && to_remove.indexOf("img:first") === -1 ) {
774					raw_txt = img_loading_fix(raw_txt, max_img_size, true);
775				} else {
776					raw_txt = img_loading_fix(raw_txt, max_img_size);
777				}
778			}
779			
780			// create
781			var $demo = $('<div />');
782			
783			// remove double spaces
784			/*while( raw_txt.indexOf('\n\n') != -1 ) {
785				raw_txt = raw_txt.replace(/\n\n/g, '\n');
786			}*/
787			
788			if(typeof(br_ify) != 'undefined' && br_ify) {raw_txt = raw_txt.replace(/\n/g, '<br/>');}
789			$demo.append('<div id="lcnb_util" style="display: none !important;">'+ raw_txt +'</div>');
790			$('#lcnb_util').lcnb_unselfclose_iframes();
791			
792			if(!fix_img && $demo.find('#lcnb_util img').length) {
793				var main_img = $demo.find('#lcnb_util img').first().attr('fake-src');
794				$demo.find('#lcnb_util img').first().remove();	
795			} else {
796				var main_img = (max_img_size) ? img_loading_fix(fix_img, max_img_size.w, max_img_size.h) : fix_img;
797			}
798
799			// remove unwanted tags
800			if(typeof(to_remove) != 'undefined' && to_remove && $.trim(to_remove).length > 0) { 
801				var rm_blacklist = to_remove.split(',');
802				$.each(rm_blacklist, function(i, v) { 
803					$demo.find('#lcnb_util '+ v).remove();
804				});
805			}
806
807			// strip unwanted tags
808			if(to_strip == 'all') {
809				$demo.find('#lcnb_util *').not('p, br, iframe').each(function() {
810					var content = $(this).contents();
811					$(this).replaceWith(content);
812				});	
813			}
814			else if(typeof(to_strip) != 'undefined' && to_strip && $.trim(to_strip).length > 0) { 
815				var strip_blacklist = to_strip.split(',');
816				$.each(strip_blacklist, function(i, v) { 
817					$demo.find('#lcnb_util '+v).each(function() {
818                        var content = $(this).contents();
819    					$(this).replaceWith(content);
820                    });
821				});	
822			}
823				
824			// clean html and remove empty tags
825			$demo.find('#lcnb_util *').removeAttr('style');
826			$demo.find('*:empty').not('br, img, i, iframe').remove(); 
827			
828			// remove initial <br>, duplicated <br> and <br> after a paragraph
829			for(x=0; x<5; x++) {
830				// if first child is BR - remove it
831				if($demo.find('#lcnb_util *:first').is('br')) {
832					$demo.find('#lcnb_util *:first').remove();	
833				}
834				
835				$demo.find('br').each(function() {
836					/*if( $(this).next().is('br') ) {
837						$(this).next().remove();	
838					}*/
839					if( $(this).prev().is('p')) {
840						$(this).remove();
841					}
842				});
843			}
844			
845			// get final text
846			var clean_txt = $.trim( $demo.find('#lcnb_util').html());
847			return {txt: $.trim(clean_txt), img : main_img};
848		}
849		
850		
851		// get the resized image url
852		var img_loading_fix = function(content, max_img_size, remove_images) {
853			if(!content) {return content;}
854			
855			var img = $.makeArray();
856			var fake = content;
857			
858			// create fake container and encapsulate images to avoid content loss
859			var $fake = $('<div />');
860			$fake.append('<div id="lcnb_fake_util" style="display: none !important;">'+ fake +'</div>');
861			$fake.find('img').wrap('<span></span>');
862			
863			// replace <img tag with fake one
864			var man_fake = $fake.find('#lcnb_fake_util').html();
865			$fake.html('<div id="lcnb_fake_util" style="display: none !important;">'+ man_fake.replace(/<img/g, '<fake-img') +'</div>');
866			
867			// turn fake img into an image with fake source
868			$fake.find('fake-img').each(function() {
869				var src = $(this).attr('src');
870				
871				// check against facebook safe-image small picures
872				if(typeof(src) != 'undefined' && src.indexOf('safe_image.php') != -1) {
873					src = get_url_param(src, 'url');
874				}
875				
876				$('<img fake-src="'+ src +'" />').insertBefore(this);
877				$(this).remove();
878			});
879
880			// if will show images and they needs to be resized
881			if(typeof(remove_images) == 'undefined' && max_img_size) {
882				$fake.find('img').each(function() {
883					var src = $(this).attr('fake-src');
884					var new_url = lcnb_script_basepath + 'php_assets/img_size_check.php?src='+ encodeURIComponent(src) +'&max_w='+ max_img_size.w +'&max_h='+ max_img_size.h;
885					$(this).attr('fake-src', new_url);
886				});
887			}
888
889			return $fake.find('#lcnb_fake_util').html();
890		}
891		
892		
893		// turn self-closed iframes into normal tags - prevent jQuery bug using .html() function
894		$.fn.lcnb_unselfclose_iframes = function() {
895			 this.each(function() {
896				$(this).find('iframe').each(function() {
897					var $subj = $(this);
898					var code = '<iframe ';
899					var attributes = $subj.prop("attributes");
900				
901					$.each(attributes, function() {
902						code += this.name +'="'+ this.value +'" ';
903					});
904					  
905					$subj.replaceWith(code + '></iframe>');
906				});
907			});
908			
909			return this;
910		}
911		
912		
913		// image url to resized one
914		var img_size_check_url = function(url, max_w, max_h) {
915			if(parseInt(max_w) && parseInt(max_h)) {
916				return lcnb_script_basepath + 'php_assets/img_size_check.php?src='+ encodeURIComponent(url) +'&max_w='+ max_w +'&max_h='+ max_h;	
917			}
918			else {return url;}
919		}
920		
921		
922		// sort news by date
923		var news_date_sort = function(subj) {
924			var vars = subj.data('lcnb_vars');
925			
926			if(vars.lcnb_ordered_news.length == settings.max_news || vars.lcnb_news_array.length == 0) {
927				vars.lcnb_news_number = vars.lcnb_ordered_news.length;
928				
929				final_news_management();
930				return true;	
931			}
932			else {
933				var mr = {index: 0, time : 0};
934				
935				$.each(vars.lcnb_news_array, function(i, v) {
936					if(v.time > mr.time) {mr = {index: i, time : v.time};}
937				});
938				
939				vars.lcnb_ordered_news.push( vars.lcnb_news_array[mr.index] );
940				vars.lcnb_news_array.splice(mr.index, 1);
941				news_date_sort(subj);
942			}
943		}
944		
945		
946		// final news sorting and management
947		var final_news_management = function() {
948			
949			// check max news to show value
950			if(settings.news_per_time > vars.lcnb_news_number) {settings.news_per_time = vars.lcnb_news_number;}
951
952			// build
953			$.each(vars.lcnb_ordered_news, function(i, v) {
954
955				//// buttons
956				// social share
957				if(settings.social_share == true) {
958					var socials = social_share_code(v.type, v);
959				} else {var socials = '';}	
960				
961				// link
962				if(typeof(v.link) != 'undefined' && v.link != '') {
963					 var trueLink = (v.type == 'soundcloud') ? v.s_link : v.link;
964					 var link = '<div class="lcnb_link"><a href="'+ trueLink +'" target="_blank" title="check original source"></a></div>';
965				} else {
966					var link = '';
967					if(settings.title_behavior == 'link')	{settings.title_behavior = 'none';}
968					if(settings.img_behavior == 'link') 	{settings.img_behavior = 'none';}
969				}
970
971				// date
972				if(settings.hide_elements.indexOf('date') == -1 ) {
973					var visibility = (settings.read_more_btn) ? 'style="display: none;"' : '';
974					var date = '<div class="lcnb_btn_time" '+visibility+'><time class="lcnb_date" pubdate="pubdate" datetime="'+ v.date +'">'+ date_format(v.date) +'</time></div>';
975				} else {var date = '';}
976				
977				
978				// read more button
979				if(settings.read_more_btn && typeof(v.link) != 'undefined' && v.link != '') {
980					var rm_btn = '<div class="lcnb_btn_time lcnb_rm_btn_wrap"><a class="lcnb_rm_btn" href="'+ trueLink +'">'+ settings.read_more_btn_txt +'</a></div>';
981					link = '';
982				} else {var rm_btn = '';}
983				
984				
985				// expand news button
986				if(settings.expandable_news == true) {
987					var expand = '<div class="lcnb_btn_expand noSwipe" title="expand text"></div>';
988				} else {
989					var expand = '';
990					if(settings.title_behavior == 'expand')	{settings.title_behavior = 'none';}
991					if(settings.img_behavior == 'expand') 	{settings.img_behavior = 'none';}
992				}	
993				
994				
995				//// buttons position
996				var btn_bar = '', top_box = '', btm_box = '';
997				
998				if(settings.hide_elements.indexOf('btn_bar') == -1) {
999					// side
1000					if(settings.buttons_position == 'side' && settings.layout == 'vertical' && settings.boxed_news) {
1001						if(
1002							settings.social_share == true || 
1003							link ||
1004							settings.hide_elements.indexOf('date') == -1
1005						) {
1006							var btn_position = (settings.btn_over_img != true  || typeof(v.img) == 'undefined' || v.img == '') ? 'relative' : 'absolute';
1007							btn_bar = '<div class="lcnb_buttons noSwipe" style="position: '+ btn_position +';">' + expand + link + socials + '</div>';
1008						}
1009					
1010						// date always in bottom position
1011						if(settings.hide_elements.indexOf('date') == -1 || rm_btn) {
1012							btm_box = '<div class="lcnb_btm_bar">' + date  + rm_btn + '</div>';
1013						} 
1014					}
1015					
1016					// top
1017					else if(settings.buttons_position == 'top') {
1018						if(
1019							settings.social_share == true || 
1020							link ||
1021							settings.hide_elements.indexOf('date') == -1 ||
1022							rm_btn
1023						) {
1024							var top_box = '<div class="lcnb_top_bar">' + expand + socials + link + date + rm_btn + '</div>';
1025						}	
1026					}
1027					
1028					// bottom 
1029					else {
1030						if(
1031							settings.social_share == true || 
1032							link ||
1033							settings.hide_elements.indexOf('date') == -1 ||
1034							rm_btn
1035						) {
1036							var btm_box = '<div class="lcnb_btm_bar">' + expand + socials + link + date + rm_btn + '</div>';
1037						}
1038					}
1039				}
1040				
1041				
1042				///////////////////////////
1043				// title
1044				if(v.title == '') {var title = '';}
1045				else {
1046					if(settings.title_behavior == 'link') {
1047						var title =  '<h3 class="lcnb_title"><a href="'+trueLink+'" class="lcnb_linked_title">'+ v.title +'</a></h3>';
1048					} else {
1049						var exp_class = (settings.title_behavior == 'expand') ? 'lcnb_expand_trig noSwipe' : '';
1050						var title =  '<h3 class="lcnb_title '+exp_class+'">'+ v.title +'</h3>';
1051					}
1052				}
1053				
1054				// author
1055				var author = (typeof(v.author) == 'undefined' || v.author == '') ? '' : '<span class="lcnb_author">'+ v.author +'</span> ';
1056				
1057				// image - lightbox code
1058				if( settings.img_behavior != 'none') {
1059					var lb_class = (v.type == 'youtube' || v.type == 'soundcloud') ? 'lcnb_video_lb' : 'lcnb_img_lb';		
1060					if(v.type == 'inline' && typeof(v.video) != 'undefined') {lb_class = 'lcnb_video_lb';}
1061					
1062					if(settings.img_behavior == 'expand' && settings.expandable_news) {lb_class += ' lcnb_expand_trig';}
1063					if(settings.img_behavior == 'link') {lb_class += ' lcnb_linked_img';}
1064					
1065					if(v.type == 'youtube') {var lb_src =  v.s_link;}
1066					else if(v.type == 'soundcloud') {var lb_src = v.link;}
1067					else if(v.type == 'inline' && typeof(v.video) != 'undefined') {var lb_src = v.video;}
1068					else {var lb_src = get_url_param(v.img, 'src');}
1069					
1070					if(!lb_src) {var lb_code = '';}
1071					else {
1072						var img_link = (settings.img_behavior == 'link') ? '<a href="'+ trueLink +'"></a>' : '';
1073						var lb_code = '<div class="'+ lb_class +' noSwipe" data-mfp-src="'+ lb_src +'"><div class="lcnb_lb_icon">'+img_link+'</div><div class="lcnb_lb_overlay"></div></div>';
1074					}
1075				} else {var lb_code = '';}
1076				
1077				var img = (typeof(v.img) == 'undefined' || v.img == '') ? '' : '<div class="lcnb_img"><div><img src="'+ v.img +'"/></div>'+ lb_code +'</div>';
1078				
1079				// contents box
1080				var box_txt = (typeof(v.excerpt) != 'undefined' && v.excerpt) ? v.excerpt : v.txt;
1081				var contents_box = '<section class="lcnb_contents"><div><div class="lcnb_contents_inner">'+ title +' <div class="lcnb_txt">'+ author + box_txt +'</div></div></div></section>';
1082
1083				////////////////////////////
1084				// append news with boxes
1085				var pre_styles = 'style="opacity: 0; filter: alpha(opacity=0); top: 30px;"'
1086				var h_img_mode = (img && settings.layout == 'horizontal' && settings.horiz_img_mode) ? 'lcnb_h_img_mode' : '';
1087				var img_mode_no_txt = (h_img_mode && !title) ? 'lcnb_him_no_txt' : '';
1088				
1089				var news_box = '<article class="lcnb_news lcnb_type_'+ v.type +' '+ h_img_mode +' '+ img_mode_no_txt +'" '+ pre_styles +' rel="'+ i +'"><div class="lcnb_news_inner">'+ 
1090									btn_bar + img + top_box + contents_box + btm_box 
1091								+'</div></article>'; 
1092				$lcnb_wrap_obj.find('.lcnb_inner').append(news_box);
1093				
1094				// save original text in array
1095				vars.lcnb_excerpts[i] = (typeof(v.excerpt) != 'undefined') ? v.excerpt : '';
1096				vars.lcnb_orig_texts[i] = author + v.txt;
1097
1098				// change the link target
1099				if(typeof(v.link_target) != 'undefined' && v.link_target) {
1100					$lcnb_wrap_obj.find('.lcnb_news:last-child a').attr('target', v.link_target);
1101				}
1102
1103				if(i == (vars.lcnb_news_number - 1)) {
1104					// size, adjust and execute
1105					size_boxes();
1106					news_img_adjust();	
1107					show_with_fx();
1108					news_txt_shortening(); 
1109					
1110					if(settings.touchswipe) {lcnb_touchswipe();}
1111				}
1112			});
1113		}
1114		
1115		
1116		// show news with effects
1117		var show_with_fx = function() {
1118			$lcnb_wrap_obj.find('.lcnb_wrap').removeClass('lcnb_loading');
1119			
1120			var settings = $lcnb_wrap_obj.data('lcnb_settings');
1121			var vars = $lcnb_wrap_obj.data('lcnb_vars');
1122			
1123			$lcnb_wrap_obj.find('.lcnb_news').each(function(i, v) {
1124				if((i + 1) > vars.lcnb_news_to_show) {i = 0;} // effect only ones to show at the beginning
1125				
1126				var $news = $(this);
1127				setTimeout(function() { 
1128					$news.animate({'opacity': 1, 'top': 0}, 550);
1129				}, (300 * i));
1130				
1131				setTimeout(function() {
1132					vars.lcnb_is_shown = true;	
1133				}, (settings.news_per_time * 300));
1134			});	
1135			
1136			// if on small screen trigger resize to fix img size delay issues on mobile
1137			if($(window).width() < 500) {
1138				setTimeout(function() {
1139					size_boxes();
1140				}, 200);
1141			}
1142			
1143			// autoplay
1144			if(settings.autoplay && vars.lcnb_is_playing === false) {
1145				lcnb_start_slideshow($lcnb_wrap_obj);	
1146			}
1147		}
1148		 
1149
1150		
1151		// get google news image
1152		var get_google_img = function(news, fix_img) {
1153			if(fix_img || typeof(news.object.attachments) == 'undefined') {
1154				var img = '';
1155			} else {
1156				if(news.object.attachments[0].objectType == 'album') {
1157					var img = news.object.attachments[0].thumbnails[0].image.url;
1158				}
1159				else if(news.object.attachments[0].objectType == 'video') {
1160					var img = news.object.attachments[0].image.url;
1161				}
1162				else {
1163					if(typeof(news.object.attachments[0].fullImage.url) == 'undefined' || news.object.attachments[0].fullImage.url == '') {
1164						var img = news.actor.image.url.replace('?sz=50', '');
1165					} else {
1166						var img = news.object.attachments[0].fullImage.url;
1167					}
1168				}
1169			}
1170			
1171			return img;
1172		}
1173		
1174
1175		// normalize date for IE8 and 9
1176		var normalize_date_str = function(str) {
1177			if( navigator.appVersion.indexOf("MSIE") != -1 ) {
1178				
1179				// set RFC 3339
1180				if(str.indexOf('Z') != -1 || str.indexOf('T') != -1) {
1181					var regexp = /(\d\d\d\d)(-)?(\d\d)(-)?(\d\d)(T)?(\d\d)(:)?(\d\d)(:)?(\d\d)(\.\d+)?(Z|([+-])(\d\d)(:)?(\d\d))/;
1182			 		var d_obj = new Date();
1183					
1184					if (str.toString().match(new RegExp(regexp))) {
1185						var d = str.match(new RegExp(regexp));
1186						var offset = 0;
1187						 
1188						d_obj.setUTCDate(1);
1189						d_obj.setUTCFullYear(parseInt(d[1],10));
1190						d_obj.setUTCMonth(parseInt(d[3],10) - 1);
1191						d_obj.setUTCDate(parseInt(d[5],10));
1192						d_obj.setUTCHours(parseInt(d[7],10));
1193						d_obj.setUTCMinutes(parseInt(d[9],10));
1194						d_obj.setUTCSeconds(parseInt(d[11],10));
1195						
1196						if (d[12]) d_obj.setUTCMilliseconds(parseFloat(d[12]) * 1000);
1197						else d_obj.setUTCMilliseconds(0);
1198
1199						
1200						if (d[13] != 'Z') {
1201							offset = (d[15] * 60) + parseInt(d[17],10);
1202							offset *= ((d[14] == '-') ? -1 : 1);
1203							d_obj.setTime(d_obj.getTime() - offset * 60 * 1000);
1204						}
1205					}
1206					else {d_obj.setTime(Date.parse(str));}
1207					
1208					return d_obj;
1209				}
1210				else {
1211					
1212					// check and eventually try to compose the UTC format (for twitter)
1213					if(isNaN( new Date(str) )) {	
1214						var t = str.split(' ');
1215						return new Date(Date.parse(t[1] + " " + t[2] + ", " + t[5] + " " + t[3] + " UTC"));
1216					} 
1217					else {
1218						return str;	
1219
1220					}
1221				}
1222			}
1223			else {return str;}
1224		}
1225		
1226		
1227		// manage the date object
1228		var date_format = function(utc_str) {
1229			var d = new Date(utc_str);
1230			
1231			// standard date 
1232			if(!settings.elapsed_time) {
1233				var clean_date = settings.date_format;
1234				var formats = ['SS', 'MM', 'HHH', 'HH', 'H', 'dddd', 'ddd', 'dd', 'd', 'mmmm', 'mmm', 'mm', 'm', 'yyyy', 'yy']
1235				var prefix = '';
1236
1237				// seconds
1238				if(clean_date.indexOf('SS') > -1) {
1239					prefix = (d.getSeconds() < 10) ? '0' : '';
1240					clean_date = clean_date.replace('SS', prefix + d.getSeconds());
1241				}
1242				
1243				// minutes
1244				if(clean_date.indexOf('MM') > -1) {
1245					prefix = (d.getMinutes() < 10) ? '0' : '';
1246					clean_date = clean_date.replace('MM', prefix + d.getMinutes());
1247				}
1248				
1249				// hour
1250				if(clean_date.indexOf('HHH') > -1) { // 12H format
1251					prefix = (d.getHours() >= 12) ? 'PM' : 'AM';
1252					clean_date = clean_date.replace('HHH', (d.getHours() % 12) +' '+ prefix); 
1253				}
1254				else if(clean_date.indexOf('HH') > -1) { // 00-23 format
1255					prefix = (d.getHours() < 10) ? '0' : '';
1256					clean_date = clean_date.replace('HH', prefix + d.getHours());
1257				}
1258				else if(clean_date.indexOf('H') > -1) { // 00-23 format
1259					clean_date = clean_date.replace('H', d.getHours());
1260				}
1261				
1262				// day
1263				if(clean_date.indexOf('dddd') > -1) { // monday-sunday format
1264					clean_date = clean_date.replace('dddd', settings.full_d_names[ d.getDay() ]);
1265				}
1266				else if(clean_date.indexOf('ddd') > -1) { // mon-sun format
1267					clean_date = clean_date.replace('ddd', settings.short_d_names[ d.getDay() ]);
1268				}
1269				else if(clean_date.indexOf('dd') > -1) { // 01-31 format
1270					prefix = (d.getDate() < 10) ? '0' : '';
1271					clean_date = clean_date.replace('dd', prefix + d.getDate());
1272				}
1273				else if(clean_date.indexOf('d') > -1) { // 1-31 format
1274					clean_date = clean_date = clean_date.replace('d', d.getDate());
1275				}
1276				
1277				// month
1278				if(clean_date.indexOf('mmmm') > -1) { // january-december format
1279					clean_date = clean_date.replace('mmmm', settings.full_m_names[ d.getMonth() ]);
1280				}
1281				else if(clean_date.indexOf('mmm') > -1) { // jan-dec formatt
1282					clean_date = clean_date.replace('mmm', settings.short_m_names[ d.getMonth() ]);
1283				}
1284				else if(clean_date.indexOf('mm') > -1) { // 01-12 format
1285					prefix = ((d.getMonth() + 1) < 10) ? '0' : '';
1286					clean_date = clean_date.replace('mm', prefix + (d.getMonth() + 1));
1287				}
1288				else if(clean_date.indexOf('m') > -1) { // 1-12 format
1289					clean_date = clean_date.replace('m', (d.getMonth() + 1));
1290				}
1291				
1292				// year
1293				if(clean_date.indexOf('yyyy') > -1) { // four digits format
1294					clean_date = clean_date.replace('yyyy', d.getFullYear());
1295				}
1296				else if(clean_date.indexOf('yy') > -1) { // two digits format
1297					var full_y = d.getFullYear().toString();
1298					clean_date = clean_date.replace('yy', full_y.substr(2));
1299				}
1300			}
1301			
1302			//elapsed time
1303			else {
1304				var n = new Date();
1305				var diff = Math.ceil( (n.getTime() - d.getTime()) / 1000);
1306				
1307				// posted seconds ago
1308				if		(diff < 60) {
1309					var clean_date = diff +' '+ settings.elapsed_names[1];
1310				}
1311				
1312				// posted one minute ago
1313				else if (diff >= 60 && diff < 120) {
1314					var clean_date = '1 ' + settings.elapsed_names[2];
1315				}
1316				
1317				// posted minutes ago
1318				else if (diff < 3600) {
1319					var val = Math.floor( diff / 60); 
1320					var clean_date = val +' '+ settings.elapsed_names[3];
1321				}
1322				
1323				// posted one hour ago
1324				else if (diff >= 3600 && diff < 7200) {
1325					var clean_date = '1 ' + settings.elapsed_names[4];
1326				}
1327				
1328				// posted hours ago
1329				else if (diff < 86400) {
1330					var val = Math.floor( (diff / 60) / 60 ); 
1331					var clean_date = val +' '+ settings.elapsed_names[5];
1332				}
1333				
1334				// posted one day ago
1335				else if (diff >= 86400 && diff < 172800) {
1336					var clean_date = '1 ' + settings.elapsed_names[6];
1337				}
1338				
1339				// posted days ago
1340				else if (diff < 604800) {
1341					var val = Math.floor( ((diff / 60) / 60) / 24 );
1342					var clean_date = val +' '+ settings.elapsed_names[7];
1343				}
1344				
1345				// posted one week ago
1346				else if (diff >= 604800 && diff < 1209600) { 
1347					var clean_date = '1 ' + settings.elapsed_names[8];
1348				}
1349				
1350				// posted weeks ago - max 4 weeks
1351				else if (diff < 2592000) { 
1352					var val = Math.floor( (((diff / 60) / 60) / 24) / 7 );
1353					var clean_date = val +' '+ settings.elapsed_names[9];
1354				}
1355				
1356				// posted one month ago
1357				else if (diff >= 2592000 && diff < 5184000) {
1358					var clean_date = '1 ' + settings.elapsed_names[10];
1359				}
1360				
1361				// posted months ago
1362				else {
1363					var val = Math.floor( (((diff / 60) / 60) / 24) / 30 );
1364					var clean_date = val +' '+ settings.elapsed_names[11];
1365				}
1366
1367				clean_date = clean_date +' '+ settings.elapsed_names[0];
1368			}
1369			
1370			return clean_date;
1371		}
1372			
1373		
1374		// size boxes	
1375		var size_boxes = function(forced_per_time) {
1376			var settings = $lcnb_wrap_obj.data('lcnb_settings');
1377			var vars = $lcnb_wrap_obj.data('lcnb_vars');
1378			
1379			if(typeof(vars) == 'undefined') {return false;}
1380			
1381			var $news_wrap = $lcnb_wrap_obj.find('.lcnb_wrap');
1382			var $news_box = $news_wrap.find('.lcnb_news');
1383			var pp = (typeof(forced_per_time) == 'undefined') ? settings.news_per_time : forced_per_time;
1384			
1385			// cmd visibility
1386			if($lcnb_wrap_obj.find('.lcnb_news').length <= pp) {
1387				$lcnb_wrap_obj.find('.lcnb_wrap').removeClass('lcnb_has_cmd');	
1388			} else {
1389				if($lcnb_wrap_obj.find('.lcnb_cmd').length) {
1390					$lcnb_wrap_obj.find('.lcnb_wrap').addClass('lcnb_has_cmd');	
1391				}
1392			}
1393			
1394			// left/top margins if is uniblock
1395			if($news_wrap.hasClass('lcnb_uniblock')) {
1396				if($news_wrap.hasClass('lcnb_horizontal')) {
1397					var uniblock_trick = get_int( $news_wrap.find('.lcnb_news').last().css('border-left-width')) * -1;
1398				} else {
1399					var uniblock_trick = get_int( $news_wrap.find('.lcnb_news').last().css('border-top-width')) * -1;
1400				}
1401			}
1402			else {var uniblock_trick = 0;}
1403			
1404			// reset fix for uniblocks
1405			$news_wrap.css('width', '');
1406			
1407			// if uniblock - count the wrapper and first box borders
1408			if($news_wrap.hasClass('lcnb_uniblock')) {
1409				var wrap_w = $news_wrap.width() - get_int( $news_wrap.css('border-left-width')) - get_int( $news_wrap.css('border-right-width')) + uniblock_trick;	
1410				var wrap_h = settings.height - get_int( $news_wrap.css('border-top-width')) - get_int( $news_wrap.css('border-bottom-width')) + uniblock_trick;	
1411			} else {
1412				var wrap_w = $news_wrap.width();
1413				var wrap_h = settings.height;	
1414			}
1415
1416			//////////////////////////////
1417			// horizontal layout
1418			if($news_wrap.hasClass('lcnb_horizontal')) {
1419				var box_w = (wrap_w / pp) - get_int( $news_box.css('margin-left')) - get_int( $news_box.css('margin-right'));
1420				if($news_wrap.hasClass('lcnb_uniblock')) {
1421					box_w = box_w + get_int( $news_box.css('border-right-width')) - get_int( $news_box.css('border-left-width')) - uniblock_trick;
1422				}
1423				
1424				// box width
1425				if(box_w < settings.min_news_w && pp > 1)	{
1426					size_boxes( pp - 1 );
1427					return false;
1428				} else {
1429					var w = Math.floor(box_w);
1430				}
1431				
1432				var h = $news_wrap.height() - get_int( $news_box.css('margin-top')) - get_int( $news_box.css('margin-bottom'));
1433				
1434				// remove/add 1px margin to wrapper if smaller than shown news
1435				var shown_news_w = pp * (w + get_int( $news_box.css('margin-left')) + get_int( $news_box.css('margin-right')));
1436				if($news_wrap.hasClass('lcnb_uniblock')) {shown_news_w = shown_news_w + (pp * uniblock_trick) - uniblock_trick;}
1437				
1438				var wrap_total_w = $news_wrap.width() + get_int( $news_wrap.css('border-top-width')) + get_int( $news_wrap.css('border-bottom-width'));
1439				
1440				if(wrap_total_w < shown_news_w) {
1441					$news_wrap.css('margin-right', ( get_int($news_wrap.css('margin-right')) - 1));	
1442				}
1443				if(wrap_total_w > shown_news_w) {
1444					$news_wrap.css('margin-right', ( get_int($news_wrap.css('margin-right')) + 1));	
1445				}
1446				
1447				vars.lcnb_news_w = w;
1448				vars.lcnb_news_h = h;
1449				vars.lcnb_news_to_show = pp;
1450				
1451				// if uniblock - check wrapper width against shown items
1452				if($news_wrap.hasClass('lcnb_uniblock')) {
1453					var diff = $news_wrap.width() - ((w*pp) - ((pp - 1) * get_int( $news_box.css('border-left-width'))));
1454					if(diff != 0) {
1455						$news_wrap.css('width', ($news_wrap.width() - diff));	
1456					}
1457				}
1458				
1459				// if passing from vertical to horizontal and has top bar - remove top padding
1460				if(settings.buttons_position == 'top') {
1461					$news_wrap.find('.lcnb_contents_inner').removeAttr('style');	
1462				}
1463			}
1464			
1465			//////////////////////////////
1466			// vertical layout
1467			else {
1468				var box_h = (wrap_h / pp) - get_int( $news_box.css('margin-top')) - get_int( $news_box.css('margin-bottom'));
1469				if($news_wrap.hasClass('lcnb_uniblock')) {
1470					box_h = box_h + get_int( $news_box.css('border-bottom-width')) - get_int( $news_box.css('border-top-width')) - uniblock_trick;
1471				}
1472
1473				// box height
1474				if(box_h < settings.min_news_h && pp > 1)	{
1475					size_boxes( pp - 1 );
1476					return false;
1477				} else {
1478					var h = Math.round(box_h);
1479				}
1480
1481				w = wrap_w - get_int( $news_box.css('margin-left')) - get_int( $news_box.css('margin-right'));
1482				if($news_wrap.hasClass('lcnb_uniblock')) {w = w - uniblock_trick;}
1483				
1484				// retouch wrapper height if smaller than shown news
1485				var shown_news_h = pp * (h + get_int( $news_box.css('margin-top')) + get_int( $news_box.css('margin-bottom')));
1486				if($news_wrap.hasClass('lcnb_uniblock')) {shown_news_h = shown_news_h + (pp * uniblock_trick) - uniblock_trick;}
1487				
1488				var wrap_total_h = settings.height + get_int( $news_wrap.css('border-top-width')) + get_int( $news_wrap.css('border-bottom-width'));
1489				
1490				if(!vars.lcnb_is_expanded) {
1491					if(wrap_total_h < shown_news_h) {
1492						$news_wrap.css('height', shown_news_h);	
1493					} else {
1494						$news_wrap.css('height', settings.height);	
1495					}
1496				}
1497				
1498				
1499				vars.lcnb_news_w = 100; // fake value
1500				vars.lcnb_news_h = h;
1501				vars.lcnb_news_to_show = pp;
1502			}
1503			
1504			
1505			// text block height
1506			if($news_wrap.hasClass('lcnb_horizontal')) {
1507				$news_box.find('.lcnb_contents').css('max-height', 'none');
1508				$news_box.find('.lcnb_contents').children().css('height','auto');
1509			} else {
1510				var cont_h = h - ($news_box.outerHeight(true) - $news_box.height());
1511				$news_box.find('.lcnb_contents').css('max-height', cont_h);
1512				
1513				var txt_h = cont_h - $news_box.find('.lcnb_btm_bar, .lcnb_top_bar').outerHeight(true) - 
1514									 ($news_box.find('.lcnb_contents').outerHeight(true) - $news_box.find('.lcnb_contents').height());
1515									 
1516				if($news_box.find('.lcnb_btm_bar, .lcnb_top_bar').length) {
1517					txt_h = txt_h - $news_box.find('.lcnb_btm_bar, .lcnb_top_bar').outerHeight(true);
1518				}
1519				
1520				$news_box.find('.lcnb_contents').children().css('height', txt_h);
1521			}
1522			
1523			
1524			//// image block sizes
1525			// reset
1526			$news_box.find('.lcnb_img, .lcnb_img_lb, .lcnb_video_lb').removeAttr('style');
1527			$news_box.find('.lcnb_img').children().removeAttr('style');
1528			
1529			if($news_wrap.hasClass('lcnb_horizontal')) {
1530				var img_h = (settings.horiz_img_h) ? settings.horiz_img_h : '';
1531				$news_box.find('.lcnb_img, .lcnb_img_lb, .lcnb_video_lb').css('width', '100%').css('max-width', 'none').css('height', img_h);
1532				$news_box.find('.lcnb_img').children().css('max-height', 'none').css('width', '100%').css('height', img_h);
1533			} 
1534			else {
1535				var img_h = h - ( $news_box.find('.lcnb_img').outerHeight(true) - $news_box.find('.lcnb_img').height()) -
1536								get_int( $news_box.css('border-top-width')) - get_int( $news_box.css('border-bottom-width'));
1537				
1538				var h_borders = $news_box.find('.lcnb_img').outerHeight(true) - $news_box.find('.lcnb_img').height();
1539				var w_border = get_int( $news_box.find('.lcnb_img').css('border-left-width'));
1540
1541				
1542				if(settings.vert_img_w) {
1543					$news_box.find('.lcnb_img').css('width', settings.vert_img_w).css('max-width', settings.vert_img_w);	
1544					$news_box.find('.lcnb_img_lb, .lcnb_video_lb').css('min-width', (settings.vert_img_w - w_border)).css('max-width', (settings.vert_img_w - w_border));
1545				} else {
1546					$news_box.find('.lcnb_img').css('width', '').css('max-width', '');	
1547					$news_box.find('.lcnb_img_lb, .lcnb_video_lb').css('max-width', (get_int( $news_box.find('.lcnb_img').css('max-width')) - w_border));
1548				}
1549				
1550				// if text block is too narrow - set a very low width				
1551				if($news_box.find('.lcnb_contents').width() < 130) {
1552					$news_box.find('.lcnb_img').css('width', 85).css('max-width', 85);					
1553					$news_box.find('.lcnb_img_lb, .lcnb_video_lb').css('min-width', (85 - w_border)).css('max-width', (85 - w_border));
1554				}
1555		
1556				
1557				$news_box.find('.lcnb_img').css('height', '100%').css('max-height', 'none');
1558				$news_box.find('.lcnb_img').children().css('max-height', img_h).css('width', $news_box.find('.lcnb_img').width());
1559			}
1560			
1561			
1562			//// vertical buttons bar
1563			if($news_box.find('.lcnb_buttons > div').length) {
1564				$news_box.find('.lcnb_buttons').each(function() {
1565					var buttons_num = $(this).children('div').length;
1566					var right_h = h - get_int( $news_box.css('border-top-width')) - get_int( $news_box.css('border-bottom-width'));
1567					
1568					if( $(this).css('position') != 'absolute' ) {
1569						$(this).css('height', right_h);
1570						$(this).css('max-height',right_h); 
1571					}
1572					
1573					$(this).children('div').css('height', Math.floor(100 / buttons_num) + '%');
1574					if(buttons_num == 3) { $(this).children('div').last().css('height', '34%'); }
1575				});
1576				
1577				// if not btn_over_img add left position to image overlay
1578				if(!settings.btn_over_img) {
1579					var left_pos = get_int( $news_box.find('.lcnb_buttons').css('max-width'));	
1580					$news_box.find('.lcnb_img_lb, .lcnb_video_lb').css('left', left_pos);
1581				}
1582			}
1583			$news_box.css('width', w).css('height', h);
1584			
1585			
1586			// bottom and top bar - width and layout - narrow txt flag
1587			if($news_box.find('.lcnb_btm_bar, .lcnb_top_bar').length) {
1588				$news_box.find('.lcnb_btm_bar, .lcnb_top_bar').removeClass('lcnb_narrow_txt'); // reset narrow_txt class
1589				
1590				if($news_wrap.hasClass('lcnb_horizontal')) {
1591					$news_box.find('.lcnb_btm_bar, .lcnb_top_bar').css('max-width', 'none');
1592					$(this).find('.lcnb_contents_inner').removeAttr('style');
1592 // reset top bar adjustment
1593				} 
1594				else {
1595					$news_box.find('.lcnb_contents').each(function() {
1596					  	var $bar = $(this).parents('.lcnb_news').find('.lcnb_btm_bar, .lcnb_top_bar');
1597						
1598						var bb_max_w = $(this).outerWidth(false);
1599						$bar.css('max-width', bb_max_w);
1600
1601						// set layout class if too narrow because of image
1602						if($(this).parents('.lcnb_news').find('.lcnb_img').length) {
1603							if( $bar.height() > 28) {
1604								$bar.addClass('lcnb_narrow_txt');
1605								
1606								// if has side buttons bar - set a maximum width
1607								if($news_box.find('.lcnb_buttons > div').length) {
1608									var bar_max_w = $news_box.width() - get_int( $news_box.find('.lcnb_buttons').css('max-width'));
1609									$bar.css('max-width', bar_max_w);
1610								} else {
1611									$bar.css('max-width', 'none');	
1612								}
1613							}
1614							else {
1615								var bb_max_w = $(this).outerWidth(false);
1616								$bar.css('max-width', bb_max_w);
1617							}
1618						}
1619						
1620						// if is vertival and has top bar - adjust txt contents top padding
1621						if( $bar.hasClass('lcnb_top_bar') ) {
1622							$(this).find('.lcnb_contents_inner').css('padding-top', ($bar.outerHeight(false) - 3));
1623						} else {
1624							$(this).find('.lcnb_contents_inner').removeAttr('style');	
1625						}
1626					});
1627				}
1628			}
1629			
1630			// image mode - set image's height proportionally with  the rest
1631			if($news_wrap.hasClass('lcnb_horizontal') && settings.horiz_img_mode) {
1632				$news_wrap.find('.lcnb_h_img_mode').each(function() {
1633					var contents_h = $(this).find('.lcnb_contents').outerHeight() + $(this).find('.lcnb_top_bar, .lcnb_btm_bar').outerHeight();
1634					var diff = $(this).height() - contents_h;
1635					
1636					$(this).find('.lcnb_img, .lcnb_img > *').css('height', diff);
1637				});
1638			}
1639		
1640			return true;
1641		}
1642		
1643		
1644		// adjust news image size and position
1645		var news_img_adjust = function() {
1646			$lcnb_wrap_obj.find('.lcnb_news').each(function(i) {
1647				if( $(this).find('.lcnb_img').length) {
1648					var $news = $(this);
1649					var $img_wrap = $(this).find('.lcnb_img');
1650					var $img = $img_wrap.find('img');
1651					
1652					$('<img/>').bind("load",function(){ 
1653						var wrap_w = $img_wrap.width();
1654						var wrap_h = $img_wrap.height();
1655						var img_w = this.width;
1656						var img_h = this.height;
1657						
1658						// reset css
1659						$img.removeAttr('style');
1660						
1661						// difference allowed to stretch
1662						var allow_diff = 120;
1663						
1664						// if both sides are bigger
1665						if(img_h > wrap_h && img_w > wrap_w) {
1666							
1667							var ratio = Math.max(wrap_w/img_w, wrap_h/img_h);
1668							var new_w = Math.ceil(img_w * ratio);
1669							var new_h = Math.ceil(img_h * ratio);
1670							
1671							var t_offset = Math.floor( (new_h - wrap_h) / 2) * -1;
1672							var l_offset = Math.floor( (new_w - wrap_w) / 2) * -1; 
1673							
1674							if(t_offset > 0) {t_offset = 0;}
1675							if(l_offset > 0) {l_offset = 0;}
1676							
1677							$img.css('width', new_w).css('height', new_h).css('margin-left', l_offset).css('margin-top', t_offset);
1678						}
1679						
1680						
1681						// if sides are bigger or the smallest one is similar to the wrapper
1682						else if (
1683							(img_w >= wrap_w && img_h < wrap_h && img_h + allow_diff >= wrap_h) || 
1684							(img_h > wrap_h && img_w < wrap_w && img_w + allow_diff >= wrap_w) || 
1685							(img_h < wrap_h && img_w < wrap_w && img_w + allow_diff >= wrap_w && img_h + allow_diff >= wrap_h)
1686						) {
1687							var ratio = Math.max(wrap_w/img_w, wrap_h/img_h);
1688							var new_w = Math.ceil(img_w * ratio);
1689							var new_h = Math.ceil(img_h * ratio);	
1690							
1691							var t_offset = Math.floor( (new_h - wrap_h) / 2) * -1;
1692							var l_offset = Math.floor( (new_w - wrap_w) / 2) * -1;
1693							if(l_offset > 0) {l_offset = 0;}
1694								
1695							$img.css('width', new_w).css('height', new_h).css('margin-left', l_offset).css('margin-top', t_offset);
1696						}
1697						
1698						
1699						// if only one side is bigger
1700						else if(img_w > wrap_w && img_h <= wrap_h) {
1701							var h_diff = Math.floor((wrap_h - img_h) / 2);
1702							var w_diff = Math.floor((wrap_w - img_w) / 2);
1703							$img.css('max-width', '100%').css('max-height', '').css('margin-left', w_diff).css('margin-top', h_diff);	
1704						}
1705						else if(img_h > wrap_h && img_w <= wrap_w) {
1706							$img.css('max-height', '100%').css('max-width', '').css('margin-left', 0).css('margin-top', 0);	 // automatically adjusted via CSS
1707						}
1708						
1709						
1710						// basic position
1711						else {
1712							var t_margin = Math.floor( (wrap_h - img_h) / 2)
1713
1714							$img.css('width', 'auto').css('height', 'auto').css('margin-top', t_margin);	
1715							if(settings.lightbox && settings.img_behavior == 'lightbox' && $news.find('.lcnb_video_lb').length == 0) { 
1716								$img_wrap.addClass('lcnb_no_lightbox'); 
1717							}
1718						}
1719						
1720						// remove the loader and show
1721						if( !$img_wrap.hasClass('lcnb_shown_img') ) {
1722							$img_wrap.addClass('lcnb_shown_img');
1723						}
1724					}).attr('src', $img.attr('src'));	
1725				}
1726			});
1727		}
1728			
1729		
1730		// news text lenght control - text shortening
1731		var news_txt_shortening = function() {
1732			var $news_wrap = $lcnb_wrap_obj.find('.lcnb_wrap');
1733			var settings = $lcnb_wrap_obj.data('lcnb_settings');
1734			var vars = $lcnb_wrap_obj.data('lcnb_vars');
1735
1736			$lcnb_wrap_obj.find('.lcnb_news').each(function() {
1737				var $news_box = $(this);
1738				var nid = $(this).attr('rel');
1739				
1740				// clean empty elements in description
1741				$news_box.find('.lcnb_txt *:empty').not('br, img, i').remove();
1742				$news_box.find('.lcnb_txt iframe').remove();
1743
1744				// set global var with orig texts
1745				var $news_txt = $news_box.find('.lcnb_txt');		
1746				if(typeof(vars.lcnb_orig_texts[nid]) == 'undefined') {vars.lcnb_orig_texts[nid] = $news_txt.html();}
1747				
1748				// reset
1749				var reset_txt = (vars.lcnb_excerpts[nid]) ? vars.lcnb_excerpts[nid] : vars.lcnb_orig_texts[nid];
1750				$news_box.find('.lcnb_txt').html(reset_txt).removeClass('lcnb_shorten');
1751
1752				// horizontal - calculate sizes
1753				if($news_wrap.hasClass('lcnb_horizontal')) {
1754					var wrap_h = $news_box.outerHeight(false) - 
1755								 ( get_int( $news_box.find('.lcnb_contents').css('padding-top')) + get_int( $news_box.find('.lcnb_contents').css('padding-bottom')) );
1756
1757					if($news_box.find('.lcnb_img').length) {
1758						wrap_h = wrap_h - $news_box.find('.lcnb_img').outerHeight(true);	
1759					}
1760					if($news_box.find('.lcnb_btm_bar, .lcnb_top_bar').length) {
1761						wrap_h = wrap_h - $news_box.find('.lcnb_btm_bar, .lcnb_top_bar').outerHeight(false);	
1762					}
1763					
1764					var txt_h = $news_box.find('.lcnb_contents').height();
1765				}
1766				
1767				// vertical - calculate sizes
1768				else {
1769					var wrap_h = parseFloat( $news_box.find('.lcnb_contents').height());
1770					var txt_h = parseFloat( $news_box.find('.lcnb_contents_inner').outerHeight(false));
1771					
1772					if($news_box.find('.lcnb_btm_bar, .lcnb_top_bar').length) {
1773						wrap_h = wrap_h - $news_box.find('.lcnb_btm_bar, .lcnb_top_bar').outerHeight(false);
1774					}
1775				}
1776					
1777				// if is higher
1778				if(wrap_h < txt_h) {
1779					// search news author
1780					if( $news_box.find('.lcnb_txt .lcnb_author').length) {
1781						var author = $news_box.find('.lcnb_txt .lcnb_author').clone().wrap('<div>').parent().html();
1782						$news_box.find('.lcnb_txt .lcnb_author').remove();
1783					} else  {
1784						var author = '';
1785					}
1786
1787					// leave only paragraphs and links to avoid slowdowns
1788					$news_box.find('.lcnb_txt *').not('a, p, br, i, iframe').each(function() {
1789						var content = $(this).contents();
1790						$(this).replaceWith(content);
1791					});
1792					
1793					// clean the attribues
1794					$news_box.find('.lcnb_txt *').lcnb_remove_all_attr();
1795					
1796					var orig_contents = $news_box.find('.lcnb_txt').html();
1797					var exploded = orig_contents.split(' ');
1798					var new_contents = '';
1799					var right_h_txt = '';
1800					
1801					var txt_h = 0;
1802					var a = 0;
1803
1804					while(txt_h < wrap_h && a < exploded.length) {
1805						if( typeof(exploded[a]) != 'undefined') {
1806							right_h_txt = new_contents;
1807							new_contents = new_contents + exploded[a] + ' ';	
1808							
1809							// append and clean	
1810							$news_box.find('.lcnb_txt').html(author + new_contents + '<span class="lcnb_read_more">'+ settings.read_more_txt +'</span>');	
1811							
1812							// remove initial <br>, duplicated <br> and <br> after a paragraph
1813							for(x=0; x<2; x++) {
1814								// if first child is BR - remove it
1815								if($news_box.find('.lcnb_txt > *:first').is('br')) {
1816									$news_box.find('.lcnb_txt > *:first').remove();	
1817								}
1818								
1819								$news_box.find('.lcnb_txt br').each(function() {
1820									/*if( $(this).next().is('br') ) {
1821										$(this).next().remove();	
1822									}*/
1823									if( $(this).prev().is('p')) {
1824										$(this).remove();
1825									}
1826								});
1827							}
1828							
1829							// remove BR before the "read more" text
1830							while( $news_box.find('.lcnb_txt').html().indexOf('<br\> <span class="lcnb_read_more">') != -1 ) {
1831								$news_box.find('.lcnb_read_more').prev().remove();	
1832							}
1833
1834							txt_h = ($news_wrap.hasClass('lcnb_horizontal')) ? $news_box.find('.lcnb_contents').height() : $news_box.find('.lcnb_contents_inner').height();
1835							a++;
1836						}
1837					}
1838					
1839					
1840					// check unclosed tags 
1841					var tags = ['a', 'p', 'i'];
1842					$.each(tags, function(i, v) {
1843						var open_count = right_h_txt.match('<'+v, 'g');  
1844						var close_count = right_h_txt.match('</'+v, 'g');
1845						
1846						if(open_count != null) {
1847							if(open_count != null && close_count == null || open_count.length > close_count.length) {
1848								right_h_txt = right_h_txt + '</'+ v +'>';
1849							}
1850						}
1851						
1852						if(i == (tags.length - 1)) {
1853							$news_box.find('.lcnb_txt').html(author + right_h_txt + '<span class="lcnb_read_more">'+ settings.read_more_txt +'</span>');	
1854							$news_box.find('.lcnb_txt *:empty').not('br').remove();
1855							
1856							// remove duplicated <br> and <br> after a paragraph
1857							for(x=0; x<2; x++) {
1858								// if first child is BR - remove it
1859								if($news_box.find('.lcnb_txt > *:first').is('br')) {
1860									$news_box.find('.lcnb_txt > *:first').remove();	
1861								}
1862								
1863								$news_box.find('.lcnb_txt br').each(function() {
1864									if( $(this).next().is('br') ) {
1865										$(this).next().remove();	
1866									}
1867									if( $(this).prev().is('p')) {
1868										$(this).remove();
1869									}
1870								});
1871							}
1872							
1873							// remove BR before the "read more" text
1874							while( $news_box.find('.lcnb_txt').html().indexOf('<br\> <span class="lcnb_read_more">') != -1 ) {
1875								$news_box.find('.lcnb_read_more').prev().remove();	
1876							}
1877						}
1878					});
1879
1880					// last P tag fix
1881					$news_box.find('.lcnb_txt p').last().replaceWith( $news_box.find('.lcnb_txt p').last().html() );
1882
1883					// save the real text and add class
1884					$news_txt.addClass('lcnb_shorten');
1885				}
1886			});
1887		}
1888			
1889		
1890		// remove all the tags attributes except the link href and target
1891		$.fn.lcnb_remove_all_attr = function() {
1892			return this.each(function() {
1893				var attributes = $.map(this.attributes, function(item) {
1894				  return item.name;
1895				});
1896				
1897				var obj = $(this);
1898				$.each(attributes, function(i, item) {
1899					if( item != "href" && item != "target") {
1900						obj.removeAttr(item);
1901					}
1902				});
1903			});
1904		}
1905		
1906			
1907		// dynamic box layout
1908		var dynamic_layout = function() {
1909			var settings = $lcnb_wrap_obj.data('lcnb_settings');
1910			var $news_wrap = $lcnb_wrap_obj.find('.lcnb_wrap');
1911			var min_w = (settings.min_horiz_w < settings.min_news_w) ? settings.min_news_w : settings.min_horiz_w;
1912	
1913			// horizontal to vertical
1914			if($news_wrap.width() < min_w) {
1915				if($news_wrap.hasClass('lcnb_horizontal')) {
1916					$news_wrap.removeClass('lcnb_horizontal').addClass('lcnb_vertical');	
1917					vars.lcnb_news_to_show = settings.news_per_time;
1918					if(settings.touchswipe) {lcnb_touchswipe(true);}
1919				}
1920			}
1921			
1922			// vertical to Horizontal
1923			else {
1924				if(settings.layout == 'horizontal' && !$news_wrap.hasClass('lcnb_horizontal')) {
1925					$news_wrap.removeClass('lcnb_vertical').addClass('lcnb_horizontal');
1926					vars.lcnb_news_to_show = settings.news_per_time;
1927					if(settings.touchswipe) {lcnb_touchswipe(true);}
1928				}
1929			}
1930			
1931			return true;
1932		}
1933			
1934		
1935		// get the current news box size (with margins)
1936		var get_box_size = function(subj) {
1937			var vars = subj.data('lcnb_vars');
1938			var $news_wrap = $('.lcnb_wrap', subj);
1939			var $news_box = $('.lcnb_news', subj);
1940		
1941			// box sizes
1942			if($news_wrap.hasClass('lcnb_horizontal')) {
1943				var size = vars.lcnb_news_w + get_int( $news_box.css('margin-left')) + get_int( $news_box.css('margin-right')); 
1944				if($news_wrap.hasClass('lcnb_uniblock')) {size = size - get_int( $news_wrap.find('.lcnb_news').css('border-left-width'));}
1945			} 
1946			else {
1947				var size = vars.lcnb_news_h + get_int( $news_box.css('margin-top')) + get_int( $news_box.css('margin-bottom')); 
1948				if($news_wrap.hasClass('lcnb_uniblock')) {size = size - get_int( $news_wrap.find('.lcnb_news').css('border-top-width'));}	 
1949			}
1950			
1951			return size;
1952		}	
1953		
1954
1955		// news slide
1956		lcnb_news_slide = function(subj, direction) {
1957			var vars = subj.data('lcnb_vars');
1958			var settings = subj.data('lcnb_settings');
1959			var $news_wrap = $('.lcnb_wrap', subj);
1960			
1961			if(vars.lcnb_news_to_show < vars.lcnb_news_number) {
1962				
1963				// infinite carousel management
1964				if(settings.carousel && vars.lcnb_news_to_show < vars.lcnb_news_number) {
1965
1966					// if is the first time - save the boxes code to be appended
1967					if(vars.lcnb_carousel_obj === false) {
1968						vars.lcnb_carousel_obj = [];
1969						
1970						$news_wrap.find('.lcnb_news').each(function(i, v) {
1971							vars.lcnb_carousel_obj[i] = $(this).clone().wrap('<div>').parent().html();
1972						});	
1973					}
1974					var tot_news = vars.lcnb_carousel_obj.length - 1;
1975					
1976					// perform
1977					if(direction == 'next') {
1978						var first_rel = get_int( $news_wrap.find('.lcnb_news').not('.lcnb_cloned_n').first().attr('rel'));
1979						$news_wrap.find('.lcnb_news').not('.lcnb_cloned_n').first().addClass('lcnb_cloned_n');
1980						
1981						if($news_wrap.find('.lcnb_cloned_p[rel="'+ first_rel +'"]').length) {
1982							$news_wrap.find('.lcnb_news[rel="'+ first_rel +'"]').not('.lcnb_cloned_n').first().removeClass('lcnb_cloned_p');
1983						} else {
1984							$news_wrap.find('.lcnb_inner').append( vars.lcnb_carousel_obj[ first_rel ] );
1985						}
1986					}
1987					else {	
1988						var last_rel = get_int( $news_wrap.find('.lcnb_news').not('.lcnb_cloned_p').last().attr('rel'));
1989						$news_wrap.find('.lcnb_news').not('.lcnb_cloned_p').last().addClass('lcnb_cloned_p');
1990						
1991						if($news_wrap.find('.lcnb_cloned_n[rel="'+ last_rel +'"]').length) {
1992							$news_wrap.find('.lcnb_cloned_n[rel="'+ last_rel +'"]').last().removeClass('lcnb_cloned_n');
1993						} else {
1994							$news_wrap.find('.lcnb_inner').prepend( vars.lcnb_carousel_obj[ last_rel ] );
1995						}
1996
1997						// add dynamically the margin to be smooth
1998						if(vars.lcnb_show_offset == 0) {
1999							var size = get_box_size(subj);
2000							var pos_subj = ( $('.lcnb_wrap', subj).hasClass('lcnb_horizontal')) ? 'left' : 'top';
2001							
2002							var new_offset = $('.lcnb_inner', subj).lcnb_get_pos(pos_subj) - size;
2003							$('.lcnb_inner', subj).lcnb_set_pos(pos_subj, new_offset);
2004						}
2005					}
2006					
2007					$news_wrap.find('.lcnb_news').lcnb_clone_fix(vars);
2008				}
2009				
2010				// calculate the offset and execute
2011				if(direction == 'next') {
2012					if( (vars.lcnb_news_to_show + vars.lcnb_show_offset) < vars.lcnb_news_number || settings.carousel) {
2013						vars.lcnb_show_offset = vars.lcnb_show_offset + 1;
2014					} 
2015					else { // return to the first news
2016						vars.lcnb_show_offset = 0;
2017					}
2018				}
2019				else {
2020					if(!settings.carousel) {
2021						vars.lcnb_show_offset = (vars.lcnb_show_offset <= 0) ? 0 :  vars.lcnb_show_offset - 1;
2022					} else {
2023						vars.lcnb_show_offset = 0 + $news_wrap.find('.lcnb_cloned_n').length;
2024					}
2025				}
2026
2027				// if is expanded
2028				if(vars.lcnb_is_expanded) {
2029					var $wrapper = $('.lcnb_inner_wrapper', subj);
2030					
2031					if(direction == 'next') {
2032						var $next = $wrapper.find('.expanded').next('.lcnb_news');	
2033						expand_news($wrapper, $next, true);
2034					} else {
2035						var $prev = $wrapper.find('.expanded').prev('.lcnb_news');	
2036						expand_news($wrapper, $prev, true);
2037					}
2038				}
2039
2040				if(!settings.carousel) {
2041					arrows_visibility(subj);
2042				}	
2043				news_offset(subj);
2044				
2045				
2046				// if carousel - remove the cloned element
2047				if(settings.carousel && vars.lcnb_news_to_show < vars.lcnb_news_number ) {
2048					if(typeof(nb_carousel_timeout) != 'undefined') {clearTimeout(nb_carousel_timeout);}
2049					
2050					nb_carousel_timeout = setTimeout(function() {
2051						$news_wrap.find('.lcnb_cloned_n, .lcnb_cloned_p').remove();
2052
2053						vars.lcnb_show_offset = 0;
2054						news_offset(subj, true);
2055						if(settings.carousel) {size_boxes();} // check again box sizes after clone cleanup
2056						
2057					}, (settings.animation_time + 30)); 
2058				}
2059			}
2060		}
2061		
2062		
2063		// adjust the news wrapper offset
2064		var news_offset = function(subj, no_animation) {
2065			var vars = subj.data('lcnb_vars');
2066			var settings = subj.data('lcnb_settings');
2067		
2068			if(typeof(vars) == 'undefined') {return false;}
2069		
2070			var $news_wrap = $('.lcnb_wrap', subj);
2071			var $news_box = $('.lcnb_news', subj);
2072			var size = get_box_size(subj);
2073			
2074			// calculate
2075			var px_offset = Math.ceil(size * vars.lcnb_show_offset);
2076			if(px_offset != 0) {px_offset = px_offset * -1;}
2077
2078			if(!settings.carousel) {
2079				// avoid too much offset passing from horizontal to vertical
2080				if($news_wrap.hasClass('lcnb_vertical') && $lcnb_wrap_obj.find('.lcnb_inner').lcnb_get_pos('top') == 0 ) {
2081					var max_offset = (size * (vars.lcnb_news_number - vars.lcnb_news_to_show)) * -1;
2082					if (px_offset < max_offset) {px_offset = max_offset;}
2083				}
2084	
2085				// avoid too much offset passing from vertical to horizontal
2086				if($news_wrap.hasClass('lcnb_horizontal') && $lcnb_wrap_obj.find('.lcnb_inner').lcnb_get_pos('left') == 0 ) {
2087					var max_offset = (size * (vars.lcnb_news_number - vars.lcnb_news_to_show)) * -1;
2088					if (px_offset < max_offset) {px_offset = max_offset;}
2089				}
2090			}
2091	
2092			// animation easing
2093			var easing = (settings.slideshow_time == 0 && vars.lcnb_is_playing) ? 'linear' : 'swing';
2094
2095			// animation time
2096			var duration = (typeof(no_animation) != 'undefined') ? 0 : settings.animation_time; 
2097
2098			// animation type - slide
2099			if($news_wrap.hasClass('lcnb_horizontal')) {
2100				$('.lcnb_inner', subj).lcnb_animate_pos('left', px_offset, duration, easing);
2101			} 
2102			else {
2103				$('.lcnb_inner', subj).lcnb_animate_pos('top', px_offset, duration, easing);
2104			}
2105			
2106			// setup moving flag
2107			vars.lcnb_is_moving = true;
2108			setTimeout(function() {
2109				vars.lcnb_is_moving = false;
2110			}, duration);		
2111		}
2112		
2113		
2114		// navigation arrows visibility
2115		var arrows_visibility = function(subj) {
2116			var vars = subj.data('lcnb_vars');
2117			
2118			if(vars.lcnb_news_to_show >= vars.lcnb_news_number) {
2119				$('.lcnb_next', subj).addClass('lcnb_disabled');
2120				$('.lcnb_prev', subj).addClass('lcnb_disabled');	
2121			}
2122			else {
2123				if(vars.lcnb_show_offset > 0) {
2124					$('.lcnb_prev', subj).removeClass('lcnb_disabled');
2125				} else {
2126					$('.lcnb_prev', subj).addClass('lcnb_disabled');
2127				}
2128				
2129				
2130				if((vars.lcnb_news_to_show + vars.lcnb_show_offset) < vars.lcnb_news_number) {
2131					$('.lcnb_next', subj).removeClass('lcnb_disabled');	
2132				} else {
2133					$('.lcnb_next', subj).addClass('lcnb_disabled');	
2134				}
2135			}
2136		}
2137		
2138		
2139		// opacity and position fix
2140		$.fn.lcnb_clone_fix = function(obj_vars) {
2141			var $clone = this;
2142			$clone.css('opacity', 1).css('filter', 'alpha(opacity=100)');
2143			
2144			$clone.each(function() {
2145				var img_opacity = ( get_int( $(this).find('.lcnb_img img').css('opacity')) == 0) ? 0 : 1;
2146				$(this).find('.lcnb_img img').css('opacity', img_opacity).css('filter', 'alpha(opacity='+ img_opacity +'00)');	
2147				
2148				if(img_opacity == 0) {news_img_adjust();}
2149			});
2150			
2151			//$clone.css('top', 0);
2152			$clone.lcnb_animate_pos('top', 0, 0);
2153			
2154			return $clone;	
2155		}
2156		
2157		
2158		// start the slideshow
2159		lcnb_start_slideshow = function($elem, find_the_wrap) {
2160			if(typeof(find_the_wrap) != 'undefined') {	
2161				$elem = $elem.parents('.lcnb_wrap').parent();
2162			} 
2163
2164			var vars = $elem.data('lcnb_vars');	
2165			var settings = $elem.data('lcnb_settings');
2166			var add_delay = (settings.slideshow_time == 0 && !vars.lcnb_is_shown) ? 1200 : 0;
2167			
2168			// if is expanded or already playing - do nothing
2169			if(vars.lcnb_is_expanded || vars.lcnb_is_playing) {return true;}
2170			
2171			// start immediately if slideshow time == 0 
2172			if(settings.slideshow_time == 0) {
2173				setTimeout(function() {
2174					vars.lcnb_is_playing = true;
2175					lcnb_news_slide($elem, 'next');	
2176				}, add_delay);
2177			}
2178			
2179			setTimeout(function() {
2180				vars.lcnb_is_playing = setInterval(function() {
2181					
2182					var to_slide = (settings.slide_all && settings.slideshow_time > 0) ? vars.lcnb_news_to_show : 1;
2183					for(zz = 0; zz < to_slide; zz++) {
2184						lcnb_news_slide($elem, 'next');
2185					}
2186				}, (settings.slideshow_time + settings.animation_time));	
2187			}, add_delay + 10);
2188		}
2189		
2190		
2191		// stop the slideshow
2192		var stop_slideshow = function($elem, elem_is_wrapper) {
2193			if(typeof(elem_is_wrapper) == 'undefined') {	
2194				$elem = $elem.parents('.lcnb_wrap').parent();
2195			} 
2196
2197			var vars = $elem.data('lcnb_vars');	
2198			var settings = $elem.data('lcnb_settings');
2199			
2200			clearInterval(vars.lcnb_is_playing);
2201			vars.lcnb_is_playing = null;
2202			
2203			// limit animation time for manual changes
2204			if(settings.autoplay && settings.slideshow_time == 0 && settings.animation_time > 1800) {
2205				var orig_time = settings.animation_time;
2206				settings.animation_time = 1800;
2207				
2208				// return to normal animation time
2209				setTimeout(function() {
2210					settings.animation_time = orig_time;	
2211				}, 200);
2212			}
2213		}
2214		
2215		
2216		// pause on hover
2217		if(settings.autoplay && settings.pause_on_hover) {
2218			$lcnb_wrap_obj.on('mouseenter', '.lcnb_inner_wrapper', function() {
2219				$(this).parents('.lcnb_wrap').parent().lcsb_stop_slideshow();
2220			})
2221			.on('mouseleave', '.lcnb_inner_wrapper', function() {
2222				$(this).parents('.lcnb_wrap').parent().lcsb_start_slideshow();
2223			});
2224		}
2225
2226
2227		// html to tweet text 
2228		var html_to_tweet = function(txt) { 
2229			// strip text
2230			var $demo = $('<div/>');	
2231			$demo.append('<div id="lcnb_util_2" style="display: none !important;">'+ txt +'</div>');
2232			
2233			$demo.find("*").not('iframe').each(function() {
2234				var content = $(this).contents();
2235				$(this).replaceWith(content);
2236			});
2237			
2238			// get the short text
2239			var short_txt = $demo.text().replace(/[^ -~]/g, '').substring(0, 117);
2240			return encodeURIComponent(short_txt).replace(/'/g,"\\'");
2241		}
2242		
2243		
2244		// social share code
2245		var social_share_code = function share(type, v) {
2246			var settings = $lcnb_wrap_obj.data('lcnb_settings');
2247			
2248			// normalize code and remove author
2249			var $fc = $('<div />').append(v.txt);
2250			$fc.find('.lcnb_author, iframe').remove();
2251			$fc.find('*').not('a, iframe').each(function() {
2252				var content = $(this).contents();
2253				$(this).replaceWith(content);
2254			});	
2255			var s_txt_orig = $fc.html();
2256			
2257			var s_title = encodeURIComponent(v.title).replace(/'/g,"\\'");
2258			var s_txt = encodeURIComponent( s_txt_orig.substring(0,1000) ).replace(/'/g,"\\'");
2259			var s_link = (typeof(v.s_link) == 'undefined' || v.s_link == '') ? encodeURIComponent(location.href) : encodeURIComponent(v.s_link);
2260			var s_fb_image = (typeof(v.img) == 'undefined' || v.img == '') ? '' : '&picture='+ settings.fb_share_fix +'?u='+encodeURIComponent(v.img).replace(/'/g,"\\'");
2261			
2262			var code = '<div class="lcnb_social_trigger noSwipe" title="share"><ul class="lcnb_social_box">';
2263			
2264			// facebook
2265			code += '<li class="lcnb_share_fb" title="share on Facebook" onClick="window.open(\'https://www.facebook.com/sharer/sharer.php?u='+ s_link +'&display=popup\',\'sharer\',\'toolbar=0,status=0,width=548,height=325\');"></li>';
2266
2267			// twitter
2268			if(type == 'twitter') { // retweet code
2269				code += '<li class="lcnb_share_tw lcnb_retweet" title="share on Twitter" onClick="window.open(\'https://twitter.com/intent/retweet?tweet_id='+ v.tweet_id +'&amp;via='+ v.user_id +'\',\'sharer\',\'toolbar=0,status=0,width=548,height=325\');" ontouchstart="window.open(\'https://twitter.com/intent/retweet?tweet_id='+ v.tweet_id +'&amp;via='+ v.user_id +'\',\'sharer\',\'toolbar=0,status=0,width=548,height=325\');"></li>';
2270			} 
2271			else {
2272				code += '<li class="lcnb_share_tw" title="share on Twitter" onClick="window.open(\'https://twitter.com/share?text='+ html_to_tweet(s_txt_orig) +'&amp;url='+ s_link +'\',\'sharer\',\'toolbar=0,status=0,width=548,height=325\');" ontouchstart="window.open(\'https://twitter.com/share?text='+ html_to_tweet(s_txt_orig) +'&amp;url='+ s_link +'\',\'sharer\',\'toolbar=0,status=0,width=548,height=325\');"></li>';
2273			}
2274			
2275			// google plus
2276			if(typeof(v.s_link) != 'undefined' && v.s_link != '') {
2277				code += '<li class="lcnb_share_gg" title="share on Google+" onClick="window.open(\'https://plus.google.com/share?url='+ s_link +'\',\'sharer\',\'toolbar=0,status=0,width=548,height=325\');" ontouchstart="window.open(\'https://plus.google.com/share?url='+ s_link +'\',\'sharer\',\'toolbar=0,status=0,width=548,height=325\');"></li>';
2278			}
2279			
2280			code += '</ul>';
2281			
2282			return code + '</ul></div>';
2283		}
2284		
2285		
2286		// vertical button bar - toggle news socials
2287		$.fn.lcnb_btn_bar_toggle_socials = function(action) {
2288			return this.each(function() {
2289				var $sb = $(this);
2290				var $nb = $(this).parents('.lcnb_news');
2291				var $flap = $(this).find('.lcnb_social_box');				
2292				var offset = $(this).width();
2293				
2294				if(action == 'show' && $flap.is(':hidden')) {
2295					$flap.css('width', (36 * $flap.children().length)); // social block width + 1px border
2296					
2297					var border_w = get_int( $sb.parent('.lcnb_buttons').children().first().css('border-bottom-width'));
2298					var h = $sb.height() + (border_w * 2);
2299					if(border_w > 0) {$flap.css('top', (border_w * -1));}
2300					
2301					$sb.addClass('socials_shown');
2302					$flap.css('display', 'inline-block').css('height', h).lcnb_set_pos('left', ($flap.width() * -1)).lcnb_animate_pos('left', offset, 400, 'linear');
2303				}
2304				else {
2305					var w = $flap.width(); 
2306					var left = w * -1;
2307
2308					$flap.lcnb_animate_pos('left', left, 400, 'linear');
2309					
2310					setTimeout(function() {
2311						$sb.removeClass('socials_shown');
2312						$flap.hide();
2313					}, 400);
2314				}
2315			});
2316		}
2317
2318		
2319		// toggle socials 
2320		$.fn.lcnb_toggle_socials = function(action) {
2321			return this.each(function() {
2322				var $sb = $(this);
2323				var $nb = $(this).parents('.lcnb_news');
2324				var $flap = $(this).find('.lcnb_social_box');				
2325
2326				// for bottom bar and expanded
2327				if( $sb.parent().hasClass('lcnb_btm_bar') || $sb.parents('.lcnb_wrap ').find('.lcnb_exp_data').length) {
2328					var correct_pos = 25 + (29 * $flap.children('li').length);
2329					
2330					if(action == 'show' && $flap.is(':hidden')) {
2331						$flap.parent().addClass('socials_shown');
2332						$flap.show();
2333	
2334						// set bottom position the first time
2335						if( get_int($flap.css('bottom')) == 9) {
2336							$flap.css('bottom', correct_pos + 5);	
2337						}
2338						
2339						$nb.css('overflow', 'visible').css('z-index', 60); // avoid hidden parts on small boxes
2340						$flap.clearQueue().animate({'opacity': 1, 'bottom': correct_pos}, 200);
2341					}
2342					else {
2343						$flap.clearQueue().animate({'opacity': 0, 'bottom': correct_pos + 5}, 200);
2344						
2345						setTimeout(function() {
2346							$nb.css('overflow', 'hidden').css('z-index', '');
2347							$flap.parent().removeClass('socials_shown');
2348							$flap.hide();
2349						}, 200);
2350					}
2351				}
2352				
2353				// for top bar
2354				else {
2355					var correct_pos = -11 + $sb.outerHeight();
2356					
2357					if(action == 'show' && $flap.is(':hidden')) {
2358						$flap.parent().addClass('socials_shown');
2359						$flap.show();
2360	
2361						// set top position the first time
2362						if( get_int($flap.css('top')) == 9) {
2363							$flap.css('top', correct_pos + 5);	
2364						}
2365						
2366						$nb.css('overflow', 'visible').css('z-index', 60); // avoid hidden parts on small boxes
2367						$flap.clearQueue().animate({'opacity': 1, 'top': correct_pos}, 200);
2368					}
2369					else {
2370						$flap.clearQueue().animate({'opacity': 0, 'top': correct_pos + 5}, 200);
2371						
2372						setTimeout(function() {
2373							$nb.css('overflow', 'hidden').css('z-index', '');
2374							$flap.parent().removeClass('socials_shown');
2375							$flap.hide();
2376						}, 200);
2377					}	
2378				}
2379			});
2380		}
2381		
2382		
2383		// toggle socials on click
2384		$('.lcnb_social_trigger').unbind('click');
2385		$lcnb_wrap_obj.delegate('.lcnb_social_trigger', vars.lcnb_event_type, function() {
2386			var $subj = $(this);
2387			if(typeof(lcnb_one_click) != 'undefined') {clearTimeout(lcnb_one_click);}
2388			
2389			lcnb_one_click = setTimeout(function() {
2390				stop_slideshow($subj);
2391				
2392				// if button bar
2393				if($subj.parent().hasClass('lcnb_buttons')) {
2394					if($subj.find('.visible_socials').length) {
2395						$subj.lcnb_btn_bar_toggle_socials('hide');
2396					} else {
2397						$subj.lcnb_btn_bar_toggle_socials('show');	
2398						
2399						// hide other ones
2400						$('.socials_shown', $lcnb_wrap_obj).not($subj).lcnb_btn_bar_toggle_socials('hide');
2401					}	
2402				}
2403				
2404				// bottom bar
2405				else {
2406					if($subj.find('.visible_socials').length) {
2407						$subj.lcnb_toggle_socials('hide');
2408					} else {
2409						$subj.lcnb_toggle_socials('show');	
2410						
2411						// hide other ones
2412						$('.socials_shown', $lcnb_wrap_obj).not($subj).lcnb_toggle_socials('hide');
2413					}	
2414				}
2415			}, 5);
2416		});
2417	
2418	
2419		// expand news
2420		var expand_news = function($wrapper, $news, nav_trigger) {
2421			var vars = $wrapper.parents('.lcnb_wrap').parent().data('lcnb_vars');
2422			var settings = $wrapper.parents('.lcnb_wrap').parent().data('lcnb_settings');
2423			
2424			if(!vars.lcnb_is_expanded || typeof(nav_trigger) != 'undefined') {
2425				vars.lcnb_is_expanded = true;	
2426				var news = vars.lcnb_ordered_news[$news.attr('rel')];
2427
2428				// exp img management - position
2429				var exp_img_pos = (typeof(news.exp_img_pos) != 'undefined') ? news.exp_img_pos : settings.exp_main_img_pos;
2430				
2431				// set expanded class
2432				$wrapper.find('.lcnb_news').removeClass('expanded');
2433				$news.addClass('expanded');
2434				
2435				// if is changing displayed news
2436				if(typeof(nav_trigger) != 'undefined') { 
2437					$wrapper.find('.lcnb_exp_block').last().css('z-index', 150).fadeTo(300, 0);
2438
2439					setTimeout(function() {
2440						$wrapper.find('.lcnb_exp_block').last().remove();
2441					}, 300);
2442				}
2443				
2444				// image block
2445				var has_img = (news.img) ? true : false;
2446
2447				// force side img hiding
2448				if(exp_img_pos == 'hidden' || exp_img_pos == 'inside') { 
2449					has_img = false;
2450				}
2451				var img = (has_img) ? '<div class="lcnb_exp_img_wrap">'+ $news.find('.lcnb_img').html() +'</div>' : '';
2452				var fulltxt_class = (!has_img) ? 'lcnb_only_text' : ''; // fulltext class if image does not exists
2453				
2454				// clean image block
2455				if(has_img && img) {
2456					var $img_code = $(img);
2457
2458					// remove no-lightbox elements 
2459					if($news.find('.lcnb_img').hasClass('lcnb_no_lightbox')) { 
2460						$img_code.find('.lcnb_img_lb, .lcnb_video_lb').remove();
2461					} 
2462					img = $img_code.clone().wrap('<div>').parent().html();
2463				}
2464				
2465				// data block
2466				var socials = (settings.social_share) ? social_share_code(news.type, news) : ''; 
2467
2468				var date = (!settings.read_more_btn && settings.hide_elements.indexOf('date') == -1) ? '<div class="lcnb_exp_date"><div class="lcnb_btn_time"><time class="lcnb_date">'+ date_format(news.date) +'</time></div></div>' : '';
2469				
2470				if(typeof(news.link) != 'undefined' && news.link != '') {
2471					 var trueLink = (news.type == 'soundcloud') ? news.s_link : news.link;
2472					 var link = '<div class="lcnb_link"><a href="'+ trueLink +'" target="_blank"></a></div>';
2473				} 
2474				else {var link = '';}
2475				
2476				var data_block = '<div class="lcnb_exp_data">' + date + socials + link + '</div>';
2477				
2478				// text box
2479				var title = (news.title) ? $news.find('.lcnb_title').clone().removeAttr('style').wrap('<div>').parent().html() : '';
2480				var txt = news.txt.replace(/fake-src="/g, 'src="');
2481				
2482				// if main image to put inside - prepend
2483				if(exp_img_pos == 'inside' && news.img) {
2484					txt = '<p><img src="'+ news.img +'" class="lcnb_exp_main_img" /></p>' + txt;	
2485				}
2486				
2487				// advanced images management for expanded layout
2488				if(settings.manage_exp_images) {txt = txt_img_management(txt, settings, $news, news);}
2489	
2490				// append the expanded block
2491				var exp_block = '<div class="lcnb_exp_block noSwipe '+ fulltxt_class +'">' + 
2492								'<span class="lcnb_close"></span>'+ img +'<div class="lcnb_exp_txt">'+ title + txt + data_block +'</div><div style="clear:both;"></div></div>';
2493				$wrapper.css('position', 'relative').prepend(exp_block);
2494				
2495				// expanded initial height
2496				if(settings.boxed_news) {
2497					var $obj = $wrapper.find('.lcnb_exp_block').first();
2498					
2499					var bn_margin = get_int($obj.css('margin-top')) + get_int($obj.css('margin-bottom'));
2500					var exp_h = settings.height - bn_margin;
2501				} else {
2502					var exp_h = settings.height;
2503				}
2504				$wrapper.find('.lcnb_exp_block').first().css('min-height', exp_h);
2505				
2506				// if has images, trigger preloader
2507				if( $wrapper.find('.lcnb_exp_txt:first img').length) {
2508					exp_img_loading( $wrapper.parents('.lcnb_wrap') );
2509				}
2510				
2511				if(has_img) {
2512					// clean cloned inline css 
2513					var $img_wrap = $wrapper.find('.lcnb_exp_img_wrap:first img').parent();
2514					$img_wrap.css('height', 'auto').css('max-height', 'none');
2515					$img_wrap.find('img').removeAttr('style').css('opacity', 0); // hide image until everything is created to avoid bad sizing on opening
2516					$wrapper.find('.lcnb_exp_img_wrap .lcnb_img_lb, .lcnb_exp_img_wrap .lcnb_video_lb').removeAttr('style').removeClass('lcnb_expand_trig lcnb_linked_img');
2517				}
2518
2519				// hide news
2520				if(typeof(nav_trigger) == 'undefined') {
2521					$wrapper.find('.lcnb_news').parent().fadeTo(500, 0);
2522					$wrapper.find('.lcnb_news').lcnb_animate_pos('top', '80%', 500);
2523				}
2524				
2525				// show the block
2526				setTimeout(function() {
2527					// change the link target
2528					if(typeof(news.link_target) != 'undefined' && news.link_target) {
2529						$wrapper.find('.lcnb_exp_block a').attr('target', news.link_target);
2530					}
2531					
2532					$wrapper.find('.lcnb_exp_block').stop().animate({'opacity': 1, 'top': 0}, 400);
2533					
2534					setTimeout(function() {
2535						man_expanded_layout( $wrapper.parents('.lcnb_wrap') );
2536					}, 200);
2537				}, 100);
2538				
2539				// show the text
2540				setTimeout(function() {
2541					$wrapper.find('.lcnb_exp_txt').fadeIn(200);
2542				}, 400);
2543			}
2544		}
2545		$lcnb_wrap_obj.delegate('.lcnb_btn_expand, .lcnb_expand_trig', vars.lcnb_event_type, function() {
2546			var vars = $(this).parents('.lcnb_wrap').parent().data('lcnb_vars');
2547			var $news = $(this).parents('.lcnb_news');
2548			var $wrapper = $(this).parents('.lcnb_inner_wrapper');
2549			
2550			vars.lcnb_paused_on_h = false;
2551			stop_slideshow( $(this) );
2552			
2553			// close any social box
2554			if( $wrapper.find('.lcnb_buttons').length) { // if button bar
2555				$wrapper.find('.socials_shown').lcnb_btn_bar_toggle_socials('hide');
2556			}
2557			else { // bottom bar
2558				$wrapper.find('.socials_shown').lcnb_toggle_socials('hide');
2559			}
2560			
2561			var delay = ($wrapper.find('.socials_shown').length) ? 250 : 0; 
2562			setTimeout(function() {
2563				expand_news($wrapper, $news);
2564			}, delay); 
2565			
2566			// check and adjust window offset to show beginning of expanded box
2567			var offset = $wrapper.offset();
2568			if($(window).scrollTop() > (offset.top - 20)) {
2569				$('html, body').animate({'scrollTop' : (offset.top - 10)}, 600, 'linear');	
2570			}
2571		});
2572		
2573		
2574		// advanced images management in news texts
2575		var txt_img_management = function(txt, settings, $news, news_obj) {
2576			var $fake = $('<div class="outer_wrap">'+ txt +'</div>');
2577			
2578			$fake.find('img').each(function(i, v) {
2579				if(!$(this).parent().hasClass('outer_wrap')) {
2580					var $img = $(this);
2581					var $parent = $(this).parent();
2582
2583					$fake.children().each(function() {
2584						if( $(this).find($img).length > 0) {
2585							$parent = $(this);		
2586							return false;
2587						}
2588					});
2589					$(this).remove();
2590					
2591					// get full URL for lightbox
2592					var code = '<div>'+ $img.clone().wrap('<div>').parent().html() +'</div>';
2593					if(settings.lightbox) {	
2594						
2595						// switch to display youtube/soundcloud players
2596						if($news.find('.lcnb_video_lb').length) {
2597							var lb_class = 'lcnb_video_lb';
2598							var lb_url = $news.find('.lcnb_video_lb').attr('data-mfp-src');
2599						}
2600						else {
2601							var lb_class = 'lcnb_img_lb';
2602							var lb_url = get_url_param($img.attr('src'), 'src');	
2603						}
2604	
2605						code += '<div class="'+lb_class+' noSwipe" data-mfp-src="'+ lb_url +'">' + 
2606							'<div class="lcnb_lb_icon"></div><div class="lcnb_lb_overlay"></div>' +
2607						'</div>';
2608					}
2609					$parent.before('<div class="lcnb_exp_body_img"><div>' + code + '</div></div>');
2610				}
2611				else {
2612					var $img = $(this);
2613					var code = '<div>'+ $img.clone().wrap('<div>').parent().html() +'</div>';
2614					
2615					if(settings.lightbox) {	
2616						var img_url = get_url_param($img.attr('src'), 'src');
2617						code += '<div class="lcnb_img_lb noSwipe" data-mfp-src="'+ img_url +'">' + 
2618							'<div class="lcnb_lb_icon"></div><div class="lcnb_lb_overlay"></div>' +
2619						'</div>';
2620					}
2621					$(this).replaceWith('<div class="lcnb_exp_body_img"><div>' + code + '</div></div>');	
2622				}
2623			});
2624			
2625			// clean empty elements in description
2626			$fake.find('*:empty').not('br, img, i, iframe, .lcnb_exp_body_img *').remove();
2627			$fake.find('.lcnb_exp_body_img img').addClass('lcnb_exp_man_img');
2628			
2629			// exp sizes for the news
2630			var exp_img_w = (news_obj.exp_img_w) ? news_obj.exp_img_w : settings.exp_img_w;
2631			var exp_img_h = (news_obj.exp_img_h) ? news_obj.exp_img_h : settings.exp_img_h;
2632			
2633			if(exp_img_h != 225) {
2634				$fake.find('.lcnb_exp_body_img').css('height', exp_img_h);	
2635			}
2636			
2637			if(exp_img_h == 'auto') {
2638				$fake.find('.lcnb_exp_body_img img').css('max-width', '100%').css('min-width', 0).css('max-height', '100%').css('min-height', 0);	
2639			} 
2640			else {
2641				// css centering class	
2642				if(navigator.appVersion.indexOf("MSIE 8.") == -1) {
2643					$fake.find('.lcnb_exp_body_img img').each(function() {
2644						$(this).parent().css('background-image', 'url('+ $(this).attr('src') +')').addClass('lcnb_center_img_bg');;
2645					});
2646				}
2647			}
2648
2649			// sizing class
2650			$fake.find('.lcnb_exp_body_img').addClass('lcnb_exp_img_'+exp_img_w);
2651			
2652			return $fake.html(); 	
2653		}
2654		
2655		
2656		// manage expanded layout and swiftbox height
2657		var man_expanded_layout = function($subj) {
2658			var settings = $subj.parent().data('lcnb_settings');	
2659			var treshold = ($subj.find('.lcnb_exp_txt:first .lcnb_exp_body_img') > 1) ? 450 : 350;
2660			
2661			// responsive class
2662			if( $subj.find('.lcnb_exp_txt').width() < treshold) {
2663				$subj.find('.lcnb_exp_block').addClass('lcnb_exp_mobile');	
2664				var is_mobile = true;
2665			} 
2666			else {
2667				$subj.find('.lcnb_exp_block').removeClass('lcnb_exp_mobile');	
2668				var is_mobile = false;
2669			}
2670			
2671			// adjust main side-image wrapper's height
2672			if( $subj.find('.lcnb_exp_block .lcnb_exp_img_wrap:first').length) {
2673				var $img_wrap = $subj.find('.lcnb_exp_block .lcnb_exp_img_wrap:first img').parent();
2674				$('<img />').bind("load",function(){ 
2675					$img_wrap.css('height', ''); // reset
2676					
2677					// control image height
2678					if(!is_mobile) {
2679						var txt_h = $subj.find('.lcnb_exp_txt').outerHeight(true);
2680						var exp_min_h = get_int( $subj.find('.lcnb_exp_block').css('min-height')) - ($subj.find('.lcnb_exp_block').outerHeight() - $subj.find('.lcnb_exp_block').height());
2681						
2682						var max_h = (txt_h < exp_min_h) ? exp_min_h : txt_h;
2683						var img_h = $img_wrap.find('img').height();
2684						
2685						if(img_h > max_h) {
2686							$img_wrap.css('height', max_h);
2687						} else {
2688							$img_wrap.css('height', img_h);
2689						}
2690					}
2691					else {
2692						$img_wrap.css('height', 'auto');		
2693					}
2694					
2695					// show image after being sized
2696					if( $subj.find('.lcnb_exp_img_wrap img').css('opacity') == 0 ) {
2697						$subj.find('.lcnb_exp_img_wrap img').fadeTo(450, 1);	
2698					}
2699					
2700					$img_wrap.find('img').lcnb_center_img();
2701				}).attr('src', $img_wrap.find('img').attr('src') );	
2702			}
2703			
2704			
2705			// wait 300ms for CSS animations
2706			setTimeout(function() {
2707				// expanded box height
2708				var exp_h = $subj.find('.lcnb_exp_txt').outerHeight(true) + ($subj.find('.lcnb_exp_block ').outerHeight(false) - $subj.find('.lcnb_exp_block ').height());	
2709				
2710				// if image exists
2711				if(is_mobile && typeof($img_wrap) != 'undefined' && $img_wrap.length) {
2712					exp_h = exp_h + $img_wrap.find('img').outerHeight(true);
2713				}
2714				
2715				// boxed news margin to show shadows
2716				var nb_margin = (settings.boxed_news) ? get_int($subj.css('margin-top')) + get_int($subj.css('margin-bottom')) : 0;
2717				
2718				// animate swiftbox wrapper height	
2719				if((exp_h + nb_margin) > settings.height) {	
2720					if( $subj.height() != (exp_h + nb_margin) ) {
2721					
2722						// check to trigger smooth trick
2723						if((exp_h + nb_margin) - settings.height > 70) {
2724							var smooth_timing = Math.round( (((exp_h + nb_margin) - 400) / 30) * 17);
2725							$subj.clearQueue().animate({'height': exp_h + nb_margin}, (400 + smooth_timing));
2726						}
2727						else {
2728							$subj.clearQueue().animate({'height': exp_h + nb_margin}, 400);
2729						}
2730					}
2731				} 
2732				else {
2733					if( $subj.height() != settings.height ) {
2734						$subj.clearQueue().animate({'height': settings.height}, 400);
2735					}
2736				}
2737			}, 300);
2738		}
2739		
2740		
2741		// manage text images loading on expanded mode
2742		var exp_img_loading = function($wrapper) {
2743			var exp_preload = $.makeArray();
2744			
2745			$wrapper.find('.lcnb_exp_txt:first img').each(function(i, v) {
2746            	var $subj = $(this);
2747			   
2748				exp_preload[i] = setTimeout(function() {
2749					$subj.addClass('lcnb_exp_img_preload');
2750		 		}, 120);
2751
2752				$(this).bind("load",function(){ 
2753					clearTimeout(exp_preload[i]);
2754					
2755					if($subj.hasClass('lcnb_exp_man_img')) {
2756						if(this.width < this.height) {$subj.addClass('lcnb_portrait_img');}
2757						else {
2758							
2759							// IE fix on managed images with fixed height
2760							if(navigator.appVersion.indexOf("MSIE") != -1 || navigator.appVersion.indexOf("rv:11.") != -1) {
2761								if( $wrapper.find('.lcnb_exp_body_img').first().css('height') != 'auto' ) {
2762									var wrap_h = get_int($wrapper.find('.lcnb_exp_body_img').first().css('height')); 
2763									var new_w = Math.ceil( (wrap_h * this.width) / this.height);
2764									
2765									$(this).css('width', new_w);	
2766								}
2767							}
2768						}
2769
2770						setTimeout(function() {
2771							if(navigator.appVersion.indexOf("MSIE 8.") != -1) {
2772								$subj.lcnb_center_img();
2773							}
2774							
2775							$subj.parents('.lcnb_exp_body_img').addClass('lcnb_loaded');
2776						}, 400);
2777					}
2778					
2779					if( $(this).hasClass('lcnb_exp_img_preload') ) {
2780						$(this).removeClass('lcnb_exp_img_preload');
2781						man_expanded_layout($wrapper);	
2782					}
2783				});
2784        	});
2785		}
2786		
2787		
2788		// center images in their wrapper
2789		$.fn.lcnb_center_img = function() {
2790			return this.each(function() {
2791				var $subj = $(this);
2792				var $wrap = $(this).parent();
2793				
2794				var w_diff = $subj.width() - $wrap.width();
2795				if(w_diff > 1) {$subj.css('margin-left', (Math.floor(w_diff/2) * -1) );} 
2796				else {$subj.css('margin-left', 0);}
2797				
2798				var h_diff = $subj.height() - $wrap.height();
2799				if(h_diff > 1) {$subj.css('margin-top', (Math.floor(h_diff/2) * -1) );} 
2800				else {$subj.css('margin-top', 0);}
2801			});
2802		}
2803		
2804		
2805		// close expanded news 
2806		var close_expanded = function($wrapper) {
2807			var settings = $wrapper.parents('.lcnb_wrap').parent().data('lcnb_settings');
2808			var vars = $wrapper.parents('.lcnb_wrap').parent().data('lcnb_vars');
2809			vars.lcnb_is_expanded = false;
2810			
2811			//// return to the original swiftbox height
2812			var exp_h = $wrapper.find('.lcnb_exp_block').height();
2813			
2814			// check for smoother trick
2815			if(exp_h - settings.height > 70) {
2816				var timing = 500 + Math.round( (exp_h / 30) * 18);
2817			} else {
2818				var timing = 500;	
2819			}
2820			
2821			$wrapper.parents('.lcnb_wrap').stop().animate({'height': settings.height}, 500);
2822			
2823			// if is scroll expanded items - check and adjust window offset
2824			if(settings.scroll_exp_elem){
2825				var offset = $wrapper.offset();
2826				if($(window).scrollTop() > (offset.top + settings.height - 20)) {
2827					$('html, body').animate({'scrollTop' : (offset.top - 10)}, 600, 'linear');	
2828				}
2829			}
2830			
2831			// hide the block
2832			$wrapper.find('.lcnb_exp_block').clearQueue().animate({ 'top': '-' + (exp_h + 100)  }, timing);
2833			$wrapper.find('.lcnb_exp_block').clearQueue().animate({'opacity': 0}, 500);
2834			
2835			// show news
2836			setTimeout(function() {
2837				$wrapper.find('.lcnb_news').parent().fadeTo(400, 1);
2838				$wrapper.find('.lcnb_news').lcnb_animate_pos('top', 0, 400);
2839			}, 100);
2840			
2841			// clean
2842			setTimeout(function() {
2843				$wrapper.find('.lcnb_news').removeClass('expanded');
2844				$wrapper.find('.lcnb_exp_block').remove();
2845				$(window).trigger('resize'); // avoid bottom part cut-off
2846				
2847				// if autoplay was acting - resume
2848				var settings = $wrapper.parents('.lcnb_wrap').parent().data('lcnb_settings');
2849				if(settings.autoplay && settings.autop_after_exp) {
2850					lcnb_start_slideshow($wrapper.find('.lcnb_news').first(), true);	
2851				}
2852			}, 550);
2853			
2854		}
2855		$lcnb_wrap_obj.delegate('.lcnb_exp_block .lcnb_close', vars.lcnb_event_type, function() {
2856			var $wrapper = $(this).parents('.lcnb_inner_wrapper');
2857			close_expanded($wrapper);
2858		});
2859		
2860
2861		// lightbox integration
2862		$lcnb_wrap_obj.delegate('.lcnb_img_lb:not(.lcnb_expand_trig, .lcnb_linked_img)', 'click ontouchstart', function() {
2863			var vars = $(this).parents('.lcnb_wrap').parent().data('lcnb_vars');
2864			
2865			vars.lcnb_paused_on_h = false;
2866			stop_slideshow( $(this));
2867			
2868			var src = $(this).attr('data-mfp-src');
2869			var $zoom_subj = $(this).parent().find('img');
2870			
2871			$.magnificPopup.open({
2872			  items: {
2873				src: src
2874			  },
2875			  type: 'image',
2876			  mainClass: 'mfp-with-zoom',
2877			  closeOnContentClick: true,
2878			  image: {
2879				verticalFit: true
2880			  },
2881			  zoom: {
2882				enabled: true, 
2883				duration: 300,
2884				easing: 'ease-in-out',
2885				opener: function(element) {
2886				  return $zoom_subj;
2887				}
2888			  }
2889			}, 0);	
2890		});
2891		$lcnb_wrap_obj.delegate('.lcnb_video_lb:not(.lcnb_expand_trig, .lcnb_linked_img)', 'click ontouchstart', function() {
2892			stop_slideshow( $(this));
2893			var src = $(this).attr('data-mfp-src');
2894
2895			$.magnificPopup.open({
2896			  items: {
2897				src: src
2898			  },
2899			  type: 'iframe',
2900			  iframe: {
2901				patterns: {
2902					youtube: {
2903					  src: '//www.youtube.com/embed/%id%?autoplay=1&rel=0'
2904					}
2905				}
2906			  }
2907			}, 0);
2908		});
2909		
2910		
2911		// touchswipe integration
2912		var lcnb_touchswipe = function(changing_layout) {
2913			if(typeof(swipe) != 'function') {return false;}
2914			
2915			if(typeof(changing_layout) != 'undefined') {
2916				$lcnb_wrap_obj.find('.lcnb_touchswipe .lcnb_inner_wrapper').swipe("destroy");
2917			}
2918			
2919			// vertical layout
2920			$lcnb_wrap_obj.find('.lcnb_vertical.lcnb_touchswipe .lcnb_inner_wrapper').swipe( {
2921				swipe:function(event, direction) {
2922					stop_slideshow( $(this) );
2923	
2924					if(direction == 'up') {
2925						lcnb_news_slide($lcnb_wrap_obj, 'next');
2926					}
2927					if(direction == 'down') {
2928						lcnb_news_slide($lcnb_wrap_obj, 'prev');	
2929					}
2930				},
2931				threshold: 80,
2932				allowPageScroll: "horizontal"
2933			});
2934			
2935			// horizontal layout
2936			$lcnb_wrap_obj.find('.lcnb_horizontal.lcnb_touchswipe .lcnb_inner_wrapper').swipe( {
2937				swipe:function(event, direction) {
2938					stop_slideshow( $(this) );
2939	
2940					if(direction == 'right') {
2941						lcnb_news_slide($lcnb_wrap_obj,'prev');
2942					}
2943					if(direction == 'left') {
2944						lcnb_news_slide($lcnb_wrap_obj,'next');	
2945					}
2946				},
2947				threshold: 80,
2948				allowPageScroll: "vertical"
2949			});	
2950		}
2951		
2952		
2953		// parseInt function with fallback for IE8
2954		var get_int = function(val) {
2955			var raw = parseInt( val );
2956			return (isNaN(raw)) ? 0 : raw;
2957		}
2958
2959		
2960		// animate object position
2961		$.fn.lcnb_animate_pos = function(side, val, duration, easing) {
2962			return this.each(function() {
2963				var $obj = $(this);
2964				if(typeof(easing) == 'undefined') {easing = 'swing';}
2965				
2966				$obj.animate({lcnbSlide : $obj.lcnb_get_pos(side)}, 0).stop().animate({lcnbSlide : val}, {	
2967					easing: easing,
2968					duration: duration,
2969					step: function(now, fx) {
2970						$obj.lcnb_set_pos(side, now);
2971					}
2972				});
2973			});
2974		}
2975
2976
2977		// set object position for CSS2 or CSS3
2978		$.fn.lcnb_set_pos = function(side, val) {
2979			return this.each(function() {
2980				var $obj = $(this);
2981				var vars = $obj.parents('.lcnb_wrap').parent().data('lcnb_vars');
2982				
2983				if(typeof(vars) == 'undefined') {
2984					var vars = $lcnb_wrap_obj.data('lcnb_vars');
2985				}
2986				
2987				if(vars.lcnb_css3_browser) {
2988					if(side == 'left') {
2989						$obj.css('-webkit-transform', 'translate3d('+ val +'px, 0px, 0px)');	
2990						$obj.css('transform', 'translate3d('+ val +'px, 0px, 0px)');	
2991					} else {
2992						$obj.css('-webkit-transform', 'translate3d(0px, '+ val +'px, 0px)');	
2993						$obj.css('transform', 'translate3d(0px, '+ val +'px, 0px)');		
2994					}
2995				}
2996				else {
2997					$obj.css(side, val);
2998				}
2999			});
3000		}
3001		
3002
3003
3004		// get object position for CSS2 or CSS3
3005		$.fn.lcnb_get_pos = function(side) {
3006			var $obj = this;
3007			var val = 0;
3008			var vars = $obj.parents('.lcnb_wrap').parent().data('lcnb_vars');
3009			
3010			if(typeof(vars) == 'undefined') {
3011				var vars = $lcnb_wrap_obj.data('lcnb_vars');
3012			}
3013			
3014			if(vars.lcnb_css3_browser) {
3015				var matrix = $obj.css("-webkit-transform") || $obj.css("transform");			 
3016				if(matrix == 'none') {return 0;}
3017				
3018				var values = matrix.split('(')[1];
3019				values = values.split(')')[0];
3020				values = values.split(',');
3021				
3022				if(side == 'left') {
3023					val = Math.round(values[4]);	
3024				} else {
3025					val = Math.round(values[5]);	
3026				}
3027			}
3028			else {
3029				if(side == 'left') {
3030					val = parseFloat( $obj.css('left'));	
3031				} else {
3032					val = parseFloat( $obj.css('top'));	
3033				}
3034				
3035				if(isNaN(val)) {return 0;}
3036			}
3037
3038			return val;
3039		}
3040		
3041		
3042		// given an url - get a specific parameter or return original url
3043		var get_url_param = function(url, param) {
3044			var results = new RegExp('[\?&]' + param + '=([^&#]*)').exec(url);
3045			if (results == null){
3046			   return url;
3047			}else{
3048			   return decodeURIComponent(results[1]) || 0;
3049			}
3050		}
3051		
3052		
3053		// check if browser supports CSS property
3054		var CSS3_transform = function() {
3055		  if(
3056		  	navigator.appVersion.indexOf("MSIE") != -1 ||
3057			navigator.appVersion.indexOf("rv:11.") != -1 ||
3058			navigator.userAgent.indexOf("Opera") != -1 ||
3059			(navigator.appVersion.indexOf("Safari") != -1 && (navigator.appVersion.indexOf("Version/5.") != -1 || navigator.appVersion.indexOf("Version/4.") != -1))
3060		  ) {return false;}
3061		  
3062		  var $obj = $('<div/>');
3063		  $obj.css('-webkit-transform', 'translate3d(100px, 0px, 0px)');	
3064		  $obj.css('transform', 'translate3d(100px, 0px, 0px)');	
3065		  
3066		  var matrix = $obj.css("-webkit-transform") || $obj.css("transform");
3067		  			 
3068		  return (matrix == 'none') ? false : true;
3069		}
3070		  
3071		
3072		// check if mobile browser
3073		var is_mobile = function() {
3074			if( /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|
3074sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent) ) 
3075			{ return true;}
3076			else { return false; }
3077		}
3078
3079
3080		////////////////////////////////////////////
3081		
3082		// next news - click event
3083		$('.lcnb_next').unbind('click');
3084		$lcnb_wrap_obj.delegate('.lcnb_next:not(.lcnb_disabled)', 'click', function() {
3085			var $subj = $(this);
3086			if(typeof(lcnb_one_click) != 'undefined') {clearTimeout(lcnb_one_click);}
3087			
3088			lcnb_one_click = setTimeout(function() {
3089				stop_slideshow($subj);
3090				lcnb_news_slide($lcnb_wrap_obj, 'next');	
3091			}, 5);
3092		});
3093
3094
3095		// prev news - click event
3096		$('.lcnb_prev').unbind('click');
3097		$lcnb_wrap_obj.delegate('.lcnb_prev:not(.lcnb_disabled)', 'click', function() {
3098			var $subj = $(this);
3099			if(typeof(lcnb_one_click) != 'undefined') {clearTimeout(lcnb_one_click);}
3100			
3101			lcnb_one_click = setTimeout(function() {
3102				stop_slideshow($subj);
3103				lcnb_news_slide($lcnb_wrap_obj, 'prev');	
3104			}, 5);
3105		});
3106		
3107		////////////////////////////////////////////
3108		
3109		
3110		// debounce resize to trigger only once
3111		var lcnb_debouncer = function($,cf,of, interval){
3112			var debounce = function (func, threshold, execAsap) {
3113				var timeout;
3114				
3115				return function debounced () {
3116					var obj = this, args = arguments;
3117					function delayed () {
3118						if (!execAsap) {func.apply(obj, args);}
3119						timeout = null;
3120					}
3121				
3122					if (timeout) {clearTimeout(timeout);}
3123					else if (execAsap) {func.apply(obj, args);}
3124					
3125					timeout = setTimeout(delayed, threshold || interval);
3126				};
3127			};
3128			jQuery.fn[cf] = function(fn){ return fn ? this.bind(of, debounce(fn)) : this.trigger(cf); };
3129		};
3130		lcnb_debouncer(jQuery,'lcnb_smartresize', 'resize', 100);
3131		
3132		// responsive behaviors
3133		$(window).lcnb_smartresize(function() {
3134			var vars = $lcnb_wrap_obj.data('lcnb_vars');
3135			var settings = $lcnb_wrap_obj.data('lcnb_settings');
3136			
3137			if(!vars.lcnb_is_playing || settings.slideshow_time >= 50) {
3138				dynamic_layout();
3139				size_boxes();
3140				news_img_adjust();
3141				
3142				// perform only if wrapper width is different and not expanded
3143				if(!vars.lcnb_is_expanded && vars.lcnb_wrap_width != $lcnb_wrap_obj.width()) {
3144					vars.lcnb_wrap_width = $lcnb_wrap_obj.width();		
3145					
3146					news_offset($lcnb_wrap_obj);
3147					news_txt_shortening();
3148				}
3149				
3150				// if is expanded
3151				if(vars.lcnb_is_expanded) {
3152					man_expanded_layout( $lcnb_wrap_obj.find('.lcnb_wrap') );
3153					
3154					if(navigator.appVersion.indexOf("MSIE 8.") != -1) {
3155						$lcnb_wrap_obj.find('.lcnb_exp_man_img').lcnb_center_img();
3156					}
3157				}
3158			}
3159		});
3160		
3161		
3162		// debounce scroll to trigger only once
3163		lcnb_debouncer(jQuery,'lcnb_smartscroll', 'scroll', 50);
3164		
3165		// expanded news - scroll events
3166		$(window).lcnb_smartscroll(function() {
3167			var settings = $lcnb_wrap_obj.data('lcnb_settings');	
3168			
3169			if($lcnb_wrap_obj.find('.lcnb_exp_block').length && settings.scroll_exp_elem) {
3170				var $subj = $lcnb_wrap_obj.find('.lcnb_exp_block').first();
3171				var offset = $subj.offset();
3172				
3173				if($subj.height() > settings.height + 30 && $(window).scrollTop() > (offset.top + 30)) {
3174					
3175					// for the closing button
3176					if($(window).scrollTop() < (offset.top + ($subj.height() - 35)) ) {
3177						var margin_top = Math.floor( $(window).scrollTop() - offset.top - 7); 
3178						$subj.find('.lcnb_close').css('margin-top', margin_top);
3179					} 
3180					
3181					// for the image
3182					if($(window).scrollTop() < (offset.top + ($subj.height() - ($subj.find('.lcnb_exp_img_wrap' ).height() - 25) )) ) {
3183						if($subj.hasClass('lcnb_exp_mobile')) {
3184							$subj.find('.lcnb_exp_img_wrap').css('margin-top', 0);
3185						}
3186						else {
3187							var margin_top = Math.floor( $(window).scrollTop() - offset.top); 
3188							$subj.find('.lcnb_exp_img_wrap').css('margin-top', margin_top);
3189						}
3190					}
3191				} 
3192				else {
3193					$subj.find('.lcnb_close, .lcnb_exp_img_wrap').css('margin-top', 0);
3194				}
3195			}
3196		});
3197
3198
3199		//////////////////////////////////////////
3200		
3201		// script and styles loader
3202		var assets_loader = function() {
3203			
3204			// retrieve basepath
3205			if( typeof(lcnb_script_basepath) == 'undefined' ) {
3206				if(settings.script_basepath) { 
3207					lcnb_script_basepath = settings.script_basepath;
3208				} 
3209				else {
3210					$('script').each(function(index, element) {
3211                        var src = $(this).attr('src');
3212						if( typeof(src) != 'undefined' && src.indexOf('swift-box') != -1 ) {
3213							var src_arr = src.split('/');
3214							var lastEl = src_arr[src_arr.length - 1];	
3215							lcnb_script_basepath = src.replace(lastEl, '');
3216						}
3217                    });	
3218				}
3219			}
3220			
3221			// load theme
3222			if( typeof(lcnb_loaded_themes) == 'undefined' ) {lcnb_loaded_themes = $.makeArray();}
3223			if( $.inArray(settings.theme, lcnb_loaded_themes) == -1 ) {
3224				lcnb_loaded_themes.push(settings.theme);
3225				$('head').append('<link rel="stylesheet" href="'+ lcnb_script_basepath +'themes/'+ settings.theme +'.css">');	
3226			}
3227			
3228			//// load scripts
3229			if( typeof(lcnb_loaded_scripts) == 'undefined' ) {lcnb_loaded_scripts = $.makeArray();}
3230			
3231			// magnific popup
3232			if(settings.lightbox && $.inArray('magnific_popup', lcnb_loaded_scripts) == -1 && !eval("typeof magnificPopup == 'function'")) {
3233				lcnb_loaded_scripts.push('magnific_popup');
3234				$('head').append('<link rel="stylesheet" href="'+ lcnb_script_basepath +'js_assets/magnific-popup/magnific-popup-style.css">');
3235				$('body').append('<script src="'+ lcnb_script_basepath +'js_assets/magnific-popup/magnific-popup.min.js" type="text/javascript"></script>');	
3236			}
3237			
3238			// touchswipe
3239			if(settings.touchswipe && $.inArray('touchswipe', lcnb_loaded_scripts) == -1 && !eval("typeof swipe == 'function'")) {
3240				lcnb_loaded_scripts.push('touchswipe');
3241				$('body').append('<script src="'+ lcnb_script_basepath +'js_assets/TouchSwipe/jquery.touchSwipe.min.js" type="text/javascript"></script>');	
3242			}
3243			
3244			return true;
3245		}
3246		
3247		//////////////////////////////////////////
3248		//////////////////////////////////////////
3249		
3250		// set the wrapper width for responsive behavior
3251		vars.lcnb_wrap_width = $lcnb_wrap_obj.width();
3252		
3253		// load styles and scripts
3254		var result = assets_loader();
3255		
3256		//// Initialize the news box - create the html structure
3257		parse_inline_news();
3258		
3259		//// CLASSES
3260		
3261		// theme class
3262		var theme_class = 'lcnb_'+ settings.theme +'_theme';
3263		
3264		// nav_arrows class
3265		if(!settings.nav_arrows) {var cmd_class = '';}
3266		else {
3267			var cmd_class = 'lcnb_has_cmd lcnb_'+ settings.nav_arrows +'_cmd';
3268			
3269			if(settings.nav_arrows.match(/top/g)) {cmd_class += ' lcnb_top_cmd';}
3270			if(settings.nav_arrows.match(/bottom/g)) {cmd_class += ' lcnb_bottom_cmd';}
3271		}
3272
3273		// source logos class
3274		var src_logo_class = (!settings.show_src_logo || settings.layout == 'horizontal') ? '' : 'lcnb_src_logo'; 
3275		
3276		// boxed news class
3277		var boxed_class = (!settings.boxed_news) ? 'lcnb_uniblock' : 'lcnb_boxed';
3278		
3279		// touchswipe class
3280		var ts_class = (!settings.touchswipe) ? '' : 'lcnb_touchswipe';
3281		
3282		var wrap_classes = theme_class +' '+ cmd_class +' '+ ts_class +' '+ src_logo_class +' '+ boxed_class;
3283		
3284		///////////////////////////////
3285		// structure init
3286		var structure = '<div class="lcnb_wrap lcnb_loading lcnb_'+settings.layout+' '+ wrap_classes +'" style="height: '+settings.height+'px;">';
3287		
3288		// command box
3289		if(settings.nav_arrows) {
3290			var disabled_class = (!settings.carousel) ? 'lcnb_disabled' : '';
3291			structure += '<div class="lcnb_cmd"><div class="lcnb_prev '+ disabled_class +'"><span></span></div><div class="lcnb_next"><span></span></div></div>';	
3292		}
3293		
3294		// inner wrapper and inner 
3295		structure += '<div class="lcnb_inner_wrapper"><div class="lcnb_inner" style="height: '+settings.height+'px;"></div></div>';
3296		
3297		$lcnb_wrap_obj.html(structure + '</div>');
3298		
3299		//////////////////////////////
3300		
3301		// CSS fixes for IE8 - 9
3302		if(typeof(lcnb_IE_css_appended) == 'undefined' && (navigator.appVersion.indexOf("MSIE 8.") != -1 || navigator.appVersion.indexOf("MSIE 9.") != -1)) {
3303			lcnb_IE_css_appended = true;
3304			$('head').append('<style>.lcnb_btm_bar .lcnb_social_box:after, .lcnb_exp_data .lcnb_social_box:after, .lcnb_top_bar .lcnb_social_box:before {display: none !important;</style>');		
3305		}
3306		
3307		// event type definition for mobile
3308		if(is_mobile()) {vars.lcnb_event_type = 'tap';}
3309		
3310		//// browser test against CSS3 3D translation
3311		// if carousel, autoplay and slideshow_time < 50 set to false to avoid CSS3 bug
3312		if((settings.carousel && settings.autoplay && settings.slideshow_time <= 50) || settings.max_news > 10) {
3313			vars.lcnb_css3_browser = false;	
3314		} else {
3315			vars.lcnb_css3_browser = CSS3_transform();
3316		}
3317
3318		///////////////////////////////
3319
3320		// execution
3321		setTimeout(function() {
3322			dynamic_layout();
3323			handle_sources();
3324		}, 50);
3325
3326		return this;
3327	};	
3328		
3329	////////////////////////////////////////////
3330	
3331	// init
3332	$.fn.lc_swift_box = function(lcnb_settings) {
3333
3334		// destruct
3335		$.fn.lcsb_destroy = function() {
3336			var $elem = $(this);
3337			
3338			// clear slideshow interval
3339			var vars = $elem.data('lcnb_vars');
3340			if(vars.lcnb_is_playing) {clearInterval(vars.lcnb_is_playing); }
3341			$elem.find('.lcnb_inner').stop(); // if was moving - clear animation
3342			
3343			// destroy touchswipe
3344			var settings = $elem.data('lcnb_settings');
3345			if(settings.touchswipe) {$elem.find('.lcnb_touchswipe .lcnb_inner_wrapper').swipe("destroy");}
3346			
3347			// undelegate events
3348			$elem.undelegate('.lcnb_inner_wrapper', 'mouseenter mouseleave');
3349			$elem.undelegate('.lcnb_social_trigger', vars.lcnb_event_type);
3350			$elem.undelegate('.lcnb_btn_expand', vars.lcnb_event_type);
3351			$elem.undelegate('.lcnb_exp_block .lcnb_close', vars.lcnb_event_type);
3352			$elem.undelegate('.lcnb_img_lb, .lcnb_video_lb', 'click ontouchstart');
3353			$elem.find('.lcnb_next, .lcnb_prev').undelegate('click');
3354			
3355			// remove stored data
3356			$elem.removeData('lcnb_vars');
3357			$elem.removeData('lcnb_settings');
3358			$elem.removeData('lc_swiftbox');
3359			
3360			return true;
3361		};	
3362		
3363		
3364		// pagination (next/prev)
3365		$.fn.lcsb_paginate = function(direction) {
3366			var $elem = $(this);
3367
3368			var vars = $elem.data('lcnb_vars');	
3369			var settings = $elem.data('lcnb_settings');
3370			
3371			if(typeof(vars.lcnb_is_playing) != 'undefined') {
3372				clearInterval(vars.lcnb_is_playing);
3373			}
3374			vars.lcnb_is_playing = null;
3375
3376			lcnb_news_slide($elem, direction);
3377			return true;
3378		};
3379		
3380		
3381		// start slideshow
3382		$.fn.lcsb_start_slideshow = function() {
3383			var $elem = $(this);
3384			
3385			var vars = $elem.data('lcnb_vars');	
3386			var settings = $elem.data('lcnb_settings');	
3387
3388			// wait until animation stops
3389			vars.lcnb_is_waiting_for_anim = setInterval(function() {
3390				if(!vars.lcnb_is_moving) {
3391					var delay = (settings.slideshow_time > 1000) ? 1000 : settings.slideshow_time;
3392					
3393					setTimeout(function() {
3394						lcnb_start_slideshow($elem);
3395					}, delay);
3396					
3397					clearInterval(vars.lcnb_is_waiting_for_anim);		
3398				}
3399			}, 5);
3400
3401			return true;
3402		};
3403		
3404		
3405		// stop the slideshow
3406		$.fn.lcsb_stop_slideshow = function() {
3407			var $elem = $(this);
3408
3409			var vars = $elem.data('lcnb_vars');	
3410			var settings = $elem.data('lcnb_settings');
3411			
3412			clearInterval(vars.lcnb_is_playing);
3413			vars.lcnb_is_playing = null;
3414			
3415			if(typeof(vars.lcnb_is_waiting_for_anim) != 'undefined') {
3416				clearInterval(vars.lcnb_is_waiting_for_anim);	
3417			}
3418			
3419			return true;
3420		};
3421
3422
3423		// construct
3424		return this.each(function(){
3425            // Return early if this element already has a plugin instance
3426            if ( $(this).data('lc_swiftbox') ) { return $(this).data('lc_swiftbox'); }
3427			
3428            // Pass options to plugin constructor
3429            var swift_box = new lc_SwiftBox(this, lcnb_settings);
3430			
3431            // Store plugin object in this element's data
3432            $(this).data('lc_swiftbox', swift_box);
3433        });
3434	};			
3435	
3436})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.