/* --------------------------------------------------
	News
-------------------------------------------------- */
/* Load JSONP */
(function($){
$(function(){
	if(!document.getElementById('headlineNews')){
		return;
	}
	$.ajax({
		type: 'GET',
		url: '/TEMPLATE/XML/news_data.xml',
		dataType: 'xml',
		success : newsCallback
	});
});
})($jq);

/* Callback */
function newsCallback(dataXml){
(function($){
	var $items = $(dataXml).find('itemlist item');

	var $headlineNews = $('#headlineNews');
	var _codeList = [];
	var _count = 0;

	var _code = "";
	$items.each(function(index, item){
		if(index%3 == 0){
			_code = "";
		}
		_code += '<p><a href="' + item.getAttribute('href') + '" target="' + item.getAttribute('target') + '">' + item.getAttribute('date') + ' ' + item.getAttribute('text') + '</a></p>';
		
		if(index%3 == 2 || index == $items.length-1){
			_codeList.push(_code);
		}
	});
	$headlineNews.html(_codeList[_count]);
	newsLoop();

	function newsLoop(){
		setTimeout(function(){
			$headlineNews.fadeOut(250, function(){
				_count++;
				_count = _count >= _codeList.length ? 0 : _count;
				$headlineNews.html(_codeList[_count]);
				$headlineNews.fadeIn(250);
				newsLoop();
			});
		}, 8000);
	}
})($jq);
}

/* cycle */
$(function() {
	$('#tncVisualSec a:first img').fadeIn(1000, function() {
		$('#tncVisualSec').after('<ul id="tncVisualNav" class="clearfix">').cycle({ 
			fx:               'fade',
			speed:             1000,
			timeout:           3000,
			after:             onAfter,
			pager:            '#tncVisualNav',
			pause:             true,
			pauseOnPagerHover: true,
			pagerEvent:       'mouseover',
			
			// callback fn that creates a thumbnail to use as pager anchor 
			pagerAnchorBuilder:function(idx, slide){
				return'<li><a href="#"></a></li>';
			}
		});
	});
});

function onAfter() {
	$('#output').html("Current anchor: " + this.href);
}


