$(document).ready(function() {

	// Home page navigation
	$("#home-menu").hover(function(){
		$("#home-menu ul").stop(true, true).fadeIn(100);
	},
	function() {
		$("#home-menu ul").stop(true, true).fadeOut(500);
	});
	
	
	// CS navigation
	$("#cs-vertical-navigation li li, #cs-horizontal-navigation li li").hover(function(){
		$("a", this).addClass('trans-white');
		$("ul", this).stop(true, true).show();	
		$(this).css("background-image", "url(images/arrow_black.png)");
	},
	function() {
		$("a", this).removeClass('trans-white');
		$("ul", this).stop(true, true).hide();
		$(this).css("background-image", "url(images/arrow.png)");
	});
	
	// Fancy box galleries
	$("#thumbnails a").fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'showNavArrows' : true

	});

	/*
	function content() { // size content height to correct dimensions.
		windowHeight = $(window).height();
		contentHeight = windowHeight - 380;
		if(contentHeight < windowHeight) {
			$('#content').height(contentHeight);
		}
	}

	content();
	*/

	function minHeight(divName) { // min height function to set all heights equal to heighest value
		var minHeight = 0;
		var element = $(divName);
		element.each(function() {
			if($(this).height() > minHeight) {
				minHeight = $(this).height(); // subtract 6 for borders
			}
		});
		$(divName).height(minHeight); // set largest height
	}
	
	
	$('#slider').baregallery({ // set up gallery options
		'speed'				: 1000,
		'cycleSpeed'	:	5000,
		'cycle'				: true,
		'captionType' : '.pager-caption',
		'imageNext'		: 'gallery-next',
		'imagePrev'		: 'gallery-prev'
	});

	$(window).load(minHeight('.equalHeight'));

	$('.mini-slider #next').click(function() {
		li = $('.mini-slider ul li:first').detach();
		li.appendTo('.mini-slider ul');
		miniSlider(30);
	});


	
	var refreshIntervalId = setInterval(mainSlider, 4000);
	
	function mainSlider() {
		$('#main-slider ul').stop(true, false).animate({marginLeft:-200}, 2000, function(){
			li = $('#main-slider li:first').detach();
			li.appendTo('#main-slider ul');
			$(this).css({marginLeft:0});
		});
	}
});	
