var embed = function(a){
var options = {
	width: 0,
	height: 0,
	flashvars: '',
	wmode: '',
	allowfullscreen: '',
	allowscriptaccess: '',
	quality: 'high',
	src: ''
};
embed.browser();
var a = document.getElementById(a);
if(embed.browser.app == 'IE'){
	var b;
	if(a.tagName.toLowerCase() == 'object'){
		b = a;
	}else{
		for(var o=0; o < a.children.length; o++)
			if(a.children[o].tagName.toLowerCase() == 'object') b = a.children[o];
	}
	options.width = (b.getAttribute('width') != null)?b.getAttribute('width'):options.width;
	options.height = (b.getAttribute('height') != null)?b.getAttribute('height'):options.height;
	var r = b.childNodes;
	for(var o=0; o<r.length; o++){
		switch(r[o].getAttribute('name').toLowerCase()){
			case 'width':
				options.width = (r[o].getAttribute('value') != '')?r[o].getAttribute('value'):options.width;
				break;
			case 'height':
				options.height = (r[o].getAttribute('value') != '')?r[o].getAttribute('value'):options.height;
				break;
			case 'flashvars':
				options.flashvars = (r[o].getAttribute('value') != '')?r[o].getAttribute('value'):options.flashvars;
				break;
			case 'wmode':
				options.wmode = (r[o].getAttribute('value') != '')?r[o].getAttribute('value'):options.wmode;
				break;
			case 'allowfullscreen':
				options.allowfullscreen = (r[o].getAttribute('value') != '')?r[o].getAttribute('value'):options.allowfullscreen;
				break;
			case 'allowscriptaccess':
				options.allowscriptaccess = (r[o].getAttribute('value') != '')?r[o].getAttribute('value'):options.allowscriptaccess;
				break;
			case 'quality':
				options.quality = (r[o].getAttribute('value') != '')?r[o].getAttribute('value'):options.quality;
				break;
			case 'src':
				options.src = (r[o].getAttribute('value') != '')?r[o].getAttribute('value'):options.src;
				break;
			case 'movie':
				options.src = (r[o].getAttribute('value') != '')?r[o].getAttribute('value'):options.src;
				break;
		}
	}
}else{
	var b;
	if(a.tagName.toLowerCase() == 'object'){
		b = a;
		options.width = (b.getAttribute('width') != null)?b.getAttribute('width'):options.width;
		options.height = (b.getAttribute('height') != null)?b.getAttribute('height'):options.height;
		options.src = (b.getAttribute('data') != null)?b.getAttribute('data'):options.src;
		var r = b.childNodes;
		for(var o=0; o<r.length; o++){
			switch(r[o].getAttribute('name').toLowerCase()){
				case 'width':
					options.width = (r[o].getAttribute('value') != '')?r[o].getAttribute('value'):options.width;
					break;
				case 'height':
					options.height = (r[o].getAttribute('value') != '')?r[o].getAttribute('value'):options.height;
					break;
				case 'flashvars':
					options.flashvars = (r[o].getAttribute('value') != '')?r[o].getAttribute('value'):options.flashvars;
					break;
				case 'wmode':
					options.wmode = (r[o].getAttribute('value') != '')?r[o].getAttribute('value'):options.wmode;
					break;
				case 'allowfullscreen':
					options.allowfullscreen = (r[o].getAttribute('value') != '')?r[o].getAttribute('value'):options.allowfullscreen;
					break;
				case 'allowscriptaccess':
					options.allowscriptaccess = (r[o].getAttribute('value') != '')?r[o].getAttribute('value'):options.allowscriptaccess;
					break;
				case 'quality':
					options.quality = (r[o].getAttribute('value') != '')?r[o].getAttribute('value'):options.quality;
					break;
				case 'src':
					options.src = (r[o].getAttribute('value') != '')?r[o].getAttribute('value'):options.src;
					break;
				case 'movie':
					options.src = (r[o].getAttribute('value') != '')?r[o].getAttribute('value'):options.src;
					break;
				case 'data':
					options.src = (r[o].getAttribute('value') != '')?r[o].getAttribute('value'):options.src;
					break;
			}
		}
	} else {
		if(a.tagName.toLowerCase() == 'embed'){
			b = a;
		}else{
			for(var o=0; o < a.childNodes.length; o++)
				if(typeof a.childNodes[o].tagName != 'undefined' && a.childNodes[o].tagName.toLowerCase() == 'embed') b = a.childNodes[o];
		}
		options.width = (b.getAttribute('width') != null)?b.getAttribute('width'):options.width;
		options.height = (b.getAttribute('height') != null)?b.getAttribute('height'):options.height;
		options.flashvars = (b.getAttribute('flashvars') != null)?b.getAttribute('flashvars'):options.flashvars;
		options.wmode = (b.getAttribute('wmode') != null)?b.getAttribute('wmode'):options.wmode;
		options.allowfullscreen = (b.getAttribute('allowfullscreen') != null)?b.getAttribute('allowfullscreen'):options.allowfullscreen;
		options.allowscriptaccess = (b.getAttribute('allowscriptaccess') != null)?b.getAttribute('allowscriptaccess'):options.allowscriptaccess;
		options.quality = (b.getAttribute('quality') != null)?b.getAttribute('quality'):options.quality;
		options.src = (b.getAttribute('src') != null)?b.getAttribute('src'):options.src;
	}
}
embed.open(embed.code(options));
};
embed.browser = function(){
if(navigator.userAgent.indexOf('MSIE') != -1){
	embed.browser.app = 'IE';
	var nav = navigator.appVersion;
	var version = nav.substr(nav.indexOf('MSIE')+4,nav.indexOf(';',nav.indexOf('MSIE'))-(nav.indexOf('MSIE')+4));
	embed.browser.version = (!isNaN(Number(version)))?Number(version):0;
}else{
	embed.browser.app = 'Other';
}
};
embed.browser.app = '';
embed.browser.version = 0;
embed.code = function(options){
var obj_code = '<object width="'+options.width+'" height="'+options.height+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">';
	obj_code += '<param name="_cx" value="8466"/>';
	obj_code += '<param name="_cy" value="6879"/>';
	obj_code += '<param name="FlashVars" value="'+options.flashvars+'"/>';
	obj_code += '<param name="Movie" value="'+options.src+'"/>';
	obj_code += '<param name="Src" value="'+options.src+'"/>';
	obj_code += '<param name="WMode" value="'+options.wmode+'"/>';
	obj_code += '<param name="Play" value="0"/>';
	obj_code += '<param name="Loop" value="-1"/>';
	obj_code += '<param name="Quality" value="'+options.quality+'"/>';
	obj_code += '<param name="SAlign" value="LT"/>'
	obj_code += '<param name="Menu" value="-1"/>';
	obj_code += '<param name="Base" value=""/>';
	obj_code += '<param name="AllowScriptAccess" value="'+options.allowscriptaccess+'"/>';
	obj_code += '<param name="Scale" value="NoScale"/>';
	obj_code += '<param name="DeviceFont" value="0"/>';
	obj_code += '<param name="EmbedMovie" value="0"/>';
	obj_code += '<param name="BGColor" value=""/>';
	obj_code += '<param name="SWRemote" value=""/>';
	obj_code += '<param name="MovieData" value=""/>';
	obj_code += '<param name="SeamlessTabbing" value="1"/>';
	obj_code += '<param name="Profile" value="0"/>';
	obj_code += '<param name="ProfileAddress" value=""/>';
	obj_code += '<param name="ProfilePort" value="0"/>';
	obj_code += '<param name="AllowNetworking" value="all"/>';
	obj_code += '<param name="AllowFullScreen" value="'+options.allowfullscreen+'"/>';
	obj_code += '<embed width="'+options.width+'" height="'+options.height+'" flashvars="'+options.flashvars+'" wmode="'+options.wmode+'" allowfullscreen="'+options.allowfullscreen+'" allowscriptaccess="'+options.allowscriptaccess+'" quality="'+options.quality+'" src="'+options.src+'" type="application/x-shockwave-flash"/>';
	obj_code += '</object>';
return obj_code;
};
embed.style = function(x,s){
var s = s.split(';');
for(var o in s){
	if(!isNaN(Number(o))){
		if(s[o]!=''){
			var f = s[o].split(':');
			var d = f[0];
			var v = f[1];
			if(d.indexOf('-') != -1){
				i = d.split('-');
				d = i[0].toLowerCase()+i[1].substr(0,1).toUpperCase()+i[1].substr(1,i[1].length-1).toLowerCase();
			}else{
				d = d.toLowerCase();
			}
			if(d=='float' && embed.browser.app != 'IE') d = 'cssFloat';
			v = v.replace(/\'/g,"\\\'");
			eval('document.getElementById(\''+x+'\').style.'+d+'=\''+v+'\';');
		}
	}
}
};
embed.open = function(code){
var body = document.body;

var ha = document.documentElement.clientHeight;
var h = Math.floor(ha/2);
var af = (embed.browser.app == 'IE' && embed.browser.version < 7)?'absolute':'fixed';

var el = document.createElement('div');
	body.appendChild(el);
	el.setAttribute('id','ec_f');
	embed.style('ec_f','position:'+af+';width:100%;top:0;left:0px;overflow:visible;z-index:100000;');

var f = document.createElement('div');
	el.appendChild(f);
	f.setAttribute('id','ec_b');
	embed.style('ec_b','position:absolute;z-index:0;top:0;left:0px;height:'+ha+'px;width:100%;');
	
	if(embed.browser.app == 'IE'){
		f.attachEvent('onclick',embed.close);
	}else{
		f.addEventListener('click',embed.close,false);
	}
	
var p = document.createElement('div');
	el.appendChild(p);
	p.setAttribute('id','ec_p');
	embed.style('ec_p','height:'+h+'px;margin-bottom:-111px;');

var w = document.createElement('div');
	el.appendChild(w);
	w.setAttribute('id','ec_w');
	embed.style('ec_w','z-index:10000;clear:both;width:322px;height:222px;margin:auto;background-image:url(\'/kstream/images/module_background.png\');position:relative;');
	
var b = document.createElement('div');
	w.appendChild(b);
	b.setAttribute('id','ec_c');
	embed.style('ec_c','width:300px;height:200px;position:absolute;top:10px;left:10px;background-color:white;border: 1px solid #cccccc;');

var l = document.createElement('div');
	b.appendChild(l);
	l.setAttribute('id','ec_l');
	embed.style('ec_l','width:100%;height:36px;background-color:#f2f2f2;color:#232323;border-bottom: 1px solid #cccccc;font:bold 10px arial;line-height:18px;');
	var xc = document.createElement('div');
	xc.setAttribute('id','ec_x');
	l.appendChild(xc);
	embed.style('ec_x','font:bold 14px arial;width:15px;height:15px;margin:3px;cursor:pointer;float:right;');
	xc.innerHTML = 'X';
	if(embed.browser.app == 'IE'){
		l.innerHTML = l.innerHTML + 'Copy the code below and paste into your personal blog or other webpage.';
		document.getElementById('ec_x').attachEvent('onclick',embed.close);
	}else{
	xc.addEventListener('click',embed.close,false);
			var lt = document.createTextNode('Copy the code below and paste into your personal blog or other webpage.');
			l.appendChild(lt);
		}
		
	var c = document.createElement('textarea');
		b.appendChild(c);
		c.setAttribute('id','ec_d');
		c.setAttribute('id','ec_d');
		embed.style('ec_d','margin:5px 0 0 5px;border: 1px solid #cccccc;width:288px;height:151px;overflow:hidden;');
		c.value = code;
		
		if(embed.browser.app == 'IE'){
			c.attachEvent('onclick',embed.textselect);
		}else{
			c.addEventListener('click',embed.textselect,false);
		}
};
embed.textselect = function(){
	var a = 'ec_d';
	document.getElementById(a).focus();
	document.getElementById(a).select();
};
embed.close = function(){
	var f = document.getElementById('ec_b');
	
	if(embed.browser.app == 'IE'){
		f.detachEvent('onclick',embed.close);
	}else{
		f.removeEventListener('click',embed.close,false);
	}
	
	var a = document.getElementById('ec_f');
		a.parentNode.removeChild(a);
};
