function move(e){
  if(!pageHasLoaded) return;
  mouseX=(document.all)?event.clientX+document.body.scrollLeft:e.pageX;
  mouseY=(document.all)?event.clientY+document.body.scrollTop:e.pageY;
  if((mouseX>picture_x)&&(mouseX<(picture_x+picture_w))&&(mouseY>picture_y)&&(mouseY<(picture_y+picture_h))){
    showCaption();
    return false;
  }else{
    hideCaption();
  }
};
var caption_visible=false;
function hideCaption(){
  if(!capObj) return;
  if(pageHasLoaded){
    if(caption_visible){
      capObj.hide();
      caption_visible=false;
    }
  }
};
function showCaption(){
  if(!capObj) return;
  if(pageHasLoaded){
    if(!caption_visible){
      capObj.show();
      caption_visible=true;
    }
  }
};        
// reloads page to position the layers again
function reloadPage(){
	location.reload();
};
// Page layout variables
var	textbox_width=349;
var	textbox_height=249;
//set this for now
var picture_w=300;
var picture_h,picture_x,picture_y;
var rhs_x=400;
var lhs_x=50;
var rhs_xoffset=0;
var lhs_xoffset=0;
var yoffset=0;
var start_y=100;
var pageHasLoaded=false;
// Page Layout script
// global variables to hold cross browser objects for content
var contentObj,picObj,capObj,spObj;
// global variables to indicate whether certain parts of this page are present
function windowOnload(){
  //set which orientation we are doing the layout for
  var flip=(imageOnLeft=="undefined"||imageOnLeft==true)?false:true;
  /***********set up the text layer*************/
  //adjust x co-ordinate in line with screen size
  var as=(cbeInnerWidth()-((picture_w)+textbox_width));
  rhs_xoffset+=((as-299)>0)?(Math.floor((as-150)/150))*50:0;
  lhs_xoffset+=((as-199)>0)?(Math.floor((as-50)/150))*50:0;
  rhs_xoffset+=lhs_xoffset;
  rhs_x+=rhs_xoffset;
  lhs_x+=lhs_xoffset;
  //place the text layer on the page
  if(testCbe('contentLayer')){
    contentObj=cbeGetElementById('contentLayer').cbe;
    contentObj.width(textbox_width);
    if(contentObj.height()<textbox_height){
      contentObj.height(textbox_height);
    }else{
      var newHeight=contentObj.height()+(49-(contentObj.height()%50));
      contentObj.height(newHeight);
    }
    yoffset+=(cbeInnerHeight()>(contentObj.height()+150))?((Math.floor((cbeInnerHeight()-(contentObj.height()+150))/150))*50):0;
    var textbox_x=flip?lhs_x:rhs_x;
    var textbox_y=start_y+yoffset;
    contentObj.moveTo(textbox_x,textbox_y);
    contentObj.show();
  }
  /*********set up the picture and caption layers*********/
  var pic_bottom=0;
  if(testCbe('picture')){
    picObj=cbeGetElementById('picture').cbe;
    picture_w=picObj.width();
    picture_h=picObj.height();
    picture_x=flip?rhs_x:lhs_x+(300-picture_w);
    picture_y=start_y+yoffset;
    picObj.moveTo(picture_x,picture_y);
    picObj.show();
    pic_bottom+=(picture_y+picture_h);
  }
  if(testCbe('caption')){
    capObj=cbeGetElementById('caption').cbe;
    capObj.width(picture_w);
    capObj.height(50+(50-(picture_h%50)));
    var cap_x=picture_x;
    var cap_y=picture_y+picture_h;
    capObj.moveTo(cap_x,cap_y);
    capObj.zIndex(100);
    pic_bottom+=capObj.height();
  }
  //set up the sponsors layer
  if(testCbe('sponsors')){
    spObj=cbeGetElementById('sponsors').cbe;
    var sponsor_y=(cbeInnerHeight()-spObj.height());
    if(testCbe('contentLayer')){
      var text_bottom=contentObj.top()+contentObj.height();
      var bottom=(text_bottom>pic_bottom)?text_bottom:pic_bottom;
      if(sponsor_y<bottom){
        sponsor_y=bottom+25;
      }
    }
    var sponsor_x=(cbeInnerWidth()-spObj.width())-((cbeInnerWidth()-spObj.width())%50);
    spObj.width(cbeInnerWidth()-sponsor_x);
    spObj.height(cbeInnerHeight()-sponsor_y)
    spObj.moveTo(sponsor_x,sponsor_y);
    spObj.show();
  }
  window.cbe.addEventListener("resize", reloadPage, false);
  pageHasLoaded=true;
};
// CBE test function
function testCbe(divId){
  var testObj=cbeGetElementById(divId);
  return(testObj && testObj.cbe);
};

