function handleSearch(event, myid, myurl, myquery) {
	switch (event) {
	case "onMouseOver":
	    switch (myid.charAt(0)) {
			case 'd':
			$("#" + myid).css({
				'background-color': '#ffff60'
			});
			break;
		default:
			$("#" + myid).css({
				'background-color': '#0000ff'
			});
		}
		document.body.style.cursor = 'pointer';
		break;
	case "onMouseOut":
		var bcolor = {
			'background-color': '#6699cc'
		};
		switch (myid.charAt(0)) {
		case 'b':
			bcolor = {
				'background-color': '#336699'
			};
			break;
		case 'c':
			bcolor = {
				'background-color': '#003366'
			};
			break;
		case 'd':
			bcolor = {
				'background-color': '#ffffc0'
			};
			break;
		}
		$("#" + myid).css(bcolor);
		document.body.style.cursor = 'default';
		break;
	case "onClick":
		var value = document.getElementById('searchinput').value;
		if (value == '' || myquery == '_none') {
			window.location = myurl;
		} else {
			window.location = myquery + value;
		}
		break;
	}
}

//---------------------------------------------------------------------------------------------------------------------

function top20header() {
	var title_lines = new Array;
	var length_line0 = 0;
	var length_line1 = 0;
	var title_width = 0;
	if (g_site_title.match("<br")) {
		title_lines = g_site_title.split('<br />');
		length_line0 = title_lines[0].length * 22;
		length_line1 = title_lines[1].length * 6;
		if (length_line0 > length_line1) {
			title_width = length_line0;
		} else {
			title_width = length_line1;
		}
		title_lines[1] = "<br />" + title_lines[1];
	} else {
		title_lines[0] = g_site_title;
		title_lines[1] = "";
		if (title_lines[0].length > 24) {
			title_width = title_lines[0].length * 17;
		} else {
			title_width = title_lines[0].length * 23;
		}
	}

	if (title_width > 534) {
		title_width = 534;
	}

	if (title_lines[0].length > 24) {
		$('#pagetitle_top20head').css({
			'padding-top': '6px',
			'height': '35px'
		});
		$('#pagetitle_top20head_h1').css({
			'font-size': '30px'
		});
	}
	/* $('#top20head').append('<div id="date_top20head">' + g_site_date + '</div>'); */

	$('#pagetitle_top20head').css({
		width: title_width.toString() + "px"
	});
	$('#date_top20head').css({
		width: title_width.toString() + "px"
	});

	//Adjust header height

	var ua = navigator.userAgent.toLowerCase();
	var browser_type = "";
	if (ua.indexOf('safari/') != -1) {
		browser_type = "safari";
	}

	//Cross Browser Functionality
	if (navigator.appName != "Microsoft Internet Explorer" && browser_type != "safari") {
		document.getElementById("title_text").style.fontSize = '15pt';
		document.getElementById("title_text").style.marginTop = '0';
		document.getElementById("toptitle_top20head").style.marginLeft = '0';
		document.getElementById("bottom_top20head").style.marginLeft = '0';
		document.getElementById("links_top20head").style.paddingTop = '0';
		document.getElementById("links_top20head").style.height = '60px';
		document.getElementById("pagetitle_top20head").style.height = '50px';
	}

	//Populate the content
	var links = new Array;
	var index = 0;
	links[index++] = 'News,top20newslinks';
	links[index++] = 'Sports,top20sports';
	links[index++] = 'Stocks,top20stockmarketlinks';
	links[index++] = 'Finance,top20finance';
	links[index++] = 'Weather,top20weather';
	links[index++] = 'Health,top20health';
	links[index++] = 'Styles,top20styles';
	links[index++] = 'br';
	links[index++] = 'Education,top20education';
	links[index++] = 'Books,top20books';
	links[index++] = 'Music,top20musiclinks';
	links[index++] = 'Entertainment,top20entertainment';
	links[index++] = 'Games,top20games';
	links[index++] = 'Travel,top20travel';
	links[index++] = 'br';
	links[index++] = 'Shopping,top20shopping';
	links[index++] = 'Gifts,top20gifts';
	links[index++] = 'Kids,top20kids';
	links[index++] = 'Computers,top20computers';
	links[index++] = 'Internet,top20internet';
	links[index++] = 'Autos,top20autos';
	links[index++] = 'Free,top20freestuff';

	var i = 0;
	while (i < links.length) {
		var items = new Array;
		if (links[i] == 'br') {
			$('#links_top20head').append('<br />');
		} else {
			items = links[i].split(',');
			if (items[0] != 'News' && items[0] != 'Education' && items[0] != 'Shopping') $('#links_top20head').append(' | ');
			$('#links_top20head').append("<a class=\"title_link\" href=\"http://www." + items[1] + ".com\">" + items[0] + "</a>");
		}
		i++;
	}

	// Apply the curvy corners after the content has been written

	var curves = {
		tl: {
			radius: 9
		},
		tr: {
			radius: 9
		},
		bl: {
			radius: 9
		},
		br: {
			radius: 9
		},
		antiAlias: true
	}
	curvyCorners(curves, document.getElementById("toptitle_top20head"));
	curvyCorners(curves, document.getElementById("bottom_top20head"));

	var curves = {
		tl: {
			radius: 12
		},
		tr: {
			radius: 0
		},
		bl: {
			radius: 12
		},
		br: {
			radius: 0
		},
		antiAlias: true
	}
	curvyCorners(curves, document.getElementById("title_top20head"));

	var curves = {
		tl: {
			radius: 0
		},
		tr: {
			radius: 12
		},
		bl: {
			radius: 0
		},
		br: {
			radius: 12
		},
		antiAlias: true
	}
	curvyCorners(curves, document.getElementById("links_top20head"));

	var curves = {
		tl: {
			radius: 12
		},
		tr: {
			radius: 12
		},
		bl: {
			radius: 0
		},
		br: {
			radius: 0
		},
		antiAlias: true
	}
	curvyCorners(curves, document.getElementById("pagetitle_top20head"));

	var curves = {
		tl: {
			radius: 0
		},
		tr: {
			radius: 0
		},
		bl: {
			radius: 12
		},
		br: {
			radius: 12
		},
		antiAlias: true
	}
	curvyCorners(curves, document.getElementById("date_top20head"));

}

