$(document).ready(function(){
	function centerThis(div,divwidth) {
        var winH = $(window).height();
        var winW = $(window).width();
        var scrolltop=$(window).scrollTop();
        var scrollleft=$(window).scrollLeft();
        var centerDiv = $('#' + div);
        centerDiv.css('position','absolute');
        if(divwidth){
        	centerDiv.css('top', ((winH/2)-(divwidth)/2)+scrolltop);
        	centerDiv.css('left', (winW/2)-(divwidth/2));
        }else{
        	centerDiv.css('top', 0+scrolltop);
        	centerDiv.css('left',0+scrollleft);
        }
	}
	
	$("#overlay").height($(window).height());
	centerThis('overlay');
	centerThis('enlargedimage',312);
	$("#closetab").css("position","absolute");
	$("#closetab").css("top",0);
	$("#closetab").css("left",$("#enlargedimage").css("left"));
	$(window).scroll(function () { 
		$("#overlay").height($(window).height());
		$("#overlay").width($(window).width());
		centerThis('overlay');
		centerThis('enlargedimage',312);
		centerThis('closetab',312);
		var position = $("#enlargedimage").position();
		$("#closetab").css("top",position.top-35);
	});
	$(".optionthumb").mouseover(function(){
  			$(this).attr("src","/images/dino/options/zoom_"+$(this).attr("id")+".jpg");
		}).mouseout(function(){
			$(this).attr("src","/images/dino/options/"+$(this).attr("id")+".jpg");
		});
	
	$(".optionthumb").click(function(){
		$("#overlay").height($(window).height());
		centerThis('overlay');
		$("#enlargedimage").attr("src","/images/dino/options/Large/"+$(this).attr("id")+".jpg");
		centerThis('enlargedimage',312);
		centerThis('closetab',312);
		$("#popup").show();
		$("#overlay").show();
		var position = $("#enlargedimage").position();
		//$("#closetab").css("left",position.left);
		$("#closetab").css("top",position.top-35);
		
	});
	
	$("#overlay").click(function(){
		$("#popup").hide();
		$(this).hide();
	});
	$("#enlargedimage").click(function(){
		$("#popup").hide();
		$("#overlay").hide();
	});
	$("#closetab").click(function(){
		$("#popup").hide();
		$("#overlay").hide();
	});
	$("#catstandard").click(function(){
		$("#standardoptions").show("blind","","slow");
		$("#flowoptions").hide();
		$("#volumeoptions").hide();
		$("#dustoptions").hide();
		$("#safetyoptions").hide();
		$("#wearoptions").hide();
	});
	$("#catflow").click(function(){
		$("#flowoptions").show("blind","","slow");
		$("#standardoptions").hide();
		$("#volumeoptions").hide();
		$("#dustoptions").hide();
		$("#safetyoptions").hide();
		$("#wearoptions").hide();
	});
	$("#catvolume").click(function(){
		$("#volumeoptions").show("blind","","slow");
		$("#flowoptions").hide();
		$("#standardoptions").hide();
		$("#dustoptions").hide();
		$("#safetyoptions").hide();
		$("#wearoptions").hide();
	});
	$("#catdust").click(function(){
		$("#dustoptions").show("blind","","slow");
		$("#flowoptions").hide();
		$("#volumeoptions").hide();
		$("#standardoptions").hide();
		$("#safetyoptions").hide();
		$("#wearoptions").hide();
	});
	$("#catsafety").click(function(){
		$("#safetyoptions").show("blind","","slow");
		$("#flowoptions").hide();
		$("#volumeoptions").hide();
		$("#dustoptions").hide();
		$("#standardoptions").hide();
		$("#wearoptions").hide();
	});
	$("#catwear").click(function(){
		$("#wearoptions").show("blind","","slow");
		$("#flowoptions").hide();
		$("#volumeoptions").hide();
		$("#dustoptions").hide();
		$("#safetyoptions").hide();
		$("#standardoptions").hide();
	});
	$("#showall").click(function(){
		$("#standardoptions").show("blind","","slow");
		$("#flowoptions").show("blind","","slow");
		$("#volumeoptions").show("blind","","slow");
		$("#dustoptions").show("blind","","slow");
		$("#safetyoptions").show("blind","","slow");
		$("#wearoptions").show("blind","","slow");
	});
});