function trackplay(theId) {
	if (document.getElementById("AudioPlayer-object")) { 
		document.getElementById("AudioPlayer-object").sendFlashTheTrack(theId);
	}
}

$(document).ready(function () {
	jQuery("a[rel=external]").attr("target", "_blank");
	
	jQuery('.listNewsArchive').accordion({ 
		header: 'h3',
		autoheight: false,
		active: '.selected'
	});
	
	jQuery('.listNewsArchive ol').accordion({ 
		header: 'h4',
		autoheight: false,
		active: '.selected'
	});
	
	
	/*tour page*/
	if (  $('#tour').length > 0  ) {
			

			// show hide	
			$('.kicker p').addClass('jshide');
			var ps = $('.kicker p');
			
			$(ps[0]).removeClass('jshide');
			
			if (ps[1])
				$(ps[1]).removeClass('jshide');
				
			if (ps[2])
				$(ps[2]).removeClass('jshide');
				
			if (ps[3])
				$(ps[3]).removeClass('jshide');
			
			if (ps[4])
				$(ps[4]).removeClass('jshide');
				
			if (ps[5])
				$(ps[5]).removeClass('jshide');
			

			$('.scroll_hold').removeClass('scroll_hold');
			// carousels
			var scrollstep = 4;
			var visiblecount = 4;
			
			jQuery('.carousel ul').jcarousel({
				circular: false,							 	
				scroll: scrollstep,
				visible:visiblecount								 
			});
			
			
			$('.carousel').each(function(){
										 
				total = $(this).find("ul li").length
				count = total/4 
				$(this).append(' <p class="counter">showing <em>'+visiblecount+'</em> of '+total+'</p>');
				
				
				var showing = visiblecount;
				
				$(this).find('.jcarousel-next').click(function(){
						var target = $(this).parents('.carousel').find('.counter em')
						
						var this_total = $(this).parents('.carousel').find("ul li").length	;							   
						var new_count = (scrollstep + showing);
						
						if ( new_count > this_total ) {
							
							showing = this_total
							target.html(showing);
							
						} else {
							showing = new_count
							target.html(showing);
						}
				});
				
				$(this).find('.jcarousel-prev').click(function(){
						var target = $(this).parents('.carousel').find('.counter em')
						
						var this_total = $(this).parents('.carousel').find("ul li").length;								   
						var new_count = (showing - scrollstep);
						
						if ( new_count < visiblecount ) {
							
							showing = visiblecount;
							target.html(showing);
							
						} else {
							showing = new_count;
							target.html(showing);
						}
				});
				
			});
			
			// lightboxes
			$("#moremore").colorbox({
				width:600, 
				inline:true, 
				href:"#showhide", 
				close : "X - Close"
				});
			
			$("a[rel='tour_pics']").colorbox({
				transition:'fade', 
				speed:500, 
				close : "X - Close",
				opacity :.8
			});
			
			$("a[rel='tour_pics2']").colorbox({
				transition:'fade', 
				speed:500, 
				close : "X - Close",
				opacity :.8
			});

			$("a[rel='tour_vids']").colorbox({
				iframe:true, 
				innerWidth:670, 
				innerHeight:600,
				transition:'fade', 
				speed:500, 
				close : "X - Close",
				opacity :0.8,
				current: "video {current} of {total}"
			});
			
			$("a[rel='tour_vids2']").colorbox({
				iframe:true, 
				innerWidth:670, 
				innerHeight:600,
				transition:'fade', 
				speed:500, 
				close : "X - Close",
				opacity :0.8,
				current: "video {current} of {total}"
			});
			
	}
	
	$('.linkAll').live('click', function() {
	    var a = $('a', this);
	    if (a.length) {
	        console.log(a[0]);
	        window.location = a[0].href;
	    }
	}).addClass('js');
	
});

//fading images
function slideSwitch() {
	var $active = $('#imgbanner img.active');

	if ( $active.length == 0 ) $active = $('#imgbanner img:last');

	var $next =  $active.next().length ? $active.next()
		: $('#imgbanner img:first');

	$active.addClass('last-active');

	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
			$active.removeClass('active last-active');
		});
}

$(function() {
	setInterval( "slideSwitch()", 5000 );
});

