var Affililates = {

	affiliatesCookie	:'myaffiliate',
	affiliatesURL		:'/fod/affiliates/index.php',
	responseHolder		: false,

	updateLogo:function() {
		affiliateName = false;

		// Check URL first
		urlArr = location.pathname.split('/');
		if(urlArr.length > 3) {
			for(var i=0; i<urlArr.length; i++) {
				if(urlArr[i] == "affiliates") {
					oneup = i + 1;
					if(urlArr[oneup] != "undefined" && urlArr[oneup] != null && urlArr[oneup] != "") {
						affiliateName = urlArr[oneup];
						break;
					}
				}
			}
		}
		// Check for /fod/
		else {
			if(urlArr[1] == "fod" && (urlArr[2] == "" || urlArr[2].indexOf("index.htm") != -1)) {
				affiliateName = true;
			}
		}

		// Then check for cookie
		if(affiliateName == false) {
			affiliateName = this.checkForCookie(this.affiliatesCookie);
		}

		// If found ajax GET PHP - return JSON
		if(affiliateName) {
			new Ajax.Request(this.affiliatesURL, {
				method:	'post',
				parameters:	{
					affiliate:	affiliateName,
					r:	new Date().getTime()
				},
				onSuccess:	function(resp) {
					if(resp.responseJSON) {
						img = {};
						img.url	= resp.responseJSON.url;
						img.w	= resp.responseJSON.width;
						img.h	= resp.responseJSON.height;
						// Update logo...
						$$('h1 a img')[0].setAttribute('src',img.url);
						$$('h1 a img')[0].setAttribute('width',img.w);
						$$('h1 a img')[0].setAttribute('height',img.h);
					}
					this.responseHolder = resp.responseJSON;
				},
				onFailure: function(resp) {},
				onComplete:	function(resp) {}
			});
			// If affiliate JSON
		}
	},

	checkAffiliate:function() {
		var m = this.checkForCookie(this.affiliatesCookie);
		if(	m == "myfoxaustin" ||
			m == "myfoxchicago" ||
			m == "myfoxdc" ||
			m == "myfoxhouston") {
			return m;
		}
		else {
			return null;
		}
	},

	checkForCookie:function(cookieName) {
		// Check for cookie
		if (document.cookie.length > 0) {
			var theCookie = ""+document.cookie;
			var ind = theCookie.indexOf(cookieName);
			if(ind == -1 || cookieName == "") return false;
			var ind1 = theCookie.indexOf(';',ind);
			if(ind1 == -1) ind1 = theCookie.length;
			return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
		}
	}

};