function Connector(board,connectorImage,firstCell,secondCell,vertical)
{
	this.board=board;
    this.connectorImage = connectorImage;
	document.getElementById(this.connectorImage).connector = this;
	document.getElementById(this.connectorImage).onclick = function(event)
	{
		this.connector.onClick();
	}
    this.firstCell = firstCell;
    this.secondCell = secondCell;
    this.connected = false;
	this.lit = false;
	this.vertical = vertical;
	this.section = -1;
	this.connectorId = 0;
    this.update = function()
    {
        var img = document.getElementById(this.connectorImage);
        if(this.connected)
        {
			if(this.lit)
			{
				img.src = "images/jsconnect/"+themes.getCurrent().path + "minuslit"+((this.vertical)?("vertical"):(""))+((properties.options.colorDeadEndChainsDifferently)?((this.board.sectionTallies[this.section]>1)?(""):("deadend")):("deadend")) +".png";
			}
			else
			{
				img.src = "images/jsconnect/"+themes.getCurrent().path + "minus"+((this.vertical)?("vertical"):(""))+((properties.options.colorDeadEndChainsDifferently)?((this.board.sectionTallies[this.section]>1)?(""):("deadend")):("deadend")) +".png";
			}
        }
        else
        {
            if((this.firstCell.openConnections>0)&&(this.secondCell.openConnections>0)&&((this.firstCell.section!=this.secondCell.section)||(properties.options.allowShortCircuits)))
            {
                img.src = "images/jsconnect/"+themes.getCurrent().path + "plus"+((this.vertical)?("vertical"):(""))+((properties.options.colorDeadEndChainsDifferently)?((this.board.sectionTallies[this.section]>1)?(""):("deadend")):("deadend")) +".png";
            }
            else
            {
                img.src = "images/jsconnect/"+themes.getCurrent().path + "blank"+((this.vertical)?("vertical"):(""))+((properties.options.colorDeadEndChainsDifferently)?((this.board.sectionTallies[this.section]>1)?(""):("deadend")):("deadend")) +".png";
            }
        }
    }
	this.clear = function()
	{
		this.connected=false;
	}
	this.onClick = function()
	{
		if(board.undoIndex<board.undoList.length) 
		{
			if(confirm("You are looking at a historical point in the game. If you decide to make this move, all stored moves after this point will be lost!"))
			{
				board.revert();
			}
			else
			{
				return;
			}
		}
		if(board.solved) return;
		if(this.connected)
		{
			board.addMove(this.connectorId);
			this.connected=false;
			this.firstCell.openConnections++;
			this.secondCell.openConnections++;
		}
		else
		{
            if((firstCell.openConnections>0)&&(secondCell.openConnections>0)&&((firstCell.section!=secondCell.section)||(properties.options.allowShortCircuits)))
            {
				board.addMove(this.connectorId);
    			this.connected=true;
    			this.firstCell.openConnections--;
    			this.secondCell.openConnections--;
            }
		}
		board.update();
		mainFrame.navigatorFrame.update();
	}
	this.light = function()
	{
		if(this.lit) return;
		if(!this.connected) return;
		this.lit = true;
		this.firstCell.light();
		this.secondCell.light();
	}
	this.paint = function (section)
	{
		if(this.section!=-1) return;
		if(!this.connected) return;
		this.section = section;
		this.firstCell.paint(section);
		this.secondCell.paint(section);
	}
}
