var arUnreal2k4Images = ["Resources/Gallery/3d/20xx/001","Resources/Gallery/3d/20xx/002","Resources/Gallery/3d/20xx/003","Resources/Gallery/3d/20xx/004","Resources/Gallery/3d/20xx/005","Resources/Gallery/3d/20xx/006","Resources/Gallery/3d/20xx/008","Resources/Gallery/3d/20xx/009","Resources/Gallery/3d/20xx/010","Resources/Gallery/3d/20xx/011"];
var arUnreal3Images = ["Resources/Gallery/3d/NLG/DemoworkC","Resources/Gallery/3d/NLG/DemoworkD","Resources/Gallery/3d/NLG/DemoworkE"];
var arPropImages = ["Resources/Gallery/3d/Props/Vendingmachine","Resources/Gallery/3d/Props/AncientRuins003","Resources/Gallery/3d/Props/AncientRuins002","Resources/Gallery/3d/Props/AncientRuins001","Resources/Gallery/3d/Props/WineDrum002","Resources/Gallery/3d/Props/WineDrum001","Resources/Gallery/3d/Props/WineDrum004","Resources/Gallery/3d/Props/oilpump"];

var arCharacterImages = ["Resources/Gallery/2d/Characters/ChargedCharacter","Resources/Gallery/2d/Characters/DespoticStudioThumbnails","Resources/Gallery/2d/Characters/machoidsthumbnails","Resources/Gallery/2d/Characters/MonsterValueConcepts"];
var arIllustrationImages = [ "Resources/Gallery/2d/Illustrations/Alley",
			"Resources/Gallery/2d/Illustrations/Jungleconcept_2009",
			"Resources/Gallery/2d/Illustrations/Theroom",
			"Resources/Gallery/2d/Illustrations/UncleTomsCabin",
			"Resources/Gallery/2d/Illustrations/Me_and_my_dog_Skip",
			"Resources/Gallery/2d/Illustrations/RedCityfinal300dpi",
			"Resources/Gallery/2d/Illustrations/church2",
			"Resources/Gallery/2d/Illustrations/SPIDERc",
			"Resources/Gallery/2d/Illustrations/midevil",
			"Resources/Gallery/2d/Illustrations/BoyandhisBot",
			"Resources/Gallery/2d/Illustrations/concpetbg006b",
			"Resources/Gallery/2d/Illustrations/bgconceptbg002",
			"Resources/Gallery/2d/Illustrations/environmentpage"];

var currentImages = arIllustrationImages;
var begIndex = 0;
var endIndex = 6;
var thumbnailSize = 7;
var shiftSize = 1;
var imageIndex = 1;

var extensionThumbnail = "_Thumbnail.jpg";
var extensionPreview = "_Preview.jpg";
var extensionGreyscale = "_Greyscale.jpg";
var extensionNormal = ".jpg";

function F_ShiftLeft()
{
	if( thumbnailSize >= currentImages.length )
		return;
		
	endIndex = begIndex;
	begIndex = begIndex - shiftSize;
	
	if( begIndex < 0 )
	{
		begIndex = currentImages.length + begIndex;
	}

	//document.write( begIndex );
	//document.write( endIndex );

	var i=begIndex;
	var j=0;
	for(j=0; j<=shiftSize; j++)
	{		
		if( j == 0 )
			F_Swap_Image('thumb01',currentImages[i]+extensionGreyscale);
		if( j == 1 )
			F_Swap_Image('thumb02',currentImages[i]+extensionGreyscale);
		if( j == 2 )
			F_Swap_Image('thumb03',currentImages[i]+extensionGreyscale);
		if( j == 3 )
			F_Swap_Image('thumb04',currentImages[i]+extensionGreyscale);
		if( j == 4 )
			F_Swap_Image('thumb05',currentImages[i]+extensionGreyscale);
		if( j == 5 )
			F_Swap_Image('thumb06',currentImages[i]+extensionGreyscale);
		if( j == 6 )
			F_Swap_Image('thumb07',currentImages[i]+extensionGreyscale);
			
		i++;	
		if( i >= currentImages.length )
			i = 0;
	}
}

