$(document).ready(function(){
	var isIE6;
	if ($(".popOuter .popTop .edge").css("height") == "140px") {
		//IE 6
		isIE6 = true;
	} else {
		//other browsers
		isIE6 = false;
	}
	// Buy dropdown function
	$("#ssl_table a.buy").click(function(){
		window.location.href = $(this).prev("select").val();
		return false;
	});
	// Pop-up boxes function
	$("td a.rec").hoverIntent(
		function(){
			var pop_el = $(this).next("div.popOuter");
			var pop_height = pop_el.height();
			var pop_width = pop_el.width();
			var pop_startx = $(this).offset().left;
			var pop_starty = $(this).offset().top;
			
			var xoff = 0;
			var yoff = 0;
			
			if (isIE6) {
				//IE 6
				xoff = 20;
				yoff = -25;
			} else {
				//other browsers
				xoff = 10;
				yoff = -15;
			}
			
			if (pop_el.hasClass(".bottom")) {
				yoff = (pop_height + yoff -15)*-1;
			}
			//Need to hide these 2 select boxes for IE6 behaviour of popups
			$("table#main select").eq(0).hide();
			$("table#main select").eq(1).hide();
			pop_el.css({"left":parseInt(pop_startx-pop_width+xoff)+"px","top":parseInt(pop_starty+yoff)+"px"}).show();
			
		},
		function(){
			//Get coordinates to find out when to hide
			var pop_el = $(this).next("div.popOuter");
			var pop_height = pop_el.height();
			var pop_width = pop_el.width();
			var pop_startx = pop_el.offset().left;
			var pop_starty = pop_el.offset().top;
			
			$(document).bind("mousemove", function(e) {
				if (!(((e.pageX >= pop_startx) && (e.pageX <= (pop_startx + pop_width))) &&
					((e.pageY >= pop_starty) && (e.pageY <= (pop_starty + pop_height))))) {
					pop_el.hide();
					//Display select boxes for IE6 behaviour of popups again
					$("table#main select").eq(0).show();
					$("table#main select").eq(1).show();
					$(document).unbind("mousemove");
					
				}
			});
		}
	).click(function(){return false;});
	
	$("a[rel^='pop']").hoverIntent(
		function(){
			var xpos = $(this).offset().left;
			var ypos = $(this).offset().top;
			
			$("#"+$(this).attr("rel")).css({"left":parseInt(xpos+$(this).width()-5)+"px","top":parseInt(ypos-20)+"px"}).show();
	    }, 
		function(){
			//Get coordinates to find out when to hide
			var pop_el = $("#"+$(this).attr("rel"));
			var pop_height = pop_el.height();
			var pop_width = pop_el.width();
			var pop_startx = pop_el.offset().left;
			var pop_starty = pop_el.offset().top;
			
			$(document).bind("mousemove", function(e) {
				if (!(((e.pageX >= pop_startx) && (e.pageX <= (pop_startx + pop_width))) &&
					((e.pageY >= pop_starty) && (e.pageY <= (pop_starty + pop_height))))) {
					pop_el.hide();
					$(document).unbind("mousemove");
					
				}
			});
	    }
	);
});

