function installSearchEngine() {
	if (window.external && ("AddSearchProvider" in window.external)) {
		window.external.AddSearchProvider("http://www.alexa.com/xml/opensearch.xml");
	}
}

$(document).ready(function () {
	//this should only run if #searchbox is defined
	if(0 !== $('#searchbox').size()) {
		$("#searchbox").autocomplete("/wwwdata/autocomplete", {
			delay:100,
			minChars:2,
			selectFirst:false			  
		}).result(function(event, item){
			$('#searchBox_form').submit();
		});
	}

	if ($.cookie('ax_search_install') != 'hide') {
		if (window.external && ("AddSearchProvider" in window.external)) {    
			$('#search_pointer').show();    
		}
	}
	faviconFunc=function(){
		$(this).attr('src', '/images/site/favicon.png');
	};
	$('div.favicon img').error(faviconFunc);    
	$('span.faviconBox img').error(faviconFunc);    

	$('#search_pointer .ch').click( function() {
		$.cookie('ax_search_install', 'hide', {  path: '/', expires: 365});   
		installSearchEngine();
		$('#search_pointer').hide();
	});

	$('#search_pointer p a').click( function() {
		$('#search_pointer').hide();
		$.cookie('ax_search_install', 'hide', { path: '/', expires: 365});    
	});   

	if ($.cookie('safe-mode') !== 'off') {
		$('#siteinfotabs .safe-off').hide();       
	} else {
		$('#siteinfotabs .safe-on').hide();
	}

	$('#safeMode.safe-on a').click( function() {
		$('#keywords ul').show();
		$('#relatedlinks ul').show();
		$.cookie('safe-mode', 'off', { path: '/', expires: 365});   
		window.location.href = window.location.href;
	}); 

	$('#safeMode.safe-off a').click( function() {
		$('#keywords ul').hide();
		$('#relatedlinks ul').hide();
		$.cookie('safe-mode', 'on', { path: '/', expires: 365});
		window.location.href = window.location.href;
	});

	var hu=$("#hoturls-content");
	if(hu[0]){
		var h="/wwwdata/hoturls";
		hu.load(h);
	}

	if ($('#mySites')) {
		$('.removeSite').click( function() {
			$(this).parent().parent().find('.step1').hide();
			$(this).parent().parent().find('.step2').show();
		});
		$('.no').click( function() {
			$(this).parent().parent().find('.step1').show();
			$(this).parent().parent().find('.step2').hide();
		});
	}

	$('.moreText').click(function() {	  	    
		if ($(this).text() == 'Learn More') {
			$(this).text('Hide');
			$(this).parent().find('span').show();
		} else {
			$(this).text('Learn More');	  	
			$(this).parent().find('span').hide();
		}
	});
	$('.exampleText').click(function() {	  	    
		$current_text = $(this).text();
		$target = $(this).parent().find('.moreContent');
		$target.toggle().removeClass('textOff');
		if ($target.is(':visible')) {
			$(this).text("Hide "+$current_text);
		} else {
			$(this).text($current_text.replace('Hide ',''));
		}
	});
});

function SetCookie(cookieName,cookieValue,nDays) {
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue) + ";domain=.alexa.com;path=/" + ";expires="+expire.toGMTString();
}
