var Browser = {
	a : navigator.userAgent.toLowerCase()
}
Browser = {
	ie : /*@cc_on true || @*/ false,
	ie6 : Browser.a.indexOf('msie 6') != -1,
	ie7 : Browser.a.indexOf('msie 7') != -1,
	opera : !!window.opera,
	safari : Browser.a.indexOf('safari') != -1,
	safari3 : Browser.a.indexOf('applewebkit/5') != -1,
	mac : Browser.a.indexOf('mac') != -1
}
function $(e) {
	if(typeof e == 'string')
    	return document.getElementById(e);
	return e;
}
function createElement(name, attrs, doc, xmlns) {
	var doc = doc ? doc : document;
	var elm;
	if(doc.createElementNS)
		elm = doc.createElementNS(xmlns ? xmlns : "http://www.w3.org/1999/xhtml", name);
	else
		elm = doc.createElement(name);
	if(attrs)
		for(attr in attrs)
			elm.setAttribute(attr, attrs[attr]);
	return elm;
}
function setDisplay(e, display) {
	$(e).style.display = display;
}
function hide(e) {
	setDisplay(e, 'none');
}
function show(e) {
	setDisplay(e, '');
}
function showBlock(e) {
	setDisplay(e, 'block');
}
function visible(e) {
	return $(e).style.display != 'none';
}
function toggle(e) {
	(visible(e) ? hide : show)(e);
}
function visibleInverse(e) {
	return $(e).style.display != '';
}
function toggleInverse(e, display) {
	setDisplay(e, visibleInverse(e) ? '' : display);
}
function overflow(e) {
	return $(e).style.height != 'auto';
}
function setHeight(e, height) {
	$(e).style.height = height;
}
function auto(e) {
	setHeight(e, 'auto');
}
function notauto(e) {
	setHeight(e, '');
}
function toggleContent(e, f, anchor, collapsed, expanded) {
	if(visible(e)) {
		hide(e);
		show(f);
		anchor.innerHTML = collapsed;
	} else {
		show(e);
		hide(f);
		anchor.innerHTML = expanded;
	}
}
function toggleOverflow(e, anchor, collapsed, expanded) {
	if(overflow(e)) {
		auto(e);
		anchor.innerHTML = collapsed;
	} else {
		notauto(e);
		anchor.innerHTML = expanded;
	}
}
function swap(e,f) {
	hide(e);
	showBlock(f);
}
function getChildElementsByTagName(e, tagName) {
	var nodes = [];
	for(var i = 0; i < e.childNodes.length; i++)
		if(e.childNodes[i].nodeName.toLowerCase() == tagName)
			nodes.push(e.childNodes[i]);
	return nodes;
}
function removeChildren(e) {
	while(e.firstChild)
		e.removeChild(e.firstChild);
}
function addEvent(obj, evType, fn) {
	if(obj.addEventListener) {
		obj.addEventListener(evType, fn, false);
		return true;
	} else if(obj.attachEvent)
		return obj.attachEvent("on" + evType, fn);
	return false;
}
function getFormQueryString(form) {
	var pairs = [];
	var inputs = form.getElementsByTagName('input');
	var textareas = form.getElementsByTagName('textarea');
	var selects = form.getElementsByTagName('select');

	for(var i = 0, input; input = inputs[i]; i++)
		pairs.push(input.name + '=' + encodeURI(input.value));

	for(var i = 0, input; input = textareas[i]; i++)
		pairs.push(input.name + '=' + encodeURI(input.value));

	for(var i = 0, input; input = selects[i]; i++)
		for(var j = 0, option; option = input.options[j]; j++)
			if(option.selected)
				pairs.push(input.name + '=' + encodeURI(option.value));

	return pairs.join('&');
}

function getURLParams() {
	var map = {};
	var entries = document.location.search.substr(1).split('&');
	for(var i = 0; i < entries.length; i++) {
		var entry = entries[i].split('=', 2);
		if(!map[entry[0]])
			map[entry[0]] = [];
		map[entry[0]].push(entry.length == 2 ? decodeURIComponent(entry[1]) : null);
	}
	return map;
}

function createURLSearchString(map) {
	var search = '';
	for(field in map)
		if(!Object.prototype[field]) {
			var array = map[field];
			for(var i = 0; i < array.length; i++) {
				if(search != '')
					search += '&';
				search += field;
				if(array[i] != null)
					search += '=' + array[i];
			}
		}
	if(search != '')
		search = '?' + search;
	return search;
}

function setURLParam(parameter, value) {
	var url = document.location.protocol + '//' + document.location.host + document.location.pathname;
	var params = getURLParams();
	params[parameter] = [value];
	url += createURLSearchString(params);
	url += document.location.hash;
	return url;
}

