/**
 * Flash Intro page scripts
 *
 * @copyright (c) 2004-2006, SWsoft
 */

function SbFlashList(name) {
	this.input = document.getElementById(name);
	this.flashesList = new Array();
	this.currentFlash = null;
	this.flashContainer = null;
}

SbFlashList.prototype.Init = function(code) {
	for(var i = 0; i < this.flashesList.length; i++) {
		if (this.flashesList[i].code == code) {
			this.currentFlash = this.flashesList[i];
			this._ChangeBorderColor(this.flashesList[i], '#ff0000');
			break;
		}
	}
}

SbFlashList.prototype.InitCurrentFlash = function(flashId) {
	this.flashContainer = document.getElementById(flashId + 'Container');
	this.ShowCurrentFlash();
}

SbFlashList.prototype.ShowCurrentFlash = function() {
	var flashVars = this._GetFlashVars();
	var flashHtml = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="180" height="90" align=""><param name="movie" value="';
	flashHtml += this.currentFlash.url;
	flashHtml += '"><param name="quality" value="high"><param name="Scale" value="ShowAll"><param name=wmode value="transparent"><param name="wmode" value="opaque"><param name="FlashVars" value="';
	flashHtml += flashVars;
	flashHtml += '"><embed quality="high" bgcolor="#ffffff" width="180" height="90" align="" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="opaque" src="';
	flashHtml += this.currentFlash.url;
	flashHtml += '" FlashVars="';
	flashHtml += flashVars;
	flashHtml += '"></embed></object>';
	this.flashContainer.innerHTML = flashHtml;
}

SbFlashList.prototype.Select = function(code) {
	if (this.input.value == code) {
		return;
	}
	this.input.value = code;
	for(var i = 0; i < this.flashesList.length; i++) {
		if (this.flashesList[i].code == code) {
			this.currentFlash = this.flashesList[i];
			this._ChangeBorderColor(this.currentFlash, '#ff0000');
		} else {
			this._ChangeBorderColor(this.flashesList[i], '#ffffff');
		}
	}
	var isSelected = false;
	var schemeCombo = document.getElementById('flash_scheme');
	var currentScheme = schemeCombo.options[schemeCombo.selectedIndex].text;
	schemeCombo.options.length = 0;
	for(var i = 0; i < this.currentFlash.schemesList.length; i++) {
		schemeCombo.options[i] = new Option(this.currentFlash.schemesList[i].title, this.currentFlash.schemesList[i].code);
		if (currentScheme == this.currentFlash.schemesList[i].title) {
			schemeCombo.selectedIndex = i;
			isSelected = true;
		}
	}
	if (!isSelected) {
		schemeCombo.selectedIndex = 0;
	}
	isSelected = false;
	var backgroundCombo = document.getElementById('flash_background');
	var currentBackground = backgroundCombo.options[backgroundCombo.selectedIndex].text;
	backgroundCombo.options.length = 0;
	for(var i = 0; i < this.currentFlash.backgroundsList.length; i++) {
		backgroundCombo.options[i] = new Option(this.currentFlash.backgroundsList[i].title, this.currentFlash.backgroundsList[i].code);
		if (currentBackground == this.currentFlash.backgroundsList[i].title) {
			backgroundCombo.selectedIndex = i;
			isSelected = true;
		}
	}
	if (!isSelected) {
		backgroundCombo.selectedIndex = 0;
	}
	sbApplyChangesObject.registerChange();
	this.ShowCurrentFlash();
}

SbFlashList.prototype._ChangeBorderColor = function(flashItem, color) {
	var border = document.getElementById('Flash' + flashItem.code + 'Border');
	border.style.borderColor = color;
}

SbFlashList.prototype._GetFlashVars = function() {
	var result = 'BackgroundId=';
	result += escape(document.getElementById('flash_background').value);
	result += '&ObjectId=';
	result += escape(document.getElementById('flash_scheme').value);
	result += '&Text1=';
	result += encodeURI(document.getElementById('header_text').value);
	result += '&Text2=';
	result += encodeURI(document.getElementById('body_text').value);
	result += '&IsRelative=false';
	return result;
}

SbFlashList.prototype.AddFlash = function(item) {
	this.flashesList[this.flashesList.length] = item;
}



function SbFlashItem(code) {
	this.code = code;
	this.backgroundsList = new Array();
	this.schemesList = new Array();
	this.url = '';
}

SbFlashItem.prototype.SetBinaryUrl = function(url) {
	this.url = url;
}

SbFlashItem.prototype.AddBackground = function(code, title) {
	this.backgroundsList[this.backgroundsList.length] = new SbFlashSelectItem(code, title);
}

SbFlashItem.prototype.AddScheme = function(code, title) {
	this.schemesList[this.schemesList.length] = new SbFlashSelectItem(code, title);
}


function SbFlashSelectItem(code, title) {
	this.code = code;
	this.title = title;
}