var Globals = {
	urls: {
		add_to_folder: '/myworkouts/addroutine',
		new_folder: '/myworkouts/newfolder'
	}
}


Effect.MoveTo = function(element, toTop, toLeft) {
  return new Effect.Move(element, 
    Object.extend({ x: toLeft, y: toTop }, arguments[3] || {}));
};
Effect.ReduceTo = function(element) {
  element = $(element);
  element.makeClipping();
  return new Effect.Scale(element, 15,
    Object.extend({ scaleContent: false, 
      scaleX: false, 
      restoreAfterFinish: false,
      afterFinishInternal: function(effect) {
       // effect.element.hide();
       // effect.element.undoClipping();
      } 
    }, arguments[1] || {})
  );
}

Effect.IncreaseTo = function(element) {
  element = $(element);
  var elementDimensions = element.getDimensions();
  return new Effect.Scale(element, 100, Object.extend({ 
    scaleContent: false, 
    scaleX: false,
    scaleFrom: 20,
    scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
    restoreAfterFinish: false,
    afterSetup: function(effect) {
      effect.element.makeClipping();
      effect.element.setStyle({height: '0px'});
      effect.element.show(); 
    },  
    afterFinishInternal: function(effect) {
      //effect.element.undoClipping();
    }
  }, arguments[1] || {}));
}
function $ID(elem, arr) {
	ids = elem.id.split('__');
	if (arr) return ids;
	return ids[1] ? ids[1] : '';  
}
var Logger = {
	debug: false,
	write: function(mesg, fn) {
		if (!Logger.debug) return;		
		debugwin = document.getElementById("debugger");
		if (!debugwin) {
			debugwin = document.createElement("div");
			debugwin.className = 'debugger';
			debugwin.id = 'debugger';

			debugwinlogger = document.createElement("div");
			debugwin.appendChild(debugwinlogger);

			clearbtn = document.createElement("input");
			clearbtn.setAttribute('name', 'clear');
			clearbtn.setAttribute('value', 'Clear');
			clearbtn.setAttribute('type', 'button');
			clearbtn.addEventListener("click", Logger.clear, false);

			debugwin.appendChild(clearbtn);

			bd = document.getElementsByTagName('body');
			bd[0].appendChild(debugwin);

		}
		dt = new Date;
		now = dt.getHours() + ":" + dt.getMinutes() + ":" + + dt.getSeconds();

		msg = document.createElement('p');
		msg.innerHTML = now + "<br><strong>"+ fn + "</strong><br /><em>" + mesg + "</em>";
		debugwinlogger.appendChild(msg);
		debugwinlogger.scrollTop = debugwinlogger.scrollHeight
	},
	clear: function(e) {
		debugwin.childNodes[0].innerHTML = '';
	}
}
var log = Logger.write;

var XHR = {
	onCreate: function() {
		log('started', 'xhr.onCreate');
	},
	onComplete: function() {
		log('completed', 'xhr.onComplete');
	},
	onFailure: function(){ 
		log('A connection could not be established. Please try again later') 
	}
}


Ajax.Responders.register({
  onCreate: XHR.onCreate,
  onComplete: XHR.onComplete,
  onFailure: XHR.onFailure
});



