function isInternetExplorer()
{
  return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

function calculatedWidth(object)
{
	return (typeof(object.clientWidth) !== 'undefined') && (object.clientWidth > 0) 
		? object.clientWidth 
		: object.width; 
}

function calculatedHeight(object)
{
	return (typeof(object.clientHeight) !== 'undefined') && (object.clientHeight > 0) 
			? object.clientHeight 
			: object.height; 
}

function getAdjustedDimensions(initialWidth, initialHeight, vwWidth, vwHeight)
{
	adjustedWidth = initialWidth;
	adjustedHeight = initialHeight;
	
	if (initialWidth > vwWidth) 
	{
		factor = vwWidth/initialWidth;
		adjustedWidth = initialWidth * factor;
		adjustedHeight = initialHeight * factor;
	}

	if (adjustedHeight > vwHeight) 
	{
		factor = vwHeight/adjustedHeight;
		adjustedWidth = adjustedWidth * factor;
		adjustedHeight = adjustedHeight * factor;
	}
	
	result = 
	{
			width : adjustedWidth,
			height : adjustedHeight
	};

	return result;
}

function getTargetAdjustedDimensions(initialWidth, initialHeight, target)
{
	result = getAdjustedDimensions
	(
			initialWidth, 
			initialHeight, 
			calculatedWidth(target), 
			calculatedHeight(target)
	);

	return result;
}

function getObjectsDimensions(object, target)
{
	result = getAdjustedDimensions
	(
				calculatedWidth(object), 
				calculatedHeight(object), 
				calculatedWidth(target), 
				calculatedHeight(target)
	);

	return result;
}

function fillAndCenter(object, target)
{
	result = getObjectsDimensions(object, target);

    $(object).width(result.width);
    $(object).height(result.height);
    $(object).css('left', ($(target).width() - $(object).width())/2);
    $(object).css('top', ($(target).height() - $(object).height())/2);

	return result;
}

function fillAndCenterRelative(object, target)
{
	result = getObjectsDimensions(object, target);

    $(object).width(result.width);
    $(object).height(result.height);
    $(object).css('margin-left', ($(target).width() - $(object).width())/2);
    $(object).css('margin-top', ($(target).height() - $(object).height())/2);

	return result;
}

function convertTextBreaks(input)
{
	if (input)
	{
		return input.replace(/\n/g, '<br/>');	
	}
	return  '';
}

function depixelize(value)
{
	return parseInt(value.substring(0, value.length - 2));
}

function computeLocationHashed(hashValue)
{
	protocol = window.location.protocol;
	host = window.location.host;
	port = window.location.port;
	
	newLocation = protocol + '//' + host + ((port.length == 0) ? '' : ':' + port) + '#p=' + hashValue;
	return newLocation;
}

function setLocationHash(hashValue)
{
	window.location.replace(computeLocationHashed(hashValue));
}

function getPathElementName(name)
{
	name = name.replace(/ /g, '_');
	name = name.replace(/[^a-zA-Z0-9_]+/g, '');
	return name.toLowerCase();
}
