
var resetSubmenu              = false;
var hideSubmenuProductsVar    = false;
var goBack                    = false;

document.observe('dom:loaded', function() {
	
	// Positionate the photoalbum div in the middle
	// Calculate left offset
	if($('menu_products')) {
    $('menu_products').setStyle({top: "0px"});			
	}
});


/* Show the submenu products bar */
function showSubMenuProducts() {

			if($('submenu_products').getStyle("position") == "absolute") {
				var wi = "715px";
				var top  = "38px";
				var left = "275px";	
				
      $('submenu_products').setStyle({top: top,
                               left: left, width: wi});
			}
    if(!$('submenu_products').visible()) {
      $('submenu_products').appear({duration: 0.2, queue: 'parallel'});
    }
}

/* Hide the submenu products bar */
function hideSubmenuProducts() {
  setTimeout( function f(){
    if(hideSubmenuProductsVar == true) {
      $('submenu_products').fade({duration: 0.2, queue: 'parallel', 
                                     afterFinish: deselectItemMenuProducts() });
    }
  }, 2250);
}

/* Mark the given item as selected */
function selectItemMenuProducts(item) {
  item.addClassName('selected');
  $('menu_products').descendants().each(function(s) {
    if(s != item && s.hasClassName('selected'))
      s.removeClassName('selected');
  });  
}

/* Mark the given item as no selected */
function deselectItemMenuProducts() {
  $('menu_products').descendants().each(function(s) {
    if(s.hasClassName('selected'))
      s.removeClassName('selected');
  });  
}

/* Center the suboptions onder the principal option */
function centerSubMenu(parentItem) {

  setTimeout(function f(){
  var dimParent = parentItem.getDimensions();
  var coParent  = parentItem.cumulativeOffset();
  
  var dimsubmenu_products = $('submenu_products').getDimensions();
  var cosubmenu_products  = $('submenu_products').cumulativeOffset();
  
  var dimSubsubmenu = $('submenu_content').getDimensions();
  var coSubsubmenu  = $('submenu_content').cumulativeOffset();  

 
  if($('submenu_content')) {
      var centred = coParent.left - $('submenu_products').cumulativeOffset().left - 24 - ( ((dimSubsubmenu.width-24)/2) - (dimParent.width) /2 );
      if(centred < 0) {
        $('submenu_content').setStyle({left: 0 +'px'});
      } else if( $('submenu_content').getDimensions().width + centred > $('options_container').getDimensions().width ) {
        centred -= $('submenu_content').getDimensions().width + centred - $('options_container').getDimensions().width;
        if(centred <= 0)
          $('submenu_content').setStyle({left: 0 +'px'});
        else 
          $('submenu_content').setStyle({left: centred +'px'});          
      } else {
        $('submenu_content').setStyle({left: centred +'px'});
      }
			$('submenu_content').show();
    }
  }, 50);
  showScroll();
}

function showScroll() {

  setTimeout(function f() {
  var parent    = $('options_container');
  var options   = $('submenu_content');
  
  if(!(parent && options))
    return;
  
  var parentDim  = parent.getDimensions();
  var parentCo   = parent.cumulativeOffset();
  
  var optionsDim = options.getDimensions();
  var optionsCo  = options.cumulativeOffset();
 
  // Show scroll right if content outside of right boundary
  optionsRightBoundary = optionsCo.left + optionsDim.width;
  parentRightBoundary  = parentDim.width + parentCo.left;

//  alert (optionsRightBoundary+' '+parentRightBoundary);
//  alert($('submenu_content').cumulativeOffset().left +' '+$('options_container').cumulativeOffset().left);
  
  if(optionsRightBoundary > parentRightBoundary) {
    $$('img.scroll_right').each( function(e){e.show();});
  } else if(optionsRightBoundary <= parentRightBoundary) {
    $$('img.scroll_right').each( function(e){e.hide();});
  }
  
  if($('submenu_content').cumulativeOffset().left < 
                              $('options_container').cumulativeOffset().left ) {
    $$('img.scroll_left').each( function(e){e.show();});
  } else if( $('submenu_content').cumulativeOffset().left >= 
                             $('options_container').cumulativeOffset().left ) {
    $$('img.scroll_left').each( function(e){e.hide();});
  }
  }, 100);
}

function scroll(direction) {
  var options   = $('submenu_content');

  var co = $('submenu_content').cumulativeOffset();
  var dim = $('submenu_content').getDimensions();
  
  var cop = $('submenu_products').cumulativeOffset();
  var dimp = $('submenu_products').getDimensions();

  if(direction == 'right')
    var v = co.left - cop.left - 150;
  else if(direction == 'left')
    var v = co.left - cop.left + 150;    
  new Effect.Morph('submenu_content', {
  style: 'left: '+v+'px;', 
  duration: 0.3 , afterFinish: showScroll()});
}

function printPage(logo, content) {
    var newWindow = window.open("", null, "height=600,width=800,status=yes,toolbar=no,menubar=no,location=no, scrollbars=yes");
    var copy = Object.clone(content);
    
    var html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"";
        html += " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
        html += "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head> \
                 <meta http-equiv=\"Content-Type\" content=\"text/html; \
                 charset=iso-8859-1\" />";
    html += "<title>Verhaar Omega</title><link rel=\"stylesheet\" type=\"text/css\" href=\"http://www.verhaar.com/public/stylesheets/print.css\"></head>";
    html += "<body style='padding-left: 30px; padding-right: 30px;' onload='javascript:window.print();'>";
//    html += "<body >";
    
    html += "<div style='width: 600;'>";
    html += "<div style='border-bottom: solid 1px #747060; text-align: left; width: 100%; padding-bottom: 10px;'>";    
    html += logo.innerHTML;
    html += "</div><br />";
        
    html += copy.innerHTML;
    
    html += "</div>";
    
    html += "<div id='address' style='color: #747060;'>Verhaar - P.O. Box 119 - NL-2340 AC - Oegstgeest - T: +31(0)71-71 517 26 31- M: info@verhaar.com - I: www.verhaar.com</div>"
    html += "</body>";
    html += "</html>";
   
    newWindow.document.open()
    newWindow.document.write(html)
    newWindow.document.close()
}

function showPic(img) {
		var o = new Image();
		o.src = img;
    var newWindow = window.open("", null, "height=690,width=1014,status=yes,toolbar=no,menubar=no,location=no, scrollbars=auto");
    var html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"";
        html += " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
        html += "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head> \
                 <meta http-equiv=\"Content-Type\" content=\"text/html; \
                 charset=iso-8859-1\" /></head>";
				html += "<style type=\"text/css\"> "+
								"<!-- BODY {  margin : 0px; } -->"+
								"</style>";
		    html += "<body>";
				html += "<a href='javascript:self.close();' style='text-align: center;'>";
		    html += "<img style='border: none;' alt=\"Click Image to Close\" src='"+img+"' /></a>";
		    html += "</body>";
		    html += "</html>";
   
    newWindow.document.open();
    newWindow.document.write(html);
	  setTimeout(function() {
	    newWindow.resizeTo(o.width, o.height+62);}, 100);
    newWindow.document.close()
    newWindow.moveTo((document.viewport.getWidth()-1014)/2, 0);
}


