/**
 * Utilities library
 *
 * @author Vali Dumitru
 */
var Utils = window.Utils || {};

/**
 * Redirects the user to a given URL
 *
 * @param {String} url
 */
Utils.goToURL = function(url) {
	if(url == undefined || url == null) {
		alert('Invalid URL passed in (Utils::goToURL)!');
		return false;
	}

	window.location.href = url;
}

/**
 * Fixes the links that need to be opened in another window/parent window, etc.
 * Using the target attribute on links in XHTML Strict breaks the markup validation
 */
Utils.parseLinks = function() {
	var allLinks = $$('body a[rel=external]');
	var totalLinks = allLinks.length;

	if (totalLinks > 0) {
		for (var i = 0; i < totalLinks; i++) {
			allLinks[i].target = '_blank';
		}
	}
}

/**
 * Embeds a SWF into a page using the given options
 *
 * @param {Object} options
 */
Utils.embedSWF = function(options)
{
	var defaults = {
		url: '',
		container: 'elementID',
		width: 500,
		height: 350,
		flashVars: {},
		parameters: {
			quality: 'high',
			menu: false,
			wmode: 'transparent'
		},
		attributes: {}
	};

	if(options == undefined || options == null)
	{
		options = defaults;
	}
	else
	{
		// Allow skipping certain options to be set to the default values
		// You can pass in only the options you want to override
		for(var x in defaults)
		{
			eval('if(!options.' + x + ') options.' + x + ' = defaults.' + x + ';');
		}
	}

	swfobject.embedSWF(options.url, options.container, options.width, options.height, '9.0.0', '', options.flashVars, options.parameters, options.attributes);
}

