// JavaScript Document#

jQuery(document).ready(function() {
								
	function mycarousel_initCallback(carousel) {
		jQuery('.jcarousel-control li').bind('click', function() {
			carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
			return false;
		}); 
	};
	jQuery(document).ready(function() {
	   jQuery("#banner").jcarousel({
		   scroll: 1,
		   auto: 5,
		   wrap: 'both',
		   initCallback: mycarousel_initCallback,
		   // This tells jCarousel NOT to autobuild prev/next buttons
		   itemVisibleInCallback: {
			 onAfterAnimation: function(c, o, i, s) {
			   jQuery('.jcarousel-control a').removeClass('selected');
			   jQuery('.jcarousel-control a:eq('+i+')').addClass('selected');
			 }
		   }
	   });
	});
	
	
	function init_HomeSlideShow() {
		$('.hp-slides').cycle({
			fx:     'fade',
			speed:  'slow',
			timeout: 4000,
			pager:  '.hp-banner-nav',
			pause:	1,
			after:  onAfter,
			pauseOnPagerHover: 1,
			pagerAnchorBuilder: function(idx, slide) {
				return '.hp-banner-nav li:eq(' + (idx) + ') a';
			}
		});
		function onAfter(curr, next, opts) {
			var myIndex = opts.currSlide + 1;
			$('.hp-banner-nav li a').removeClass('selected');
			$('.hp-banner-nav li:nth-child('+myIndex+') a').addClass('selected');
		}
	}
	init_HomeSlideShow();
	
});


jQuery(document).ready(function(){

	$("#accordion").accordion({
		collapsible: true,
		active: false,
		autoHeight: false,
		change: function(event, ui) {
			if ($(ui.newHeader).hasClass('ui-accordion-header')) {
				//if (isScrolledIntoView(ui.newHeader)) {
					$.scrollTo(ui.newHeader, 500, {offset: {top:0, left:0}});
				//}
			}
		}
	});
	
	function isScrolledIntoView(elem) {
		
		var docViewTop = $(window).scrollTop();
		var docViewBottom = docViewTop + $(window).height();
	
		var elemTop = $(elem).offset().top;
		var elemBottom = elemTop + $(elem).height();
	
		return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom));
	}

	
	
});
