// JavaScript Document
var other = {
	initNews : function(){
		this.newsBlock = $('#news-block');
		
		if(this.newsBlock.is('.complete')) return this;
		
		this.newsWrap = $('#news-wrapper');
		this.newsUl = $('#news-tabs');
		this.newsTabs = $('#news-tabs > li');
		this.newsClose = $('a.news-close', this.newsBlock);
		this.newsToggle = $('a#news-toggle', this.newsBlock);

		this.newsTabs.children('a').click(function(e){
			$(this.parentNode).active(true).siblings('.first').active(false);
			e.preventDefault();
			e.stopPropagation();
		});
		
		var timeout = 5e3, timer, 
		
		startTimer = function(){
			timer = setInterval(function(){
				if(!other.newsTabs.filter('.first').next().children('a').click().length) other.newsTabs.filter(':first').children('a').click();
			}, timeout);
		}, 
		
		stopTimer = function(){
			clearInterval(timer);
		};
		
		startTimer();
		this.newsBlock.hover(stopTimer, startTimer);
		
		//FOLDING
		other.newsWrap.css({
			height: function(){ return $(this.parentNode).height(); },
			width: function(){ return $(this.parentNode).width(); }
		});
		
		var foldS = {width:85, height:22}, duration = 500, w, h,
			fold = function(now){
					w = w || other.newsBlock.width();
					h = h || other.newsBlock.height();
				if(ie6 || (typeof now == 'boolean' && now)){
					other.newsWrap.add(other.newsBlock).stop(true).css(foldS);
					other.newsUl.stop(true).fadeTo(0, 0);
					other.newsToggle.stop(true).show().fadeTo(0, 1).removeClass('open');//.ieClearType();
				}else{
					other.newsWrap.add(other.newsBlock).stop(true).animate(foldS, duration);
					other.newsUl.stop(true).delay(duration).fadeTo(duration * 0, 0);
					other.newsBlock.css('overflow', 'visible');
					other.newsToggle.stop(true).delay(duration).queue(function(){ $(this).show().dequeue(); }).fadeTo(0, 1, function(){ $(this).removeClass('open')/*.ieClearType()*/; });
				}
				$.cookie('foldnews', 'false');
			},
			unfold = function(){
				if(ie6){
					other.newsWrap.add(other.newsBlock).stop(true).css({width: w, height: h});
					other.newsUl.fadeTo(0, 1, function(){$(this).ieClearType();});
					other.newsToggle.fadeTo(0, 0).hide().addClass('open');
				}else{
					other.newsWrap.add(other.newsBlock).stop(true).animate({width: w, height: h}, duration);
					other.newsUl.stop(true).fadeTo(duration * 0, 1, function(){$(this)/*.ieClearType()*/;});
					other.newsBlock.css('overflow', 'visible');
					other.newsToggle.stop(true).fadeTo(duration * .5, 0, function(){ $(this).hide().addClass('open'); });
				}
				$.cookie('foldnews', 'true');
			}
		other.newsClose.click(fold);
		other.newsToggle.click(unfold);
		if($.cookie('foldnews') == "false") fold(true);
		this.newsBlock.addClass('complete');
		return this;
	}
};

$(document).ready(function(){
	other.initNews();
});


