// JavaScript Document

var count = 0;
var timeDelay = 4000;
var newsItems = null;
var newsCount = null;

function setupTicker() {
	newsItems = document.getElementById("news-items").getElementsByTagName("div");
	newsCount = newsItems.length;
	interval = window.setInterval("updateTicker()", timeDelay)
	updateTicker();
}

function updateTicker() {
	var newsItem = newsItems[count].getElementsByTagName("span");
	document.getElementById("news-title").innerHTML = "<span>" + newsItem[0].innerHTML + "</span>";
	document.getElementById("news-description").innerHTML = "<span>" + newsItem[1].innerHTML + "</span>";
	count++;
	if(count >= newsCount) { count = 0; }
}

function toggleMenu(node) {
	
	var lNodes = node.parentNode.parentNode.childNodes;
	
	for (var i = 0; i < lNodes.length; i++) {
		if(lNodes[i].className == 'expand') { lNodes[i].className = 'collapse'; }
	}
	
	switch (node.parentNode.className) {
		case 'expand':		node.parentNode.className = 'collapse'; break
		case 'collapse':	node.parentNode.className = 'expand'; break
	}
}

function wwefiximages (e) {
	if (document.getElementById) {
		var element = document.getElementById(e)
		
		var imgs = element.getElementsByTagName('img');
		for (i=0; i<imgs.length; i++) {
			imgs[i].className  = imgs[i].getAttribute('align');
		}
	}
}

function popup(url, width, height, resizable, location, statusbar, menubar, toolbar, scrollbars) {
	if (!width || !height) {
		// open a full browser window
		window.open(url);
	} else {
		// open a popup with options
		var day = new Date();
		var id = day.getTime();

		var params = '';
	
		if (!width) width = 0;
		if (!height) height = 0;
		if (!resizable) resizable = 0;
		if (!location) location = 0;
		if (!statusbar) statusbar = 0;
		if (!menubar) menubar = 0;
		if (!toolbar) toolbar = 0;
		if (!scrollbars) scrollbars = 0;
		
		if (height >= (window.screen.availHeight - 40)) {
			height = window.screen.availHeight - 40;
			width = width + 20;
			scrollbars = 1;
		}
		
		if (width >= (window.screen.availWidth - 20)) {
			width = window.screen.availWidth - 20;
			scrollbars = 1;
		}
		
		params += 'width=' + width + ',';
		params += 'height=' + height + ',';
		params += 'resizable=' + resizable + ',';
		params += 'location=' + location + ',';
		params += 'statusbar=' + statusbar + ',';
		params += 'menubar=' + menubar + ',';
		params += 'toolbar=' + toolbar + ',';
		params += 'scrollbars=' + scrollbars + ',';
		
		window.open(url, id, params);
	}
}

function wwevideoplayer(path, type, parent) {
	var show = 'wwe';
	if (typeof(type) == 'undefined') type = 'general';
	if (typeof(parent) == 'undefined') parent = '';
	
	if (window.location.pathname.indexOf('shows/raw') >= 0) {
		show = 'raw';
	} else if (window.location.pathname.indexOf('shows/smackdown') >= 0) {
		show = 'smackdown';
	} else if (window.location.pathname.indexOf('shows/247') >= 0) {
		show = '247';
	} else if (window.location.pathname.indexOf('community/bytethis') >= 0) {
		show = 'bytethis';
	}

	switch(type) {
   		case 'general':
   			popup(path + '?show=' + show, 700, 515);
   			break
   		case 'jukebox':
   			popup(path + "?view=jukebox&parent=" + parent, 650, 530);
   			break
   		default:
   			break
	}
}

function wwecookie (document, name, hours, path, domain, secure) {
	this.$document = document;
	this.$name = name;
	if (hours) {
		this.$expiration = new Date((new Date()).getTime( ) + hours*3600000);
	} else {
		this.$expiration = null;
	}
	if (path) this.$path = path; else this.$path = null;
	if (domain) this.$domain = domain; else this.$domain = null;
	if (secure) this.$secure = true; else this.$secure = false;
}

