//if ( com == undefined ) com = {};
//if ( com.soulfresh == undefined ) com.soulfresh = {};

/**
 * Change the colors of elements on the homepage
 */
com.soulfresh.ChangeColors = function()
{
	// create the list of colors over which we will iterate
	this.colors = [ "#99cc00", "#33cc99", "#0066ff", "#663399", "#990033", "#cc0000", "#ff6600", "#ffbb00" ];
}

/**
 * Change the color of the portfolio items
 */
com.soulfresh.ChangeColors.prototype.changePortfolioItems = function()
{
	// get the portfolio items
	var items = this.getItemsByClass( document.body, "div", "item" );
	
	// change the colors of all portfolio items
	this.setColors( items );
}

/**
 * Change the color of the page background
 */
com.soulfresh.ChangeColors.prototype.changeBackground = function()
{
	// change the body's background color
	var vRand = Math.floor( Math.random() * this.colors.length );
	document.body.style.backgroundColor = this.colors[ vRand ];
}

/**
 * Change the color of the items in the additional info section
 */
com.soulfresh.ChangeColors.prototype.changeInfo = function()
{
	// get the info items
	var container = this.getItemsByClass( document.body, "div", "contactItems")[0];
	var h3List = container.getElementsByTagName( "h3" );
	var pList = container.getElementsByTagName( "p" );
	
	// loop through these items
	var n = h3List.length;
	for ( var i = 0; i < n; i++ )
	{
		// set background color
		h3List[i].style.backgroundColor = this.colors[i];
		
		// set text
		pList[i].style.color = this.colors[i];
		
		// set the link colors
		var links = pList[i].getElementsByTagName( "a" );
		var m = links.length;
		for ( var j = 0; j < m; j++ )
		{
			links[j].style.color = this.colors[i];
		}
	}
}

/**
 * Set the colorizable parts of all divs passed in
 * @param vItems the list of portfolio divs to be colored
 */
com.soulfresh.ChangeColors.prototype.setColors = function( vItems )
{
	var vColor = 0;
	var n = vItems.length;
	for ( var i = 0; i < n; i++ )
	{
		// set items
		this.setHeaderColor( vItems[i], this.colors[ vColor ] );
		this.setContentBorderColor( vItems[i], this.colors[ vColor ] );
		this.setImageBorderColor( vItems[i], this.colors[ vColor ] );
		this.setLinksColor( vItems[i], this.colors[ vColor ] );
		
		// change color
		if ( vColor < this.colors.length - 1 )
			++vColor;
		else vColor = 0;
	}
}

com.soulfresh.ChangeColors.prototype.setHeaderColor = function( vItem, vC )
{
	var vHeader = vItem.getElementsByTagName( "h3" )[0];
	vHeader.style.backgroundColor = vC;	
}

com.soulfresh.ChangeColors.prototype.setContentBorderColor = function( vItem, vC )
{
	var vContent = this.getItemsByClass( vItem, "div", "details" )[0];
	vContent.style.borderColor = vC;
}

com.soulfresh.ChangeColors.prototype.setImageBorderColor = function( vItem, vC )
{
	var vImageContainer = this.getItemsByClass( vItem, "div", "image" )[0];
	var vImage = vImageContainer.getElementsByTagName( "img" )[0];
	vImage.style.borderColor = vC;
}

com.soulfresh.ChangeColors.prototype.setLinksColor = function( vItem, vC )
{
	var vLinksDiv = this.getItemsByClass( vItem, "div", "view" )[0];
	var vLinks = vLinksDiv.getElementsByTagName( "a" );
	
	var n = vLinks.length;
	for ( var i = 0; i < n; i++ )
	{
		var vCurrL = vLinks[i];
		vCurrL.style.color = vC;
	}
}

/**
 * Find a list of nodes in an HTML Collection by tagname and classname
 * 
 * @param {@code Node}: the node within which to search
 * @param {@code String}: the tagname of the element you wish to find
 * @param {@code String}: the class of the element you wish to find
 * @return {@code Array}: an array of matching nodes
 */
com.soulfresh.ChangeColors.prototype.getItemsByClass = function( varNode, varTagName, varClassName )
{

	// declare variables
	var varArray = [];
	var varCollection = varNode.getElementsByTagName( varTagName );
	var varTotal = varCollection.length;
	
	// loop
	for ( var i = 0; i < varTotal; i++ )
	{
		// declare variables
		var varCurr = varCollection[i];
		var varCurrClass = varCurr.className;
		
		// if this is one of the elements we're looking for, save it
		if ( varCurrClass == varClassName )
			varArray.push( varCurr );
	}
	
	return varArray;

}
