<!-- Copyright (c) 2005 by Cisco Systems, Inc. -->
// discover.js - Will discover 2960 devices.
// Support added for WS-C2960-48TC-L, WS-C2960-24TC-L, WS-C2960G-24TC-L, WS-C2960-48TT-L, WS-C2960-24TT-L and WS-C2960G-48TC-L devices

//////////////////////////////////////////////////////////////////////////////////////////////

function WSC296044_4_composite(int_status, media_type) 
{
	var dev = new top.device();
	dev.noofports = 48;
	dev.x=0;
	dev.y=0;
	dev.image = "images/c2960_44_4_composite.gif";	

	// Construct the mode button and the system LEDs
	constructModeSysleds(dev);

	// Create the Ports.
	var port;
	var portWidth = 19;
	var portImages = top.rj45portImages();
	var portInvImages = top.rj45portInvImages();
	var xPortGap = 1;
	var xPortGroupGap = 9;
	var xPortStartPos = 68;
	var xPortCoord = xPortStartPos;
	var yPortCoord;

	// Add the 44 FastEthernet ports in 2 groups of 16 each and 1 group of 14 ports.
	for(i=0; i<44; i++) 
	{
		if(i%2 == 0) 
		{
			yPortCoord = 27;
			port = new top.rj45portInv(portInvImages);
		} 
		else
		{
			yPortCoord = 43;
			port = new top.rj45port(portImages);
		}
		port.index = i;
		port.x = xPortCoord;
		port.y = yPortCoord;
		port.id = "port_" + i;
		if( i%2 !=0 ) 
		{
			xPortCoord += portWidth + xPortGap;
		}
		if ( i==15 || i == 31 )
		{
			xPortCoord += (xPortGroupGap - xPortGap);
		}
		dev.addPort(port);
	}

	// Add the 4 Composite ports.
	xPortCoord = 532;
	xPortGap = 13;
	yPortCoord = 35;
	for(i=44; i<48; i++) 
	{       
		var intType = int_status[i][6].indexOf("SFP") != -1 ? int_status[i][6] + "-10/100/1000BaseTX" : "10/100/1000BaseTX";
		port = new top.rj45Compositeport(intType,portImages);
        port.index = i;
        port.x = xPortCoord;
        port.y = yPortCoord;
        port.width = 19;
        port.height = 33;
		port.sfpx = 0;
		port.sfpy = 0;
		port.rj45x = 1;
		port.rj45y = 19;
		port.id = "port_" + i;
		dev.addPort(port);
		xPortCoord += 32;
	}
	return dev;
}


function WSC296048_2_composite(int_status, media_type) 
{
	var dev = new top.device();
	dev.noofports = 50;
	dev.x=0;
	dev.y=0;
	dev.image = "images/c2960_48_2_composite.gif";	

	// Construct the mode button and the system LEDs
	constructModeSysleds(dev);

	// Create the Ports.
	var port;
	var portWidth = 19;
	var portImages = top.rj45portImages();
	var portInvImages = top.rj45portInvImages();
	var xPortGap = 1;
	var xPortGroupGap = 9;
	var xPortStartPos = 68;
	var xPortCoord = xPortStartPos;
	var yPortCoord;

	// Add the 48 FastEthernet ports in 4 groups of 12 each.
	for(i=0; i<48; i++) 
	{
		if(i%2 == 0) 
		{
			yPortCoord = 27;
			port = new top.rj45portInv(portInvImages);
		} 
		else
		{
			yPortCoord = 43;
			port = new top.rj45port(portImages);
		}
		port.index = i;
		port.x = xPortCoord;
		port.y = yPortCoord;
		port.id = "port_" + i;
		if( i%2 !=0 ) 
		{
			xPortCoord += portWidth + xPortGap;
		}
		if ( i==11 || i == 23 || i==35 )
		{
			xPortCoord += (xPortGroupGap - xPortGap);
		}
		dev.addPort(port);
	}

	// Add the 2 Composite ports.
	xPortCoord = 588;
	xPortGap = 13;
	yPortCoord = 35;
	for(i=48; i<50; i++) 
	{       
		var intType = int_status[i][6].indexOf("SFP") != -1 ? int_status[i][6] + "-10/100/1000BaseTX" : "10/100/1000BaseTX";
		port = new top.rj45Compositeport(intType,portImages);
        port.index = i;
        port.x = xPortCoord;
        port.y = yPortCoord;
        port.width = 19;
        port.height = 33;
		port.sfpx = 0;
		port.sfpy = 0;
		port.rj45x = 1;
		port.rj45y = 19;
		port.id = "port_" + i;
		dev.addPort(port);
		xPortCoord += 32;
	}
	return dev;
}

