
function prod_box_resize()
{
	//resizing prod boxes on products startup page
	var prodSquareHolder = $(".prod_square_holder");
	if (prodSquareHolder)
	{
		var ccWidth = parseInt($("#center_content").width(),10);
		var hWidth = ccWidth - 20;
		var minContainerWidth = 180;
		$(".prod_box").css({ 'width' : minContainerWidth});
		var containerOuterWidth = parseInt($(".prod_box").outerWidth(true),10);
		var minNumContainers = Math.floor(hWidth / containerOuterWidth);
		var leftOverSpace = hWidth - (minNumContainers*containerOuterWidth);
		var addition = Math.floor(leftOverSpace / minNumContainers);
		var newContainerInnerWidth = minContainerWidth + addition;
		$(".prod_box").css({ 'width' : newContainerInnerWidth});
	}
	//resizing center content to fit height & left menu to fit right menu
	var centerContent = $("#center_content");
	if (centerContent)
	{
		var iLen = String(document.location.href).length;
		if (document.location.href.substring(iLen, iLen - 11) != 'company.php')
		{
			var centerContentBotPosition = parseInt($("#center_content").height(),10) + parseInt($("#center_content").offset().top,10);
			var lastImageBotPosition = parseInt($("#right_container .last").height(),10) + parseInt($("#right_container .last").offset().top,10);
			var h180midBotPosition = parseInt($("#h_180_mid").height(),10) + parseInt($("#h_180_mid").offset().top,10);
			if (centerContentBotPosition < lastImageBotPosition)
			{
				var diff = lastImageBotPosition - centerContentBotPosition;
				var centerContentHeight = parseInt($("#center_content").height(),10)
				$("#center_content").css({ 'height' : centerContentHeight+diff});
				$("#center_content .inner").css({ 'height' : centerContentHeight+diff-30});
			}
			var diff2 = lastImageBotPosition - h180midBotPosition - 10;
			if (diff2 > 0)
			{
				var h180midHeight = parseInt($("#h_180_mid").height(),10);
				$("#h_180_mid").css({ 'height' : h180midHeight+diff2});
			}
		}
	}
}

$(document).ready(function(){
	
	$(window).bind("resize", resizeWindow);
	function resizeWindow( e ){	prod_box_resize();}
	
	prod_box_resize();
	
	if ($('#more_info_holder').length > 0) { $('#more_info_holder').tabs(); }
	
	if ($('#t_specs').length > 0) { CKEDITOR.replace('t_specs'); }
	if ($('#t_features').length > 0) { CKEDITOR.replace('t_features'); }
	if ($('#t_desc').length > 0) {CKEDITOR.replace('t_desc');}
	
	$("a[rel='cb_image']").colorbox(); 
	$(".cb").colorbox({
		iframe:true, 
		innerWidth:600, 
		innerHeight:500, 
		scrolling:false, 
		onClosed:function(){if(get_cookie(cookieName)==null){document.location.href='products.php';}}
	});
	
	$(".dlogin").colorbox({
		iframe:true, 
		innerWidth:600, 
		innerHeight:500, 
		scrolling:false, 
		onClosed:function(){document.location.href=document.location.href;}
	});
	
	$(".feedback").colorbox({
		iframe:true, 
		innerWidth:600, 
		innerHeight:500, 
		scrolling:false
	});
	
	$(".speedtest").colorbox({
		iframe:true, 
		innerWidth:450, 
		innerHeight:250, 
		scrolling:false
	});
	
});
//preload certain images
if (document.images){
	pic1= new Image(114,42); 
	pic1.src="http://computerelite.net/images/button_small.png";
	pic2= new Image(114,42); 
	pic2.src="http://computerelite.net/images/button_small_hover.png";
	pic3 = new Image(600,150);
	pic3.src="http://computerelite.net/images/dealer_login_banner.png";
	pic4 = new Image(600,150);
	pic4.src="http://computerelite.net/images/dealer_registration_banner.png";
	pic5 = new Image(600,150);
	pic5.src="http://computerelite.net/images/submit_order_banner.png";
	pic6 = new Image(600,150);
	pic6.src="http://computerelite.net/images/forgotten_password_banner.png";
}