//---------------------------------------------------------------------------------------------------------------------

function top20search() {
	var curves = {
		tl: {
			radius: 18
		},
		tr: {
			radius: 18
		},
		bl: {
			radius: 0
		},
		br: {
			radius: 0
		},
		antiAlias: true
	}
	curvyCorners(curves, document.getElementById("search_level1"));

	var curves = {
		tl: {
			radius: 0
		},
		tr: {
			radius: 0
		},
		bl: {
			radius: 18
		},
		br: {
			radius: 18
		},
		antiAlias: true
	}
	curvyCorners(curves, document.getElementById("search_level3"));

	var curves = {
		tl: {
			radius: 12
		},
		tr: {
			radius: 12
		},
		bl: {
			radius: 0
		},
		br: {
			radius: 0
		},
		antiAlias: true
	}
	curvyCorners(curves, document.getElementById("search_diversions_top"));
	curvyCorners(curves, document.getElementById("search_music_top"));

	var curves = {
		tl: {
			radius: 0
		},
		tr: {
			radius: 0
		},
		bl: {
			radius: 12
		},
		br: {
			radius: 12
		},
		antiAlias: true
	}
	curvyCorners(curves, document.getElementById("search_diversions_bottom"));
	curvyCorners(curves, document.getElementById("search_music_bottom"));
}

//---------------------------------------------------------------------------------------------------------------------

