// the ftk class contains shared varaibles as well as being an umbrella class used
// for registering ftk components
function ftk(){}

//---------------------- Static Class Variables ----------------------//
ftk.componentPath = '';
ftk.intervalDelay = 5; // delay between interval calls
ftk.loadedComponents = new Array();
//this._isIE = navigator.appName == "Microsoft Internet Explorer"; // haven't found a need for this yet

//------------------------ Static Functions ------------------------//

// sets path used for registerComponent. call this before registerComponent
// the trailing '/' is optional and is added if missing
ftk.setComponentPath = function(path)
{
	if(path.charAt(path.length-1)!='/')
		path=path+'/';
	ftk.componentPath=path;
}

// imports another script file containing a ftk component
ftk.registerComponent = function(name)
{
	// check if already registered
	if(ftk.isComponentRegistered(name))
		return;

	// import script
	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.src = ftk.componentPath + name + '.js';
	document.getElementsByTagName('head')[0].appendChild(script);
	
	// add to Array
	ftk.loadedComponents.push(name);
}

// checks to see if component has been REGISTERED. This does not guarentee it has been fully loaded yet
ftk.isComponentRegistered = function(name)
{
	for(var i = 0 ; i < ftk.loadedComponents.length ; i++)
		if(ftk.loadedComponents[i] == name)
			return true;
	return false;
}

// checks to see if component has been registered and is completely loaded.
ftk.isComponentLoaded = function(name)
{
	if(!ftk.isComponentRegistered(name))
		return false;
		
	try
	{
		var tmp = eval(name + ".loaded");
		return tmp;
	}
	catch(e)
	{
		return false;
	}
}

ftk.areAllComponentsLoaded = function()
{
	for(var i = 0 ; i < ftk.loadedComponents.length ; i++)
		if(!ftk.isComponentLoaded(ftk.loadedComponents[i]))
			return false;
	return true;
}

// utility function for getting the viewport's width
ftk.getViewportDimensions = function()
{
	var dim = new Array();
	
	if(document.body.innerWidth != null && document.body.innerHeight != null)
	{
		dim['width'] = document.body.innerWidth;
		dim['height'] = document.body.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		dim['width'] = document.documentElement.clientWidth;
		dim['height'] = document.documentElement.clientHeight;
	}
	else
	{
		dim['width'] = document.body.clientWidth;
		dim['height'] = document.body.clientHeight;
	}
	
	return dim;
}

// utility function for getting the scroll positions
ftk.getScrollPosition = function()
{
	var coords = new Array();

	if(document.body.pageXOffset != null && document.body.pageYOffset != null)
	{
		coords['x'] = document.body.pageXOffset;
		coords['y'] = document.body.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		coords['x'] = document.documentElement.scrollLeft;
		coords['y'] = document.documentElement.scrollTop;
	}
	else
	{
		coords['x'] = document.body.scrollLeft;
		coords['y'] = document.body.scrollTop;
	}
	
	return coords;
}

// utility function for setting opacity, cross-browser
ftk.setOpacity = function(id, opacity)
{
	// can pass an ID *OR* the object itself
	obj = typeof id == 'string' ? document.getElementById(id) : id;
	
	if(obj == null)
		return;

    obj.style.opacity = (opacity/101).toFixed(4); 
    obj.style.MozOpacity = (opacity/101).toFixed(4); 
    obj.style.KhtmlOpacity = (opacity/100).toFixed(4); 
    obj.style.filter = "alpha(opacity="+opacity+")"; 
}