// JavaScript Document

function ReplaceChar(TPstring){
	for (i=1; i<256; i++){
		var re = new RegExp('&amp;#' + i + ';', 'gi');
		TPstring = TPstring.replace(re, String.fromCharCode(i))
	}
		return TPstring;
}
	var TellerCount = 0;
	var _TEMPcontent ='';
	var _StringContentCount=0;
	
	function NextTeller(){
		
		var callbackCnt = 1;

		$('.TPTells1 table').fadeOut('fast', function () {
			
			if (callbackCnt == 1) {
								
				_TEMPcontent = $('#ShopMainLayOutTable #TEMPcontent .item').eq(TellerCount)
		
				$('.TPTells1 .emne div').html(_TEMPcontent.find('.title').html());
				$('.TPTells1 .description div').html(_TEMPcontent.find('.description').html());
				$('.TPTells1 .authorLink').attr('href',_TEMPcontent.find('.descriptionLINK').html());
				$('.TPTells1 .stars img').attr('src','http://casara.dk/images/template/small-star'+ _TEMPcontent.find('.stars').html() +'.png');

				var authorNameSplit = _TEMPcontent.find('.author').html().split(" ")
				$('.TPTells1 .author .authorname').html(authorNameSplit[0])
				
				var authorDATESplit = _TEMPcontent.find('.authorDATE').html().split(" ")

				$('.TPTells1 .authordate').html(authorDATESplit[1] +'&nbsp;'+ authorDATESplit[2] +'&nbsp;'+ authorDATESplit[3]);
		
				TellerCount++

				if (_StringContentCount-1 == TellerCount){TellerCount=0;}
			}
			
		$('.TPTells1 table').fadeIn('fast');
			
			callbackCnt++;
		
		});

	}



$(document).ready(function(){

	var _StringContent='';
	
	$.ajax({
		type: 'GET',
		dataType: 'xml',
	    url: '/js/tp.asp',
	    success: function(data) {

			$(data).find('item').each(function(){
				if ($(this).find('tpstars').text() >= 4){
		  		_StringContent += '<hr><div class="item"><span class="title">'+ ReplaceChar($(this).find('title').text()) +'</span><span class="description">'+ ReplaceChar($(this).find('description').text()) +'</span><span class="descriptionLINK">'+ ReplaceChar($(this).find('link').text()) +'</span><span class="stars">'+ ReplaceChar($(this).find('tpstars').text()) +'</span><span class="author">'+ ReplaceChar($(this).find('tpauthorname').text()) +'</span><span class="authorCITY">'+ ReplaceChar($(this).find('tpcity').text()) +'</span><span class="authorDATE">'+ ReplaceChar($(this).find('pubDate').text()) +'</span></div><hr>';
				_StringContentCount++
				}
			})

			$('#ShopMainLayOutTable .TPTells1').after('<div id="TEMPcontent" style="display:none;"></div>')
			$('#ShopMainLayOutTable #TEMPcontent').html(_StringContent)

			NextTellerTimer = setInterval('NextTeller()',4000);
			
	 	}
	});

	$(".TPTells1").hover(
	  function () {
		clearInterval(NextTellerTimer);
	  },
	  function () {
		NextTellerTimer = setInterval('NextTeller()',4000);
	  }
	);

})
