/*
 * Set the configurations for the FlexPlayer
 */

	function PlayerConfig () {
		this.src = '';
		this.slicer = 'http://www.protonradio.com/player/beta/mp3slicer.php';
		this.buffering = 4;
		this.statusCall = 'alert'; // function to call;
		this.autoplay = true;
		this.imageDir = 'images/';
		this.transitionType = 'fade'; // fade or none;
		this.defaultVolume = 0.1;
		this.domains = new Array();
		this.mixes = new Array();
		this.streams = new Array();
		this.buttons = new Object();
		this.sliders = new Object();
		this.images = new Array();
		this.midImages = new Array();
		this.topImages = new Array(); // images that are loaded on top of everything else
		this.progbars = new Object();
		this.altlcd; // id of the lcd that alt tags should show up on.
		this.lcd = new Object();
		this.mixmenus = new Object();
		this.trackmenus = new Object();
		this.groups = new Object();
		this.containers = new Object();
		this.tabGroups = new Object();
		this.tabs = new Object();
		this.scrollbarConfigs = null;
		this.hideOnStreamPlay = new Array();
		this.loginForm = new Object();
		this.loginOnlyList = new Object();
		this.queEmptyOnlyList = new Object();
		
		this.addMix = function (id,title,url,sliceable,start,length,bytes,comments) {
			var mix = new Object();
			mix.id = id;
			mix.title = title;
			mix.url = url;
			mix.sliceable = sliceable;
			mix.offset = start;
			mix.soundLength = length;
			mix.bytes = bytes;
			mix.comments = comments ? comments : 0;
			this.mixes.push(mix);
		}
		
		this.addStream = function (url) {
			var obj = new Object();
			obj.url = url;
			obj.failed = false;
			this.streams.push(obj);
		}
		
		
		this.addTrack = function (mixIndex,paramsArrays) {
			if(this.mixes[mixIndex] && !this.mixes[mixIndex].tracks) {
				this.mixes[mixIndex].tracks = new Array();
			}
			var track = new Array();
			for(var i=0;i<paramsArrays.length;++i) {
				track.push(new Object({'str':paramsArrays[i][0],'color':paramsArrays[i][1],'align':(paramsArrays[i][2]?paramsArrays[i][2]:'left'),'bold':(paramsArrays[i][3]?true:false)}));
			}
			this.mixes[mixIndex].tracks.push(track);
		}
		
		this.addDomain = function (url) {
			this.domains.push({'url':url});
		}
		
		this.addButton = function (name,imgType,out,over,down,disbtn,x,y,disabled,toggleid,transitions,alt) {
			this.buttons[name] = new PlayerButton(imgType,out,over,down,disbtn,x,y,disabled,toggleid,transitions,alt);
		}
		
		this.addUrl = function(name,urlObj) {
			this.buttons[name].url = urlObj;
		}
		
		this.addRevealer = function (name,action,sliderid,revealid,direction) {
			// direction must slide one of these directions.
			if(direction == 'left' || direction == 'up' || direction == 'right' || direction == 'down') {
				this.buttons[name].action = action;
				sliderid ? (this.buttons[name].sliderid = sliderid) : null;
				revealid ? (this.buttons[name].revealid = revealid) : null;
				this.buttons[name].direction = direction;
			} else {
				alert('invalid direction for reveal button');
			}
		}
		
		this.addSlider = function (name,slider, x, y, disabled) {
			slider.x = x;
			slider.y = y;
			slider.disabled = disabled;
			this.sliders[name] = slider;
		}
		
		this.addImage = function (name,imgType,src,x,y) {
			//this.images[name] = new PlayerImage(imgType,src,x,y);
			var order = this.topImages.length;
			this.images[name] = new PlayerImage(imgType,src,x,y);
			this.images[name].order = order;
		}
		
		this.addMidImage = function (name,imgType,src,x,y) {
			//this.images[name] = new PlayerImage(imgType,src,x,y);
			var order = this.midImages.length;
			this.midImages[name] = new PlayerImage(imgType,src,x,y);
			this.midImages[name].order = order;
		}
		
		this.addTopImage = function (name,imgType,src,x,y) {
			//this.images[name] = new PlayerImage(imgType,src,x,y);
			var order = this.topImages.length;
			this.topImages[name] = new PlayerImage(imgType,src,x,y);
			this.topImages[name].order = order;
		}
		
		this.addProgressBar = function (name,imgType,bdr,bg,clr,clr2,x,y,width,height) {
			this.progbars[name] = new ProgressBar(imgType,bdr,bg,clr,clr2,x,y,width,height);
		}
		
		this.addSoundPos = function(x,y) {
			this.soundPos = new Object();
			this.soundPos.soundpos = new Object();
			this.soundPos.soundpos.x = x;
			this.soundPos.soundpos.y = y;
		}
		
		this.addEqualizer = function (minbars,maxbars,x,y,transitions,frequency,fakeSpectrumUrl) {
			this.equalizer = new Object();
			this.equalizer.equalizer = new Object();
			this.equalizer.equalizer.minbars = minbars;
			this.equalizer.equalizer.maxbars = maxbars;
			this.equalizer.equalizer.x = x;
			this.equalizer.equalizer.y = y;
			this.equalizer.equalizer.transitions = transitions;
			this.equalizer.equalizer.frequency = frequency ? true : false;
			this.equalizer.equalizer.fakeSpectrumUrl = fakeSpectrumUrl;
		}
		
		this.addLCD = function (name,x,y,w,h,text,urlStr) {
			if(!this.altlcd) {
				this.altlcd = name;
			}
			this.lcd[name] = new LCD(x,y,w,h,text,urlStr);
		}
		
		this.addMixMenu = function (name,x,y,w,h,defaultText,showAry,hideAry) {
			this.mixmenus[name] = new Object({'x':x,'y':y,'w':w,'h':h,'text':defaultText});
		}
		
		this.addTrackMenu = function (name,x,y,w,h,defaultText,showAry,hideAry) {
			this.trackmenus[name] = new Object({'x':x,'y':y,'w':w,'h':h,'text':defaultText});
		}
		
		this.addGroup = function (key,x,y,width,height,childrenArray,bgcolor) {
			var obj = new Object();
			for(var i=0;i<childrenArray.length;++i) {
				obj[childrenArray[i]] = i;
			}
			var order = count(this.groups);
			bgcolor = bgcolor ? bgcolor : 0;
			this.groups[key] = {'x':x,'y':y,'width':width,'height':height,'order':order,'children':obj,'bgcolor':bgcolor};
		}
		
		this.addTabGroup = function (name,x,y,width,height,depth) {
			var obj = new Object();
			obj.name = name;
			obj.order = count(this.tabGroups);
			obj.x = x;
			obj.y = y;
			obj.width = width;
			obj.height = height;
			obj.depth = depth;
			this.tabGroups[name] = obj;
		}
		
		this.addTab = function (g,title,content,onSelectCall,showAry, hideAry) {
			var tab = new Object();
			tab.tabGroup = g;
			tab.order = count(this.tabs);
			tab.title = title;
			tab.content = content;
			tab.show = showAry;
			tab.hide = hideAry;
			tab.onSelectCall = onSelectCall ? onSelectCall : '';
			this.tabs[g+tab.order] = tab;
		}
		
		this.addContainer = function (type,name,x,y,width,height,nineSliceObj,content,depth,scrollbar) {
			var i = name; //count(this.containers);
			var c = count(this.containers);
			this.containers[i] = new Object();
			this.containers[i].type = type;
			this.containers[i].order = c;
			this.containers[i].width = width;
			this.containers[i].height = height;
			this.containers[i].x = x;
			this.containers[i].y = y;
			this.containers[i].images = nineSliceObj;
			this.containers[i].content = content;
			this.containers[i].depth = depth;
			this.containers[i].scrollbar = scrollbar ? true : false;
			this.containers[i].attachments = new Object();
		}
		
		this.attachToContainer = function(name,align,items) {
			for(var i in items) {
				if(typeof(this.containers[name].attachments[items[i]]) != 'object') {
					this.containers[name].attachments[items[i]] = new Object();
				}
				this.containers[name].attachments[items[i]][align] = 1;
			}
		}
		
		this.addContainerCollapse = function (name,height,internal,external) {
			this.containers[name].collapse = {'height':height,'internal':internal,'external':external};
		}
		
		this.simplify = function(obj) {
			// strip object of all functions. leave everything else
			for(var i in this) {
				if(typeof(this[i]) != 'function') {
					obj[i] = this[i];
				}
			}
			return obj;
		}
		
		this.addHideOnStreamPlay = function (list) {
			if(typeof('list') == 'string') {
				for(var i in list) {
					this.hideOnStreamPlay.push(list[i]);
				}
			} else {
				this.hideOnStreamPlay.push(list[i]);
			}
		}
		
		this.addLogin = function(x,y) {
			this.loginForm['login'] = {'x':x,'y':y};
		}
		
		this.setLoginVisibleOnlyList = function (ary) {
			this.loginOnlyList = ary;
		}
		
		this.queEmptyVisibleOnlyList = function (ary) {
			this.queEmptyOnlyList = ary;
		}
		
	}
	
	function resizePlayer(width,height) {
//		var plyr = document.getElementById('FlexPlayer');
//		plyr.style.width = width+'px';
//		plyr.style.height = height+'px';
	}
	
	function isReservedButton(str) {
		var types = new Object();
		types.play = 1;
		types.stop = 1;
		types.mute = 1;
		types.unmute = 1;
		return exists(types,str);
	}
	
	function PlayerButton(type,out,over,down,disabled,x,y,isdisabled,toggleid,transitions,alt) {
		this.out = new PlayerImage(type,out,0,0);
		this.over = new PlayerImage(type,over,0,0);
		this.down = new PlayerImage(type,down,0,0);
		this.disabled = new PlayerImage(type,disabled,0,0);
		this.isdisabled = isdisabled;
		this.x = x;
		this.y = y;
		if(toggleid) {
			this.toggleid = toggleid;
		}
		this.transitions = transitions;
		this.alt = alt;
	}
	
	function Slider() {
		this.bg = new Object();
		this.thumb = new Object();
		this.arrows = new Object();
		this.addBg = function (type,src,disc,width,height) {
			if(type == 'image' || type == 'anigif' || type == 'swf') {
				this.bg.img = new PlayerImage(type,src,0,0);
				this.bg.disabled = new PlayerImage(type,disc,0,0);
				this.bg.width = width;
				this.bg.height = height;
			} else if (type == 'thermometer') {
				this.bg.img = {'type':type,'itemname':src};
				this.bg.disabled = new PlayerImage('image',disc,0,0);
				this.bg.width = width;
				this.bg.height = height;
			}
		}
		this.addThumb = function (type,src,disc) {
			this.thumb.img = new PlayerImage(type,src,0,0);
			this.thumb.disabled = new PlayerImage(type,disc,0,0);
		}
		this.addArrows = function (type,left,right) {
			this.arrows.left = new PlayerImage(type,left,0,0);
			this.arrows.right = new PlayerImage(type,right,0,0);
		}
	}
	
	function ProgressBar(type,bdr,bg,clr,clr2,x,y,width,height) {
		if(type == 'image' || type == 'anigif' || type == 'swf') {
			this.bdr = new PlayerImage(type,bdr,0,0);
			this.bg = new PlayerImage(type,bg,0,0);
		} else if(type == 'vector') {
			this.bdr = bdr;
			this.bg = bg;
		}
		this.clr = clr;
		this.clr2 = clr2;
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
	}
	
	function PlayerImage (type,src,x,y) {
		if((src+'').match(/\.gif/i) && type == 'anigif') {
			type = 'anigif';
		} else if ((src+'').match(/\.swf/i) && type == 'swf') {
			type = 'swf';
		} else if(type != 'image') {
			type = 'image';
			alert('Error: Invalid type. '+src+' is not an \'anigif\' changing type to \'image\'. ');
		}
		this.type = type; // String - must be 'anigif' of 'image'
		this.src = src; // String
		this.x = x; // Number
		this.y = y; // Number
	}
	
	function URLObject(type,url) { // type, url, ...rest
		this.type = type;
		this.url = url;
		this.params = new Object();
		if(this.type == 'javascript') {
			// take as an array
			for(var i=2;i<arguments.length; ++i) {
				this.params[i] = arguments[i];
			}
		} else {
			// do as key values
			for(var i=2; i < arguments.length; i+=2) {
				this.params[arguments[i]] = arguments[i+1];
			}
		}
	}
	
	function Transitions() {
		this.addTran = function (str,speed,over,out,down,up) {
			var obj = new Object();
			obj.speed = speed;
			obj.over = over ? true : false;
			obj.out = out ? true : false;
			obj.down = down ? true : false;
			obj.up = up ? true : false;
			this[str] = obj;
		}
	}
	
	function LCD(x,y,w,h,text,urlStr) {
		this.x = x;
		this.y = y;
		this.w = w;
		this.h = h;
		this.text = text ? text : '';
		this.url = urlStr ? urlStr : '';
	}
	
	function NineSliceContainerImages(tl,tm,tr,cl,cm,cr,bl,bm,br) {
		this.tl = new PlayerImage('image',tl,0,0);
		this.tm = new PlayerImage('image',tm,0,0);
		this.tr = new PlayerImage('image',tr,0,0);
		this.cl = new PlayerImage('image',cl,0,0);
		this.cm = new PlayerImage('image',cm,0,0);
		this.cr = new PlayerImage('image',cr,0,0);
		this.bl = new PlayerImage('image',bl,0,0);
		this.bm = new PlayerImage('image',bm,0,0);
		this.br = new PlayerImage('image',br,0,0);
	}
	
	function NSCScrollbarConfig(bgc,bga,sbc,sba,taImg,baImg) {
		this.bgc = bgc;
		this.bga = bga;
		this.sbc = sbc;
		this.sba = sba;
		this.up = taImg;
		this.down = baImg;
	}