
$(document).ready(function(){

	
	var fadeTime;
	if (browserVar == "IE") {
		fadeTime = 0;
	}
	else {
		$('body').css({opacity: .9999}); 
		fadeTime = 2000;
	}
	
	$('#footerbar').mouseenter(function(){
		if (activeFooterInfo == null) {
			
			$('div#footer-flickr').slideToggle('normal');
			activeFooterInfo = 'footer-flickr';
		} 
	});
	
	$('#footer-wrapper').mouseleave(function(){
		$('#'+activeFooterInfo).slideToggle('normal');
		activeFooterInfo = null;
	});

	function cycleImages (imgId) {
		if (imgId == undefined) {
			$("#feature-img div:first").fadeIn(fadeTime).fadeTo(5000, 1).fadeOut(fadeTime, function(){
				cycleImages($(this).next("div").attr("id"));
				/*$("#feature-img div:first").css("display","none");
				$(this).next("div").css("display","block");*/
				
			});

		}
		else {
			
			$("#"+imgId).fadeIn(fadeTime).fadeTo(5000, 1).fadeOut(fadeTime, function(){
				cycleImages($(this).next("div").attr("id"));
				
				/*$("#"+imgId).css("display","none");
				$(this).next("div").css("display","block");*/
			});
		}
	}
	
	function noCycleImages (imgId) {
		$("#feature-img-nofade div:first").fadeTo(2000, 1);
	}
	
	cycleImages();
	noCycleImages(); 
	
	$('div.side-item-open').hide('fast', function callback() {
		resizeImg();
	});
	
	$('div.side-item').click(function() {
		if ($(this).css("color") == 'rgb(0, 255, 138)' || $(this).css("color") == '#00ff8a') {
			$(this).text($(this).text().replace(/-/,'+'));
			$(this).css("color","#00B7EB");
		}
		else {
			$(this).text($(this).text().replace(/\+/,'-'));
			$(this).css("color","#00ff8a");
		}
		$(this).next("div.side-item-open").slideToggle('fast');
		return false;
	});

	function resizeImg() {
		windowRatio = $(window).width()/$(window).height();
			if (imgRatio <= windowRatio) {
				$('#bgimg').width($(window).width());
				$('#bgimg').height($(window).width()/imgRatio);
			}
			if (imgRatio > windowRatio) {
				$('#bgimg').height($(window).height());
				$('#bgimg').width($(window).height()*imgRatio);
			}
		}

	var img = $('#bgimg');

	$(window).load(function() {
		img.removeAttr("width"); 
		img.removeAttr("height");
	});

	var imgRatio = img.width()/img.height();
	var windowRatio = $(window).width()/$(window).height();

	resizeImg();

	$(window).bind('resize', function(){
		resizeImg();
	});

 });
