//function installImageSwitcher(id) {
function installImageSwitcher(id, _flavor) {
	var e = document.getElementById(id);
	e.onmouseover = function() {
//		this.src = "../img/navi_" + this.id + "_over.gif";
		this.src = "../img" + _flavor + "/navi_" + this.id + "_over.gif";
	};
	
	e.onmouseout = function() {
		if(this.className.indexOf("down") == -1) {
//			this.src = "../img/navi_" + this.id + ".gif";
			this.src = "../img" + _flavor + "/navi_" + this.id + ".gif";
		} else {
//			this.src = "../img/navi_" + this.id + "_down.gif";
//			this.src = "../img/navi_" + this.id + "_over.gif";
			this.src = "../img" + _flavor + "/navi_" + this.id + "_over.gif";
		}
	};
  img = new Image();
//	img.src = "../img/navi_" + id + "_over.gif";
	img.src = "../img" + _flavor + "/navi_" + id + "_over.gif";
}

//function init() {
function init(_flavor) {
	installImageSwitcher('news', _flavor);
	installImageSwitcher('products', _flavor);
	installImageSwitcher('services', _flavor);
	installImageSwitcher('downloads', _flavor);
	installImageSwitcher('company', _flavor);
	installImageSwitcher('contact', _flavor);
}

function openWindow(url, width, height) {
	window.open(url, url, "width="+width+",height="+height);
}

function y_getBrowserInfo() {
  var agent_ = navigator.userAgent.toLowerCase();
  this.major = parseInt(navigator.appVersion);
  this.minor = parseFloat(navigator.appVersion);
  
  this.ns  = ((agent_.indexOf('mozilla')!=-1) && ((agent_.indexOf('spoofer')==-1) && (agent_.indexOf('compatible') == -1)));
  this.ns2 = (this.ns && (this.major == 2));
  this.ns3 = (this.ns && (this.major == 3));
  this.ns4 = (this.ns && (this.major >= 4)); // (document.layers);
  
  this.ie   = (agent_.indexOf("msie") != -1);
  this.ie3  = (this.ie && (this.major == 2));
  this.ie4  = (this.ie && (this.major >= 4)); // (document.all);
  
  this.op3 = (agent_.indexOf("opera") != -1);
  
  this.hasLayers = (this.ns4 || this.ie4);
}

var is_browser_ = new y_getBrowserInfo();

function y_openCenteredWindow(url_string_, width_, height_, title_, status_) {
  if (y_openCenteredWindow.arguments.length < 5) {
    status_ = "toolbar=0,location=no,directories=0,status=0,menubar=0,scrollbars=1,resizable=1";
  }
  
  if (this.m_window != null)
  {
    if (this.m_window.close != null)
    {
      this.m_window.close();
    }
  }
  
  this.m_window = window.open(url_string_, "_blank", status_+",innerWidth="+width_+",innerHeight="+height_);

  if (this.m_window == null)
  {
    return null;
  }
  
  //this.m_window.document.title = title_;
  
  if (this.m_window.opener == null)
  {
    this.m_window.opener = window;
  }
  this.m_window.opener.name = "centered_window";
  
  if (this.m_window.blur)
  {
    this.m_window.blur();
  }
  
  if (this.m_window.moveTo)
  {
    this.m_window.moveTo((screen.availWidth - width_) / 2,(screen.availHeight - height_) / 2);
  }
  
  if (is_browser_.ns4)
  {
    this.m_window.moveTo((screen.availWidth - this.m_window.outerWidth) / 2,(screen.availHeight - this.m_window.outerHeight) / 2);
  }
  
  if (this.m_window.focus)
  {
    this.m_window.focus();
  }
  
  this.m_is_closed = false;
  
  return this.m_window;
}

function y_closeCenteredWindow() {
  if (this.m_is_closed == false && this.m_window.close != null)
  {
    this.m_window.close();
    this.m_is_closed = true;
  }
}

function y_focusCenteredWindow() {
  if (this.m_is_closed == false && this.m_window.focus != null)
  {
    this.m_window.focus();
  }
}

