function windfit(action)
%WINDFIT - callback and cursor change for all
%          window links.

%   Yama Habibzai
%   Copyright (c) 1984-98 by The MathWorks, Inc. All Rights Reserved
%   $Revision: 1.4 $
%   $Date: 1997/12/03 17:30:07 $ 

if nargin < 1
  action = 'movement';
end

%Column locations of buttons
Xleftcol = 111;
Xrightcol = 341;

%The X corrdinates of the black panel links 
Xleftlink = 13;
Xrightlink = 80;

% The coordinates of each section of the Tour window
%=========================================================
%              [LEFT RIGHT BOTTOM TOP]

polyloc = zeros(18,4);
polyloc(1,:) = [Xleftlink Xrightlink 212 244];  % Product Overview 
polyloc(2,:) = [Xleftcol 183 254 274];          % MATLAB
polyloc(3,:) = [Xleftcol 195 175 193];          % SIMULINK
polyloc(4,:) = [Xleftcol 187 205 226];          % Toolboxes
polyloc(5,:) = [Xleftlink Xrightlink 14 64];    % Resources
polyloc(6,:) = [Xrightcol 538 254 272];         % Data Analysis
polyloc(7,:) = [Xrightcol 440 224 242];         % Mathematics
polyloc(8,:) = [Xrightcol 445 195 210];         % Programming
polyloc(9,:) = [Xrightcol 531 169 183];         % Dynamics Simulations
polyloc(10,:) = [Xrightcol 451 142 158];        % Control
polyloc(11,:) = [Xrightcol 467 113 129];        % Signal
polyloc(12,:) = [Xleftlink Xrightlink 150 187]; % Industry
polyloc(13,:) = [499 540 15 37];                % The close button
polyloc(14,:) = [Xleftlink Xrightlink 268 300]; % Intro to Matlab
polyloc(15,:) = [Xleftcol 183 124 148];         % Blocksets
polyloc(16,:) = [153 203 29 74];                % The Moebius plot
polyloc(17,:) = [258 312 30 74];                % The peaks plot
polyloc(18,:) = [378 423 23 74];                % The Knot
polyloc(19,:) = [Xleftlink Xrightlink 95 131];  % MATLAB Help Desk
polyloc(20,:) = [Xleftcol 191 93 115];          % Stateflow

%  If this mouse is moved over the figure
switch action
case 'movement',
  
  figNumber = findall(0, 'Name', 'MATLAB Tour');
  pos = get(figNumber, 'CurrentPoint');
  X = pos(1);
  Y = pos(2);
  
  % Check to see if X and Y are withing the squares
  inRect = (polyloc(:,1) <= X) & (X <= polyloc(:, 2)) & ...
      (polyloc(:, 3)<= Y) & (Y <= polyloc(:, 4));
  
  out = find(inRect);
  if ~isempty(out)
    set(figNumber, 'Pointer', 'custom');
  else
    set(figNumber, 'Pointer', 'arrow');
  end
  
  
  % When the area is clicked
case 'click',
  
  figNumber = gcbf;
  pos = get(figNumber, 'CurrentPoint');
  X = pos(1);
  Y = pos(2);
  
  
  % Check to see if X and Y are withing the squares
  out = find(polyloc(:,1) <= X & polyloc(:,2) >= X & ...
        polyloc(:,3) <= Y & polyloc(:,4) >=Y);
  if isempty(out)
    out = 0;
  end 
  
  switch out
  case 1,
    fig = findall(0, 'Type', 'figure',  'Name', 'MATLAB Tour');
    set(fig, 'Pointer', 'watch');
    matlfam;
    set(fig, 'Pointer', 'arrow');
  case 2, 
    tour showmatlab;
  case 3,
    tour showsimulink;
  case 4,
    tour showtoolbox;
  case 5, 
    tour showcontac;
  case 6,
    tour showdat;
  case 7, 
    tour showmath;
  case 8,
    tour showprog;
  case 9,
    tour showdss;
  case 10,
    tour showcont;
  case 11,
    tour showsig;
  case 12,
    tour showindustry;
  case 14,
    fig = findall(0, 'Type', 'figure',  'Name', 'MATLAB Tour');
    set(fig, 'Pointer', 'watch');
    mlintro;
    set(fig, 'Pointer', 'arrow');
  case 15,
    tour showblkset;
  case 16,
    fig = findall(0, 'Type', 'figure',  'Name', 'MATLAB Tour');
    set(fig, 'Pointer', 'watch');
    moeb;
    set(fig, 'Pointer', 'arrow');
  case 17,
    fig = findall(0, 'Type', 'figure',  'Name', 'MATLAB Tour');
    set(fig, 'Pointer', 'watch');
    epeak;
    set(fig, 'Pointer', 'arrow');
  case 18,
    fig = findall(0, 'Type', 'figure',  'Name', 'MATLAB Tour');
    set(fig, 'Pointer', 'watch');
    eknot;
    set(fig, 'Pointer', 'arrow');
  case 19,
    fig = findall(0, 'Type', 'figure',  'Name', 'MATLAB Tour');
    set(fig, 'Pointer', 'watch');
    helpdesk;
    set(fig, 'Pointer', 'arrow');
  case 20,
    tour showsf;
  end 
end


