var idMatch = new Array();
idMatch[0]  = "#portfolio-one";
idMatch[1]  = "#portfolio-two";
idMatch[2]  = "#portfolio-three";
idMatch[3]  = "#portfolio-four";
idMatch[4]  = "#portfolio-five";
idMatch[5]  = "#portfolio-six";
idMatch[6]  = "#portfolio-seven";
idMatch[7]  = "#portfolio-eight";
idMatch[8]  = "#portfolio-nine";
idMatch[9]  = "#portfolio-ten";
idMatch[10] = "#portfolio-eleven";
idMatch[11] = "#portfolio-twelve";
idMatch[12] = "#portfolio-thirteen";
idMatch[13] = "#portfolio-fourteen";
idMatch[14] = "#portfolio-fifteen";
idMatch[15] = "#portfolio-sixteen";
idMatch[16] = "#portfolio-seventeen";
idMatch[17] = "#portfolio-eighteen";

var videoPath = new Array();
videoPath[0]  = "../videos/claymation.flv";
videoPath[1]  = "../videos/golfers.flv";
videoPath[2]  = "../videos/claymation.flv";
videoPath[3]  = "../videos/golfers.flv";
videoPath[4]  = "../videos/claymation.flv";
videoPath[5]  = "../videos/golfers.flv";
videoPath[6]  = "../videos/claymation.flv";
videoPath[7]  = "../videos/golfers.flv";
videoPath[8]  = "../videos/claymation.flv";
videoPath[9]  = "../videos/golfers.flv";
videoPath[10] = "../videos/claymation.flv";
videoPath[11] = "../videos/golfers.flv";
videoPath[12] = "../videos/claymation.flv";
videoPath[13] = "../videos/golfers.flv";
videoPath[14] = "../videos/claymation.flv";
videoPath[15] = "../videos/golfers.flv";
videoPath[16] = "../videos/claymation.flv";
videoPath[17] = "../videos/golfers.flv";

var identPath = new Array();
identPath[0]  = "assets/videos/idents/claymation.jpg";
identPath[1]  = "assets/videos/idents/golfers.jpg";
identPath[2]  = "assets/videos/idents/claymation.jpg";
identPath[3]  = "assets/videos/idents/golfers.jpg";
identPath[4]  = "assets/videos/idents/claymation.jpg";
identPath[5]  = "assets/videos/idents/golfers.jpg";
identPath[6]  = "assets/videos/idents/claymation.jpg";
identPath[7]  = "assets/videos/idents/golfers.jpg";
identPath[8]  = "assets/videos/idents/claymation.jpg";
identPath[9]  = "assets/videos/idents/golfers.jpg";
identPath[10] = "assets/videos/idents/claymation.jpg";
identPath[11] = "assets/videos/idents/golfers.jpg";
identPath[12] = "assets/videos/idents/claymation.jpg";
identPath[13] = "assets/videos/idents/golfers.jpg";
identPath[14] = "assets/videos/idents/claymation.jpg";
identPath[15] = "assets/videos/idents/golfers.jpg";
identPath[16] = "assets/videos/idents/claymation.jpg";
identPath[17] = "assets/videos/idents/golfers.jpg";

var cuVideo = -1;
var isPlaying = true;

/* Macromedia - Flash External Interface Scripting.
-------------------------------------------------------------*/
function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    }
    else {
        return document[movieName];
    }
}

/* Macromedia - Flash External Interface Scripting.
-------------------------------------------------------------*/
function stopVideo() {
    thisMovie("mediaplayer").videoPause();
    return false;
}

/* Macromedia - Flash External Interface Scripting.
-------------------------------------------------------------*/
function loadVideo( video ) {
	num = cuVideo;
	for(var i=0;i<idMatch.length;i++) {
		if(idMatch[i] == video) {
			num = i;
		}
	}
    thisMovie("mediaplayer").videoLoad(videoPath[num],identPath[num]);
    return false;
}

/* Macromedia - Flash External Interface Scripting.
-------------------------------------------------------------*/
function nextVideo() {
	if(isPlaying) {
		cuVideo++;
		if(cuVideo > identPath.length) {
			isPlaying = false;
			return;
		}
		$("span.thumb-icon").removeClass('playing');
		$("span.thumb-icon",$('ul#portfolio-box li a').eq(cuVideo)).addClass('playing');
		thisMovie("mediaplayer").videoLoad(videoPath[cuVideo],identPath[cuVideo]);
    }
}

function randomReplace(itemToSwap) {
	var href = $('ul#portfolio-box li a img').eq(itemToSwap).attr('src');
	//alert('href:'+href);
	firstpart = href.substr(0,(href.indexOf('.jpg')));
	//check if this has a number already...
	if(firstpart.indexOf('_') != -1) {
		firstpart = href.substr(0,(href.indexOf('_')));
	}
	rand = Math.round(Math.random()*5);
	replace = firstpart+"_"+rand+".jpg";
	$('ul#portfolio-box li a img').eq(itemToSwap).attr('src',replace);
}

function chooseRandom() {
	var count = $('ul#portfolio-box li a img').length;
	randReplaceNumber = Math.round(Math.random()*count);
	randomReplace(randReplaceNumber);
	setTimeout("chooseRandom()",1000);
}

$(document).ready(function() {
	//Setup Thumb Clicks
	$('ul#portfolio-box li a').click(function(e) {
		e.preventDefault();
		var href = $(this).attr('href');
		//FIX IE (Adjust href for IE, as it returns the FULL url, not what the href attr actually contains)
		href = href.substr((href.indexOf('#')));
		$('ul#portfolio-info li').hide();
		$('#intro').show();
		//$(href).show();
		//Ignore this for the moment.
		//loadVideo(href);
	});
	
	$('ul#portfolio-box li a').mouseover(function(e) {
		e.preventDefault();
		$("span.thumb-icon",this).addClass('img-over');
	});
	
	$('ul#portfolio-box li a').mouseout(function(e) {
		e.preventDefault();
		$("span.thumb-icon",this).removeClass('img-over');
	});
	
	chooseRandom();
});