function bigtop_initCallback(carousel) {
	jQuery('#bigtopMenu a').bind('mouseenter', function() {

	  var lastid = jQuery('#bigtopMenu li.active').prevAll().length+1;
	  jQuery('#bigtopMenu li.active').removeClass('active');
	  jQuery(this).parent().addClass('active');
	  carousel.scroll(lastid, false);

	  var scrollToItem = jQuery(this).parent().prevAll().length+1;
		carousel.scroll(scrollToItem);

		var menuObj = jQuery('#bigtopMenu').get(0);
		jQuery.data(document, 'bigtop', carousel);
		if(jQuery.data(menuObj, 'bigtop_timeoutID')) {
			window.clearTimeout(jQuery.data(menuObj, 'bigtop_timeoutID'));
			jQuery.removeData(menuObj, 'bigtop_timeoutID')
		}
		jQuery.data(menuObj, 'bigtop_timeoutID', setTimeout('jQuery.data(document, "bigtop").scroll('+scrollToItem+', false)', 1000));

	  return false;
	});
};
function gallery_scrolledCallback(carousel, visibleItem) {
	jQuery.address.value('?'+jQuery(carousel.list).attr('id')+'='+(jQuery(visibleItem).prevAll().length+1));
};

jQuery(document).ready(function() {
	//textShadow
	jQuery("#homepage #bigtop .title").textShadow();
	jQuery("#homepage #bigtopMenu a").textShadow();
	jQuery("#page .textBadge").textShadow();

	//jcarousel
  jQuery('#bigtopCarousel').jcarousel({
		scroll: 1,
		initCallback: bigtop_initCallback,
		// This tells jCarousel NOT to autobuild prev/next buttons
		buttonNextHTML: null,
		buttonPrevHTML: null,
		animation: 200
	});
	jQuery('#videosCarousel').jcarousel({
		scroll: 1,
		itemFirstInCallback: function(carousel, visibleItem) {
		  jQuery(carousel.list).parent().parent().parent().parent().find('.counter').html( (jQuery(visibleItem).prevAll().length+1) + '/' + carousel.size() );
		}
	});

	jQuery('#photosCarousel li:last').css('border-right', '10px solid white');
	jQuery('#photosCarousel').jcarousel({
		scroll: 4
	});

	var startId = jQuery.address.parameter('imageGallery');
	if(startId < 1) {
		startId = 1;
	}
	jQuery('#imageGallery li:last').css('border-right', '10px solid white');
	jQuery('#imageGallery').jcarousel({
	  start: startId,
		scroll: 4,
		itemFirstInCallback: gallery_scrolledCallback,
		initCallback: function(carousel) {
			jQuery.data(carousel.list, 'carousel', carousel);
		}
	});

	jQuery('#page .jcarousel-skin-gbt-photos').jcarousel({
		scroll: 1
	});

	jQuery('#header .sitemapLink').click(function(){
	  if(jQuery("#sitemap").css('display')=='none') {
		  jQuery('#header .sitemapLink').html('Hide Site map');
      jQuery("#sitemap").slideDown("slow");
		}
		else {
		  jQuery('#header .sitemapLink').html('Site map');
      jQuery("#sitemap").slideUp("slow");
		}
		
	});

	if(jQuery().galleriffic && jQuery('#galleryPhotosThumbs ul.thumbs li').size() > 0) {
		// We only want these styles applied when javascript is enabled
		jQuery('div.content').css('display', 'block');

		// Initially set opacity on thumbs and add
		// additional styling for hover effect on thumbs
		var onMouseOutOpacity = 0.67;
		jQuery('#galleryPhotosThumbs ul.thumbs li').css('opacity', onMouseOutOpacity)
		.hover(
			function () {
				jQuery(this).not('.selected').fadeTo('fast', 1.0);
			},
			function () {
				jQuery(this).not('.selected').fadeTo('fast', onMouseOutOpacity);
			}
		);

		// Initialize Advanced Galleriffic Gallery
		var galleryAdv = jQuery('#galleryPhotos').galleriffic('#galleryPhotosThumbs', {
		delay:                  2000,
		numThumbs:              14,
		preloadAhead:           10,
		enableTopPager:         false,
		enableBottomPager:      true,
		imageContainerSel:      '#slideshow',
		controlsContainerSel:   '#controls',
		captionContainerSel:    '',
		loadingContainerSel:    '#loading',
		renderSSControls:       true,
		renderNavControls:      true,
		playLinkText:           'Play Slideshow',
		pauseLinkText:          'Pause Slideshow',
		prevLinkText:           '&lsaquo; Previous Photo',
		nextLinkText:           'Next Photo &rsaquo;',
		nextPageLinkText:       'Next &rsaquo;',
		prevPageLinkText:       '&lsaquo; Prev',
		enableHistory:          true,
		autoStart:              false,
		onChange:               function(prevIndex, nextIndex) {
			jQuery('#galleryPhotosThumbs ul.thumbs').children()
				.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
				.eq(nextIndex).fadeTo('fast', 1.0);
		},
		onTransitionOut:        function(callback) {
			jQuery('#slideshow').fadeTo('fast', 0.0, callback);
		},
		onTransitionIn:         function() {
			jQuery('#slideshow').fadeTo('fast', 1.0);

			////console.log( jQuery('#slideshow .image-wrapper:first .advance-link:first') );
			////console.log( jQuery('#slideshow .image-wrapper:first .advance-link:first img:first') );
			var galHeight = jQuery('#slideshow .advance-link').height();
			var img = jQuery('#slideshow img');
			img.css('margin-top', parseInt( (galHeight-img.height())/2 ) );
			var galHeight = jQuery('#slideshow .advance-link').height();
		},
		onPageTransitionOut:    function(callback) {
			jQuery('#galleryPhotosThumbs ul.thumbs').fadeTo('fast', 0.0, callback);
		},
		onPageTransitionIn:     function() {
			jQuery('#galleryPhotosThumbs ul.thumbs').fadeTo('fast', 1.0);
		}
		});
	}
	
	if(jQuery().selectbox) {
	  $('.skinnedSelect').selectbox({debug: true});
	}

	jQuery('.mapDescText ul li .maproll').mouseenter(function(){
		jQuery('#mapImg').removeClass().addClass( 'mappos'+parseInt(jQuery(this).siblings(".mappos").text()) );
		jQuery('#mapText').html( jQuery(this).siblings(".description").html() );

	});
	jQuery('.mapDescText ul li a').mouseenter(function(){
		jQuery('#mapImg').removeClass().addClass( 'mappos'+parseInt(jQuery(this).siblings(".mappos").text()) );
		jQuery('#mapText').html( jQuery(this).siblings(".description").html() );
		
	});
	jQuery('.mapDescText ul li a').each(function(){
    var mappos = parseInt(jQuery(this).siblings(".mappos").text());
    if(mappos > 0)
    {
      var mappoint = jQuery('#mapPoint'+mappos).get(0);
      jQuery.data( mappoint, 'linkitem', this);
      jQuery('#mapPoint'+mappos).mouseenter( function() {
        var maplink = jQuery.data( this, 'linkitem');
        jQuery(maplink).trigger('mouseenter');
      });
      jQuery('#mapPoint'+mappos).click( function() {
        var maplink = jQuery.data( this, 'linkitem');
        window.location.href = jQuery(maplink).attr('href');
      });
		}
	});
	jQuery('.mapDesc').mouseleave(function(){
		jQuery('#mapImg').removeClass();
		jQuery('#mapText').html( '' );

	});
	
	jQuery('.contactPage #page .pageText .sectionHr:first').css('width', '464px');

});