//* Define Functions
	
	//
	// This will fire on load and resize to size #frame
	// based on window height.  Scrollbars are toggled 
	// to work around scrollbar sizing bug.
	
	function sizeFrame() {
		// Grab window dimensions
		var wWidth = $(window).width();
		var wHeight = $(window).height();
		// Manage width
		if (wWidth <= 960) {
			// Turn on scrollbars and set #frame to 960 wide
			$('html').css('overflow-x','auto');
			$('#frame,body').css({'width':'960px'});
			if (ie7) $('#interface').css('left','-540px');
		} else {
			// Turn scrollbars off and set #frame to wWidth
			$('html').css('overflow-x','hidden');
			$('#frame,body').css({'width':wWidth + 'px'});
			if (ie7) $('#interface').css('left','-270px');
		}
		// Manage Height
		if (wHeight <= 778) {
			// Turn on scrollbars and set #frame to 778 high
			$('html').css('overflow-y','auto');
			$('#frame,body').css('height','778px');
		} else if (wHeight > 778 && wHeight < 830) {
			// Turn scrollbars off and set #frame to wHeight
			$('html').css('overflow-y','hidden');
			$('#frame,body').css('height',wHeight + 'px');
		} else {
			// Turn scrollbars off and set #frame to 830 high
			$('html').css('overflow-y','hidden');
			$('#frame,body').css('height','830px');
		}
		ieResizeOk = true
	}
	
	function slideshowInit() {
		slideshow.count = $('#slides>div').length;
		slideshow.num = 0;
		slideshow.arr = new Array();
		slideshow.ok = true;
		$('#slides>div').each(function(n) {
			html = $(this).html();
			slideshow.arr.push(html);
		});
		$('#slideshow-a').html(slideshow.arr[0]).addClass('active');
		$('#slideshow-b').html(slideshow.arr[1]);
	}
	function slideshowPlay() {
		if (slideshow.ok) {
			slideshow.ok = false;
			slideshow.num = ((slideshow.num + 1) == slideshow.count) ? 0 : slideshow.num + 1;
			slideshow.targ = $('.slideshow:not(.active)');
			// Populate slide under current
			slideshow.targ.html(slideshow.arr[slideshow.num]);
			// Fade current slide
			slideshowAnimate();
		}
	}
	function slideshowAnimate() {
		var dir = ($('.slideshow.active .blurb').hasClass('left')) ? 'left' : 'right';
		if (dir == 'left') {
			$('.slideshow.active .blurb').animate({left:'800px',opacity:0},750, function() {
				$('.slideshow.active').fadeOut(500, function() {
					slideshowActive()
				});
			});
		} else {
			$('.slideshow.active .blurb').animate({right:'800px',opacity:0},750, function() {
				$('.slideshow.active').fadeOut(500, function() {
					slideshowActive()
				});
			});
		}
	}
	function slideshowActive() {
		$('#slide-controler .active').removeClass('active');
		$('#slide-marker-' + slideshow.num).addClass('active');
		$('.slideshow.active').removeClass('active');
		$('.slideshow:visible').addClass('active');
		$('.slideshow:hidden').show();
		slideshow.ok = true;
	}



//* Global Vars

	//
	// Detect IE7 from CSS Browser Selector
	var ie7 = ($('html').hasClass('ie7')) ? true : false;
	var ieResizeOk = true
	var slideshow = {};



//* Ready

	//
	// Take action
	$(document).ready(function() {
		
		sizeFrame();
		$(window).resize(function() {
			if (ie7 && ieResizeOk) {
				ieResizeOk = false;
				var ieResizeTimeout = setTimeout('sizeFrame()', 100);
			} else {
				sizeFrame();
			}
		});
		
		slideshowInit();
		slideshow.interval = setInterval('slideshowPlay()',7000);
		$('.slide-marker').click(function() {
			if (slideshow.ok && ($(this).attr('id').split('marker-')[1] != slideshow.num)) {
				var obj = $(this);
				slideshow.ok = false;
				slideshow.num = obj.attr('id').split('marker-')[1];
				clearTimeout(slideshow.interval);
				slideshow.targ = $('.slideshow:not(.active)');
				// Populate slide under current
				slideshow.targ.html(slideshow.arr[slideshow.num]);
				// Fade current slide
				slideshowAnimate();
			}
		});
		
	});