function F_ShiftRight()
{
	if( thumbnailSize >= currentImages.length )
		return;
		
	begIndex = begIndex + 1;
	endIndex = endIndex + 1;
	
	if( begIndex >= currentImages.length )
	{
		begIndex = begIndex - currentImages.length;
	}
	if( endIndex >= currentImages.length )
	{
		endIndex = endIndex - currentImages.length;
	}
	
	var i=begIndex;

	var j=0;
	for(j=0; j<=thumbnailSize-1; j++)
	{		
		if( j == 0 )
			F_Swap_Image('thumb01',currentImages[i]+extensionGreyscale);
		if( j == 1 )
			F_Swap_Image('thumb02',currentImages[i]+extensionGreyscale);
		if( j == 2 )
			F_Swap_Image('thumb03',currentImages[i]+extensionGreyscale);
		if( j == 3 )
			F_Swap_Image('thumb04',currentImages[i]+extensionGreyscale);
		if( j == 4 )
			F_Swap_Image('thumb05',currentImages[i]+extensionGreyscale);
		if( j == 5 )
			F_Swap_Image('thumb06',currentImages[i]+extensionGreyscale);
		if( j == 6 )
			F_Swap_Image('thumb07',currentImages[i]+extensionGreyscale);
		
		i++;	
		if( i >= currentImages.length )
			i = 0;
	}
}

//Declare functions
function F_CurrentImageSelected(id)
{
	if(document.getElementById) 
	{
		var img = document.getElementById(id);
		var imgSrc = img.src;

		return img.src;
	}
}

function F_SetTargetHref(id,target)
{
	if(document.getElementById) 
	{
		var img = document.getElementById(id);
		img.href = target;
	}
}

function F_FindName(name)
{	
	if(currentImages[imageIndex].search(name) == -1)
	{
		return false;
	}
	
	return true;
}

function F_UpdateDescription()
{
	var imageDescription = document.getElementById("Description_Text");

	if( currentImages == arIllustrationImages )	// ILLUSTRATIONS
	{
		if( F_FindName("Alley") )
		{
			imageDescription.innerHTML = "Through this concept art, I was able to help MageStick to define the art direction of its upcoming action title. Copyright MageStick Games 2009";
		}
		else if( F_FindName("Jungleconcept_2009") )
		{
			imageDescription.innerHTML = "A conceptual image for MageStick Games";
		}
		else if( F_FindName("UncleTomsCabin") )
		{
			imageDescription.innerHTML = "A conceptual painting of a derelict  cabin . Inspiration for this  piece came from watching the movie Monster House.";
		}
		else if( F_FindName("Theroom") )
		{
			imageDescription.innerHTML = "Simple concept painting of a indoor storage room";		
		}
		else if( F_FindName("RedCityfinal300dpi") )
		{
			imageDescription.innerHTML = "Focusing on rule of thirds and circle composition. This was more less an experiment in combining what I have learned about composition.";		
		}
		else if( F_FindName("bgconceptbg002") )
		{
			imageDescription.innerHTML = "An early concept of what 20xx could be.";
		}
		else if( F_FindName("BoyandhisBot") )
		{
			imageDescription.innerHTML = "A Boy and his Bot was composition study inspired by my childhood fascination of robots. I think every child wants a GIANT Robot at some point in their life… go Tae kwon V!";
		}
		else if( F_FindName("church2") )
		{
			imageDescription.innerHTML = "20xx is a conceptual painting of a level I created in unreal2k4. I experimented with several different moods and values. Several images were created before the final level was completed.";			
		}
		else if( F_FindName("concpetbg006b") )
		{
			imageDescription.innerHTML = "This concept   was to experiment with mood for 20xx Unreal level. This concept really helped to establish an overall color palate. This was the start of what I wanted to achieve in Unreal.";		
		}
		else if( F_FindName("environmentpage") )
		{
			imageDescription.innerHTML = "This was done using Painter x. ";		
		}
		else if( F_FindName("Me_and_my_dog_Skip") )
		{
			imageDescription.innerHTML = "This is a painting of me and my dog, Who just passed away at 18 (human) years…Insane I know… This painting is about reaching out and combining real life experiences with imagination... Oh the possibilities...";		
		}
		else if( F_FindName("SPIDERc") )
		{
			imageDescription.innerHTML = "I did several designs of creatures and various Spider like ideas. Again starting with a thumbnail sketches, pushing it further then taking it to finalized concept stage.";		
		}
		else if( F_FindName("midevil") )
		{
			imageDescription.innerHTML = "A thumbnail study inspired by 300 and lord of the rings. This was part of an in class demo I gave in china.";
		}
		else
		{
			imageDescription.innerHTML = "";	
		}		
	}
	else if( currentImages == arCharacterImages ) // CHARACTERS
	{
		if( F_FindName("machoids") )
		{
			imageDescription.innerHTML = "More thumbnail sketches.";	
		}
		else if( F_FindName("ChargedCharacter") )
		{
			imageDescription.innerHTML = "A conceptual character design for an indie game called Charged. I stared out with various thumbnails, and value studies… Then when I had that nailed down I took it into painter to have some fun.";
		}
		else if( F_FindName("DespoticStudioThumbnails") )
		{
			imageDescription.innerHTML = "These are just some of the various thumbnails and sketches used for Charged. I love this stage of design. If I could I would do this all day. At This stage you are really just focusing on 1-2 aspects of the design… Thanks CB!";
		}
		else if( F_FindName("MonsterValueConcepts") )
		{
			imageDescription.innerHTML = "Some creature renders… Done with ball point sketches then rendered with grayscale markers.";		
		}
		else 
		{
			imageDescription.innerHTML = "";	
		}
	}
	else if( currentImages == arPropImages ) // PROPS
	{
		imageDescription.innerHTML = "These are various in game props created in Maya. Textures were created in Photoshop. Normal maps were generated in Maya and Crazy bump.";		
	}
	else if( currentImages == arUnreal3Images ) // NEXT LEVEL GAMES STUFF
	{
		imageDescription.innerHTML = "This is a small environment based on a next level games concept. Final renders were done in unreal 3. All static meshes were created using Maya. Normal maps were generated using both Maya and Photoshop. Diffuse maps and Spec maps were created in Photoshop.";		
	}
	else if( currentImages == arUnreal2k4Images ) // 20XX
	{
		imageDescription.innerHTML = "20xx is my own concept brought to life using the Unreal 2k4 game engine. All static meshes were modeled in Maya and nothing is default Unreal. All Texture maps and Spec maps created using Photoshop CS and Painter x. Conceptual design works of 20xx can be seen in the illustration section.";		
	}
	else
	{
		imageDescription.innerHTML = "";
	}
}


