function _unrulyEC(a){
	var b="";
	for(i=a.length-1;i>=0;i--) {
		b+=a.charCodeAt(i)+1+"x";
	}
	return b;
};


/**
 * This file should have no external JS dependencies (not even unrulyInfo)
 */

var unrulyUtil = unrulyUtil || {};

(function() {
	unrulyUtil.getFixedUrl = function(url, protocol) {
		if (url.indexOf('http') != 0) {
			url = protocol + url;
		}
		
		var encProtocol = encodeURIComponent(protocol);
		var doubleEncProtocol = encodeURIComponent(encProtocol);
		
		if (protocol === 'https:') {
			url = url.replace(/cloud\.video\.unrulymedia\.com/g, 'video.unrulymedia.com');
		}
		
		return (url.replace(/https?:/g,     protocol)
				   .replace(/https?%3A/g,   encProtocol)
				   .replace(/https?%253A/g, doubleEncProtocol));
	};
		
})();

var UnrulyTrackingUtils;

////
if (typeof UnrulyTrackingUtils == 'undefined') {
	UnrulyTrackingUtils =  {
			
		parsePublisherMacros : function(url) {
			var localPublisherMacros = [];
			
			var publisherMacrosString = url.substring(url.indexOf('#'));
	
			if ( typeof publisherMacrosString == 'undefined' ||
				 publisherMacrosString.length < 2 ||
				 publisherMacrosString.indexOf('#') !== 0 || 
				 publisherMacrosString.indexOf('=') === -1) {
				return localPublisherMacros;
			}
			
			var macros = publisherMacrosString.substring(1).split('&');
			
			for (var i=0; i < macros.length; i++) {
				var macro_pair = macros[i].split('=');
				var macro_name = macro_pair[0];
				var macro_value = macro_pair[1];
				localPublisherMacros[macro_name] = decodeURIComponent(macro_value);
			}
			
			return localPublisherMacros;
		},
	
		encodePublisherMacros : function(publisherMacros) {
			var encodedMacroString = "";
			
			if (typeof publisherMacros == 'undefined') {
				return encodedMacroString;
			}
			
			for (var macroName in publisherMacros ) {
				
				if ( !publisherMacros.hasOwnProperty(macroName) ||
					  typeof publisherMacros[macroName] == 'undefined' || 
					  publisherMacros[macroName].indexOf("%%") == 0 || 
					  macroName==='uuid') {
					continue;
				}
				
				if (encodedMacroString.length > 0) {
					encodedMacroString +="&";
				}
				
				encodedMacroString += macroName + '=' + encodeURIComponent(publisherMacros[macroName]); 
			}
			
			return encodedMacroString;
		}
	
	};
}var unrulyHttpsUtil = unrulyHttpsUtil || {};

(function() {
	unrulyHttpsUtil.getFixedUrl = function(url) {
		var allowHttps = true;
				var protocol = (allowHttps ? document.location.protocol : 'http:');
		return unrulyUtil.getFixedUrl(url, protocol);
	};
})();


function _unrulyCollapseAd() {
	return false;
}

        	function _unrulyGetContentType(supportedFormats) {
            var listHasItem = function (formats, format) {
                for(i=0;i<formats.length;i++) {
                    if(formats[i] == format) {
                        return true;
                    }
                }
                return false;
            };
            
			if(listHasItem(supportedFormats, "html5")) {
                return ((navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.indexOf("Mac") == -1 &&   navigator.appVersion.indexOf("3.1") == -1) 
                     || (navigator.plugins && navigator.plugins["Shockwave Flash"]) || navigator.plugins["Shockwave Flash 2.0"])
                    ? "flash" : "html5";
            }
            else {
                return "flash";
            }
    	}
	function _unrulyRefUrl() {
	if (top === self || typeof(document.referrer) == "undefined" || document.referrer.length < 1) { 
		return document.location.href;
	} else { 
		return document.referrer;
	}
}


