jQuery.noConflict();
	jQuery(document).ready(function() {

	jQuery('#boxoneouter').hoverIntent(function() {
		jQuery('#homecontentcontainer').fadeIn('fast');
		jQuery('#homecontentcontainer').animate({'top': '-=191px'}, 'easeOutElastic');
	}, function() {
		jQuery('#homecontentcontainer').animate({'top': '+=191px'}, 2000);
	});


	jQuery('#boxtwoouter').hoverIntent(function() {
		jQuery('#homecontentcontainertwo').fadeIn('fast');
		jQuery('#homecontentcontainertwo').animate({'top': '-=228px'}, 'easeOutElastic');
	}, function() {
		jQuery('#homecontentcontainertwo').animate({'top': '+=228px'}, 2000);
	});


	jQuery('#boxthreeouter').hoverIntent(function() {
		jQuery('#homecontentcontainerthree').fadeIn('fast');
		jQuery('#homecontentcontainerthree').animate({'top': '-=302px'}, 'easeOutElastic');
	}, function() {
		jQuery('#homecontentcontainerthree').animate({'top': '+=302px'}, 2000);
	});


	jQuery('#boxfourouter').hoverIntent(function() {
		jQuery('#homecontentcontainerfour').fadeIn('fast');
		jQuery('#homecontentcontainerfour').animate({'top': '-=191px'}, 'easeOutElastic');
	}, function() {
		jQuery('#homecontentcontainerfour').animate({'top': '+=191px'}, 2000);
	});

//	jQuery("a[rel='prettyPhoto']").prettyPhoto();


	//////////////////////////////
	// CASE STUDY POPUP DISPLAY //
	//////////////////////////////

	// 0 = Deactivated and 2 = Case Study Activated
	var popupStatus = 0;

	function activateCasestudy(casestudyId) {
		// Centre the Popup Vertically and Horizontally
		var winWidth	= jQuery(window).width();
		var winHeight	= jQuery(window).height();
		var popWidth	= jQuery("#popupContent").width();
		var popHeight	= jQuery("#popupContent").height();
		jQuery("#popupContent").css({
			"position": "fixed",
			"top": winHeight/2-popHeight/2,
			"left": winWidth/2-popWidth/2
		});

		// Activate Popup
		if (popupStatus==0) {
			jQuery("#popupBackground2").css({"opacity": "0.7"});
			jQuery("#popupBackground2").fadeIn("slow");
			jQuery("#popupContent").fadeIn("slow");
			popupStatus = 2;
			jQuery.get("http://rpsindustries.com.au/casestudy_display.php", "id="+casestudyId, function (data) {
//			jQuery.get("/home/hosting/template-v0c/admin_user.php", "id="+casestudyId, function (data) {
				jQuery("#popupContent").html(data);
			});
		}
	};

	function deactivateCasestudy() {
		if (popupStatus==2) {
			jQuery("#popupBackground2").fadeOut("slow");
			jQuery("#popupContent").fadeOut("slow");
			popupStatus = 0;
		}
	};

	jQuery(".infocasestudyouter").click(function() {
		var casestudyId = jQuery(this).attr('id');
		activateCasestudy(casestudyId);
	});

	jQuery("#popupBackground2").click(function() {
		deactivateCasestudy();
	});

	jQuery("#close").click(function() {
		deactivateCasestudy();
	});

	jQuery(".close").live('click', function() { // use live version of click for injected html elements
		deactivateCasestudy();
	});

	jQuery(document).keypress(function(e) {
		// Close popup if Esc key is pressed
		if (e.keyCode==27 && popupStatus==2) {
			deactivateCasestudy();
		}
	});

	///////////////////////////
	// PRODUCT POPUP DISPLAY //
	///////////////////////////

	///////////////////////////
	//
	// FEATURES LIST
	//
	// 1. Popup repositions when window is resized
	// 2. Popup has minimum margin of 20px to keep darkness around it
	// 3. If popup is bigger than window when opened, the popup will resize to fit
	// 4. Can be closed by pressing the ESC key
	//
	///////////////////////////

	// 0 = Deactivated and 1 = Product Activated
	var popupStatus = 0;

	function activatePopup(productId) {
		// GET DATA TO POSITION POPUP
		var winWidth	= jQuery(window).width();
		var winHeight	= jQuery(window).height();
		var popWidth	= jQuery("#popupProduct").width();
		var popHeight	= jQuery("#popupProduct").height();

		// CALCULATE POPUP POSITION
		var topMargin	= winHeight/2-popHeight/2;
		var leftMargin	= winWidth/2-popWidth/2;

		jQuery("#popupProduct").css({
			"position": "fixed",
			"top": winHeight/2-popHeight/2,
			"left": winWidth/2-popWidth/2
		});

		// SETUP MINIMUM MARGIN OF 20PX AROUND POPUP
		if (topMargin < 20) {
			jQuery("#popupProduct").css({ "top": "20px" });
		}
		if (leftMargin < 20) {
			jQuery("#popupProduct").css({ "left": "20px" });
		}

		// IF POPUP BIGGER THAN WINDOW, SET MAX SIZE TO FIT
		if (winHeight < popHeight) {
			jQuery("#popupProduct").css({ "max-height": winHeight-70 });
		}
		if (winWidth < popWidth) {
			jQuery("#popupProduct").css({ "max-width": winWidth-70 });
		}

		// ACTIVATE POPUP
		if (popupStatus==0) {
			jQuery("#popupBackground").css({"opacity": "0.7"});
			jQuery("#popupBackground").fadeIn("slow");
			jQuery("#popupProduct").fadeIn("slow");
			popupStatus = 1;
			jQuery.get("http://rpsindustries.com.au/product_display.php", "id="+productId, function (data) {
				jQuery("#popupProduct").html(data);
			});
		}
	};

	function deactivatePopup() {
		if (popupStatus==1) {
			jQuery("#popupBackground").fadeOut("slow");
			jQuery("#popupProduct").fadeOut("slow");
			popupStatus = 0;
		}
	};

	jQuery(window).resize(function() {
		if (popupStatus===1) {
			// GET INFO TO DETERMINE POPUPS NEW POSITION WHEN WINDOW IS RESIZED
			var newWidth	= jQuery(window).width();
			var newHeight	= jQuery(window).height();

			var popWidth	= jQuery("#popupProduct").width();
			var popHeight	= jQuery("#popupProduct").height();

			// CALCULATE POPUP POSITION
			var topMargin	= newHeight/2-popHeight/2;
			var leftMargin	= newWidth/2-popWidth/2;

			// IF POPUP BIGGER THAN WINDOW, SET MAX SIZE TO FIT
			jQuery("#popupProduct").css({ "max-height": newHeight-70 });
			jQuery("#popupProduct").css({ "max-width": newWidth-70 });

			jQuery("#popupProduct").css({
				"position": "fixed",
				"top": newHeight/2-popHeight/2,
				"left": newWidth/2-popWidth/2
			});

			// SETUP MINIMUM MARGIN OF 20PX AROUND POPUP
			if (topMargin < 20) {
				jQuery("#popupProduct").css({ "top": "20px" });
			}
			if (leftMargin < 20) {
				jQuery("#popupProduct").css({ "left": "20px" });
			}
		} else if (popupStatus===2) {
			var newWidth	= jQuery(window).width();
			var newHeight	= jQuery(window).height();
			var popWidth	= jQuery("#popupContent").width();
			var popHeight	= jQuery("#popupContent").height();

			// CALCULATE POPUP POSITION
			var topMargin	= newHeight/2-popHeight/2;
			var leftMargin	= newWidth/2-popWidth/2;

			// IF POPUP BIGGER THAN WINDOW, SET MAX SIZE TO FIT
			jQuery("#popupContent").css({ "max-height": newHeight-70 });
			jQuery("#popupContent").css({ "max-width": newWidth-70 });

			jQuery("#popupContent").css({
				"position": "fixed",
				"top": newHeight/2-popHeight/2,
				"left": newWidth/2-popWidth/2
			});

			// SETUP MINIMUM MARGIN OF 20PX AROUND POPUP
			if (topMargin < 20) {
				jQuery("#popupContent").css({ "top": "20px" });
			}
			if (leftMargin < 20) {
				jQuery("#popupContent").css({ "left": "20px" });
			}
		} // End determine which box is open

	});

	jQuery(".infoproductsouter").click(function() {
		var productId = jQuery(this).attr('id');
		activatePopup(productId);
	});

	jQuery(".infoproductsouter2").click(function() {
		var productId = jQuery(this).attr('id');
		activatePopup(productId);
	});


	jQuery("#popupBackground").click(function() {
		deactivatePopup();
	});


	jQuery("#close").click(function() {
		deactivatePopup();
	});

	jQuery(".close").live('click', function() { // use live version of click for injected html elements
		deactivatePopup();
	});

	jQuery(document).keypress(function(e) {
		// Close popup if Esc key is pressed
		if (e.keyCode==27 && popupStatus==1) {
			deactivatePopup();
		}
	});

	/////////////////////////////
	// PRODUCT IMAGE SWITCHING //
	/////////////////////////////

	function changeImage(largePath) {
		jQuery('#popupProduct').animate({ scrollTop: jQuery('.productimageslarge').offset().top }, 500);
		jQuery('.productLarge').fadeOut('slow');
		jQuery('.productLarge').queue(function() { jQuery(this).attr( 'src', largePath ).dequeue(); });
		jQuery('.productLarge').fadeIn('slow');
	}

	// If a thumbnail is clicked
	jQuery('.productThumb').live('click', function() {

		var largePath = jQuery(this).attr('id');
		imgPre = new Image();
		imgPre.src = largePath;
		changeImage(largePath);
	return false;
	});


});

