// Note: Many of these functions have been copied 'as is' from the Dreamweaver original

var BrowserDetect = {  // note this is from www.quirksmode.org/js/detect.html and it works like a treat!
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};   // end of BroswerDetect function

function MM_openBrWindow(theURL,winName,features) { //only used by privacy and disclaimer scripts in the footers
  window.open(theURL,winName,features);
}

function adjust_sidebar_font_size ()
{
	var s_w = $('#sidebar').width();
	if (s_w >= 220)
		{ 
			var f_s = (220 / 2.4) + '%';
			$('#sidebar a').css('fontSize', f_s);
		}
	else 
		{
			var f_s = (s_w / 2.4) + '%';
			$('#sidebar a').css('fontSize', f_s);
		}
}

function adjust_sidebarA_font_size ()
{
	var s_w = $('#col1A').width();
	if (s_w >= 220)
		{ 
			var f_s = (220 / 2.4) + '%';
			$('#col1A a').css('fontSize', f_s); 
		}
	else 
		{
			var f_s = (s_w / 2.4) + '%';
			$('#col1A a').css('fontSize', f_s);
		}
}

function adjust_image_spacing ()
{
	var col_heightx = $('#col2A').height();  // gives an integer (units are px)
	//$('#col_height').html(col_heightx); // puts this value into the message at the bottom of col3A
	// now calculate the padding percentage - hmmmm!!
	var padd = 1.0 + ((col_heightx - 1237) * 0.105191);
	// the base percentage padding value is 1%
	// the padding gets increased by 0.105191% for each pixel that the left main column height is greater than 1237 pixels
	// or decreased by the same amount for each pixel less than 1237
	if (padd <= 0)
		{
			padd = 0;
		}
	padd = r1(padd);  // round to one decimal place
	//$('#padding').html(padd);  // puts this value into the message at the bottom of col3A
	padd = padd + '%';
	$('.whatson_image').css('paddingTop', padd);
	$('.whatson_image').css('paddingBottom', padd);
	// note: left and right padding are zero
}

// Round to 1 decimal place 
function r1(n) { 
			  var ans = n * 100; 
 			  ans = Math.round(ans /10) + ""; 
  			  while (ans.length < 2) {ans = "0" + ans}; 
 			  var len = ans.length; 
  			  ans = ans.substring(0,len-1) + "." + ans.substring(len-1,len);
  			  return ans; 
} // end r1 function
