﻿$(document).ready(function(){   
	$("#content").load("data/home.txt");
	$('#arrowup').click(function(){
		$('html,body').animate({scrollTop: '0px'}, 800);
	}); 
	$('#arrowdown').click(function(){
		$('html,body').animate({scrollTop:$('#footer').offset().top}, 800);
	});
	$("a[rel='topexternal']").click(function() {
		window.open(this.href);
		return false;
	});

	var originalFontSize = $('#content').css('font-size');
	$(".resetFont").click(function(){
		$('#content').css('font-size', originalFontSize);
	});
	$(".increaseFont").click(function(){
		var currentFontSize = $('#content').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		if (currentFontSizeNum >= 18) {return false;} else {
		var newFontSize = currentFontSizeNum+1;
		$('#content').css('font-size', newFontSize);
		return false;
		}
	});
	$(".decreaseFont").click(function(){
		var currentFontSize = $('#content').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		if (currentFontSizeNum <= 12) {return false;} else {
		var newFontSize = currentFontSizeNum-1;
		$('#content').css('font-size', newFontSize);
		return false;}
	});

	$("#content").ajaxSend(function(){
		$('#content').hide();
		$('#loading').show();
	});
	$("#content").ajaxComplete(function(){
		$('#loading').removeClass('disappear');
		$('#loading').hide();
		$('#content').fadeIn('slow');
		//$('html,body').animate({scrollTop: '358px'}, 400);
		$('html,body').animate({scrollTop: '0px'}, 400);
		$('a.lightbox').lightBox();
		$("a[rel='external']").click(function() {
			window.open(this.href);
			return false;
		});
		$(".striped tr:nth-child(even)").addClass("even");
		$(".logo img").each(function() {
			var maxWidth = 150;
			var maxHeight = 300;
			var ratio = 0;
			var width = $(this).width();
			var height = $(this).height();
 
			if(width > maxWidth){
				ratio = maxWidth / width;
				$(this).css("width", maxWidth);
				$(this).css("height", height * ratio);
				height = height * ratio;
				width = width * ratio;
			}
 
			if(height > maxHeight){
				ratio = maxHeight / height;
				$(this).css("height", maxHeight);
				$(this).css("width", width * ratio);
				width = width * ratio;
			}
		});
	});
});
$(window).scroll(function(){
	var scrollTop = $(window).scrollTop();
	
	var userAgent = window.navigator.userAgent.toLowerCase();
	$.browser.msie8 = $.browser.msie && /msie 8\.0/i.test(userAgent);
	$.browser.msie7 = $.browser.msie && /msie 7\.0/i.test(userAgent);
	$.browser.msie6 = !$.browser.msie8 && !$.browser.msie7 && $.browser.msie && /msie 6\.0/i.test(userAgent);

	if (scrollTop > 358) {
		if ($.browser.msie6) {
			$('#menu').css({position:'absolute', top:scrollTop}).animate('400');
		} else {
			$('#menu').css({position:'fixed',top:'0px'}).animate('400');
		}
	} else {
		$('#menu').css({position:'static'}).animate('400');
	}

	if (scrollTop > 415) {
		$('#out').css({top:scrollTop}).animate('400');
	} else {
		$('#out').css({top:'415px'}).animate('400');
	}

});
