$(document).ready(function() {
	mac_pc();
	if ($('#without_ease').length <= 0) { jQuery.easing.def = 'easeOutQuad'; }
	if ($('#social').length > 0) social_fade();
	if ($('#board_members').length > 0) member_hovers();
	if ($('#scrollable').length > 0) scrollable();

	$('#switchcal select').change(function() { 
		window.location = $(this).val();
	});
});
function scrollable() {
	if ($('#ease').length > 0) {
		// set fake height of browser to gain easing control of window
		$('#footer').css({'width':$('#container').width()});
		var h = $('#container').height();
		if (h > $(window).height()) {
			$('body').prepend('<div id="pseudo_h" style="height:'+h+'px;"></div>');
			$('#container').css({'position':'fixed'});
			$('#footer').css({'position':'relative'});
		} else {
			$('#footer').css({'position':'absolute'});
		}

		function rollit() {
			var ch = $('#container').height(),
				wh = $(window).height(),
				sh = $('#scrollable').height(),
				st = $(window).scrollTop(),
				t = (0-st)/((ch-wh)/(sh-wh));
			$('#scrollable').animate({'top':t+'px'},{duration:200,queue:false});
			$('#container').animate({'top':-st+'px'},{duration:200,queue:false});
		}
		rollit();
		$(window).scroll(function() {
			rollit();
		});
	} else if ($('#without_ease').length > 0) {	
		function refit() {
			$('#scrollable').css({'width':$('#stackable').width()});
			$('#footer').css({'width':$('#container').width()});
		
		
	
			function rollit() {
				// fix small window fixed-position issue
				if ($(window).width() < 1040) {
					$('#scrollable').css({'left':($('#container').width()-$(window).scrollLeft())+'px'});
				} else {
					$('#scrollable').css({'left':'auto'});
				}
			
				var ch = $('#container').height(),
					wh = $(window).height(),
					sh = $('#scrollable').height(),
					st = $(window).scrollTop(),
					t = (0-st)/((ch-wh)/(sh-wh));
				$('#scrollable').css({'top':t+'px'});
				//$('#container').animate({'top':-st+'px'},{duration:200,queue:false});
			}
			rollit();
			$(window).scroll(function() {
				rollit();
			});
		}
		refit();
		$(window).resize(function() { refit(); });
	} else {	
		function refit() {
			$('#scrollable').css({'width':$('#stackable').width()});
			$('#footer').css({'width':$('#container').width()});

			function rollit() {
				// fix small window fixed-position issue
				if ($(window).width() < 1040) {
					$('#scrollable').css({'left':($('#container').width()-$(window).scrollLeft())+'px'});
				} else {
					$('#scrollable').css({'left':'auto'});
				}

				var ch = $('#container').height(),
					wh = $(window).height(),
					sh = $('#scrollable').height(),
					st = $(window).scrollTop(),
					t = (0-st)/((ch-wh)/(sh-wh));
					if (ch > wh) $('#scrollable').animate({'top':t+'px'},{duration:200,queue:false});
				//$('#container').animate({'top':-st+'px'},{duration:200,queue:false});
			}
			rollit();
			$(window).scroll(function() {
				rollit();
			});
		}
		refit();
		$(window).resize(function() { refit(); });
	}
}
function member_hovers() {
	$('.member').hover(function() {
		var t = 160-$('.info',this).height();
		$('.info',this).animate({'top':t+'px'},{duration:200,queue:false});
	},function() {
		$('.info',this).animate({'top':'123px'},{duration:200,queue:false});
	});
}
function social_fade() {
	$('#social a img').hover(function() {
		$(this).fadeTo(200,.5);
	},function() {
		$(this).fadeTo(200,1);
	});
}
function clear_text() {
	$('input.text').each(function() {
		var text = $(this).attr('value');
		$(this).click(function() { if ($(this).attr('value') == text) $(this).attr('value',''); });
		$(this).blur(function() { if ($(this).attr('value') == '') $(this).attr('value',text); });
	});
}
function mac_pc() {
	if (navigator.appVersion.indexOf("Mac")!=-1) {
		$('body').addClass('mac');
	} else {
		$('body').addClass('pc');
	}
	$.each($.browser, function(i,e) {
		if (i != 'version') {
			$('body').addClass(i);
		} else {
			var v = String(e).split('.');
			$('body').addClass('v'+v[0]);
		}
	});
}
function slideshow_setup() {

	$('.slideshow').each(function() {
		var my_div = $(this);
		add_slideshow(my_div);
	});

	function add_slideshow(el) {
		var current = 0;
		var total = $('img',el).length;

		// set captions
		$('.captions .cap',el).each(function() {
			var y = -($(this).height()+23);
			if (y >= -23) { y = -350; }
			$(this).css({'margin-top':y+'px','display':'none'});
		});

		$('img',el).each(function() {
			$(this).css({'margin-left':-($(this).width()/2)+'px','margin-top':-($(this).height()/2)+'px'});
			var ind = $('img',el).index(this);
			if (ind != current) {
				$(this).fadeTo(0,0);
			} else {
				$(this).fadeTo(0,1);
			}
		});
		
		el.hover(function() {
			$(this).addClass('hover');
			slide_caption_down();
		},function() {
			$(this).removeClass('hover');
			slide_caption_up();
		});

		function slide_caption_down() {
			if ($('.cap',el).eq(current).html() != '' && el.hasClass('hover')) {
				$('.cap',el).eq(current).css({'display':'block'}).animate({'margin-top':'0px'},{duration:300,queue:false});
			}
		}
		function slide_caption_up() {
			var y = -($('.cap',el).eq(current).height()+23);
			$('.cap',el).eq(current).animate({'margin-top':y+'px'},{duration:300,queue:false});
		}
		
		if (total > 1) {
			$('.circle_nav a',el).click(function() {
				var i = $('.circle_nav a',el).index(this);
				fade_slide(i);
				clearInterval(ss_timer);
				return false;
			});
	
			$('img',el).click(function() {
				clearInterval(ss_timer);
				if (current < (total-1)) {
					var next = current+1;
				} else {
					var next = 0;
				}
				fade_slide(next);
				return false;
			});
	
			function fade_slide(next) {
				slide_caption_up();
				$('.circle_nav a',el).removeClass('active');
				$('img',el).eq(current).fadeTo(300,0);
				$('img',el).eq(next).fadeTo(300,1);
				$('.circle_nav a',el).eq(next).addClass('active');
				current = next;
				slide_caption_down();
			}

			var ss_timer = setInterval(function() {
				if (current < (total-1)) {
					var next = current+1;
				} else {
					var next = 0;
				}
				fade_slide(next);
			},5000);

		} else {
			$('.circle_nav a',el).hide();
			$('img',el).css({'cursor':'default'});
		}

	}
}
