/*
 * Copyright 2006 OST-SYSTEMS. All rights reserved.
 */

var ICON_WIDTH = 80;
var MobileWindow = new Object();

function setupWindow() {
  
}

function addError(error) {
  widgetContext.addError(error);
}

function clearErrors() {
  widgetContext.clearError();
}

function clearStorage() {
  keyStorage.setStorage(new Array());
  selectedWidgetId = null;
}

function addWidget(id, plist, widgetPath) {  
  singleWidgetId = id;  
  var path = widgetsPath + widgetPath + "/";
  var widgets = document.getElementById("Widgets");
  var widget = document.createElement("div");
  var widgetId = widgetIdPrefix + id;
  widget.setAttribute("class", "widget");
  widget.setAttribute("id", widgetId);
  widget.setAttribute("onmouseover", "widgetMouseOver(this);");
  widget.setAttribute("onmouseout", "widgetMouseOut(this);");
  if (widgetsHelper.getWidgetValue(id, "top")) {
    widget.style.top = widgetsHelper.getWidgetValue(id, "top");
    widget.style.left = widgetsHelper.getWidgetValue(id, "left");
  }  
  widgets.appendChild(widget);
  
  var widgetBorder = document.createElement("div");
  widgetBorder.setAttribute("class", "widgetBorder");
  widgetBorder.setAttribute("id", "Border" + widgetId);
  if (myBrowser.isIFrameHidden) {
    widgetBorder.style.visibility = "visible";
  }
  widget.appendChild(widgetBorder);

  var defaultImage = document.createElement("img");
  defaultImage.setAttribute("class", "widgetDefaultImage");
  defaultImage.setAttribute("id", "DefaultImage" + widgetId);
  if (true || myBrowser.isIE) {
    defaultImage.onload = function() {
    //not called by IE
      addFrame(widget, plist, path, defaultImage, widgetBorder);
    };
  }  
  defaultImage.setAttribute("src", path + "Default.png");
  widgetBorder.appendChild(defaultImage);  
    
  var loadingImage = document.createElement("img");
  loadingImage.setAttribute("class", "widgetLoading");
  loadingImage.setAttribute("id", "LoadingImage" + widgetId);
  loadingImage.setAttribute("src", "images/loading.gif");
  widgetBorder.appendChild(loadingImage);  
    
  widgetToFront(widget);
  addWidgetTitle(id, getPListName(plist));
  if (plist.AllowNetworkAccess || plist.AllowFullAccess) {
    widgetsHelper.storeWidgetKey(id, "HasNetworkAccess", true);
  }
  if (false && myBrowser.isIE) {
    addFrame(widget, plist, path, defaultImage, widgetBorder);
  }
}

function addWidgetTitle(id, title) {
}

function widgetMouseOver(widget) {
}

function widgetMouseOut(widget) {
}

function widgetBorderHide(widget) {
}

function widgetBorderShow(widget) {
}

function widgetClose(widgetId) {
  var widget = document.getElementById(widgetId);
  var w = getWidget(widget);
  if (w.onremove) {
    w.onremove();
  }
  widget.parentNode.removeChild(widget);
  if (iconifyToDock) {
    var dockIcon = document.getElementById("DockIcon" + widgetId);
    dockIcon.parentNode.removeChild(dockIcon);
  }  
  widgetsHelper.removeWidget(getWidgetId(widget));
}

function hideAllWidgets() {
  var widgets = document.getElementById("Widgets");
  for (var i = 0; i < widgets.childNodes.length; i++) {
  	var w = getWidget(widgets.childNodes[i]);
  	if (w && w.onhide ) {
  	  w.onhide();
  	}
  }
}

function getWidgetId(element) {
  var index = element.id.indexOf(widgetIdPrefix);
  return element.id.substring(index + widgetIdPrefix.length);
}

function widgetResized(frame) {
}

function restoreFavouritesDock() {}  