var DOM = {
	Select: function(n, opts) {
		var s = this.elem('select', {'name' : n});
		
		for (opt in opts) {
				o = D.Create.elem('option', {'value' : opts[opt]});
				D.append(o, D.Create.txt(opt));
				D.append(s, o);
			
			}
		return s;
	},
	textField: function(name, value) {
		return this.elem("input", {'name': name, 'id': name, 'value': value, 'type': 'text'});
	},
	e: function(block) {
		    var el;
		    if ('string'==typeof block) {
		        el=document.createTextNode(block);
		    } else {
		        el=document.createElement(block.tag);
		        delete(block.tag);
		        if ('undefined'!=typeof block.children) {
		            if ('string'==typeof block.children ||
		                'undefined'==typeof block.children.length) {
		                el.appendChild(DOM.e(block.children));
		            } else {
		                //array
		                for (var i=0, child=null; 'undefined'!=typeof (child=block.children[i]); i++) {
		                    el.appendChild(DOM.e(child));
		                }
		            }
		            delete(block.children);
		        }
				if ('undefined'!=typeof block.events) { 
					for (ev in block.events)
						Event.observe(el, ev, block.events[ev]);

					delete block.events;
				}
				if ('undefined'!=typeof block.styles) { 
					el.setStyle(block.styles);
					delete block.events
				}
		        for (attr in block) {
					if (attr == 'class')
						el.className = block[attr];
					else
		            	el[attr]=block[attr];
		        }
		    }

		    return el;
		},	
	New: {
		elem: function(name, attrs) {
			try {
				e = document.createElement(name);
				for (a in attrs) {
					if (a == 'class') 
					 	e.className = attrs[a] 
					else if (a == 'name')
						e.setAttribute('name', attrs[a]);
					else 
						e[a] = attrs[a];
					}
				return e;
			} catch (e) {return false}
		},
		text: function() {
			try {
				return document.createTextNode(text);
			} catch(e) { return false }
		},
		div: function(attrs) {
			return DOM.New.elem('div', attrs);
		}
	},	
	append: function(par, nodes) {	
		try {	
			nodes.each(function(node) {
				par.appendChild(node);	
			})
			return par;
		} catch(e) {
			try {
				return par.appendChild(nodes);
			} catch(e) {
				return false;
			}
		}
	},
	prepend: function(parent, newelem, oldelem) {
		try {
			return parent.insertBefore(newelem, parent.firstChild);
		} catch (e) {}
	},
	Insert: {
		before: function() {},
		after: function() {}
	},
	remove: function(o) {
		return o.parentNode.removeChild(o);
	}
}
var Indicator = {
	current: [],
	currentClassNames: [],
	defaultClass: 'loading',
	add: function(obj, classn) {
		obj = $(obj);
		if (!classn) classn = this.defaultClass;
		obj.className += ' ' + classn;
		if (obj) {
			this.current.push(obj);
			this.currentClassNames.push(classn);
		}
	},
	clear: function(obj, classn) {
		if (!classn)
			classn = this.defaultClass;
		obj.className = obj.className.replace(classn, '');
	},
	clearAll: function(classn) {
		if (!classn)
			classn = this.defaultClass;
		cl = this.current.length;
		for (i=0;i<cl;i++) {
			this.current[i].className = this.current[i].className.replace(this.currentClassNames[i], '');
		}
		this.current = [];
		this.currentClassNames = [];
	}
	
};


var Req = {
	__GET: {},
	filename: '',
	query_string: location.search || '',
	type: '',
	uri: location.href,
	initialized: false,
	
	init: function() {
		ps = this.uri
				
		this.type = ps.match(/^https?|ftp|file/);		
		ps = ps.replace(/https?:\/\/|file:\/|ftp:\/\//g, '');
		
		ps = ps.split('/');
		psl = ps.length
		 
		ps[psl-1] = ps[psl-1].split('?');
		this.filename = (ps[psl-1].length > 1) ? ps[psl-1].shift() : ps.pop();
		
		params = location.search.slice(1).split('&');
		for (i=0;i<params.length;i++) {
			x = params[i].split('=');
			this.__GET[x[0]] = unescape(x[1]);
		}
		this.initialized = true;
	},
	get: function(key) {
		return (this.__GET[key] != undefined) ? this.__GET[key] : false;
	},
	set: function(params) {
		//params {'key':'value', 'key2':'value2'}
		try {
			for (key in params) {
				if (key != '')
					this.__GET[key] = params[key];
			}
		} catch(e) {}
	},
	serialize: function() {
		params = [];
		for (key in this.__GET)
			if (key != '')
				if (this.__GET[key] != undefined)
					params.push(key + '=' + escape(this.__GET[key]))
		
		return params.join('&');
		
	},
	Cookie: {
		set: function(name,value,days,path,domain,secure) {
			if (!days) days = 360;
		    
			var date = new Date();
		    date.setTime(date.getTime() + (days*24*60*60*1000) );
		   	expires = date.toGMTString();
		  	
		   document.cookie = name + "=" + escape(value) +
		    ((expires) ? "; expires=" + expires : "") +
		    ((path) ? "; path=" + path : "") +
		    ((domain) ? "; domain=" + domain : "") +
		    ((secure) ? "; secure" : "");
		},

		get: function(name) {
		  var nameEQ = name + "=";
		  var ca = document.cookie.split(';');
		  for(var i=0;i < ca.length;i++) {
		    var c = ca[i];
		    while (c.charAt(0)==' ') c = c.substring(1,c.length);
		    if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));
		  }
		  return null;
		}
	}
}
Req.init();