function y_createCenteredWindow() {
  this.m_window = null;
  this.m_is_closed = true;
  
  this.openWindow = y_openCenteredWindow;
  this.closeWindow = y_closeCenteredWindow;
  this.focusWindow = y_focusCenteredWindow;
}

////////////////////////////////////////////////////////////////////////////////
function ImageViewer() {
  this.popup = null;
  this.images = new Array();
  this.currIndex = 0;
  
  this.openViewer = IV_openViewer;
  this.getImageIndex = IV_getImageIndex;
  this.initImageData = IV_initImageData;
  this.showPrevious = IV_showPrevious;
  this.showNext = IV_showNext;
  
  this.initImageData();
}

function IV_initImageData() {
  this.images[0] = new ImageData("circular_bcc_compact.png", "Circular Layout");
  this.images[1] = new ImageData("circular.png", "Circular Layout");
  this.images[2] = new ImageData("hierarchic_1.png", "Hierarchic Layout");
  this.images[3] = new ImageData("hierarchic_2.png", "Hierarchic Layout");
  this.images[4] = new ImageData("tree_balloon_3.gif", "Treelike Layout");
  this.images[5] = new ImageData("tree_directed_3.png", "Treelike Layout");
  
  for (i = 0; i < this.images.length; i++) {
    this.images[i].addDescription("<p>Blabla</p>");
    this.images[i].addURLPrefix("../img/gallery/");
  }
}

function IV_getImageIndex(imageName_) {
  var result = -1;
  for (i = 0; i < this.images.length; i++) {
    if (imageName_ == this.images[i].imageName) {
      result = i;
      break;
    }
  }
  
  return result;
}

function IV_openViewer(imageName_, width_, height_) {
  if (this.popup != null) {
    if (this.popup.close != null) {
      this.currIndex = IV_getImageIndex(imageName_);
      showImage();
      this.popup.document.title = "Showing " + imageName_;
      
      if (this.popup.focus) {
        this.popup.focus();
      }
      
      return this.popup;
    }
  }
  
  status_ = "toolbar=0,location=no,directories=0,status=0,menubar=0,scrollbars=1,resizable=1";
  this.popup = window.open("_imageviewer.htm", "_blank", status_ + ",innerWidth=" + width_ + ",innerHeight=" + height_);
  
  if (this.popup == null) {
    return null;
  }
  
  this.popup.document.title = "Image Viewer";
  
  if (this.popup.opener == null) {
    this.popup.opener = window;
  }
  this.popup.opener.name = "ImageViewer";
  
  if (this.popup.blur) {
    this.popup.blur();
  }
  
  if (this.popup.moveTo) {
    this.popup.moveTo((screen.availWidth - width_) / 2,(screen.availHeight - height_) / 2);
  }
  
  if (is_browser_.ns4) {
    this.popup.moveTo((screen.availWidth - this.popup.outerWidth) / 2,(screen.availHeight - this.popup.outerHeight) / 2);
  }
  
  if (this.popup.focus) {
    this.popup.focus();
  }
  
  return this.popup;
}

function IV_showImage() {
  var image = this.popup.getElementById('image');
  image.src = this.images[this.currIndex].URL;
  var desc = this.popup.getElementById('description');
  description.data = this.images[this.currIndex].description;
}

function IV_showPrevious() {
  this.currIndex--;
  if (this.currIndex < 0) {
    this.currIndex = this.images.length;
  }
  showImage();
}

function IV_showNext() {
  this.currIndex++;
  if (this.currIndex > this.images.length) {
    this.currIndex = 0;
  }
  showImage();
}

function ImageData(imageName_, heading_) {
  this.imageName = imageName_;
  this.URL = null;
  this.heading = heading_;
  this.description = null;
  
  this.addURLPrefix = ID_addURLPrefix;
  this.addDescription = ID_addDescription;
}

function ID_addDescription(description_) {
  this.description = description_;
}

function ID_addURLPrefix(prefix_) {
  this.URL = prefix_ + this.imageName;
}