wwecookie.prototype.store = function () {
	var cookieval = "";
	for(var prop in this) {
		if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function') || (prop == '')) continue;
		if (cookieval != "") cookieval += '&';
		cookieval += prop + ':' + escape(this[prop]);
	}

	var cookie = this.$name + '=' + cookieval;
	if (this.$expiration) cookie += '; expires=' + this.$expiration.toGMTString();
    if (this.$path) cookie += '; path=' + this.$path;
    if (this.$domain) cookie += '; domain=' + this.$domain;
    if (this.$secure) cookie += '; secure';

    this.$document.cookie = cookie;
}

wwecookie.prototype.load = function() {
	var allcookies = this.$document.cookie;
	if (allcookies == "") return false;

	var start = allcookies.indexOf(this.$name + '=');
	if (start == -1) return false;
	start += this.$name.length + 1;
	var end = allcookies.indexOf(';', start);
	if (end == -1) end = allcookies.length;
	var cookieval = allcookies.substring(start, end);

	var a = cookieval.split('&');
	for(var i=0; i < a.length; i++) {
		a[i] = a[i].split(':');
	}

	for(var i = 0; i < a.length; i++) {
		this[a[i][0]] = unescape(a[i][1]);
	}

	return true;
}

wwecookie.prototype.remove = function() {
	var cookie;
	cookie = this.$name + '=';
	if (this.$path) cookie += '; path=' + this.$path;
	if (this.$domain) cookie += '; domain=' + this.$domain;
	cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';

	this.$document.cookie = cookie;
}

// Setup Global Cookie
var host;
if (window.location.host.toString() != 'localhost') host = '.wwe.com';
var visitordata = new wwecookie(document, ".visitor", 24*356, '/', host);
if (!visitordata.load()) visitordata.store();

function countrySelect(country) {
		//set country cookie
		if (countrydata == null) {
			var countrydata = new wwecookie(document, ".country", 24*356, '/', host);
		}
		countrydata.country = country;
		countrydata.store();
		document.location.href='?country='+country;
}