function addStylesheet(href, media) {
	document.getElementsByTagName("head")[0].appendChild(createElement('link', {
		'rel': 'stylesheet',
		'type': 'text/css',
		'media': media ? media : 'screen, projection',
		'href': href
	}));
}

function createObject(id, type, data, width, height, params, fallbackContent, createElementFunc) {
	var createElementFunc = createElementFunc || createElement;
	var obj = createElementFunc('object', {
		'type': type,
		'data': data,
		'width': width,
		'height': height
	});
	if(id)
		obj.setAttribute('id', id);
	if(params)
		for(var i = 0, pair; pair = params[i]; i++)
			obj.appendChild(createElementFunc('param', {
				'name': pair[0],
				'value': pair[1]
			}));
	if(fallbackContent)
		obj.appendChild(fallbackContent);
	return obj;
}

function createElementStr(name, attrs) {
	return new NodeStr(name, attrs);
}

// used for DOM-like creation of object elements in IE
var NodeStr = function(name, attrs) {
	this.name = name;
	if(attrs)
		this.attrs = attrs;
	else
		this.attrs = {};
	this.childNodes = [];
}
NodeStr.prototype = {
	appendChild : function(node) {
		this.childNodes.push(node);
		return node;
	},
	setAttribute : function(name, value) {
		this.attrs[name] = value;
	},
	toString : function() {
		var str = '<' + this.name;
		if(this.attrs)
			for(attr in this.attrs)
				str += ' ' + attr + '="' + this.attrs[attr] + '"';
		str += '>';
		for(child in this.childNodes)
			str += this.childNodes[child];

		return str + '</' + this.name + '>';
	}
}

function setFlash(target, id, data, width, height, params, fallback, containsAgeGate) {
	var FLASH_MEDIA_TYPE = 'application/x-shockwave-flash';
	var targetNode = $(target);

	if(containsAgeGate)
		AgeGate.addListenerId(id);

	// DOM manipulation and styling of OBJECT tags is not available in IE
	if(Browser.ie) {
		if(typeof fallback != 'string')
			fallback = fallback.innerHTML;
		targetNode.innerHTML = createObject(id, FLASH_MEDIA_TYPE, data, width, height, params, fallback, createElementStr);
	} else {
		if(typeof fallback == 'string')
			fallback = document.createTextNode(fallback);
		removeChildren(targetNode);
		targetNode.appendChild(createObject(id, FLASH_MEDIA_TYPE, data, width, height, params, fallback));
	}
	return targetNode.firstChild;
}

function loadScript(src, id) {
	var head = document.getElementsByTagName('head')[0];
	var script = createElement('script', {
		'type': 'text/javascript',
		'src': src
	});
	if(id) {
		var old = document.getElementById(id);
		if(old)
			old.parentNode.removeChild(old);
		script.id = id;
	}
	head.appendChild(script);
}

function jsonCallback(result) {
	// ageAppropriate is global
	var tmp = result.ageAppropriate;

	if(tmp == null)
		ageAppropriate = null;
	else if(typeof tmp == 'string')
		ageAppropriate = tmp == "true";
	else
		ageAppropriate = !!tmp;
}

var AgeGate = {
	FORM_ID: 'ageGateForm',
	day: '',
	month: '',
	year: '',
	listenerIds: [],
	verify: function() {
		if(ageAppropriate == null)
			return null;
		return ageAppropriate;
	},
	setYear: function(v) {
		AgeGate._set('year', v);
	},
	setMonth: function(v) {
		AgeGate._set('month', v);
	},
	setDay: function(v) {
		AgeGate._set('day', v);
	},
	addListenerId: function(id) {
		AgeGate.listenerIds.push(id);
	},
	setCookies: function(cookies) {
		jsonCallback(cookies);
		for(index in AgeGate.listenerIds) {
			//alert('notifying listener: ' + AgeGate.listenerIds[index] + ', ageAppropriate = ' + ageAppropriate);
			$(AgeGate.listenerIds[index]).passedAgeGate(ageAppropriate);
		}
	},
	verifyRedirect: function(loc) {
		var validated = AgeGate.verify();
		if(validated)
			window.location = loc
		else if(validated == false)
			alert('not old enough');
		else
			alert('show age gate');
	},
	_set: function(name, value) {
		var form = $(AgeGate.FORM_ID);
		if(form) { // full site age gate
			form[name].value = value;
			if(form.year.value != '' &&
					form.month.value != '' &&
					form.day.value != '')
				form.submit();
		} else { // per asset age gate
			AgeGate[name] = value;
			if(AgeGate.year != '' && AgeGate.month != '' && AgeGate.day != '')
				loadScript(jsRoot + 'agegate.xml?callback=AgeGate.setCookies&year=' + AgeGate.year +
						'&month=' + AgeGate.month +	'&day=' + AgeGate.day, 'cookiejson');
		}
	}
}