var FlashBridgeBase = {
	registered: {},
	init: function(flashMovie) {
		if (!flashMovie) return;
		this.movie = flashMovie;
		window[flashMovie.id+'_DoFSCommand'] = this.despatch.bind(this)
	},
	register: function(func_name, func) {
		this.registered[func_name] = func
	},
	getRegistered: function(funcname) {
		if (this.registered[funcname] != undefined)
			return this.registered[funcname];
		return false;
	},
	despatch: function(command, args) {
		//alert(args)
		//f = command.split(':')[1];
		f = command
		func = this.getRegistered(f);
		if (func) func.call(func, args);
	},
	call: function(func_name, args, callback) {
		if (callback) 
			this.register(func_name, callback);
		
		this.movie.SetVariable('FunctionArgs', args);
		this.movie.SetVariable('FunctionName', func_name);
	}
	
}
var FlashBridge = function(movie) { this.init(movie) }
FlashBridge.prototype = FlashBridgeBase;


var Win = new Object();
Win.InlineWindow = function() {};
Win.InlineWindow.prototype = {
	open: function(name, options) {
		var n = name.replace(' ', '_');
		this.__name = n;
		this.win = DOM.e({
						tag:'div', 'class':'iwin',
						id:'win__'+n, children: [
							{
								tag:'div',
								id:'win_content'+n,
								'class':'iwin_root',
								children: [
									{tag:'div', 'class':'top', children: [
										{tag: 'div', 'class':'indicator', id:'iwin_indicator_'+n},
										{tag: 'div', 'class': 'close', children: 'x', events: {
																					'click':this.close.bind(this)}}
									]},
									{tag:'div', 'class':'bg', children: {
										tag: 'div', id:'iwin_content_'+name, 'class':'content'
									}},
									{tag:'div', 'class':'bot'}
								]
							},
							{tag:'div', id:'win_bg_'+n, 'class':'iwin_bg', children: {
								tag: 'iframe', src:'', allowtransparency:'true'
							}}
							]
						})
		$('player_container').hide();
		
		//$$('object').each(function(o) {
		//	o.style.display = 'hidden'
		//})
		document.body.appendChild(this.win);
		//this.win.style.height = document.body.offsetHeight;
		//$('win_bg_'+n).style.height = document.body.offsetHeight;

	  },
	close: function() { this.destroy()},
	destroy: function() {
		this.win.parentNode.removeChild(this.win)
		$('player_container').show();
		//$$('object').each(function(o) {
		//	o.style.visibility = 'visible'
		//})
	},
	showIndicator: function() {
		$('iwin_indicator_'+this.__name).show()
	},
	hideIndicator: function() {
		$('iwin_indicator_'+this.__name).hide()
	},
	content: function(html) {
		var c = $('iwin_content_'+this.__name)
		c.update(html)
		this.hideIndicator();
		return c
	}
};

