function updateDirection(module, direction){
	switch(module.name()){
		case "Module1N":
			if(direction == "S"){
				connect_x = module.x();
				connect_y = module.y() + module.height();
				connect_dir = "S";
			}
			if(direction == "N"){
				connect_x = module.x();
				connect_y = module.y();
				connect_dir = "N";
			}
		break;

		case "Module1S":
			if(direction == "N"){
				connect_x = module.x();
				connect_y = module.y();
				connect_dir = "N";
			}
			if(direction == "S"){
				connect_x = module.x();
				connect_y = module.y()+module.height()-10;
				connect_dir = "S";
			}
		break;

		case "Module1W":

			if(direction == "E"){
				connect_y = module.y();
				connect_x = module.x()+module.width()-10;
				connect_dir = "E";
			}
			if(direction == "W"){
				connect_y = module.y();
				connect_x = module.x();
				connect_dir = "W";
			}
		break;

		case "Module1E":
			if(direction == "E"){
				connect_y = module.y();
				connect_x = module.x()+module.width();
				connect_dir = "E";
			}
			if(direction == "W"){
				//alert("Heading W");
				connect_y = module.y();
				connect_x = module.x()+10;
				connect_dir = "W";
			}
		break;




		/*########### MODULE 2 ############*/
		case "Module2N":
			if(direction == "S"){
				connect_x = module.x()-10;
				connect_y = module.y()+module.height();
				connect_dir = "S";
			}

			if(direction == "N"){
				connect_x = module.x()-10;
				connect_y = module.y();
			}
		break;

		case "Module2W":
			if(direction == "W"){
				connect_x = module.x();
				connect_dir = "W";
			}
			if(direction == "E"){
				connect_x = module.x()+module.width();
				connect_y = module.y()-10;
			}
		break;


		/*########### MODULE 3 ############*/
		case "Module3N":
			if(direction == "E"){
				connect_x = module.x()+33;
				connect_y = module.y()+module.height()-15;
				connect_dir = "S";
			}

			if(direction == "N"){
				connect_x = module.x()+15;
				connect_y = module.y();
				connect_dir = "W";
			}
		break;

		case "Module3W":
			if(direction == "S"){
				connect_x = module.x()+15;
				connect_y = module.y()+34;
				connect_dir = "W";
			}
			if(direction == "E"){
				connect_x = module.x()+35;
				connect_y = module.y()+5;
				connect_dir = "N";
			}
		break;

		case "Module3E":
			if(direction == "W"){
				connect_y = module.y()+module.height()-15;
				connect_x = module.x();
				connect_dir = "S";
			}
			if(direction == "E"){
				connect_x -= imgWidth;
			}

			if(direction == "N"){
				connect_y = module.y();
				connect_x = module.x()+module.width()-14;
				connect_dir = "E";
			}
		break;

		case "Module3S":
			if(direction == "S"){
				connect_x = module.x()+module.width()-15;
				connect_y = module.y()+35;
				connect_dir = "E";
			}
			if(direction == "W"){
				connect_x = module.x();
				connect_y = module.y()+5;
				connect_dir = "N";
			}

		break;

		/*########### MODULE 4 ############*/
		case "Module4N":
			if(direction == "S"){
				connect_x = module.x()+2;
				connect_y = module.y() + module.height()-14;
				connect_dir = "S";
			}
			break;

		case "Module4S":

			if(direction == "S" || direction == "N"){
				connect_x = module.x()+2;
				connect_y = module.y()+5;
				if(!index){
					connect_dir = "N";
				}
			}

			break;

		case "Module4W":

			if(direction == "W"){
				connect_x = module.x()-14;
				connect_y = module.y()+10;
				connect_dir = "E";
			}
			if(direction == "E"){
				connect_x = module.x()+module.width()-15;
				connect_y = module.y()+2;
				connect_dir = "E";
			}

			if(direction == "S"){
				connect_x = module.x()+module.width()-15;
				connect_y = module.y()+2;
				connect_dir = "E";
			}

			break;

		case "Module4E":
			if(direction == "W"){
				connect_x = module.x()+14;
				connect_y = module.y()+2;
				connect_dir = "W";
			}
			if(direction == "E"){
				connect_x = module.x();
				connect_y = module.y();
				connect_dir = "E";
			}

			if(direction == "S"){
				connect_x = module.x()+14;
				connect_y = module.y()+2;
				connect_dir = "W";
			}
			break;

		/*########### MODULE 4v2 ############*/
		case "Module4v2N":
			if(direction == "S"){
				connect_x = module.x()+2;
				connect_y = module.y() + module.height()-14;
				connect_dir = "S";
			}
			break;

		case "Module4v2S":

			if(direction == "S" || direction == "N"){
				connect_x = module.x()+2;
				connect_y = module.y()+5;
				if(!index){
					connect_dir = "N";
				}
			}

			break;

		case "Module4v2W":

			if(direction == "W"){
				connect_x = module.x()-14;
				connect_y = module.y()+10;
				connect_dir = "E";
			}
			if(direction == "E"){
				connect_x = module.x()+module.width()-15;
				connect_y = module.y()+2;
				connect_dir = "E";
			}

			if(direction == "S"){
				connect_x = module.x()+module.width()-15;
				connect_y = module.y()+2;
				connect_dir = "E";
			}

			break;

		case "Module4v2E":
			if(direction == "W"){
				connect_x = module.x()+14;
				connect_y = module.y()+2;
				connect_dir = "W";
			}
			if(direction == "E"){
				connect_x = module.x();
				connect_y = module.y();
				connect_dir = "E";
			}

			if(direction == "S"){
				connect_x = module.x()+14;
				connect_y = module.y()+2;
				connect_dir = "W";
			}
			break;

		/*########### MODULE 5 ############*/
		case "Module5N":
			if(direction == "N"){
				connect_x = module.x();
				connect_y = module.y();
			}

			if(direction == "S"){
				connect_x = module.x();
				connect_y = module.y()+module.height()-2;
			}
		break;

		case "Module5W":
			if(direction == "W"){
				connect_x = module.x()+4;
				connect_y = module.y();
			}

			if(direction == "E"){
				connect_x = module.x()+module.width()-2;
				connect_y = module.y();
			}
		break;

		/*########### MODULE 6 ############*/
		case "Module6N":
			if(direction == "S"){
				// connect_x = module.x();
				// connect_y = module.y()+module.height();
				connect_x = module.x()-12;
				connect_y = module.y();

				if(modules.length <= 1) {
				    connect_dir = "N";
				}

			}

			if(direction == "N"){
				connect_x = module.x()-12;
				connect_y = module.y();
			}
		break;

		case "Module6S":
			if(direction == "S"){
				connect_x = module.x()-10;
				connect_y = module.y()+module.height()-2;
			}

		break;

		case "Module6W":
			if(direction == "W"){
				connect_x += 0;
				connect_y = 0;
			}
			if(direction == "E"){
				connect_x = module.x()+module.width();
				connect_y = module.y()-10;
			}

			if(direction == "S"){
				connect_x = module.x()+module.width();
				connect_y = module.y()-10;
				connect_dir = "E";
			}

		break;

		case "Module6E":
			if(direction == "S"){
				connect_x = module.x();
				connect_y = module.y()-10;
				connect_dir = "W";
			}
			if(direction == "W"){
				connect_x = module.x();
				connect_y = module.y()-10;
			}
			if(direction == "E"){
				connect_x = module.x();
				connect_y = module.y();
			}
		break;

		case "Module7N":
			if(direction == "S"){
				connect_x = module.x()-10;
				connect_y = module.y()+module.height();
				connect_dir = "S";
			}

			if(direction == "N"){
				connect_x = module.x()-10;
				connect_y = module.y();
			}
		break;

		case "Module7W":
			if(direction == "W"){
				connect_x = module.x();
				connect_y = module.y()-10;
			}
			if(direction == "E"){
				connect_x = module.x()+module.width();
				connect_y = module.y()-10;
			}
		break;



		case "Module7BN":
			if(direction == "S"){
				connect_x = module.x();
				connect_y = module.y() + module.height();
				connect_dir = "S";
			}
			if(direction == "N"){
				connect_x = module.x();
				connect_y = module.y();
				connect_dir = "N";
			}
			break;

		case "Module7BS":
			if(direction == "N"){
				connect_x = module.x();
				connect_y = module.y();
				connect_dir = "N";
			}
			if(direction == "S"){
				connect_x = module.x();
				connect_y = module.y()+module.height()-10;
				connect_dir = "S";
			}
			break;

		case "Module7BW":

			if(direction == "E"){
				connect_y = module.y();
				connect_x = module.x()+module.width()-10;
				connect_dir = "E";
			}
			if(direction == "W"){
				connect_y = module.y();
				connect_x = module.x();
				connect_dir = "W";
			}
			break;

		case "Module7BE":
			if(direction == "E"){
				connect_y = module.y();
				connect_x = module.x()+module.width();
				connect_dir = "E";
			}
			if(direction == "W"){
				//alert("Heading W");
				connect_y = module.y();
				connect_x = module.x()+10;
				connect_dir = "W";
			}
			break;



		/*########### MODULE 8 ############*/
		case "Module8N":
			if(direction == "E"){
				connect_x = module.x()+64;
				connect_y = module.y()+module.height()-12;
				connect_dir = "S";
			}

			if(direction == "N"){
				connect_x = module.x()+10;
				connect_y = module.y();
				connect_dir = "W";
			}
		break;

		case "Module8S":
			if(direction == "S"){
				connect_x = module.x()+module.width()-12;
				connect_y = module.y()+60;
				connect_dir = "E";
			}
			if(direction == "W"){
				connect_x = module.x();
				connect_y = module.y();
				connect_dir = "N";
			}
		break;

		case "Module8W":
			if(direction == "S"){
				connect_x = module.x()+10;
				connect_y = module.y()+60;
				connect_dir = "W";
			}
			if(direction == "E"){
				connect_x = module.x()+60;
				connect_y = module.y();
				connect_dir = "N";
			}
		break;

		case "Module8E":
			if(direction == "W"){
				connect_y = module.y()+module.height()-10;
				connect_x = module.x();
				connect_dir = "S";
			}
			if(direction == "E"){
				connect_x -= imgWidth;
			}

			if(direction == "N"){
				connect_y = module.y()+2;
				connect_x = module.x()+module.width()-10;
				connect_dir = "E";
			}
		break;



		/*########### MODULE 9 ############*/

		case "Module9N":
			if(direction == "N"){
				connect_x = module.x()+3;
				connect_y = module.y()+12;
			}

			if(direction == "S"){
				connect_x = module.x();
				connect_y = module.y()+module.height()-15;
			}
		break;

		case "Module9S":
			if(direction == "N"){
				connect_x = module.x()+32;
				connect_y = module.y()+5;
			}
			if(direction == "S"){
				connect_x = module.x()+32;
				connect_y = module.y()+module.height()-15;
			}

		break;

		case "Module9W":
			if(direction == "W"){
				connect_x = module.x()+15;
				connect_y = module.y()+1;
			}
			if(direction == "E"){
				connect_x = module.x()+module.width()-15;
				connect_y = module.y();
			}
		break;

		case "Module9E":
			if(direction == "W"){
				connect_y = module.y()+32;
				connect_x = module.x()+15;
			}
			if(direction == "E"){
				connect_x = module.x()+module.width()-15;
				connect_y = module.y()+32;
			}
		break;

		/*########### MODULE 9 ############*/

		case "Module10N":
			if(direction == "N"){
				connect_x = module.x()+3;
				connect_y = module.y()+12;
			}

			if(direction == "S"){
				connect_x = module.x()+2;
				connect_y = module.y()+module.height()-20;
			}
		break;

		case "Module10S":
			if(direction == "N"){
				connect_x = module.x()+58;
				connect_y = module.y()+5;
			}
			if(direction == "S"){
				connect_x = module.x()+58;
				connect_y = module.y()+module.height()-20;
			}

		break;

		case "Module10W":
			if(direction == "W"){
				connect_x = module.x()+18;
				connect_y = module.y()+5;
			}
			if(direction == "E"){
				connect_x = module.x()+module.width()-18;
				connect_y = module.y()+5;
			}
		break;

		case "Module10E":
			if(direction == "W"){
				connect_y = module.y()+56;
				connect_x = module.x()+18;
			}
			if(direction == "E"){
				connect_x = module.x()+module.width()-18;
				connect_y = module.y()+55;
			}
		break;


	}
}