function F_SetImageIndex(i)
{
	var referenceIndex;
	referenceIndex = begIndex + i;
	
	if( referenceIndex > currentImages.length )
		referenceIndex = referenceIndex - currentImages.length;
				
	imageIndex = referenceIndex-1;
	F_UpdateDescription();
}

function F_GetImagePath_ByType(id,type)
{
	var referenceIndex;
	if( id == 'thumb01' )
		referenceIndex = begIndex;
	if( id == 'thumb02' )
		referenceIndex = begIndex + 1;
	if( id == 'thumb03' )
		referenceIndex = begIndex + 2;
	if( id == 'thumb04' )
		referenceIndex = begIndex + 3;
	if( id == 'thumb05' )
		referenceIndex = begIndex + 4;
	if( id == 'thumb06' )
		referenceIndex = begIndex + 5;
	if( id == 'thumb07' )
		referenceIndex = begIndex + 6;
	
	if( referenceIndex >= currentImages.length )
		referenceIndex = referenceIndex - currentImages.length;
	
	var path = currentImages[referenceIndex] + type;
	
	return path;
}

function F_DoNothing()
{
	
}

function F_SetupGallery()
{
	var iterations = 0;
	
	if( thumbnailSize <= currentImages.length )
	{
		iterations = thumbnailSize;
	}
	else
	{
		iterations = currentImages.length;	
	}
	
	var i=0;
	var thumb;
	var thumbLink;
	var thumbId;
	var bNotEnoughThumbs = ( currentImages.length > thumbnailSize );
	
	for( i=0;i<iterations;i++ )
	{
		if( i == 0 )
		{
			thumb = document.getElementById("thumb01"); 
			thumbId = "'thumb01'";
			thumbLink = document.getElementById("thumb01_link");
		}
		else if( i == 1 )
		{
			thumb = document.getElementById("thumb02");
			thumbId = "'thumb02'";
			thumbLink = document.getElementById("thumb02_link");			
		}
		else if( i == 2 )
		{
			thumb = document.getElementById("thumb03");
			thumbId = "'thumb03'";
			thumbLink = document.getElementById("thumb03_link");			
		}
		else if( i == 3 )
		{
			thumb = document.getElementById("thumb04");
			thumbId = "'thumb04'";
			thumbLink = document.getElementById("thumb04_link");			
		}
		else if( i == 4 )
		{
			thumb = document.getElementById("thumb05");
			thumbId = "'thumb05'";
			thumbLink = document.getElementById("thumb05_link");			
		}
		else if( i == 5 )
		{
			thumb = document.getElementById("thumb06");
			thumbId = "'thumb06'";
			thumbLink = document.getElementById("thumb06_link");			
		}
		else if( i == 6 )
		{
			thumb = document.getElementById("thumb07");
			thumbId = "'thumb07'";
			thumbLink = document.getElementById("thumb07_link");			
		}
		
		thumb.src = currentImages[begIndex+i]+extensionGreyscale;
		thumb.border = 0;
		thumb.style.visibility = "visible";
		
		thumbLink.onMouseOver = "F_Swap_Image(" + thumbId + ",F_GetImagePath_ByType(" + thumbId + ",extensionThumbnail));";
		thumbLink.onMouseOut = "F_Swap_Image(" + thumbId + ",F_GetImagePath_ByType(" + thumbId + ",extensionGreyscale));";
		thumbLink.href = "javascript:F_Swap_Image('swapme',F_GetImagePath_ByType(" + thumbId + ",extensionPreview)); " + 
								  "F_SetTargetHref('swapme_Link',F_GetImagePath_ByType(" + thumbId + ",extensionNormal)); " +
								  "F_SetImageIndex(" + (i+1) + ")";
	}
	
	var removeArrows = false;
	
	var stuff = ""
	
	for( i=iterations;i<thumbnailSize;i++)
	{
		if( i == 0 )
		{
			thumb = document.getElementById("thumb01");
			thumbLink = document.getElementById("thumb01_link");
		}
		else if( i == 1 )
		{
			thumb = document.getElementById("thumb02");
			thumbLink = document.getElementById("thumb02_link");
		}
		else if( i == 2 )
		{
			thumb = document.getElementById("thumb03");
			thumbLink = document.getElementById("thumb03_link");
		}
		else if( i == 3 )
		{
			thumb = document.getElementById("thumb04");
			thumbLink = document.getElementById("thumb04_link");
		}
		else if( i == 4 )
		{
			thumb = document.getElementById("thumb05");
			thumbLink = document.getElementById("thumb05_link");
		}
		else if( i == 5 )
		{
			thumb = document.getElementById("thumb06");
			thumbLink = document.getElementById("thumb06_link");
		}
		else if( i == 6 )
		{
			thumb = document.getElementById("thumb07");
			thumbLink = document.getElementById("thumb07_link");
		}

		thumb.src = "Resources/Backgrounds/greySpace.jpg";
		thumb.border = 0;
		thumb.style.visibility = "hidden";
		
		thumbLink.onMouseOver = "";
		thumbLink.onMouseOut = "";
		thumbLink.href = "javascript:F_DoNothing();";

		removeArrows = true;
	}

	//document.write( stuff );

	if( removeArrows )
	{
		var arrow = document.getElementById("shift_right");
		var arrowLink = document.getElementById("shift_right_Link");
		arrowLink.style.visibility = "hidden";
		arrow.src = "Resources/Backgrounds/greySpace.jpg";
	}
	else
	{
		var arrow = document.getElementById("shift_right");
		var arrowLink = document.getElementById("shift_right_Link");
		arrowLink.style.visibility = "visible";
		arrow.src = "Resources/Gallery/Arrows/RightArrow_greyscale.jpg";
	}

/*
	var arrow = document.getElementById("shiftForward");
	arrow.src = "Resources/Gallery/General/ForwardArrow.jpg";
		
	arrow = document.getElementById("shiftBack");
	arrow.src = "Resources/Gallery/General/BackArrow.jpg";
	
	if( removeArrows == true )
	{
		var arrow = document.getElementById("shiftForward");
		arrow.src = "";
		
		arrow = document.getElementById("shiftBack");
		arrow.src = "";
	}
*/

	var preview = document.getElementById("swapme");
	preview.src = currentImages[begIndex]+extensionPreview;
		
	var swapme_Link_Target = document.getElementById("swapme_Link");
	swapme_Link_Target.href = currentImages[begIndex]+extensionNormal;
	
	F_SetImageIndex(1);
}

function F_ChangeGalleryTo(newGallery)
{
	currentImages = newGallery;
	begIndex = 0;
	endIndex = 4;

	F_SetupGallery();
	F_SetImageIndex(1);
}