function _unrulyTrackCollapsedAd() {
	var trackingCode = [
		'(function() {',
        '	var unrulyTracking = new UnrulyTracking(', 
        '		unrulyHttpsUtil.getFixedUrl("http://stats.unrulymedia.com/"), ', 
        '		unrulyHttpsUtil.getFixedUrl("http://stats2.unrulymedia.com/"), ', 
        '		unrulyHttpsUtil.getFixedUrl("http://stats3.unrulymedia.com/"), ', 
        '       2643,', 
        '       230286,', 
        '       3122,', 
        '       746,', 
        '       5484,', 
        '       1557,', 
        '       "400x353",', 
        '       false,', 
        '       true,', 
        '       2313', 
        '	);',
		'	unrulyTracking.track("collapsed");',
		'}());'
	];

	document.write('<scr'+'ipt src="' + unrulyHttpsUtil.getFixedUrl("http://video.unrulymedia.com/") + 'tracking_v40.js" type="text/javascr'+'ipt"></scr'+'ipt>');
	document.write('<scr'+'ipt type="text/javascr'+'ipt">');
	document.write(trackingCode.join('\n'));
	document.write('</scr'+'ipt>');
}
	
			function UnrulyAP(sk, date, dom, apid, type, supportedFormats) {
	this.sk = sk;
	this.date = date;
	this.dom = dom;
	this.apid = "" + apid;
	this.type = type;
	this.supportedFormats = supportedFormats;
}
UnrulyAP.prototype.isViral = function() {
	return this.type == 'VIRAL';
};
UnrulyAP.prototype.url = function() {
	var url = this.dom;
	var ap = this.apid.length > 0 ? '_' + this.apid : '';
	if (this.isViral()){
		var cType = _unrulyGetContentType(this.supportedFormats);
		
		var macros = '';
		if (typeof unrulyMacros != 'undefined') {
			macros = UnrulyTrackingUtils.encodePublisherMacros(unrulyMacros);
			if (macros.length > 0) {
			   macros += '&';
			}
		}
		var fragment = '#' + macros + 'uuid=' + encodeURIComponent(_unrulyEC(_unrulyRefUrl()));
		
		if ("image" !== cType) {
			url += "iframe_" + this.sk +  "%s_" + cType + ".html?d=" + this.date +
				(typeof wildfireAddParams != "undefined" ? wildfireAddParams : '') + fragment;
		} else {
			url += "default_viral_fallback.html";
		}
	} else {
		url += 'wildfire_' + this.sk + '%s_eclipse.js';
	}
	return url.replace("%s", ap);
};		function UnrulyGeo(fback,noGeo,onHold,sk,time,dom) {
	this.fback = fback;
	this.noGeo = noGeo;
	this.onHold = onHold;
	this.map = {};
	this.sk = sk;
	this.time = time;
	this.dom = dom;
}
UnrulyGeo.prototype.add = function(countryCode, apid, unitType, supportedFormats) {
	this.map[countryCode.toLowerCase()] = new UnrulyAP(this.sk,this.time,this.dom,apid,unitType, supportedFormats);
};
UnrulyGeo.prototype.chooseAp = function(code) {
	if (this.onHold || typeof code == "undefined") {
		return this.noGeo;
	}
	if (code.toLowerCase()=="xx") {
		return this.noGeo;
	} else { 
		var ap = this.map[code.toLowerCase()];
		if (typeof ap == "undefined") {
			return this.fback;
		} else {
			return ap;
		}
	}
};		var writeViral = function(ap) {
			var i = document.getElementById("unruly1328334118400");
			i.style.display="block";
			i.src = ap.url();
		};
		unrulyGeoUrl = function() {
			function getQsParams(){
				var qsParams = {length:0, keys:new Array()};
				var usestr = _unrulyRefUrl();
				if(usestr.split("?").length == 2) {
					var paramInline = usestr.split("?")[1].split("&");
					for(var i = 0; i < paramInline.length; i++){
						qsParams.keys.push(paramInline[i].split("=")[0]);
						qsParams[paramInline[i].split("=")[0]] = paramInline[i].split("=")[1];
						qsParams.length++;
					}
				} 
				return qsParams;
			}
			var href = _unrulyRefUrl();
			if (href.indexOf("unrulyCountry") != -1) {
				var params = getQsParams();
				if (params["unrulyCountry"] != null) {
					unrulyGeoCountryCode = params["unrulyCountry"].toLowerCase();
				}
			}
			var fallback = new UnrulyAP('6685886','1328334118400', unrulyHttpsUtil.getFixedUrl("http://video.unrulymedia.com/"),'default','VIRAL', ["flash","html5"]);
			var geo = new UnrulyGeo(fallback, fallback, false,'6685886', '1328334118400', unrulyHttpsUtil.getFixedUrl("http://video.unrulymedia.com/"));
			var numTerritories = 0;
				
			var ap = geo.chooseAp(unrulyGeoCountryCode);
			
			if (typeof UNRULY_DEFAULT == 'undefined') {
				UNRULY_DEFAULT = {};
			}
			UNRULY_DEFAULT['' + ap.sk] = ( ap.apid == 'default' );
			if ((numTerritories == 0 || ap.apid == "default") && 2 == 2) {
				document.writeln("This is a community-driven website, which means it depends on you to continue existing and to grow and thrive. If you like this site, please consider helping it. You can do that by contributing in multiple ways:");
document.writeln("<ul>");
document.writeln("<li><a href=\"/im/selectCard\" title=\"You can upload new sets for your favorite game\">Uploading the card lists</a> for new sets as they become available.</li>");
document.writeln("<li><a href=\"/im/feedback\" title=\"Let me know of any errors or missing cards in the site's database\">Letting me know</a> of any errors in our card lists or any missing cards so that our card database stays correct and updated.</li>");
document.writeln("<li>Reporting any inappropriate content by just clicking on the warning icon (<img src=\"/img/report_content.png\" width=\"20\" height=\"20\">) next to it.</li>");
document.writeln("<li>Posting news in our forums and helping others with their questions.</li>");
document.writeln("<li><a href=\"/im/feedback\">Sending your suggestions</a> for improvements, or your comments on what you like the most in this site.</li>");
document.writeln("</ul>");
document.writeln("<p>Thanks a lot for your help.");

			} else if (ap.isViral()) {
				writeViral(ap);
			} else {
				document.write('<scr'+'ipt src="' + ap.url() + '" type="text/javascr'+'ipt"></scr'+'ipt>');
			}
		}

		if (_unrulyCollapseAd()) {
			_unrulyTrackCollapsedAd();
		} else {
    		document.write('<iframe id="unruly1328334118400" style="display:none;" frameborder="0" scrolling="no" width="400" height="353" src="javascript:\'\'"></iframe>');
    		document.write('<scr'+'ipt src="' + unrulyHttpsUtil.getFixedUrl('http://video.unrulymedia.com/') + 'country_code.js?version=5" type="text/javascr'+'ipt"></scr'+'ipt>');
		}
	
