var row_clicked = false;
var row_clicked_id = '';

/*
	This function is for 
	mouseover on table tds.
	To change the CSS on tds.
*/
function change_row_color(row, on_off)
{
	if(!row_clicked)
	{
		if(on_off == 1)
		{
			row.style.color = '#95A0A9';
			row.style.fontWeight = 'bold';
		}
		else
		{
			row.style.color = '#FFF';
			row.style.fontWeight = 'normal';
		}
	}
}

/*
	opens up the ajax div for 
	selecting sound fx or tracks
	for the portal. Tracks uses
	cat_id as cmd.
*/
function sound_fx_preview(row, fx_id, cat_id, buy_now_id)
{

	if(row_clicked)
	{
		row_clicked = false;
		change_row_color(row_clicked_id);
	}
	change_row_color(row, 1);
	row_clicked = true;
	row_clicked_id = row;

	var details = new Array();
	var values = new Array();
	values['fx_id'] = fx_id;
	values['cat_id'] = cat_id;
	values['buy_now_id'] = buy_now_id;
	
	execute ("1", sound_fx_preview_parse, details, values, '');
}

function sound_fx_preview_parse(responseText, responseStatus, responseXML)
{
	var reply = '';
	var swf_file = '';
	var img_id = '';
	var img_link = '';
	var old_img_id = '';
	var sound_fx_table = '';
	var delete_link = '';
	var show_alert_div = '';
	var mp3_id = '';
	var section_id = '';
	var swf_w = '';
	var swf_h = '';
	var preview = '';
	var color_scheme = '';
	
	if (responseStatus == 200)
	{
		response  = responseXML;

		if (response.firstChild.hasChildNodes())
		{	
			for (var i=0; i< response.firstChild.childNodes.length; i++)
			{					
				if(response.firstChild.childNodes[i].nodeName == "response" || response.firstChild.childNodes[i].nodeName == "swf_file" || response.firstChild.childNodes[i].nodeName == "img_id"
					|| response.firstChild.childNodes[i].nodeName == "old_img_id" || response.firstChild.childNodes[i].nodeName == "img_link" 
					|| response.firstChild.childNodes[i].nodeName == "sound_fx_table" || response.firstChild.childNodes[i].nodeName == "delete_link" || response.firstChild.childNodes[i].nodeName == "color_scheme"
					|| response.firstChild.childNodes[i].nodeName == "show_alert_div" || response.firstChild.childNodes[i].nodeName == "mp3_id" || response.firstChild.childNodes[i].nodeName == "section_id"
					|| response.firstChild.childNodes[i].nodeName == "swf_w" || response.firstChild.childNodes[i].nodeName == "swf_h" || response.firstChild.childNodes[i].nodeName == "preview")
				{
					for(j=0; j< response.firstChild.childNodes[i].childNodes.length; j++) 
					{
						if(response.firstChild.childNodes[i].childNodes[j].nodeName == "xdata" && response.firstChild.childNodes[i].childNodes[j].firstChild != null) 
						{
							if(response.firstChild.childNodes[i].nodeName == "response")
								reply += response.firstChild.childNodes[i].childNodes[j].firstChild.nodeValue;
							else if(response.firstChild.childNodes[i].nodeName == "swf_file")
								swf_file += response.firstChild.childNodes[i].childNodes[j].firstChild.nodeValue;
							else if(response.firstChild.childNodes[i].nodeName == "img_id")
								img_id += response.firstChild.childNodes[i].childNodes[j].firstChild.nodeValue;
							else if(response.firstChild.childNodes[i].nodeName == "img_link")
								img_link += response.firstChild.childNodes[i].childNodes[j].firstChild.nodeValue;
							else if(response.firstChild.childNodes[i].nodeName == "old_img_id")
								old_img_id += response.firstChild.childNodes[i].childNodes[j].firstChild.nodeValue;
							else if(response.firstChild.childNodes[i].nodeName == "sound_fx_table")
								sound_fx_table += response.firstChild.childNodes[i].childNodes[j].firstChild.nodeValue;
							else if(response.firstChild.childNodes[i].nodeName == "delete_link")
								delete_link += response.firstChild.childNodes[i].childNodes[j].firstChild.nodeValue;
							else if(response.firstChild.childNodes[i].nodeName == "show_alert_div")
								show_alert_div += response.firstChild.childNodes[i].childNodes[j].firstChild.nodeValue;
							else if(response.firstChild.childNodes[i].nodeName == "mp3_id")
								mp3_id += response.firstChild.childNodes[i].childNodes[j].firstChild.nodeValue;
							else if(response.firstChild.childNodes[i].nodeName == "section_id")
								section_id += response.firstChild.childNodes[i].childNodes[j].firstChild.nodeValue;
							else if(response.firstChild.childNodes[i].nodeName == "swf_w")
								swf_w += response.firstChild.childNodes[i].childNodes[j].firstChild.nodeValue;
							else if(response.firstChild.childNodes[i].nodeName == "swf_h")
								swf_h += response.firstChild.childNodes[i].childNodes[j].firstChild.nodeValue;
							else if(response.firstChild.childNodes[i].nodeName == "preview")
								preview += response.firstChild.childNodes[i].childNodes[j].firstChild.nodeValue;
							else if(response.firstChild.childNodes[i].nodeName == "color_scheme")
								color_scheme += response.firstChild.childNodes[i].childNodes[j].firstChild.nodeValue;
						}
					}
				}
			}
		}
	}
	
	if(reply != '')
		display_sound_preview(reply, swf_file, mp3_id, section_id, swf_w, swf_h, '', color_scheme);
		
}

/*
	display the flash and sound fx
	preview.
*/
function display_sound_preview(reply, swf_file, mp3_id, sectionID, swf_w, swf_h, sound_fx, colorScheme)
{
	sectionType = 'mp3';
	var div = document.getElementById('sound_fx_ajax_div');
	div.innerHTML = reply;
	if(swf_file != undefined && swf_file != '')
	{
		var params = {};
		params.quality = "high";
		params.wmode = "transparent";
		params.scale = "noborder";
		params.menu = "menu";
		params.oop = "false";
		var attributes = false;
		
		if(sound_fx == "1")
			var pass_vars = { preview: mp3_id, embColorText: sectionID, embColorScheme: colorScheme };
		else
			var pass_vars = { embID: mp3_id, embSection: sectionID, embColorScheme: colorScheme };

		swfobject.embedSWF(swf_file, 'sound_fx_swf', swf_w, swf_h, "9.0.0", "", pass_vars, params, attributes);
		swfobject.createCSS("#sound_fx_swf", "outline:none");
		if(sound_fx != 1)
		{
			swfobject.createCSS("#sound_fx_swf", "position:relative");
			swfobject.createCSS("#sound_fx_swf", "top:0");
			swfobject.createCSS("#sound_fx_swf", "left:0");
			swfobject.createCSS("#sound_fx_swf", "margin-top:-100px");
		}
	}
	
	centerDiv('sound_fx_ajax_div');
	div.style.display = 'block';
}

function close_sound_fx_div(row_txt, closerow)
{
	if(document.getElementById('sound_fx_swf'))
		swfobject.removeSWF("sound_fx_swf");
	
	if(closerow != 1)
	{
		if(row_txt != undefined && row_txt != '')
			row_obj = row_txt;
		else
			row_obj = row_clicked_id;
		
		if(row_clicked)
		{
			row_clicked = false;
			change_row_color(row_obj);
			row_clicked_id = '';
		}
	}
	
	var div = document.getElementById('sound_fx_ajax_div');
	div.style.display = 'none';
}