if (typeof jQuery != 'undefined')
$(document).ready(function() {
	
		$("#maincatbar_hc").each(function(i, objElem){
			//jQuery(this, i).socialize();
			$(objElem).hc_listbox({hcarray: site_hc_array});
		});

});

if (typeof jQuery != 'undefined') {
	
jQuery.fn.hc_listbox = function(settings) {
		settings = jQuery.extend({
		hcarray: null 
		}, settings);		
		var divdisplaying = 0;
		jQuery(this).mouseover(function (e) { 
				e.preventDefault();
				if ($('#hc_listbox_container'))
					$('#hc_listbox_container').remove();
				
				var top 	= jQuery(this).offset().top + jQuery(this).height() + 5;
				var height	= jQuery(this).height();
				var left	= jQuery(this).offset().left - 150;
				var pos 	= top+height+20;
				
				divdisplaying = 1;
				var div = document.createElement("div");
				$(div).hide();
				$(div).attr({ id: "hc_listbox_container"});
				$(div).addClass("hc_listbox_container");
				$(document.body).prepend(div);
				//$(div).left = left;
				$(div).css('left',left+'px');
				$(div).css('top',top+'px');
				
				var closeme = document.createElement('img');
				$(closeme).attr({ id: "hc_listbox_close", src: "/images/hc_listbox_close.gif"});
				$(closeme).addClass('hc_listbox_close');
				$(div).append(closeme);
				
				$(closeme).click(function(){
					$(div).remove();
				})
				
				$("#hc_listbox_container").mouseenter(function(){
					$(div).stop(true, true);
					divdisplaying = 1;
					$(div).show();
				})
				$("#hc_listbox_container").mouseleave(function(){
					$(div).stop(true, true);
					//$(div).fadeOut(500).remove();
					divdisplaying = 0;
					$(div).fadeOut(500, function() { $(this).remove(); });
				})

				var name = document.createElement('h1');
				$(name).html('Available Handicappers');
				$(div).append(name);
				
				var sitearray = new Array();
				sitearray = settings.hcarray;
				//sitearray.push({ name: 'ask', image: 'ask.png', hrefs: 'http://mystuff.ask.com/mysearch/QuickWebSave?v=1.2&t=webpages&url={URL}&title={TITLE}'});
	
				var col1 = document.createElement('div');
				$(col1).addClass('hc_listbox_column');
				$(div).append(col1);
				
				var col2 = document.createElement('div');
				$(col2).addClass('hc_listbox_column');
				$(div).append(col2);

				var col3 = document.createElement('div');
				$(col3).addClass('hc_listbox_column');
				$(div).append(col3);

				var counterg = 0;
				
				/*
				$.each(
					sitearray,
					function( intIndex, objValue ){ 
						var curcol = 1; 
						if (counterg > (sitearray.length/2)) curcol = 2; //vert
						//if (counterg % 2 > 0) curcol = 2; //horz
						var myLink = document.createElement('a');
						$(myLink).attr({ href: '/pages/hcrep_bio.php?hid='+objValue.hid , title: 'View '+objValue.name });
						$(myLink).html(objValue.name);
						if (curcol == 1) $(col1).append(myLink);
						else $(col2).append(myLink);
						counterg++;
					}
				);
				*/
				var norowspercol = Math.ceil(sitearray.length/3);
				var curcol = 1;
				$.each(
					sitearray,
					function( intIndex, objValue ){ 
						if (counterg >= (norowspercol*2)) curcol = 3; //vert
						else if (counterg >= norowspercol) curcol = 2; //vert
						else curcol = 1; //vert
						//if (counterg % 2 > 0) curcol = 2; //horz
						var myLink = document.createElement('a');
						$(myLink).attr({ href: '/pages/hcrep_bio.php?hid='+objValue.hid , title: 'View '+objValue.name });
						$(myLink).html(objValue.name);
						if (curcol == 3) $(col3).append(myLink);
						else if (curcol == 2) $(col2).append(myLink);
						else $(col1).append(myLink);
						counterg++;
					}
				);
				
//				$(".socializer_container").css("visibility","visible");
				//$(".hc_listbox_container").fadeIn(500).fadeOut(2000); //.delay(2000).fadeOut(500);
				//$(div).fadeIn(500).animate({opacity: 1}, 5000).fadeOut(500); //.delay(2000).fadeOut(500);
				if (this.hoverIntent_t) { this.hoverIntent_t = clearTimeout(this.hoverIntent_t); }
				this.hoverIntent_t = setTimeout( function () {if (divdisplaying) $(div).fadeIn(500).animate({opacity: 1}, 5000).fadeOut(500);} , 300);
				//$(div).show().animate({opacity: 0.75}, 2000);
					
	})		
		jQuery(this).mouseout(function (e) { 
				e.preventDefault();
				if (this.hoverIntent_t) { this.hoverIntent_t = clearTimeout(this.hoverIntent_t); }
				divdisplaying = 0;
	})		
 }
 
}

