var newsClass = function() {
	var self = this;
	
	this.slider = function() {
		if ($('#news-boxes-content').children().length > 1 ) {
			$('#news-boxes-content').cycle({
				fx:'scrollHorz',
				timeout:0,
				speed:800,
				next:'#news-boxes-right',
				prev:'#news-boxes-left',
				nowrap:1,
				after: function (curr, next, opts) {
					var index = opts.currSlide;
					if (index == 0) {
						$('#news-boxes-left').fadeOut(200);
					} else {
						$('#news-boxes-left').fadeIn(200);
					}

					if (index == (opts.slideCount - 1)) {
						$('#news-boxes-right').fadeOut(200);
					} else {
						$('#news-boxes-right').fadeIn(200);
					}
				},
				onInit: function (curr, next, opts) {
					alert(opts);
				}
			});
		} else {
			$('#news-boxes-left').hide();
			$('#news-boxes-right').hide();
		}
	};
	
	this.footertab = function() {
		// click event
		$('#footer-tabs .csc-default h1').click(function() {
			
			//avoid ie8 problems
			if($.browser.msie === true && jQuery.browser.version == '8.0')
				news.footertabAnimationIE($(this).parents('.csc-default'));
			else
				news.footertabAnimation($(this).parents('.csc-default'));
				
		});
	};
	
	this.footertabAnimationIE = function(element) {
		
		var status = ($(element).hasClass('open')) ? 'close' : 'open';
		
		$('#footer-tabs .csc-default.open').css({
			marginTop: '-48px',
			height: '42px'
		}).removeClass('open');
		
		if(status == 'close')
		{			
			$('#footer-tabs .csc-default').css({
				marginTop: '-49px',
				height:	'42px'
			});
			
			$(element).css({
				marginTop: '-48px',
				height: '42px'
			});
		}
		else
		{
			$('#footer-tabs .csc-default').css({
				marginTop: '-48px',
				height:	'42px'
			});
			
			$(element).css({
				marginTop: '-225px',
				height: '219px'
			});
		}
		
		if(status == 'open') $(element).addClass('open');
		else $(element).removeClass('open');
	};
	
	this.footertabAnimation = function(element) {
		// close all tabs before
		$('#footer-tabs .csc-default.open').animate({
			marginTop: '-48px',
			height: '42px'
		}, 200, function() {
			$(this).removeClass('open');
		});
				
		var status = ($(element).hasClass('open')) ? 'close' : 'open';
		
		$(element).animate({
			marginTop: (status == 'open') ? '-225px' : '-48px',
			height: (status == 'open') ? '219px' : '42px'
		}, 200, function() {
			if(status == 'open') $(this).addClass('open');
			else $(this).removeClass('open');
		});		
	};
	
};

var news = new newsClass();

$(function() {
	news.slider();
	news.footertab();
});