function WSC296024_2_composite(int_status, media_type) 
{
	var dev = new top.device();
	dev.noofports = 26;
	dev.x=0;
	dev.y=0;
	dev.image = "images/c2960_24_2_composite.gif";	

	// Construct the mode button and the system LEDs
	constructModeSysleds(dev);

	// Create the Ports.
	var port;
	var portWidth = 19;
	var portImages = top.rj45portImages();
	var portInvImages = top.rj45portInvImages();
	var xPortGap = 1;
	var xPortGroupGap = 20;
	var xPortStartPos = 313;
	var xPortCoord = xPortStartPos;
	var yPortCoord;

	// Add the 24 FastEthernet ports in 2 groups of 12 each.
	for(i=0; i<24; i++) 
	{
		if(i%2 == 0) 
		{
			yPortCoord = 27;
			port = new top.rj45portInv(portInvImages);
		} 
		else
		{
			yPortCoord = 43;
			port = new top.rj45port(portImages);
		}
		port.index = i;
		port.x = xPortCoord;
		port.y = yPortCoord;
		port.id = "port_" + i;
		if( i%2 !=0 ) 
		{
			xPortCoord += portWidth + xPortGap;
		}
		if ( i==11 || i == 23 )
		{
			xPortCoord += (xPortGroupGap - xPortGap);
		}
		dev.addPort(port);
	}

	// Add the 2 Composite ports.
	xPortCoord = 588;
	xPortGap = 13;
	yPortCoord = 35;
	for(i=24; i<26; i++) 
	{       
		var intType = int_status[i][6].indexOf("SFP") != -1 ? int_status[i][6] + "-10/100/1000BaseTX" : "10/100/1000BaseTX";
		port = new top.rj45Compositeport(intType,portImages);
        port.index = i;
        port.x = xPortCoord;
        port.y = yPortCoord;
        port.width = 19;
        port.height = 33;
		port.sfpx = 0;
		port.sfpy = 0;
		port.rj45x = 1;
		port.rj45y = 19;
		port.id = "port_" + i;
		dev.addPort(port);
		xPortCoord += 32;
	}
	return dev;
}

function WSC296020_4_composite(int_status, media_type) 
{
	var dev = new top.device();
	dev.noofports = 24;
	dev.x=0;
	dev.y=0;
	dev.image = "images/c2960_20_4_composite.gif";	

	// Construct the mode button and the system LEDs
	constructModeSysleds(dev);

	// Create the Ports.
	var port;
	var portWidth = 19;
	var portImages = top.rj45portImages();
	var portInvImages = top.rj45portInvImages();
	var xPortGap = 1;
	var xPortGroupGap = 20;
	var xPortStartPos = 307;
	var xPortCoord = xPortStartPos;
	var yPortCoord;

	// Add the 24 FastEthernet ports in 2 groups of 10 each.
	for(i=0; i<20; i++) 
	{
		if(i%2 == 0) 
		{
			yPortCoord = 25;
			port = new top.rj45portInv(portInvImages);
		} 
		else
		{
			yPortCoord = 41;
			port = new top.rj45port(portImages);
		}
		port.index = i;
		port.x = xPortCoord;
		port.y = yPortCoord;
		port.id = "port_" + i;
		if( i%2 !=0 ) 
		{
			xPortCoord += portWidth + xPortGap;
		}
		if ( i==9 )
		{
			xPortCoord += (xPortGroupGap - xPortGap);
		}
		dev.addPort(port);
	}

	// Add the 4 Composite ports.
	xPortCoord = 532;
	xPortGap = 13;
	portWidth = 21;
	yPortCoord = 35;
	for(i=20; i<24; i++) 
	{       
		var intType = int_status[i][6].indexOf("SFP") != -1 ? int_status[i][6] + "-10/100/1000BaseTX" : "10/100/1000BaseTX";
		port = new top.rj45Compositeport(intType,portImages);
        port.index = i;
        port.x = xPortCoord;
        port.y = yPortCoord;
        port.width = 19;
        port.height = 33;
		port.sfpx = 0;
		port.sfpy = 0;
		port.rj45x = 1;
		port.rj45y = 19;
		port.id = "port_" + i;
		dev.addPort(port);
		if ( i== 21 ) 
			xPortGap = 5;
		else
			xPortGap = 13;
		xPortCoord += portWidth+xPortGap;
	}
	return dev;
}

