$(document).ready(function() {
	// set focus to the primary text box
	$('#query0').focus();
	
	// if tip div exists set the tip variable
	if (document.getElementById("tipDiv")) var tipStyle = document.getElementById("tipDiv").style;
	
	// toggle the location form
	$('#loc0').click(function() {
		if ( $('#loc0').attr('class') !== 'loc0' ) return;
		$("#loc1").hide(); $("#loc2").show(); $("#loc").focus();
		$("#loc0").removeClass('loc0').attr('title', '');
	});
	
	// switch tabs
	$('.tab').click(function() {
		$('.browse').css('display', 'block');
		$('.tab').removeClass('sel');
		$(this).addClass('sel');
		$('.search').hide();
		$('#search'+$(this).attr('id').substr(3)).show();
	});
	
	// toggle more search options
	$('.morelink').click(function() {
		$('#morediv'+$(this).attr('id').substr(8)).toggle();
		if ( $(this).html() == 'more options' ) $(this).html('hide options');
		else $(this).html('more options');
	});
	
	// image tip events
	$('.tip').mousemove(function(e) {
		if (tipStyle == null) return;
		tipStyle.left = event.x + document.body.scrollLeft + 'px';
		tipStyle.top = event.y + document.body.scrollTop + 5 +'px';
		return true;
	});
	
	$('.tip').mouseout(function() {
		if (tipStyle == null) return;
		tipStyle.display = "none";
	});
	
	$('.tip').mouseover(function() {
		if (tipStyle == null) return;
		var url = $(this).attr('src');
		$("#tipDiv").attr('src', url);
		tipStyle.display='block'
	});

});

var uservoiceOptions = {
  /* required */
  key: 'craigz',
  host: 'craigz.uservoice.com', 
  forum: '40691',
  showTab: true,  
  /* optional */
  alignment: 'right',
  background_color:'#ff5900', 
  text_color: 'white',
  hover_color: '#fb7320',
  lang: 'en'
};

function _loadUserVoice() {
  var s = document.createElement('script');
  s.setAttribute('type', 'text/javascript');
  s.setAttribute('src', ("https:" == document.location.protocol ? "https://" : "http://") + "cdn.uservoice.com/javascripts/widgets/tab.js");
  document.getElementsByTagName('head')[0].appendChild(s);
}
_loadSuper = window.onload;
window.onload = (typeof window.onload != 'function') ? _loadUserVoice : function() { _loadSuper(); _loadUserVoice(); };