var iWin = function(name) { this.open(name) };
iWin.prototype = Object.extend(new Win.InlineWindow(), {
	test: function() {}
})
var Paginator = Class.create();
Paginator.prototype = {
	url: '',
	container: '',
	per_page: 3,
	no_of_pages: 0,
	cached_pages: {},
	page_width: 0,
	current_page: 1,
	holder: '',
	is_moving: false,
  	initialize: function(container, page_url, no_of_pages, items_per_page) {
		this.url = page_url;
		this.no_of_pages = no_of_pages || 4;
		this.per_page = items_per_page;
		this.container = container;
	},
	setup: function() {
		var c = $(this.container);
		if (!c) return;
		c.cleanWhitespace();
		var w= c.getWidth();
		var h = c.getHeight();
		this.page_width = w;
		this.holder = this.container+'__holder';
		var holder = DOM.New.div({'id': this.holder});
		holder.style.width = (w * this.no_of_pages) + 'px';
		holder.style.whitespace = 'nowrap';
		holder.style.height = h + 'px';
		holder.style.position = 'absolute'; 
		holder.style.left = 0;
		holder.style.top = 0; 		
		/*holder.setStyle({
			'width': (w * this.no_of_pages) + 'px',
			'height': h + 'px',
			position: 'absolute',
			left: '0',
			top: '0'
		})*/
		
		this.startEvents();
		var page_num = function(num) {
			return {tag:'a',
					href: '#',
					id: this.container + '_pagenum__'+num,
					'class':'pagenum n' + num,
					children: num + '',
					events:{click:this.bound_move_to_page}}
				}.bind(this);
				
		var first_page;
		var page_numbers = {
			tag: 'div',
			id: this.container + '__page_numbers',
			'class':'paginated_numbers',
			children: []
		};
		var children = c.immediateDescendants();

		if (!this.per_page) this.per_page = children.length / this.no_of_pages;
		this.no_of_pages.times(function (i){
			var pg = DOM.New.div({'id':this.container+'_page__'+(i + 1), 'class':'paginated_pg'})
			pg.style.width = w + 'px';
			pg.style.height = h + 'px';
			pg.style.cssFloat = 'left';
			pg.style.color = '#fff';
			/*pg.setStyle({
				width: w + 'px',
				height: h + 'px',
				cssFloat: 'left',
				color: '#fff'
			});*/
			if (i == 0) first_page = pg;
			//pg.innerHTML = i;
			DOM.append(holder, pg);
			if (children.length > 0) {
				this.per_page.times(function (j) {
					child = children.shift();
					if (child) DOM.append(pg, child);
				}.bind(this));
			} 
			page_numbers.children.push(page_num(i + 1));
		}.bind(this));
		//hide unused items for now;
		children.each(function(ch){ch.hide()})
		pg_num_holder = DOM.e(page_numbers);
		DOM.append(c, holder);		
		var button = function(name, _src) {
			return DOM.e({tag:'a',
					href: '#',
					id: this.container + '__'+name+'btn',
					'class':'nav_btn '+name,
					children: (!_src)?name:{tag:'img',src:_src}
					})
			}.bind(this);
		
		var prev = button('prev');
		var next = button('next');	
		Event.observe(next, 'click', this.bound_next);
		Event.observe(prev, 'click', this.bound_previous);
		DOM.append(c, [pg_num_holder, prev, next]);
		$(this.container + '_pagenum__1').addClassName('selected');
	},
	empty: function(e) {
		alert(e)
	},
	startEvents: function() {
		this.bound_next = this.next.bindAsEventListener(this);
		this.bound_previous = this.previous.bindAsEventListener(this);
		this.bound_move_to_page = this.move_to_page.bindAsEventListener(this)
	},
	onComplete: function() {
		this.is_moving = false;
	},
	set_page_num: function(num) {
		$(this.container + '__page_numbers').immediateDescendants().each(function(el) {
			el.removeClassName('selected');
			if (el.id == this.container + '_pagenum__'+num) {
				el.addClassName('selected');
			}
		}.bind(this));	
	},
	goto_page: function(num) {
		this.set_page_num(num);
		var h = $(this.holder);
		left = Position.positionedOffset(h)[0];
		x = ((this.page_width * num) - this.page_width) * -1;
		posx = x - left;
		this.move_to(posx);
		this.current_page = parseInt(num);
	},
	reset_next: function(e) {
		var h = $(this.holder);
		var last = $(h.lastChild).remove();
		h.insertBefore(last, h.firstChild);	
		h.style.left = 0 + 'px';
		this.onComplete();
	},
	reset_prev: function(e) {
		var h = $(this.holder);
		var first = $(h.firstChild).remove();
		DOM.append(h, first);
		var w = h.getWidth();
		h.style.left = (this.page_width - w) + 'px';
		this.onComplete();
	},
	move_to: function(x, cb) {
		if (this.is_moving) return;
		this.is_moving = true;
		var h = $(this.holder);
		if (!cb) cb = this.onComplete;
		new Effect.MoveTo(h, 0, x, {'duration':0.5, afterFinish:cb.bind(this)});
	},
	move_to_page: function(e) {
		Event.stop(e);
		if (this.is_moving) return;
		var evt = Event.element(e);
		var page_num = $ID(evt);
		this.goto_page(page_num);
	},
	next: function(e) {
		Event.stop(e);
		if (this.is_moving) return;
		var cpage = $(this.container + '_page__'+ this.current_page);
		var h = $(this.holder);
		if (cpage.next() == undefined) {
			var first = $(h.firstChild).remove();
			l = Position.positionedOffset(h)[0];
			DOM.append(h, first);
			h.style.left = l+this.page_width + 'px';
			this.move_to(this.page_width * -1, this.reset_next);

		} else {
			this.move_to(this.page_width * -1)
		}
		this.current_page = (this.current_page < this.no_of_pages) ? this.current_page + 1 : 1;
		this.set_page_num(this.current_page);
	},
	previous: function(e) {
		Event.stop(e);
		if (this.is_moving) return;
		var h = $(this.holder);
		var cpage = $(this.container + '_page__'+ this.current_page);
		this.current_page = (this.current_page > 1) ? this.current_page - 1 : this.no_of_pages;
		if (cpage.previous() == undefined) {
			h.style.left = 0-this.page_width + 'px';
			h.insertBefore(h.lastChild.remove(), h.firstChild);
			this.move_to(this.page_width, this.reset_prev);
		} else {
			this.move_to(this.page_width);
		}		
		this.set_page_num(this.current_page);
	}	
}