////////////////////////////////////////////////////////////////////////////////
function ImageViewerContainer() {
  this.popup = null;
  
  this.openContainer = IVC_openContainer;
  this.initDocument = IVC_initDocument;
}

function IVC_openContainer(imageName_, album_, width_, height_) {
  alreadyOpened = 0;
  if (this.popup != null) {
    if (this.popup.name == "IVC") {
      alreadyOpened = 1;
    }
  }
  
  var winLeft = (screen.availWidth - width_ ) / 2;
  var winTop = (screen.availHeight - height_ ) / 2;
  
  status_ = "toolbar=0,location=no,directories=0,status=0,menubar=0,scrollbars=1,resizable=1";
//  this.popup = window.open('', "_blank", status_ + ",innerWidth=" + width_ + ",innerHeight=" + height_);
  this.popup = window.open("imageviewer.php?img="+imageName_+"&album="+album_+"&maxWidth="+(width_-70)+"&maxHeight="+(height_+60), "IVC", status_ + ",innerWidth=" + width_ + ",innerHeight=" + height_ + ",width=" + width_ + ",height=" + height_  + ",left=" + winLeft + ",top=" + winTop );
  
  if (this.popup == null) {
    return null;
  }
  
//  this.initDocument(imageName_);
/*
  var d = this.popup.document;
  
  d.close();
  d.open();
  d.writeln("<html><title>IVC</title>\n<script type=\"text/javascript\" src=\"../imageviewer.js\"></script>");
  d.writeln("<body onload=\"initIV(\'" + imageName_ + "\');\">");
  d.writeln("</body></html>");
  d.close();*/
  
  if (this.popup.opener == null) {
    this.popup.opener = window;
  }
  this.popup.opener.name = album_;
  
  if (alreadyOpened == 0) {
    if (this.popup.blur) {
      this.popup.blur();
    }
    if (this.popup.moveTo) {
      if (is_browser_.ns4) {
        this.popup.moveTo((screen.availWidth - this.popup.outerWidth) / 2,(screen.availHeight - this.popup.outerHeight) / 2);
      }
      else {
        this.popup.moveTo((screen.availWidth - width_) / 2,(screen.availHeight - height_) / 2);
      }
    }
  }
  if (this.popup.focus) {
    this.popup.focus();
  }
  
  return this.popup;
}

function IVC_initDocument(imageName_) {
  var d = this.popup.document;
  d.close();
  d.open();
  
  d.writeln("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" "); 
  d.writeln("\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
  d.writeln("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en-US\">");
  d.writeln("<head><title>yFiles Gallery Image Viewer</title>");
  d.writeln("<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\"/>");
  d.writeln("<link rel=\"stylesheet\" type=\"text/css\" href=\"../imageviewer.css\"/>");
  d.writeln("<script type=\"text/javascript\" src=\"../imageviewer.js\"></script>");
  d.writeln("</head>");
  d.writeln("<body onload=\"initIV(\'" + imageName_ + "\');\">");
  d.writeln("<div style=\"text-align:center\">");
  d.writeln("<table>");
  d.writeln("<tr>");
  d.writeln("<td style=\"text-align:left\">");
  d.writeln("<a href=\"#\" onclick=\"var iv = getIV(); iv.showPrevious(); return false;\">previous...</a>");
  d.writeln("</td>");
  d.writeln("<td style=\"text-align:center\">");
  d.writeln("image <span id=\"currImage\"></span> of <span id=\"numImages\"></span>");
  d.writeln("</td>");
  d.writeln("<td style=\"text-align:right\">");
  d.writeln("<a href=\"#\" onclick=\"var iv = getIV(); iv.showNext(); return false;\">next...</a>");
  d.writeln("</td>");
  d.writeln("</tr>");
  d.writeln("</table>");
  d.writeln("</div>");
  d.writeln("<p style=\"text-align:center\">");
  d.writeln("<img id=\"galleryImage\" src=\"\" alt=\"\"/>");
  d.writeln("</p>");
  d.writeln("<div id=\"imageDesc\"></div>");
  d.writeln("</body>");
  d.writeln("</html>");
  
  d.close();
}

