function CityChooser()
{
	var cookie = this.getCookie("BT_City"); // Changed from "CHUM_City" so will not pick up the current cookies set for Citytv sites
	
	if( cookie != null )
	{ this.city = cookie; }
}

CityChooser.GetInstance = function()
{
	if( ! CityChooser.__instance )
	{ CityChooser.__instance = new CityChooser(); }
	
	return CityChooser.__instance;
}

CityChooser.GetCity = function() 
{
	var cc = CityChooser.GetInstance();
	return cc.city;
}

CityChooser.SetCity = function( pCity )
{
	var cc = CityChooser.GetInstance();
	
	cc.city = pCity;
	
	var futureDate = new Date();
	// TODO: Will break in 2998 but who cares since I'll be dead.
	futureDate.setFullYear( futureDate.getFullYear() + 2 );
	
	cc.setCookie( "BT_City", pCity, futureDate, "/" );
}

CityChooser.GoToCity = function( pCity )
{
	var myLocation = document.location;
	var myCity = CityChooser.GetCity();
	var newLocation = "";
	
	myCity = myCity.toLowerCase();
	
	// Citytv.com sites
	if( /citytv\.com/i.test( myLocation ) )
	{
		switch( myCity )
		{
			case "toronto" :
				newLocation = "http://www.citytv.com/toronto/";
				break;
			case "vancouver" :
				newLocation = "http://www.citytv.com/vancouver/";
				break;
			case "calgary" :
				newLocation = "http://www.citytv.com/calgary/";
				break;
			case "edmonton" :
				newLocation = "http://www.citytv.com/edmonton/";
				break;
			case "winnipeg" :
				newLocation = "http://www.citytv.com/winnipeg/";
				break;
		}
	}
	// Breakfast Television sites
	else if( /breakfasttelevision\.ca/i.test( myLocation ) )
	{
		switch( myCity )
		{
			case "toronto" :
				newLocation = "http://www.bttoronto.ca/";
				break;
			case "vancouver" :
				newLocation = "http://www.btvancouver.ca/";
				break;
			case "calgary" :
				newLocation = "http://www.btcalgary.ca/";
				break;
			case "edmonton" :
				newLocation = "http://www.btedmonton.ca/";
				break;
			case "winnipeg" :
				newLocation = "http://www.btwinnipeg.ca/";
				break;
		}
	}
	
	if ( newLocation != "" )
	{ document.location = newLocation; }
}

CityChooser.prototype.setCookie = function(name, value, expires, path, domain, secure)
{
	document.cookie= name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}

CityChooser.prototype.getCookie = function(name)
{
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1)
	{
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	}
	else
	{ begin += 2; }
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
	{ end = dc.length; }
	return unescape(dc.substring(begin + prefix.length, end));
}