function resetSkins()
{
	var winHeight = document.body.clientHeight;
	var contentHeight = document.getElementById('Content').offsetHeight;
	var navHeight = 1000; // Not dynamically generated due to liquid height in nav column - must be explicit
	
	if(document.getElementById('SideModules'))
	{
		// There are side modules
		// Check to see if Navigation column is longer than content
		if(contentHeight < navHeight)
		{
			contentHeight = navHeight;
		}
	}
	
	
	//alert("Nav Height: " + navHeight + "  |  " + "Content Height: " + contentHeight);
	
	if(contentHeight > winHeight)
	{
		document.getElementById('Wrapper').style.height=contentHeight + "px";
		document.getElementById('Navigation').style.height=contentHeight + "px";
		document.getElementById('Sidebar').style.height=contentHeight + "px";
	}
	else
	{
		document.getElementById('Wrapper').style.height=winHeight + "px";
		document.getElementById('Navigation').style.height=winHeight + "px";
		document.getElementById('Sidebar').style.height=winHeight + "px";
	}

}

$(document).ready(function() 
{
  resetSkins();
  initTabs();
  //initSetNav();
});

$(window).resize(function()
{resetSkins();});

var currentTab = "news";

function initTabs()
{
	$("#Lab").hide();
	
	$("#NewsTab").click(function () 
	{
		if(currentTab != "news")
		{
			$(this).removeClass('inactive');
			$(this).addClass('active');
			$("#LabTab").removeClass('active');
			$("#LabTab").addClass('inactive');
			
			$("#News").toggle("slide", {}, 250);
			$("#Lab").hide();
			
			currentTab = "news";
		}
    });
	 
	$("#LabTab").click(function () 
	{
		if(currentTab != "lab")
		{
			$(this).addClass('active');
			$("#NewsTab").addClass('inactive');
			
			
			$("#Lab").toggle("slide", {}, 250);
			$("#News").hide();
			
			currentTab = "lab";
		}
    });
	
}

function initLightbox()
{
	$(function() 
	{
        $('ul.thumbnails a').lightBox();
    });
}



/* Browser Detection */