function selectLanguage(lang) {
	window.location = HTTP.setURLParam('locale', lang);
}

var HTTP = {
	URL_SPACE_REGEXP : /%20/g,
	getURLParams : function(url) {
		var map = {};
		if(url) {
			var queryStart = url.indexOf('?');
			var hashStart = url.indexOf('#');
			if(queryStart != -1) {
				if(hashStart != -1)
					url = url.substring(queryStart + 1, hashStart);
				else
					url = url.substr(queryStart + 1);
			} else
				return map;
		} else
			url = window.location.search.substr(1);
		var entries = url.split('&');
		for(var i = 0; i < entries.length; i++) {
			var entry = entries[i].split('=', 2);
			if(!map[entry[0]])
				map[entry[0]] = [];
			map[entry[0]].push(entry.length == 2 ? decodeURIComponent(entry[1]) : null);
		}
		return map;
	},
	setURLParam : function(parameter, value, url) {
		var hash = '';
		var path;
		if(url) {
			var queryStart = url.indexOf('?');
			var hashStart = url.indexOf('#');
			if(queryStart != -1)
				path = url.substring(0, queryStart);
			else if(hashStart != -1)
				path = url.substring(0, hashStart);
			else
				path = url;
			if(hashStart != -1)
				hash = url.substr(hashStart);
		} else {
			url = false;
			path = window.location.pathname;
			hash = window.location.hash;
		}
		var params = HTTP.getURLParams(url);
		params[parameter] = [value];
		return path + HTTP._createQueryString(params) + hash;
	},
	encodeForm : function(form, post) {
		var pairs = [];
		var inputs = form.getElementsByTagName('input');
		var textareas = form.getElementsByTagName('textarea');
		var selects = form.getElementsByTagName('select');

		for(var i = 0, input; input = inputs[i]; i++)
			if(!input.disabled && input.name && ((input.type != 'radio' && input.type != 'checkbox') || input.checked))
				pairs.push(HTTP._formUrlEncode(input.name, post) + '=' + HTTP._formUrlEncode(input.value, post));

		for(var i = 0, input; input = textareas[i]; i++)
			if(!input.disabled && input.name)
				pairs.push(HTTP._formUrlEncode(input.name, post) + '=' + HTTP._formUrlEncode(input.value, post));

		for(var i = 0, input; input = selects[i]; i++)
			if(!input.disabled && input.name)
				for(var j = 0, option; option = input.options[j]; j++)
					if(option.selected)
						pairs.push(HTTP._formUrlEncode(input.name, post) + '=' + HTTP._formUrlEncode(option.value, post));

		return pairs.join('&');
	},
	_createQueryString : function(map) {
		var search = '';
		for(field in map)
			if(!Object.prototype[field]) {
				var array = map[field];
				for(var i = 0; i < array.length; i++) {
					if(search != '')
						search += '&';
					search += field;
					if(array[i] != null)
						search += '=' + array[i];
				}
			}
		if(search != '')
			search = '?' + search;
		return search;
	},
	_formUrlEncode : function(val, post) {
		if(post)
			return encodeURIComponent(val).replace(HTTP.URL_SPACE_REGEXP, '+');
		return encodeURIComponent(val);
	}
}
var prevtarg
garr = new Array();
function movebang(someloc,atarg)
{ 
if(prevtarg){ prevtarg.className = "" }
prevtarg = atarg;  atarg.className = "e_act"
garr.push(someloc.toLowerCase().slice(0,1)); if(garr.length>8){ garr.shift()} 
if(garr.join("") == "thatsrad") gomg()
for(x=0; x<locarr.length; x++)
{ if(locarr[x].n == someloc) someloc = locarr[x] }
pex = document.getElementById("p_excl")
pex.style.marginLeft = Number(someloc.l) - 32 + "px"
pex.style.marginTop = Number(someloc.t) - 89 + "px"
pex.style.display = "block"
}

function gomg()
{

   var so = new SWFObject("../_images/popup.swf", "gomg_f", "863", "400", "8");
   so.addParam("wmode","transparent");
   so.write("gomg"); 

}


function f_show(obj)
{  
targ =  document.getElementById("f_curr")
if(!obj)
{ targ.style.backgroundImage = "url(../_images/coverage/" + featured_items[0].img + ".jpg)"; document.getElementById("fc_desc").innerHTML = featured_items[0].txt; return; }
targ.style.backgroundImage = "url(../_images/coverage/" + featured_items[obj].img + ".jpg)"
document.getElementById("fc_desc").innerHTML = featured_items[obj].txt

}

	
function go_fc()
{ window.location.href = featured_items[0].lnk; }


