function returnObjById( id )
{
    if (document.getElementById)
        var returnVar = document.getElementById(id);
    else if (document.all)
        var returnVar = document.all[id];
    else if (document.layers)
        var returnVar = document.layers[id];
    return returnVar;
}

function switchWindow(id) {
  obj=returnObjById(id);
  z=obj.style.zIndex;
  if (z!=40) {
    obj.style.zIndex=40;
  } else {
    obj.style.zIndex=1;
  }
}

var sections=Array();

sections[0]=Array();
sections[0][0]="introMGNews";
sections[0][1]=330;
sections[0][2]=780;
sections[0][3]=0;
sections[0][4]=0;


sections[1]=Array();
sections[1][0]="introMGConcerts";
sections[1][1]=360;
sections[1][2]=810;
sections[1][3]=0;
sections[1][4]=0;

sections[2]=Array();
sections[2][0]="introMGPortfolios";
sections[2][1]=390;
sections[2][2]=840;
sections[2][3]=0;
sections[2][4]=0;

sections[3]=Array();
sections[3][0]="introMGPhotoblog";
sections[3][1]=410;
sections[3][2]=870;
sections[3][3]=0;
sections[3][4]=0;

lastClick=-1;
activ=-1;
nSections=3;

inAction=0;

function setSectionPos(n, xPos) {	
	id=sections[n][0];
	xmax=sections[n][2];
	// if (xPos==xmax) xshow=xmax+30; else xshow=30;
	
	obj=document.getElementById(id);
	
	h=parseInt(obj.style.height);
	
	obj.style.left=xPos+"px";
	// obj.style.clip="rect(0, "+xshow+"px, "+h+"px, 0)";
}

function moveSection(n,xSpeed) {
	id=sections[n][0];
	xmin=sections[n][1];
	xmax=sections[n][2];
	obj=document.getElementById(id);
	xPos=parseInt(obj.style.left);
	
	xPos=xPos+xSpeed;
	
	if (xPos >= xmax) {
		setSectionPos(n, xmax);
		inAction--;
		sections[n][3]=0;
		clearInterval(sections[n][4]);
	}
	
	if (xPos <= xmin ){
		setSectionPos(n, xmin);
		inAction--;
		sections[n][3]=1;
		clearInterval(sections[n][4]);
	}
	
	
	setSectionPos(n, xPos);
  // setTimeout('moveSection('+n+', '+xSpeed+')',10);
	return 1;
}

function closeSection(n) {

	if (n<nSections) closeSection(n+1);
	// inAction++;
	// sections[n][4]=setInterval('moveSection('+n+',3)', 10);
	xmax=sections[n][2];
	sections[n][3]=0;
	setSectionPos(n,xmax);
}

function openSection(n) {
	if (n>0) openSection(n-1);
	// inAction++;
	// sections[n][4]=setInterval('moveSection('+n+',-3)', 10);
	xmin=sections[n][1];
	sections[n][3]=1;
	setSectionPos(n,xmin);
}
	
	

function switchSection(n) {
	if (inAction>0) return 0;
	id=sections[n][0];
	isOpen=sections[n][3];
	
	if (isOpen==1) {
		if (activ==n) {
			closeSection(n);
			activ=n-1;
		} else {
			if (n<nSections) {
				closeSection(n+1);
				openSection(n);
				activ=n;
			} else {
				closeSection(n);
				activ=n-1;
			}
		}
	} else {
		openSection(n);
		lastClick=n;
		activ=n;
	}
}