var so, contentURL;



function setupSWFObject()
{
	so.addVariable('logoSrc', 'images/logo_treo500v.png');
	so.addVariable('logoSize', '94,24');
	
	var sectionIDs =
	[
		'chat',
		'browse',
		'organize',
		'play',
		'work',
		'gallery',
		'specs',
		'buy'
	];
	var sectionURLs =
	[
		'chat.html',
		'browse.html',
		'organise.html',
		'play.html',
		'work.html',
		'gallery.html',
		'specs.html',
		'http://www.palm.com/it/it/sales/'
	];
	var sectionNames =
	[
		'Chat',
		'Navigazione',
		'Organizzazione',
		'Divertimento',
		'Lavoro',
		'Galleria',
		'Specifiche',
		'Dove comprare'
	];
	
	so.addVariable('sectionIDs',   encodeURIComponent(sectionIDs.join(',')));
	so.addVariable('sectionURLs',  encodeURIComponent(sectionURLs.join(',')));
	so.addVariable('sectionNames', encodeURIComponent(sectionNames.join(',')));
	
	
	
	/////////////// TRACKING ///////////////////////////
	
	so.addVariable('AS_URL',            '/js/OmnitureActionSource.swf');
	so.addVariable('AS_Account',        'palmglobal, palmall, palmemea');
	so.addVariable('AS_PageNamePrefix', 'emea:[country abbr]:smartphones:treo500v:'); // section ID automatically appended
	so.addVariable('AS_Channel',        'products');
	
	var asProps = new Array();
	asProps[1]  = 'emea';           // region
	asProps[2]  = '[country abbr]'; // country
	asProps[4]  = '';               // os
	asProps[5]  = 'smartphones';    // product family
	asProps[6]  = 'treo500v';       // device name
	asProps[7]  = '[carrier name]'; // carrier name
	asProps[18] = 'es';             // language
	so.addVariable('AS_Props', encodeURIComponent(asProps.join(',')));
	
	so.addVariable('buy_PageURL',  '[buy link]?creativeID=[country abbr]_treo500v_buy');
	so.addVariable('buy_LinkType', 'o');
	so.addVariable('buy_PageName', '[region]:[country abbr]:treo500v:buy link');
	
	
	
	so.addParam('menu', 'false');
	so.addParam('wmode', 'transparent');
	so.write('flashcontent');
}



function loadContent(url)
{
	if (url != contentURL)
	{
		contentURL = url;
		
		if (url.substring(0, 7) == "http://")
		{
			window.open(url, '_self');
		}
		else
		{
			new Ajax.Updater('content', 'content/_'+url,
			{
				method: 'get',
				onSuccess: function()
				{
					if (navigator.userAgent.indexOf('Safari') != -1)
					{
						setTimeout('makeAbsoluteLinks()', 100);
					}
				}
			});
		}
	}
}

function makeAbsoluteLinks()
{
	var links = $$('#content a');
	links.each(function(link)
	{
		var href = link.getAttribute('href');
		var anchor = href.indexOf('#');
		if (anchor != -1)
		{
			link.setAttribute('href', 'content/' + href.substring(anchor+1, href.length) + '.html');
		}
	});
}



Event.onReady(function()
{
	menuItems = $$("#menu li > a[href]:first-child");
	so = new SWFObject('main.swf', 'flashMovie', '910', '460', '8', '#fff');
	
	if
	(
		so.skipDetect ||
		so.getAttribute('doExpressInstall') ||
		so.installedVer.versionIsValid(so.getAttribute('version'))
	)
	{
		setupSWFObject();
	}
});