function build_ls(type,port){
	var so = new SWFObject("../_flash/flvplayer.swf", "fl_live", "480", "370", "8", "#000000");
		so.addParam("flashvars", "host=cp58920.live.edgefcs.net/live&amp;file=blizzcon2008-"+type+"@"+port+"&amp;type=akamai&amp;id=livestream");
		so.write("livestream"); 
}

streams = { wow:[1,2],rts:[3,4] }
function livestream09(type){
var playerWidth = 720;
var plahyerHeight = 480 + 20;


	var so = new SWFObject(stablerelease, "bitgravity_player_6", "720", "576", "9");
	so.addParam("allowFullScreen","true")
	so.addParam("allowScriptAccess","always")
	so.addParam("flashvars", "AutoPlay=true&amp;File=http://bglive-a.bitgravity.com/blizzcon/live/stream"+ streams[type][0] +"&amp;FileQuality2=http://bglive-a.bitgravity.com/blizzcon/live/stream"+ streams[type][1] +"&amp;FileLabel=stream"+ streams[type][0] +": 700 kbps HQ RTS&amp;FileQuality2Label=stream"+ streams[type][1] +": 400 kbps LQ RTS&amp;FileBitrate=700&amp;FileQuality2Bitrate=400&amp;DefaultLevel=1&amp;Mode=live&amp;VideoFit=stretch&amp;DefaultRatio=1.777778&amp;AutoBitrate=on");
		so.write("bg_player_location"); 
		
}



function build_arc(video,dir,targ){
	var so = new SWFObject("http://blizzcon08.blizzard.com.edgesuite.net/video/video_loader1.swf", "bc_promo", "600", "380", "9", "#000000");
	so.addParam("base", "http://blizzcon08.blizzard.com.edgesuite.net/video/");
	so.addParam("allowFullScreen", "true");
	so.addVariable('vidArr',video+":bc_gen:"+dir)
	so.write("vid_arc"); 
	document.getElementById('arc_c').style.display = "block"
if(targ)
{	tgs = targ.getElementsByTagName("div")
	for(x=0;x<tgs.length;x++){ if(tgs[x].className == 'arc_txt'){ttxt = tgs[x]; } }
	if(ttxt.innerHTML){	document.getElementById('match_desc').innerHTML = ttxt.innerHTML; } 
}
}

function checkqs(){

qsv = getQueryParamValue("v")
qsd = getQueryParamValue("d")
alst = document.getElementsByTagName("a")
for(x=0; x<alst.length;x++){ if(alst[x].onclick) { if(String(alst[x].onclick).indexOf(qsv)>-1) targ = alst[x] } }
if(qsv && qsd){ build_arc(qsv,qsd,targ);  }

}
/*
	so.addParam("allowFullScreen", "true");
	so.addParam("devicefont", "false");
	so.addParam("movie", "../_flash/flvplayer");
	so.addParam("allowScriptAccess", "sameDomain");
	so.addParam("name", "test");
	so.addParam("id", "test");

*/

function storetip(targ,val)
{ targ = document.getElementById("item"+targ)
  if(prevtarg){prevtarg.style.display = "none";}
  prevtarg = targ;
  if(val == "off") { targ.unav = true; targ.style.display = "none"; setTimeout(function(){targ.style.display = "none"; targ.unav = false;},40); } 
  else { if(!targ.unav) targ.style.display = "block"  }

}

function showvideo(flv,img,dir,w,h,targ)
{
			var so = new SWFObject("http://us.media.blizzard.com/blizzcon/video_loader_dtv.swf", targ+"-id", w, h, "9");
			so.addParam("base", "http://us.media.blizzard.com/blizzcon/"); 
			so.addParam("allowScriptAccess", "always");
			so.addParam("wmode", "transparent");
			so.addVariable("vidArr", flv+":"+img+":"+dir)
			so.write(targ);   
}

function buildpip()
{   piplang = getQueryParamValue("lang").split("-")[0];
    if("es,de,fr,en".indexOf(piplang)<0) piplang = "en";
	var sso = new SWFObject("http://politeinpublic.com/flash/widget.swf", "widget", "550", "710", "9","001F2C"); 
	sso.addVariable("eventid", "1035"); 
	sso.addVariable("startrelated", true); 
	sso.addVariable("tracking", true); 
	sso.addVariable("lang", piplang) 
	sso.addVariable("titletextcolor", "D7E5F2"); 
	sso.addVariable("accentcolor", "A4FF00"); 
	sso.addVariable("bordercolor", "145471"); 
	sso.addParam("menu", "false"); 
	sso.addParam("wmode", "transparent"); 
	sso.addParam("scale", "noscale"); 
	sso.write("pipflashgalleryshell"); 

	}