// Insert Flash Fix by: Arno van Mosel //

 	var f5 = false;
 	var f6 = false;
 	var f7 = false;
 	var f8 = false;
 	
 	var cId = 0;
 	var mV = 7;
 	var aV = 0;
 	var hRV = false;
 	var jsV = 1.0;
 	var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
 	var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;

 	jsV = 1.1;

 if(isIE && isWin){
 	document.write('<scr' + 'ipt language="VBScript"\> \n');
 	document.write('on error resume next \n');
 	document.write('f5 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');
 	document.write('f6 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
 	document.write('f7 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
 	document.write('f8 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
 	document.write('</scr' + 'ipt\> \n');
 }

function checkFlash(rV){
 	var ua=navigator.userAgent.toLowerCase();
 	this.ie = (parseFloat(ua.slice(ua.indexOf("msie")+5)));
 	this.nn = (parseFloat(ua.slice(ua.indexOf("mozilla/")+8)));
 	var browser = navigator.appName.toLowerCase();
 	if (browser=="netscape"){
 	this.netscape = true;
 	}else{
 	this.netscape = false;
 	}
 	this.mac = (ua.indexOf("mac")>-1);
 	this.flash = false;

 	if (navigator.plugins){
 		if (navigator.plugins["Shockwave Flash 5.0"] || navigator.plugins["Shockwave Flash"]){
 			var isVersion5 = navigator.plugins["Shockwave Flash 5.0"] ? " 5.0" : "";
 			var fD = navigator.plugins["Shockwave Flash" + isVersion5].description;
 			var fV = parseInt(fD.charAt(fD.indexOf(".") - 1));
 			
 			f5 = fV == 5;
 			f6 = fV == 6;
 			f7 = fV == 7;
 			f8 = fV == 8;
 		}
 	}
 	for (var i = 5; i <= mV; i++) {
 		if (eval("f" + i) == true) aV = i;
 	}

 	if (aV >= rV) {
 		if (this.netscape && this.IEonly == 'TRUE' || this.mac && this.IEonly == 'TRUE'){
 			this.flash = false;
 		} else {
 			this.flash = true;
 		}
 	}
}
 
 	
function wweflashObj() {
 	cId += 1;
 	this.flashFile = "/blank.swf";
 	this.IEonly = null;
	this.redirect = null;
 	this.DenyIEdl = "FALSE";
 	this.height = "400";
 	this.width = "520";
 	this.bgcolor = null;
 	this.ID = "flash"+ cId;
 	this.name = "flash"+ cId;
 	this.FlashVer = 7;
 	this.cabVersion = "7,0,0,0";
	this.render = playWWEFlash;
}

function playWWEFlash(val) {
 	var AvMFixer=new checkFlash(this.FlashVer);
 	var sLaM;
 	if (AvMFixer.flash) {

 		if (AvMFixer.mac || AvMFixer.netscape) {
 			sLaM='<embed src="'+this.flashFile+'" width="'+this.width+'" height="'+this.height+'" quality="high" wmode="transparent" id="'+this.ID+'" name="'+this.name+'" menu="false"';
 			if (this.bgcolor) {
 				sLaM += ' bgcolor="'+this.bgcolor + '"';
 			}
 			sLaM += ' type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>';

 		} else if (this.DenyIEdl=='TRUE') {
 			sLaM="<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="+this.FlashVer+",0,0,0\" id=\""+this.ID+"\" width=\""+this.width+"\" height=\""+this.height+"\">\n";
 			sLaM+="<param name=\"movie\" value=\""+this.flashFile+"\">\n";
 			sLaM+="<param name=\"quality\" value=\"high\">\n";
 			sLaM+="<param name=\"menu\" value=\"false\">\n";
 			sLaM+="<param name=\"wmode\" value=\"transparent\">\n";
  			sLaM+="<param name=\"allowScriptAccess\" value=\"sameDomain\">\n";
 			if (this.bgcolor){
 				sLaM+="<param name=\"bgcolor\" value=\""+this.bgcolor+"\">\n";
 			}
 			if (this.bgcolor){
 			sLaM+="<embed src="+this.flashFile+" width="+this.width+" height="+this.height+" quality=\"high\" wmode=\"transparent\" id="+this.ID+" name="+this.name+" menu=\"false\" bgcolor="+this.bgcolor+" type=\"application/x-shockwave-flash\"  pluginspage=\"http://www.macromedia.com/go/getflashplayer\"></embed></object>";
 			} else {
 			sLaM+="<embed src="+this.flashFile+" width="+this.width+" height="+this.height+" quality=\"high\" wmode=\"transparent\" id="+this.ID+" name="+this.name+" menu=\"false\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"></embed></object>";
 			}

 		} else if (AvMFixer.ie>=4 && this.DenyIEdl=='FALSE') {
 			sLaM="<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="+this.cabVersion+"\" id=\""+this.ID+"\" width=\""+this.width+"\" height=\""+this.height+"\">\n";
 			sLaM+="<param name=\"movie\" value=\""+this.flashFile+"\">\n";
 			sLaM+="<param name=\"quality\" value=\"high\">\n";
 			sLaM+="<param name=\"menu\" value=\"false\">\n";
 			sLaM+="<param name=\"wmode\" value=\"transparent\">\n";
  			sLaM+="<param name=\"allowScriptAccess\" value=\"sameDomain\">\n";

 			if (this.bgcolor){
 				sLaM+="<param name=\"bgcolor\" value=\""+this.bgcolor+"\">\n";
 			}
 			sLaM+="</object>\n";
 		}
 		
 		
 	} else {
 	if (this.redirect){
 	 top.location.href = this.redirect;
 	} else {
 			sLaM="<embed src="+this.flashFile+" width="+this.width+" height="+this.height+" quality=\"high\" wmode=\"transparent\" id="+this.ID+" name="+this.name+" menu=\"false\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"></embed>";
 			
 		}
 	}

 	if (val == true) {
 		document.write(sLaM);
 	} else{
 		return sLaM;
 	}
}