/**
 * @author Ryan Johnson <ryan@livepipe.net>
 * @copyright 2007 LivePipe LLC
 * @package Control.Tabs
 * @license MIT
 * @url http://livepipe.net/projects/control_tabs/
 * @version 1.6.0
 */

if(typeof(Control) == "undefined")
	var Control = {};
Control.Tabs = Class.create();
Object.extend(Control.Tabs,{
	tabs: $A([]),
	responders: $A([]),
	addResponder: function(responder){
		Control.Tabs.responders.push(responder);
	},
	removeResponder: function(responder){
		Control.Tabs.responders = Control.Tabs.responders.without(responder);
	},
	notifyResponders: function(event_name,argument_one,argument_two){
		Control.Tabs.responders.each(function(responder){
			if(responder[event_name])
				responder[event_name](argument_one,argument_two);
		});
	},
	findByTabId: function(id){
		return this.tabs.find(function(tab){
			return tab.links.find(function(link){
				return link.key == id;
			});
		});
	}
});
Object.extend(Control.Tabs.prototype,{
	activeContainer: false,
	activeLink: false,
	initialize: function(tab_set,options){
		Control.Tabs.tabs.push(this);
		tab_set = $(tab_set);
		this.options = $H({
			beforeChange: Prototype.emptyFunction,
			afterChange: Prototype.emptyFunction,
			linkSelector: 'li a',
			activeClassName: 'active',
			defaultTab: 'first',
			autoLinkExternal: true
		});
		if(options)
			for(o in options)
				this.options[o] = options[o];
		this.containers = $H({});
		this.links = (typeof(this.options.linkSelector == "string")
			? tab_set.getElementsBySelector(this.options.linkSelector)
			: this.options.linkSelector(tab_set)
		).findAll(function(link){return (/^#/).exec(link.href.replace(window.location.href.split('#')[0],''));});
		this.links.each(function(link){
			link.key = $A(link.getAttribute('href').replace(window.location.href.split('#')[0],'').split('/')).last().replace(/#/,'');
			this.containers[link.key] = $(link.key);
			link.onclick = function(link){
				this.setActiveTab(link);
				return false;
			}.bind(this,link);
		}.bind(this));
		if(this.options.defaultTab == 'first')
			this.setActiveTab(this.links.first());
		else if(this.options.defaultTab == 'last')
			this.setActiveTab(this.links.last());
		else
			this.setActiveTab(this.options.defaultTab);
		target_regexp = /#(.+)$/;
		targets = target_regexp.exec(window.location);
		if(targets && targets[1]){
			$A(targets[1].split(',')).each(function(target){
				this.links.each(function(target,link){
					if(link.key == target){
						this.setActiveTab(link);
						throw $break;
					}
				}.bind(this,target));
			}.bind(this));
		}
		if(this.options.autoLinkExternal){
			$A(document.getElementsByTagName('a')).each(function(a){
				if(!this.links.include(a)){
					clean_href = a.href.replace(window.location.href.split('#')[0],'');
					if(clean_href.substring(0,1) == '#'){
						if(this.containers.keys().include(clean_href.substring(1))){
							$(a).observe('click',function(event,clean_href){
								this.setActiveTab(clean_href.substring(1));
							}.bindAsEventListener(this,clean_href));
						}
					}
				}
			}.bind(this));
		}
	},
	setActiveTab: function(link){
		if(typeof(link) == "undefined" || link == false)
			return;
		if(typeof(link) == "string"){
			this.links.each(function(_link){
				if(_link.key == link){
					this.setActiveTab(_link);
					throw $break;
				}
			}.bind(this));
		}else{
			this.containers.each(function(item){
				item[1].hide();
			});			
			this.links.each(function(item){
				item.removeClassName(this.options.activeClassName);
			}.bind(this));
			link.addClassName(this.options.activeClassName);
			this.options.beforeChange(this,this.activeContainer);
			Control.Tabs.notifyResponders('beforeChange',this,this.activeContainer);
			this.activeContainer = this.containers[link.key];
			this.activeLink = link;
			this.containers[link.key].show();
			this.options.afterChange(this,this.containers[link.key]);
			Control.Tabs.notifyResponders('afterChange',this,this.containers[link.key]);
		}
	},
	next: function(){
		this.links.each(function(link,i){
			if(this.activeLink == link && this.links[i + 1]){
				this.setActiveTab(this.links[i + 1]);
				throw $break;
			}
		}.bind(this));
	},
	previous: function(){
		this.links.each(function(link,i){
			if(this.activeLink == link && this.links[i - 1]){
				this.setActiveTab(this.links[i - 1]);
				throw $break;
			}
		}.bind(this));
	},
	first: function(){
		this.setActiveTab(this.links.first());
	},
	last: function(){
		this.setActiveTab(this.links.last());
	}
});








__n = false;
function isIE() { if (!__n) __n = navigator.appVersion; if (__n.indexOf('MSIE') != -1) return __n; return false; }
var PNG = {
	fixed: [], ie: isIE(), need_fix: true,
	init: function() {
		if (!this.ie) {this.need_fix = false; return false;}; 
		var arVersion = this.ie.split("MSIE"); var version = parseFloat(arVersion[1]);
		if (version <= 5.5) this.need_fix = false;
	},
	needFix: function (img) {
		if (!this.need_fix) return false; var imgName = img.src;
		if (!imgName) return false; imgName = imgName.toUpperCase();
		if (imgName.substring(imgName.length-3, imgName.length) != "PNG") return false;
		return true;
	},
	isFixed: function(img) {
		for (f=0;f<this.fixed.length;f++) {	if (this.fixed[f] == img) return true;} return false;
	},
	fixAll: function() {
		if (!this.need_fix) return false;		
		var imgs = $A(document.getElementsByTagName('img'));
		var imgl = imgs.length; for(var i=0; i<imgl; i++) { this.fix(imgs[i]);}
	},
	fix: function(img) {
		if (!this.needFix(img) || this.isFixed(img)) return true;
		var src = img.src; var imgName = src.toUpperCase();		
		var imgID = (img.id) ? "id='" + img.id + "' " : "";
		var imgClass = (img.className) ? "class='" + img.className + "' " : "";
		var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
		var imgStyle = "display:inline-block;" + img.style.cssText;
			if (img.align == "left") imgStyle = "float:left;" + imgStyle;
			if (img.align == "right") imgStyle = "float:right;" + imgStyle;
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
			var strNewHTML = "<span " + imgID + imgClass + imgTitle
			 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			 + "(src=\'" + src + "\', sizingMethod='scale');\"></span>";
			 img.outerHTML = strNewHTML;
		this.fixed.push(img);
	}
}
PNG.init();



var FileUploader = Class.create();
FileUploader.prototype = {
	options: {},
	container: '',
	swfu: '',
	_name: '',
	default_list_files_container: "SWFUploadFileListingFiles",
	initialize: function(container, options) {
		form = $$('#' + container + ' form')[0];
		hidden_fields = Form.serializeElements(form.getInputs('hidden'));
		//session_id = Req.Cookie.get('_session_id');
		handler = (form.action.indexOf('?') != -1) ? form.action + '&' + hidden_fields : form.action + '?' + hidden_fields; 
		
		this.options = options;
		this._name = 'swfu_'+container;
		this.container = container;
		var opts = Object.extend({
		upload_script: handler,
		flash_loaded_callback: this._name+".swfu.flashLoaded",
		upload_file_queued_callback : this._name +'.fileQueued',
		upload_file_start_callback : this._name +'.uploadFileStart',
		upload_progress_callback : this._name +'.uploadProgress',
		upload_file_complete_callback : this._name +'.uploadFileComplete',
		upload_file_cancel_callback : this._name +'.uploadFileCancelled',
		upload_queue_complete_callback : this._name +'.uploadQueueComplete',
		upload_error_callback : this._name +'.uploadError',
		upload_cancel_callback : this._name +'.uploadCancel',
		on_complete: this._name +'.onUploadComplete',
		allow_multiple: true,
		debug: false}, options)
		
		this.swfu = new SWFUpload(opts);
	},
	fileQueued: function(file, queuelength) {
		var listingfiles = $(this.default_list_files_container + '_' + this.container);
		
		if(!listingfiles.getElementsByTagName("ul")[0]) {

			var info = document.createElement("h4");
			info.appendChild(document.createTextNode("File queue"));

			listingfiles.appendChild(info);

			var ul = document.createElement("ul")
			listingfiles.appendChild(ul);
		}

		listingfiles = listingfiles.getElementsByTagName("ul")[0];

		var li = document.createElement("li");
		li.id = file.id;
		li.className = "SWFUploadFileItem";
		li.innerHTML = file.name + " <span class='progressBar' id='" + file.id + "progress'></span><a id='" + file.id + "deletebtn' class='cancelbtn' href='javascript:"+this._name+".swfu.cancelFile(\"" + file.id + "\");'><!-- IE --></a>";

		listingfiles.appendChild(li);
		$(this.swfu.movieName + "UploadBtn").style.display = "block";
		
		var queueinfo = $("queueinfo_"+this.container);
		
		queueinfo.innerHTML = queuelength + " files queued";
		queueinfo.style.display='block';
		
		
		
		//$("cancelqueuebtn").style.display = "block";
	},
	uploadFileCancelled: function(file, queuelength) {
		var li = $(file.id);
		var queueinfo = $("queueinfo_"+this.container);
		queueinfo.innerHTML = queuelength + " files queued";

		li.remove();
		return;

		li.innerHTML = file.name + " - cancelled";
		li.className = "SWFUploadFileItem uploadCancelled";

	},
	uploadFileStart: function(file, position, queuelength) {
		var div = $("queueinfo_"+this.container);
		div.innerHTML = "Uploading file " + position + " of " + queuelength;

		var li = $(file.id);
		li.className += " fileUploading";
	},
	uploadProgress: function(file, bytesLoaded) {

		var progress = $(file.id + "progress");
		var percent = Math.ceil((bytesLoaded / file.size) * 200)
		progress.style.background = "#f0f0f0 url(/admin/images/progressbar.png) no-repeat -" + (200 - percent) + "px 0";
	},
	uploadError: function(errno) {
		// SWFUpload.debug(errno);
	},
	uploadFileComplete: function (file) {
		var li = $(file.id);
		li.className = "SWFUploadFileItem uploadCompleted";
		
		if (this.CustomCallbacks[this.options.on_complete])
			this.CustomCallbacks[this.options.on_complete]();
	},
	cancelQueue: function() {
		this.swfu.cancelQueue();
		$(this.swfu.movieName + "UploadBtn").style.display = "none";
		$("cancelqueuebtn").style.display = "none";
	},
	uploadQueueComplete: function(file) {
		var div = $("queueinfo_"+this.container);
		div.innerHTML = "All files uploaded..."
		$("cancelqueuebtn").style.display = "none";
	},
	onUploadComplete: function() {
		//dummy function call back
		//pass :on_complete option with any method name in UploadCallbacks as string
		//
	},
	CustomCallbacks: {
		change_artwork_image: function() {
			alert('within function')
		}
	}
}






