
	newscounter = {
		
		activeItem: 0,
		
		init: function() {
			this.el = jQuery('div.news-list-container').get(0); 
			this.ct = jQuery('div.news-list-counter').get(0);  
			this.items = jQuery('div.news-list-item', this.el).get();
			
			jQuery(this.el).bind('mouseenter', {fn: 'clearTimer', scope: this}, this.onEvent);
			jQuery(this.ct).bind('mouseenter', {fn: 'clearTimer', scope: this}, this.onEvent);
			jQuery(this.el).bind('mouseleave', {fn: 'setTimer', scope: this}, this.onEvent);
			jQuery(this.ct).bind('mouseleave', {fn: 'setTimer', scope: this}, this.onEvent);
			
			this.buildCounter();
			this.setTimer();			
		},
		
		onEvent: function(e) {
			var sc = e.data.scope;
			var fn = e.data.fn;
			sc[fn] && sc[fn].call(sc, e);
		},
		
		buildCounter: function() {
			//var len = this.items.length, html = [], cls;
			var len = 3, html = [], cls;
			
			for (var i=0; i < len; i++) {
				cls = i ? '' : 'news-list-counter-active';
				html.push('<a rel="item-', i, '" href="javascript: void(0);" class="', cls,'">', i+1, '</a>');	
				i && jQuery(this.items[i]).css({
					'display': 'none',
					'opacity': '0'
				});
			}
			
			jQuery(this.ct).html(html.join(''));
			jQuery('a', this.ct).bind('click', {fn: 'onClick', scope: this}, this.onEvent);
		},
		
		setTimer: function() {
			var t = this;
			this.clearTimer();
			this.timer = setInterval(function() {
				t.activateNext.call(t);
			}, 5000);
		},
		
		clearTimer: function() {
			if (this.timer) {
				clearInterval(this.timer);
			}
		},
		
		onClick: function(e) {
			var n = e.target;
			if (n.tagName.toLowerCase() != 'a') {
				n = jQuery('a', n).get(0);
			}
			var rel = jQuery(n).attr('rel');
			if (rel) {
				rel = rel.replace(/item-/, '');
			}
			this.activateItem(rel);
		},
		
		activateNext: function() {
			var pos = (this.activeItem >= this.items.length-1) ? 0 : this.activeItem+1;
			this.activateItem(pos);
		},
		
		activateItem: function(pos) {
			if (pos == this.activateItem) {
				return;
			}
			jQuery('a[rel=item-'+this.activeItem+']').removeClass('news-list-counter-active');
			jQuery('a[rel=item-'+pos+']').addClass('news-list-counter-active');
			var ac = this.items[this.activeItem];
			var ne = this.items[pos];
			this.activeItem = parseInt(pos, 10);
			var t = this;
			jQuery(ac).fadeTo(500, 0.00,
				function() {
					jQuery(ac).css('display', 'none');
					jQuery(ne).css('display', 'block').fadeTo(500 ,1);
					t.setTimer();
				}
			);	

		}
	};

	jQuery(document).ready(function () {
		newscounter.init();
		// jQuery(document).pngFix();
	});