function top20leftbarcontrol() {
	$('#left_bar_control').append('<div id="left_bar_control_thumb" style="cursor: hand; background-color: #cccccc; font-weight: bold; font-size: 10pt; padding: 3px; border-left: 2px #003366 solid;"><<</div>');
	$('#left_bar_control').append('<div id="left_bar_control_home" style="cursor: hand; background-color: #cccccc; font-weight: bold; font-size: 10pt; padding: 3px; border-bottom: 2px #003366 solid; border-top: 2px #003366 solid; border-left: 2px #003366 solid; text-align:center;">H<br />O<br />M<br />E</div>');

	$('#left_bar_control_thumb').hover(function () {
		$(this).css({
			'background-color': '#e0e0e0'
		})
	},
	function () {
		$(this).css({
			'background-color': '#cccccc'
		})
	});

	$('#left_bar_control_home').hover(function () {
		$(this).css({
			'background-color': '#e0e0e0'
		})
	},
	function () {
		$(this).css({
			'background-color': '#cccccc'
		})
	});

	$('#left_bar_control_thumb').click(function () {
		switch ($('#left_bar_control_thumb').text()) {
		case '<<':
			$('#left_bar_control_thumb').text('>>');
			$('#left_bar_control').css({
				'height': '94px'
			});
			$('#middle').animate({
				width: '100%'
			},
			400);
			$('#left_bar').toggle("blind", {
				direction: "horizontal"
			},
			500);
			$('#right').animate({
				marginLeft: '-136px',
				width: '95%'
			},
			600);
			$('#myIframe').animate({
				width: '100%'
			},
			700);
			break;
		case '>>':
			$('#left_bar_control_thumb').text('<<');
			$('#left_bar_control').css({
				'height': '508px'
			});
			$('#myIframe').animate({
				width: '820px',
				height: '500px'
			},
			500);
			$('#right').animate({
				marginLeft: '10px',
				width: '820px',
				height: '500px'
			},
			600);
			$('#left_bar').toggle("blind", {
				direction: "horizontal"
			},
			700);
			$('#middle').animate({
				width: '1000px'
			},
			800);
			break;
		}
	});
}

// Main Program ---------------------------------------------------------------------------------------------------------------------

/*
$(document).ready(function () {
	top20header();
	top20search();
});
*/

// Service Functions -------------------------------------------------------------------------------------------------
var g_search_state = 'false';

function processGiftLinks(siteurl, num, linkURL) {
	var path = "http://www.top20online.com/pics/webpagepreviews/";
	var file = siteurl + ".sitepic" + num + '.png';
	var url = path + file;
	var myhtml = '<a href="' + linkURL + '"><img src="' + url + '" border="none"/></a>';
	$('#gift_web_preview').html(myhtml);
}

function addtofav(linkUrl,linkTitle){
   if (!document.all) {
      alert('Please hit ctrl-d to bookmark this page');
   }
   else external.AddFavorite(linkUrl,linkTitle);
   return false;
}

var BrowserDetect = {
	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"
		}
	]

};
BrowserDetect.init();

function MakeHomePage() {
	document.getElementById('make_start_page').style.visibility="visible";
	switch (BrowserDetect.browser) {
	case "Firefox" :
		document.getElementById('msp_2').innerHTML='<img src="/images/bi_mozilla64x64.png" />';
		document.getElementById('msp_3').innerHTML='<b>Mozilla Firefox: How to make Top 20 your home page:</b><ul><li>On the <b>tools</b> menu, click <b>Options</b>.</li><li>In the left pane of the <b>Options</b> dialog box, click <b>Main</b>.</li><li>In the <b>Home Page</b> text box, type <b>"'+window.location.href+'"</b>, and then click <b>OK</b>.</li></ul><a href="#" onclick="window.location.reload()">Close</a>';
		break;
	case "Chrome" :
		document.getElementById('msp_2').innerHTML='<img src="/images/bi_chrome64x64.png" />';
		document.getElementById('msp_3').innerHTML='<b>Google Chrome: How to make Top 20 your home page:</b><ul><li>Click on the Chrome "wrench" icon, located in the upper right hand corner of your browser window. When the drop-down menu appears, select the choice labeled <b>Options</b>.</li><li>In the <b>Home Page</b> section, type <b>"'+window.location.href+'"</b> in the <b>Open this page</b> text box, then click <b>Close</b>.</li></ul><a href="#" onclick="window.location.reload()">Close</a>';
		break;
	case "Safari" :
		document.getElementById('msp_2').innerHTML='<img src="/images/bi_safari64x64.png" />';
		document.getElementById('msp_3').innerHTML='<b>Apple Safari: How to make Top 20 your home page:</b><ul><li>Select <b>Safari</b> from the top menu and then <b>Preferences...</b> from the drop-down list.</li><li>In the <b>General</b> section, type <b>"'+window.location.href+'"</b> in the <b>Home page</b> text field, and then close the <b>Preferences window</b>.</li></ul><a href="#" onclick="window.location.reload()">Close</a>';
		break;
	}
}