function WSC296048_2_rj45(int_status, media_type) 
{
	var dev = new top.device();
	dev.noofports = 50;
	dev.x=0;
	dev.y=0;
	dev.image = "images/c2960_48_2_rj45.gif";	

	// Construct the mode button and the system LEDs
	constructModeSysleds(dev);

	// Create the Ports.
	var port;
	var portWidth = 19;
	var portImages = top.rj45portImages();
	var portInvImages = top.rj45portInvImages();
	var xPortGap = 1;
	var xPortGroupGap = 9;
	var xPortStartPos = 68;
	var xPortCoord = xPortStartPos;
	var yPortCoord;

	// Add the 48 FastEthernet ports in 4 groups of 12 each.
	for(i=0; i<48; i++) 
	{
		if(i%2 == 0) 
		{
			yPortCoord = 27;
			port = new top.rj45portInv(portInvImages);
		} 
		else
		{
			yPortCoord = 43;
			port = new top.rj45port(portImages);
		}
		port.index = i;
		port.x = xPortCoord;
		port.y = yPortCoord;
		port.id = "port_" + i;
		if( i%2 !=0 ) 
		{
			xPortCoord += portWidth + xPortGap;
		}
		if ( i==11 || i == 23 || i==35 )
		{
			xPortCoord += (xPortGroupGap - xPortGap);
		}
		dev.addPort(port);
	}

	// Add the 2 RJ45 ports.
	xPortCoord = 589;
	xPortGap = 13;
	yPortCoord = 54;
	for(i=48; i<50; i++) 
	{       
		port = new top.rj45port(portImages);
		port.index = i;
		port.x = xPortCoord;
		port.y = yPortCoord;
		port.id = "port_" + i;
		xPortCoord += portWidth + xPortGap;
		dev.addPort(port);
	}
	return dev;
}
function WSC296024_2_rj45(int_status, media_type) 
{
	var dev = new top.device();
	dev.noofports = 26;
	dev.x=0;
	dev.y=0;
	dev.image = "images/c2960_24_2_rj45.gif";	

	// Construct the mode button and the system LEDs
	constructModeSysleds(dev);

	// Create the Ports.
	var port;
	var portWidth = 19;
	var portImages = top.rj45portImages();
	var portInvImages = top.rj45portInvImages();
	var xPortGap = 1;
	var xPortGroupGap = 20;
	var xPortStartPos = 313;
	var xPortCoord = xPortStartPos;
	var yPortCoord;

	// Add the 24 FastEthernet ports in 2 groups of 12 each.
	for(i=0; i<24; i++) 
	{
		if(i%2 == 0) 
		{
			yPortCoord = 27;
			port = new top.rj45portInv(portInvImages);
		} 
		else
		{
			yPortCoord = 43;
			port = new top.rj45port(portImages);
		}
		port.index = i;
		port.x = xPortCoord;
		port.y = yPortCoord;
		port.id = "port_" + i;
		if( i%2 !=0 ) 
		{
			xPortCoord += portWidth + xPortGap;
		}
		if ( i==11 || i == 23 )
		{
			xPortCoord += (xPortGroupGap - xPortGap);
		}
		dev.addPort(port);
	}

	// Add the 2 RJ45 ports.
	xPortCoord = 589;
	xPortGap = 13;
	yPortCoord = 54;
	for(i=24; i<26; i++) 
	{       
		port = new top.rj45port(portImages);
		port.index = i;
		port.x = xPortCoord;
		port.y = yPortCoord;
		port.id = "port_" + i;
		xPortCoord += portWidth + xPortGap;
		dev.addPort(port);
	}
	return dev;
}

function constructModeSysleds(dev) 
{
	//Create System LEDs
	var ledImages = top.ledImages();
	var tempLed = new top.led(ledImages);
	tempLed.x = 20;
	tempLed.y = 23;
	tempLed.id = "system_led";
	tempLed.device = dev;
	dev.sysleds["SYSTEM"] = tempLed;

	tempLed = new top.led(ledImages);
	tempLed.x = 20;
	tempLed.y = 30;
	tempLed.id = "rps_led";
	tempLed.device = dev;
	dev.sysleds["RPS"] = tempLed;

	tempLed = new top.led(ledImages);
	tempLed.x = 20;
	tempLed.y = 37;
	tempLed.id = "status_led";
	tempLed.device = dev;
	dev.sysleds["STATUS"] = tempLed;

	tempLed = new top.led(ledImages);
	tempLed.x = 20;
	tempLed.y = 44;
	tempLed.id = "duplex_led";
	tempLed.device = dev;
	dev.sysleds["DUPLEX"] = tempLed;

	tempLed = new top.led(ledImages);
	tempLed.x = 20;
	tempLed.y = 51;
	tempLed.id = "speed_led";
	tempLed.device = dev;
	dev.sysleds["SPEED"] = tempLed;
	
	// Create the Mode Btn
	var modeBtn = new top.modebtn("images/c2960_mode.gif");
	modeBtn.x = 42;
	modeBtn.y = 64;
	modeBtn.id = "mode_btn";
	modeBtn.device = dev;
	dev.modebtn = modeBtn;
	// override the modes listed by show hardware led.
	dev.modes = new Array("STATUS", "DUPLEX", "SPEED");
}

function createDevice(int_status, media_type, deviceType) 
{
	var device = null;
	
	if(deviceType == null) 
		return device;

	if(deviceType == "WS-C2960-48TC-L") 
	{
		device = new WSC296048_2_composite(int_status, media_type);
	}
	else if ( deviceType == "WS-C2960-24TC-L")
	{
		device = new WSC296024_2_composite(int_status, media_type);	
	}	
	else if ( deviceType == "WS-C2960G-24TC-L")
	{
		device = new WSC296020_4_composite(int_status, media_type);	
	}	
		else if ( deviceType == "WS-C2960-48TT-L")
	{
		device = new WSC296048_2_rj45(int_status, media_type);	
	}
	else if ( deviceType == "WS-C2960-24TT-L")
	{
		device = new WSC296024_2_rj45(int_status, media_type);	
	}
	else if ( deviceType == "WS-C2960G-48TC-L")
	{
		device = new WSC296044_4_composite(int_status, media_type);	
	}		
	if(device != null) 
	{
		device.type = deviceType;
		device.family = "2960";
	}

	return device;
}
