/* <![CDATA[ */

function buildTabs()
{
	
	//resultSetLength = $("item",xmlDataSet).length;
	//var curPos = 1;
	//var itemsPerPage = resultSetLength;
	//var counter = 0;
	/*$("title:lt(" + parseInt(curPos + itemsPerPage) + ")",xmlDataSet).filter(":gt(" + parseInt(curPos - 1) + ")").each(function(i) {
		var html = '';
		var footer = '';
		var title = $(this).text();			
		var description = $("description:eq(" + parseInt(curPos + i) + ")",xmlDataSet).text();
		var copy = $(this).parent().find('[nodeName="content:encoded"]').text();
		var linkd = $("link:eq(" + parseInt(curPos + i) + ")",xmlDataSet).text();
		var image = $(this).parent().find('[nodeName="enclosure"]').attr('url');		
		html += '<div class="tabsContent">'   
        	+	'<div id="media"><a href="javascript://" class="introLnk"><img src="media/images/'+image+'" border="0" alt="'+title+'" /></a></div>'
            +	'<div class="copy">'
			+	'<div class="h2">'+description+'</div><div class="hr"></div>'
            +	copy 
			+ 	'<div id="tabsFtr">';
		if (counter != 0) {
		html += '<div id="prevDiv"><a href="javascript://" onclick="pagination('+(counter-1)+')" class="toggleBtm"><img src="images/icon.arrowBck.png" width="8" height="5" border="0" alt="" />&nbsp;Previous&nbsp;</a></div>';
		}
		if ((counter+1) < itemsPerPage) {
		html += '<div id="nextDiv"><a href="javascript://" onclick="pagination('+(counter+1)+')" class="toggleBtm">&nbsp;Next&nbsp;<img src="images/icon.arrow.png" width="8" height="5" border="0" alt="" /></a></div>';
		}			
		html += '<div id="linksDiv">'
			+	'<div><a href="mailto:&body='+linkd+'"><img src="images/icon.arrow.png" width="8" height="8" border="0" alt="" />&nbsp;Email article</a><div class="floatLft">&nbsp;&nbsp;|&nbsp;</div><a href="javascript://" onclick="window.print()"><img src="images/icon.arrow.png" width="8" height="8" border="0" alt="" />&nbsp;Print page</a></div>'
			+	'<div id="shareDiv">'
			+	'<a href="'+document.location.protocol+'//www.addthis.com/bookmark.php?v=250&pub=hoststats" onmouseover="return addthis_open(this, \'\', \''+linkd+'\', \''+title+'\')" onmouseout="addthis_close()" onclick="return addthis_sendto()"><img src="'+document.location.protocol+'//s7.addthis.com/static/btn/sm-share-en.gif" width="83" height="16" alt="Bookmark and Share" style="border:0"/></a><scr'+'ipt type="text/javascript" src="'+document.location.protocol+'//s7.addthis.com/js/250/addthis_widget.js?pub=hoststats"><\/scr'+'ipt>'
			+	'</div>'
			+	'<div class="clear"></div></div></div>';
			$('#content').append(html);	
			$('.tabsNav ul').append('<li><a href="javascript://" class="tabLink"><span>'+title+'</span></a></li>');	
			counter++;
	});	*/

	//Set default state	
	$(".tabsContent").hide(); 				//Hide all tabs except the first one		
	$(".tabsNav .tabLink:first").addClass("current");	//Set the first tab to "current" class
		
	$(".tabsNav .tabLink").hover(function(){
		$(".tabsDefault").hide();
		var index = $(".tabsNav .tabLink").index(this);				//get the number of the tab clicked
		$(".tabsContent").hide();
		$(".tabsContent").filter(":eq("+index+")").show();	//Hide all content tabs, show the selected one
		$(".tabsNav .tabLink").removeClass("current").filter(":eq("+index+")").addClass("current"); //Take "ON" state off all tab links, add to selected 
	});

	
	//Onclick - show rest of story
	var firstClick = false;
	$('.tabLink').click(function(){//when you click on the RHS tabs		
		var x = $('.tabLink').index(this);					
		$('#footnote').hide();
		if(firstClick == false) {//initial click removes tabs hover state
			var contents = $('.copy').eq(x).html();	
			$('.copy').eq(x).siblings("#media").hide();
			$('.copy').eq(x).html(contents).css('padding-left','25px').fadeIn('slow').addClass('currCopy');
			$(".tabLink").unbind("mouseover");	
			firstClick = true;
			slideshowGo();	 
		} else {			
			$(".tabsNav .tabLink").removeClass("current").filter(":eq("+x+")").addClass("current");
			var contents2 = $('.copy').eq(x).html();			
			$('.currCopy').parent().hide().removeClass('currCopy').hide();
			$('.copy').eq(x).siblings('#media').hide();			
			$('.copy').eq(x).parent().fadeIn('slow');
			$('.copy').eq(x).css('padding-left','25px').html(contents2).fadeIn('slow').addClass('currCopy');
			slideshowGo();
		}		
		
	});
	$('.introLnk').click(function(){//when you click on the interchanging image
		var copy = $(this).parent().next('.copy').html();
		$(this).parent().hide();	
		$(this).parent().html(copy).addClass('currCopy').css('padding-left','25px').fadeIn('slow');
		$(".tabLink").unbind("mouseover");			   
	});

	
	//open bookmarked stories
	var qsIndex = document.location.search.substr(((document.location.search.indexOf("?page="))+6));
	if(qsIndex) {
		//IE bug fix - position of TabNav (doesn't hurt to apply to all browsers)
		var pos = $('#tabsDivNoPad').position();	
		$('.tabsNav').css('top',pos.top);
		$(".tabsDefault").hide();
		$(".tabsContent:first #media").hide();
		$("#media").hide();	
		return pagination(qsIndex);		
	}	

	//IE bug fix - position of TabNav (doesn't hurt to apply to all browsers)
	var pos = $('#tabsDivNoPad').position();	
	$('.tabsNav').css('top',pos.top);
	
} 

//Prev+Next function at bottom of article
function pagination(tab) {	
	$(".tabsNav .tabLink").removeClass("current").filter(":eq("+tab+")").addClass("current");
	var content = $('.copy').eq(tab).html();	
	$('.currCopy').parent().hide().removeClass('currCopy').hide();
	$('.copy').eq(tab).siblings('#media').hide();			
	$('.copy').eq(tab).parent().fadeIn('slow');
	$('.copy').eq(tab).css('padding-left','25px').html(content).fadeIn('slow').addClass('currCopy');
	slideshowGo();
	setTimeout("slideshowGo()",5000);
}

//Slide show functions
$('.pause').live("click", function() {
	$(this).parent().siblings('.pics').cycle('pause'); 
	$(this).replaceWith('<a href="javascript://" class="resume">Play<img src="images/icon.arrow.png" width="8" height="8" border="0" /></a>');
});
$('.resume').live("click", function() { 
	$(this).parent().siblings('.pics').cycle('resume', true);
	$(this).replaceWith('<a href="javascript://" class="pause">Pause</a>');
});
function slideshowOnAfter(){
}
function slideshowOnBefore() {
}
function slideshowGo() {
	$('.pics').each(function() {//set slideshow
		 $(this).cycle({fx: 'scrollHorz',
		  timeout: 6000,
		  delay: -2000,
		  next:   '.next',
		  prev:   '.prev',
		  before: slideshowOnBefore,
		  after: slideshowOnAfter
		});
	});
}
/* ]]> */

