/**
 * siemoneitnews.js
 */

var newsOpen = false;

$(document).ready(function() {
	
	/**
	 * News
	 */
	if ($('#news').length) {
		
		var newslistScrollpane = $('#news .scrollNewslist').jScrollPane({showArrows: true, animateScroll: true, maintainPosition: false}).data('jsp');
		
		$('#newsActions .next').live('click', function() {
			newslistScrollpane.scrollByY(parseInt(100));
	        return false;

		});
		$('#newsActions .prev').live('click', function() {
			newslistScrollpane.scrollByY(parseInt(-100));
	        return false;
		});
		
		$('span.readAhead a').click(function() {
			var data = {
				'useHelper': 'Siemoneitnews', 
				'cmsBox': '2'
			};
			$.post($(this).attr('href'), data, function(data, textStatus) {
				if (textStatus == 'success' && data['error'] == 0) {
					$('#articleBox').html(data['response']);
					if (newsOpen == false) {
						$('#news, #newsActions').animate({
							right: '+=385'
						}, 500, function() {
							newsOpen = true;
							$('#articleBox').show();
							if ($('#articleBox .article_content').height() > 140) {
								$('#articleBox .articleScrollBox').jScrollPane({showArrows: true});
							}
						});
					} else {
						if ($('#articleBox .article_content').height() > 140) {
							$('#articleBox .articleScrollBox').jScrollPane({showArrows: true});
						}
					}
				}
			}, 'json');

			return false;
		});
		
		$('#closeArticle').live('click', function() {
			$('#articleBox').hide();
			$('#news, #newsActions').animate({
				right: '-=385'
			}, 500, function() {
				newsOpen = false;
			});
			return false;
		});
	}
	
});
