##-- Build and show the mainwindow --## 
sub build_mainwindow {
	#-- Window wide variable definitions --#
	my $button;
	my $table;
	my $cntcolumn = 0;
	my $cntrow = 0;
	my @buttontocreate;
	
	#-- Wich button to create, this is defined in the config-file. Isn't this cool :-) --#
	#-- Use the cisco specific buttonsdefinitions, if its a cisco card. --#
	if ($fromconf{cisco} =~ /yes/) {
		@buttontocreate = split (/,/,$fromconf{mwbuttons_cisco});
	}
	else {
		@buttontocreate = split (/,/,$fromconf{mwbuttons});
	}
	
	#-- Set the needed rows to display the buttons. Calculated from the amount of buttons --#	
	my $numtablerow = (@buttontocreate / $fromconf{columncount}) + 1;
	
	#-- Creating the mainwindow --#
	$g_main_window = new Gtk::Window("toplevel");
	$g_main_window->signal_connect("delete_event",sub{Gtk->exit(0);});

	##-- When the mainwindow only has one column add another title --##
	if ($fromconf{columncount} == 1) {
		$g_main_window->title("-=[ " . $fromconf{progname} ." ]=-");
		$g_main_window->set_usize(180,undef);
	}
	else {
	$g_main_window->title("-=[ " . $fromconf{progname} ." " . $fromconf{version} . " ]=-");
	}

	$g_main_window->border_width(2);
	$g_main_window->set_default_size(100,undef);

	#-- Create the placement table and add it to the mainwindow --#
	$table = new Gtk::Table($numtablerow,$fromconf{columncount},$true);
	$g_main_window->add ($table);

	#-- Generate the buttons dynamicly in the table --#
	foreach my $buttonname (@buttontocreate) {
	   #-- Create the button --#
	  	 $button = new Gtk::Button( $buttonname );
	
	  	 $button->signal_connect("clicked", \&ButtonClicked, $buttonname);
	
		   #-- Calculate the propper button placement positions --#
  		 if ($cntcolumn == $fromconf{columncount}) {
		  	  $cntcolumn = 0;
		  	  $cntrow++;
		 }
		   #-- Place the button into the table at the defined position --#
	  	 $table->attach_defaults($button, $cntcolumn,$cntcolumn + 1,$cntrow,$cntrow +1);
	  	 $button->show();
	  	 $cntcolumn++;
	}
	
	#-- Build the exit button --#
	$button = new Gtk::Button( 'Exit' );
	$button->signal_connect("clicked",sub{Gtk->exit(0);});
	#-- Place the exit button at the bottom most position --#
	$table->attach_defaults($button,0 ,$fromconf{columncount}  ,$numtablerow -1, $numtablerow);
	$button->show();
	
	#--Show the table and the window--#
	$table->show;
	$g_main_window->show;
}