var BrowserDetect = 
{
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

var currentCompetency = "Services";

function showCompetencies(btn, id)
{
	if(btn != currentCompetency)
	{
		currentCompetency = btn;
		
		// hide all competencies
		$("#Services").hide();
		$("#Technologies").hide();
		$("#Industries").hide();
		
		// Now show correct competency
		$("#" + btn + "").fadeIn("slow");
		
		// Correct breadcrumb
		$("#Button1").removeClass('active');
		$("#Button2").removeClass('active');
		$("#Button3").removeClass('active');
		
		$("#Button" + id).addClass('active');
		
	}
}

function initSetNav()
{
	initThumbStyles();
    
	var setWidth = 510;
	var ready = true;
	
	// Init Button State - using anchor tag
	$("a.next").bind("load", function(e)
	{
		var thumbDiv = $(this).parent().parent().next().children().get(0);
		var setDivision = $(this).attr("rel");
		var bcList = $(this).parent().parent().prev().prev();
		var breadcrumb = $(bcList).children().get(0);
		var numOfThumbs = $(thumbDiv).children().size();
		var numOfSets = Math.ceil(numOfThumbs / setDivision);
		
		if(numOfSets < 2)
		{$(this).parent().addClass('inactive');}
		
		
		for(var i = 1; i < numOfSets; i++)
		{
			var newBC = $(breadcrumb).clone(true).insertAfter(breadcrumb);	
			$(newBC).children().removeClass("active");
		}
		
	});
	
	$("a.next").load();
	
	
	// Init Button Actions
	$("a.next").click(function()
	{
		if(ready)
		{
			var thumbDiv = $(this).parent().parent().next().children().get(0);
			var prevLink = $(this).parent().prev();
			var setDivision = $(this).attr("rel");
			
			
			// Find Total Width of Thumbnail Container
			// Find how many LIs are in UL
			var numOfThumbs = $(thumbDiv).children().size();
			var numOfSets = Math.ceil(numOfThumbs / setDivision);
			
			var containerWidth = (numOfSets * setWidth) - setWidth;
			
			// Build Breadcrumbs
			
			// Set Navigation
			
			
			var xPos = $(thumbDiv).css("left"); // Retrieves number + px
			
			if(xPos == "auto")
			{
				xPos = "0px";
			}
			
			var temp = new Array();
			temp = xPos.split('px');
			var curX = Math.abs(temp[0]);
			var newX = 0;
			
	
			
			// First establish current set
			var curSet = (curX / setWidth) + 1;
			
			
			if(curX < containerWidth)
			{
				// X is greater than 0 -- we've gone previous
				newX = curX + setWidth;
				
				curSet++;
				
				if(curSet == numOfSets)
				{
					$(this).parent().removeClass('active');
					$(this).parent().addClass('inactive');
				}
				else
				{
					$(this).parent().removeClass('inactive');
					$(this).parent().addClass('active');
				}
			}
			else
			{
				//alert("Dont proceed");
				newX = curX;	
			}
			
			if(numOfSets > 1)
			{
				$(prevLink).removeClass("inactive");
				$(prevLink).addClass("active");		
			}
			
			var bcList = $(this).parent().parent().prev().prev();
			var oldbreadcrumb = $(bcList).children().get((curSet - 2));
			var breadcrumb = $(bcList).children().get((curSet - 1));
			
			$(oldbreadcrumb).children().removeClass("active");
			$(oldbreadcrumb).children().addClass("inactive");
			$(breadcrumb).children().addClass("active");
			
			var x = "-" + newX.toString() + "px";
			ready = false;
			$(thumbDiv).animate(
			{ 
				left: x
			}, 500, "swing", onTransitionComplete);
		}
	})
	
	$("a.previous").click(function()
	{
		if(ready)
		{
			var thumbDiv = $(this).parent().parent().next().children().get(0);
			var nextLink = $(this).parent().next();
			var setDivision = $(this).attr("rel");

			
			// Find Total Width of Thumbnail Container
			// Find how many LIs are in UL
			var numOfThumbs = $(thumbDiv).children().size();
			var numOfSets = Math.ceil(numOfThumbs / setDivision);
			
			var xPos = $(thumbDiv).css("left"); // Retrieves number + px
			var temp = new Array();
			temp = xPos.split('px');
			var curX = Math.abs(temp[0]);
			var newX = 0;
			
			// First establish current set
			var curSet = (curX / setWidth) + 1;
			
			
			
			//alert(curSet);
			
			if(temp[0] < 0)
			{
				//alert(curX);
				newX = -(curX - setWidth);
				curSet--;
				if(curSet == 1)
					{
						// Don't do anything - we're home position
						//alert("Don't proceed.");
						$(this).parent().removeClass('active');
						$(this).parent().addClass('inactive');
					}
					else
					{
						if(curSet == 1)
						{
							$(this).parent().removeClass('active');
							$(this).parent().addClass('inactive');
						}
						else
						{
							$(this).parent().removeClass('inactive');
							$(this).parent().addClass('active');
						}
					}
			}
			else
			{
				// We've gont forward and need to go back
				if(curX == 0)
				{
					
					curSet--;	
					
					// Don't do anything - we're home position
					//alert("Don't proceed.");
					$(this).parent().removeClass('active');
					$(this).parent().addClass('inactive');
				}
				else
				{
					//alert("CurX is greater than 0");
					newX = curX - setWidth;
					curSet--;	
					
					
					
					if(curSet == 1)
					{
						$(this).parent().removeClass('active');
						$(this).parent().addClass('inactive');
					}
					else
					{
						$(this).parent().removeClass('inactive');
						$(this).parent().addClass('active');
					}
				}
				
			}
			
			if(numOfSets > 1)
			{
				$(nextLink).removeClass("inactive");
				$(nextLink).addClass("active");	
			}
			
			if(curSet != 0)
			{
				var bcList = $(this).parent().parent().prev().prev();
				var breadcrumb = $(bcList).children().get((curSet - 1));
				var oldbreadcrumb = $(bcList).children().get((curSet));
				$(oldbreadcrumb).children().removeClass("active");
				$(oldbreadcrumb).children().addClass("inactive");
				$(breadcrumb).children().addClass("active");	
			}
			
			
			var x = "" + newX.toString() + "px";
			ready = false;
			$(thumbDiv).animate(
			{ 
				left: x
			}, 500, "swing", onTransitionComplete);
		}
		
			
	})
	
	function onTransitionComplete()
	{
		ready = true;
		//alert(ready);
	}
}

function initThumbStyles()
{
	// Init Styles
	$("span.pThumbContainer").mouseover(function()
	{
		$(this).removeClass('pThumbContainerOut');
		$(this).addClass('pThumbContainerOver');
	});	
	
	$("span.pThumbContainer").mouseout(function()
	{
		$(this).removeClass('pThumbContainerOver');
		$(this).addClass('pThumbContainerOut');
	});	
	
	// View
	$("span.pThumbContainer2").mouseover(function()
	{
		$(this).removeClass('pThumbContainerOut');
		$(this).addClass('pThumbContainer2Over');
	});	
	
	$("span.pThumbContainer2").mouseout(function()
	{
		$(this).removeClass('pThumbContainer2Over');
		$(this).addClass('pThumbContainerOut');
	});	
	
	
	$("ul.thumbnails").css("left", "0px");
	
}

