$j(document).ready(function(){
	var wh = $j(window).height();
	var mt = (wh - 445) / 2;
	mt = mt -25;
	$j('#wrapper').css('margin-top',mt+'px');
	

	$j('div.slides').cycle({ 
		fx:         'fade', 
		timeout:     3000 
	});
	
	
	$j('div.slides').css('width','460px;');

	function pagerFactory(idx, slide) {
		return '<a href="#"></a>';
	};
	
	$j("div#top_menu ul:first li").hover(function(){
		$j(this).find("a:first").addClass('menu_hover');
		$j(this).find('ul').show();
		$j(this).find('ul').css('display','block');
		
	},function(){
		$j(this).find('ul:first').hide();
		$j(this).find("a:first").removeClass('menu_hover');
	});
	
	var margin = 0;
	
	$j(".up").click(function(){
	  if(margin != -384){
	  	  margin = parseInt(margin) - 192;
		  $j("#scroller img").animate({ 
		    marginTop: margin+"px" 
		  }, 500 );
	  }
	  return false;
	});
	
	$j(".down").click(function(){
	  if(margin != 0){
	  	  margin = parseInt(margin) + 192;
		  $j("#scroller img").animate({ 
		    marginTop: margin+"px"
		  }, 1100 );
	  }
	  return false;
	});
	
});

function setupGallery(){
	$j('div.navigation').css({'width' : '360px', 'float' : 'left'});
	$j('div.content').css('display', 'block');

	// Initially set opacity on thumbs and add
	// additional styling for hover effect on thumbs
	var onMouseOutOpacity = 0.67;
	$j('#thumbs ul.thumbs li').opacityrollover({
		mouseOutOpacity:   onMouseOutOpacity,
		mouseOverOpacity:  1.0,
		fadeSpeed:         'fast',
		exemptionSelector: '.selected'
	});
	
	// Initialize Advanced Galleriffic Gallery
	var gallery = $j('#thumbs').galleriffic({
		delay:                     2500,
		numThumbs:                 20,
		preloadAhead:              10,
		enableTopPager:            false,
		enableBottomPager:         true,
		maxPagesToShow:            7,
		imageContainerSel:         '#slideshow',
		controlsContainerSel:      '#controls',
		captionContainerSel:       '#caption',
		loadingContainerSel:       '#loading',
		renderSSControls:          false,
		renderNavControls:         false,
		enableHistory:             false,
		autoStart:                 false,
		syncTransitions:           true,
		defaultTransitionDuration: 900,
		onSlideChange:             function(prevIndex, nextIndex) {
			// 'this' refers to the gallery, which is an extension of $('#thumbs')
			this.find('ul.thumbs').children()
				.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
				.eq(nextIndex).fadeTo('fast', 1.0);
		},
		onPageTransitionOut:       function(callback) {
			this.fadeTo('fast', 0.0, callback);
		},
		onPageTransitionIn:        function() {
			this.fadeTo('fast', 1.0);
		}
	});

}


