Cufon.replace('h1', { fontFamily: 'AvantGarDem' });
Cufon.replace('h2', { fontFamily: 'AvantGarDem' });
Cufon.replace('h3', { fontFamily: 'United'});
Cufon.replace('h4', { fontFamily: 'United'});
Cufon.replace('h5', { fontFamily: 'AvantGarDem'});
Cufon.replace('h6', { fontFamily: 'AvantGarDem'});
Cufon.replace('#disclaimer', { fontFamily: 'United'});
Cufon.replace('time', { fontFamily: 'AvantGarDem'});
Cufon.replace('#footer', { fontFamily: 'AvantGarDem'});
Cufon.replace('figcaption', { fontFamily: 'AvantGarDem'});



var $count = 1;
var $maxImages = 0;
var $width = -1*(850);
var $distance = 0;
var $wait = false;
var $creditsUp = false;
var $showcaseLink = "http://www.recstudio.tv";
var $nextUp = false;

function countPics(){
	var ul = document.getElementById('showcasePics');
	var i=0, c =0;
	while(ul.getElementsByTagName('li')[i++]) c++;
	$maxImages = c;
	
}

function swapImages(){
	if ($maxImages == 0) {
		countPics();
	}
	
	if ($wait == false) {		
		if ($count < $maxImages){
			$wait = true;
			$count++;
			var $active = $('#showcase .active');
			var $next = $('#showcase .active').next('li');
			$active.fadeOut(function(){
				$active.removeClass('active');
				$wait = false;
			});
			$next.fadeIn().addClass('active');
			
			if ($count == 11) {
				slideNavRightArrow();				
				document.getElementById("indicator").style.marginLeft = "0px"; 
			} else {
				moveArrow($count);
			}
			
		}
	}
}

function changePic(pic){
	if ($maxImages == 0) {
		countPics();
	}
	if ($count != pic) {
		if ($wait == false) {		
			if ($count <= $maxImages){
				var $picNum = pic;
				$wait = true;
				$count = $picNum;
				var $active = $('#showcase .active');
				var $next = $("ul li:nth-child(" +$picNum+ ")");
				$active.fadeOut(function(){
					$active.removeClass('active');
					$wait = false;
				});
				$next.fadeIn().addClass('active');
				//var $arrow = $('#indicator');
				moveArrow($count);
			}
		}
	}
}

function moveArrow(pic) {
	if (pic > 10){
		$distance = ((pic-11)*85.2);
	} else {
		$distance = ((pic-1)*85.2);
	}
		$('#indicator').animate({
		"marginLeft" : $distance
	}, { duration: "fast" });
}

function swapImagesBack(){
	if ($wait == false) {		
		if ($count > 1) {
			$wait = true;
			$count--;
			var $active = $('#showcase .active');
			var $prev = $('#showcase .active').prev('li');
			$active.fadeOut(function(){
				$active.removeClass('active');
				$wait = false; 
			});
			$prev.fadeIn().addClass('active');
			
			if ($count == 10) {
				slideNavLeftArrow();				
				document.getElementById("indicator").style.marginLeft = "852px"; 
			} else {
				moveArrow($count);
			}
		}
	}
}

function slideNavRight(){	
	
	if ($nextUp == false) {
		$('.items').animate({
			"marginLeft" : $width
		}, { duration: "slow" });
		$('#indicator').animate({
			"marginLeft" : $width
		}, { duration: "slow" });
		var $darken = $('#thumbNavNext a');
		$darken.css('color', '#666');
		var $lighten = $('#thumbNavPrev a');
		$lighten.css('color', '#CCC');
		$nextUp = true;
	}
	changePic(11);
}

function slideNavRightArrow(){
	if ($nextUp == false) {
		$('.items').animate({
			"marginLeft" : $width
		}, { duration: "slow" });
		$('#indicator').animate({
			"marginLeft" : 0
		}, { duration: "slow" });
		var $darken = $('#thumbNavNext a');
		$darken.css('color', '#666');
		var $lighten = $('#thumbNavPrev a');
		$lighten.css('color', '#CCC');
		$nextUp = true;
	}
}

function slideNavLeftArrow() {
	if ($nextUp == true) {
		$('.items').animate({
		  "marginLeft" : 0
		}, { duration: "slow" });
		$('#indicator').animate({
			"marginLeft" : (852 - 85.2)
		}, { duration: "slow" });
		var $darken = $('#thumbNavPrev a');
		$darken.css('color', '#666');
		var $lighten = $('#thumbNavNext a');
		$lighten.css('color', '#CCC');
		$nextUp = false;
	}
}

function slideNavLeft() {
	if ($nextUp == true) {
		$('.items').animate({
		   "marginLeft" : 0
		}, { duration: "slow" });
		$('#indicator').animate({
			"marginLeft" : ((-1*$width) + $distance )
		}, { duration: "slow" });
		var $darken = $('#thumbNavPrev a');
		$darken.css('color', '#666');
		var $lighten = $('#thumbNavNext a');
		$lighten.css('color', '#CCC');
		$nextUp = false;
	}
	changePic(10);
}

function showcaseRoll(url) {
	var $roll = $('#roll-over');
	$roll.fadeIn();
	$showcaseLink = url;
}

function showcaseRollOut() {
	var $roll = $('#roll-over');
	$roll.fadeOut();
}

function gotoURL(){
	var $urlString = "http://www.recstudio.tv/" + $showcaseLink;
	parent.location=$urlString;
}

function showCredits() {
	var $credits = $('#creditsbox');
	if ($creditsUp == false) {
		$credits.fadeIn(function(){
			$creditsUp = true; 
		});
	} else {
		$credits.fadeOut(function(){
			$creditsUp = false; 
		});
	}
}

