/*  ******************************************/
/*  **  Configuration  **/

var MHLN_FLASH_LINK_DIRECT = true; //calls the swf file directly instead of its html
var	MHLN_FLASH_MARGIN_WIDTH = 18;
var	MHLN_FLASH_MARGIN_HEIGHT = 25;

/*	Javascript functions  */
// **** Parses Query string and return an associative array *****
function parse_qs()
{
	var getitem = new Array();
	if(location.search.length > 2) 
	{
		var qs = location.search.substring(1).split('&');
		for(var i=0;i<qs.length;i++)
		{
			qsitem = qs[i].split('=');
			if(qsitem.length == 2)
				getitem[unescape(qsitem[0])] = unescape(qsitem[1]);
		}
	}
	return getitem;	
}

function strim(s)
{
	return (s.replace(/^\s+|\s+$/g,''));
}

// **** Embeds a flash animation dynamically to avoid the "click to activate" message **** 
function embed_flash(src,width,height,params)
{
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ');
	document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ');
	document.write('width="' + width + '" height="' + height + '">\n');
    document.write('<param name="movie" value="' + escape(src) + '" />\n');
    document.write('<param name="quality" value="high" />\n');
	for(param in params)
		document.write('<param name="' + param + '" value="' + params[param] + '" />\n');
    document.write('<embed src="' + escape(src) + '" ');
	for(param in params)
		document.write(param + '="' + params[param] + '" ');
	document.write(' quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" ');
	document.write('type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"></embed>\n</object>');
}

//**** Gets the asset info from asset ID used in link ****
function get_asset_info(asset_id)
{
	var asset_info = new Array();
	asset_info['type'] = asset_id.split('_')[0];
	asset_info['title'] = '';
	
	switch(asset_info['type'])
	{

		case 'PT':
			asset_info['path'] = 'PT/' + asset_id + '.swf';
			asset_info['title'] = 'Personal Tutor';
			asset_info['width'] = 801;
			asset_info['height'] = 635;
			asset_info['params'] = null;
			break;
		
		case 'CIM':
			asset_info['path'] = 'CIM/' + asset_id + '.swf';
			asset_info['title'] = 'Concepts in Motion';	
			asset_info['width'] = 550;
			asset_info['height'] = 400;	
			asset_info['params'] = null;		
			break;
			
		case 'CIMF':
			asset_info['path'] = 'CIM/' + asset_id + '/Start.swf';
			asset_info['title'] = 'Concepts in Motion';	
			asset_info['width'] = 909;
			asset_info['height'] = 639;	
			asset_info['params'] = {
				'base': 'CIM/' + asset_id,
				'allowScriptAccess': 'sameDomain'				
				};			
			break;			
			
		case 'BSS':
			asset_info['title'] = 'Blip\'s Satellite Service';
						  
		case 'BF':
			if(asset_info['title'] == '')
				asset_info['title'] = 'Bugle Farms';
				
		case 'CJ':
			if(asset_info['title'] == '')
				asset_info['title'] = 'Critter Junction';
				
		case 'MF':
			if(asset_info['title'] == '')
				asset_info['title'] = 'Mount Frost';
				
		case 'NV':
			if(asset_info['title'] == '')
				asset_info['title'] = 'Number Voyage';
				
		case 'RW':
			if(asset_info['title'] == '')
				asset_info['title'] = 'Robo Works';
				
		case 'SEC':
			if(asset_info['title'] == '')
				asset_info['title'] = 'Scrambled Egg City';
				
		case 'ST':
			if(asset_info['title'] == '')
				asset_info['title'] = 'Starfish Theater';
				
			asset_info['path'] = 'Activity.swf';
			asset_info['width'] = 800;
			asset_info['height'] = 600;	
			asset_info['params'] = {
				'FlashVars': 'webData=' + asset_id.replace(/_/g,','),
				'allowScriptAccess': 'sameDomain'
			};		
			break;
			
		default:
			asset_info['path'] = '/' + asset_id + '.swf';
			asset_info['title']  = 'Lesson Asset';
			asset_info['width'] = 640;
			asset_info['height'] = 480;
			asset_info['params'] = null;		
			break;
	}
	
	return asset_info;
	
}

/**** To popup flash assets like PT,CIM, Math Adventure lessons ****/
function pop_asset(src)
{
	inf = get_asset_info(src);
	popw = window.open('../../assets/asset_view.html?s=' + escape(src),'_blank',
		'width='+ inf['width'] + ',height=' + inf['height'] + ',status=no,scrollbars=no,resizable=no');	
}

/**** To Popup assets in external sites like MHLN ****/
function pop_mhln_asset(url,type)
{
	if(MHLN_FLASH_LINK_DIRECT)
	{
		if(url.match(/showpage.htm$/)) {marginw = 20; marginh = 20;}
		else
		{
			url = url.replace(/\.html?$/,'.swf');
			marginw = 0; marginh = 0;
		}
	}
	else
	{
		marginw = MHLN_FLASH_MARGIN_WIDTH;
		marginh = MHLN_FLASH_MARGIN_HEIGHT;
	}
	
	if(url.match(/mhln\.com\/ob\//))
	{
		if(type=='game'){width = 800; height=600;}
		else{width = 640; height=480;}
	}
	else if( url.match(/mhln\.com\/lng\//)){width = 625; height=500;}
	else{width = 640; height=480;}
	
	popext = window.open(url,'_blank','width=' + (width + marginw) + ',height='+ (height + marginh) + ',status=no,scrollbars=no,resizable=no');
}

/**** To Popup FactDash ****/
function popFactDash()
{
	popfd = window.open('../../assets/factdash.html','_blank','width=640,height=480,status=no,scrollbars=no,resizable=no')
}
