CustomMarkerData = function(markerURL, markerWidth, markerHeight) {
  this.markerURL = null;
  this.markerWidth = null;
  this.markerHeight = null;
}

AnimationData = function(animateIconUrl, animationSpeed, animateIconWidth, animateIconHeight) {
  this.animateIconUrl = null; 
  this.animationSpeed = null;
  this.animateIconWidth = null; 
  this.animateIconHeight = null;
}

DynamicTheme = function(name, themeName, visible, mapviewObject, markerURL, markerWidth, markerHeight, parameters, description, extraOptions, factoryObj) {
  if (extraOptions == null) extraOptions = new Array();
  
  this.name = name;
  this.themeName = themeName;
  this.visible = visible;
  this.mapviewObject = mapviewObject;
  this.customMarkerData = new CustomMarkerData(markerURL, markerWidth, markerHeight);
  this.themeQueryParameters = parameters;
  this.description = description;
  this.layerRefreshable = extraOptions["layerRefreshable"];
  this.bringToTopOnMouseOver = extraOptions["bringToTopOnMouseOver"];
  this.enableInfoWindow = extraOptions["enableInfoWindow"];
  this.enableLabeling = extraOptions["enableLabeling"];
  this.labelAttrName = extraOptions["labelAttrName"];
  this.themeObject = null;
  this.recordCount = null;
  this.themeLabels = new Array();
  this.enableConnectFOIs = extraOptions;
  this.connectFOIStyle = extraOptions["connectFOIStyle"];
  this.themeConnectLineObj = null;
  this.enableAnimation = extraOptions["enableAnimation"];
  this.animationData = new AnimationData(null, null, null, null);
  this.themeConnectLineGeometry = null;
  this.labelingActive = false;
  this.connectingActive = false;
  this.centerThemeDuringRefresh = false;
  this.customInfoWindowFunction = null;
  this.refreshRequester = null;
  this.lineStartPointStyle = extraOptions["lineStartPointStyle"];
  this.lineEndPointStyle = extraOptions["lineEndPointStyle"];
  this.factoryObj = factoryObj;    
  
  if (visible)
    this.populateThemeObject();
}

DynamicTheme.prototype.populateThemeObject = function() {
  var theme = this.mapviewObject.getThemeBasedFOI(this.name);
  this.mapviewObject.removeThemeBasedFOI(theme);
  theme = new MVThemeBasedFOI(this.name, this.themeName, null);
  var simpleParameterArray = this.factoryObj.convertToSimpleArray(this.themeQueryParameters)

  if (simpleParameterArray.length == 2) {
    theme.setQueryParameters(simpleParameterArray[0], simpleParameterArray[1]);
  } else if (simpleParameterArray.length == 1) {
    theme.setQueryParameters(simpleParameterArray[0]);
  } else if (simpleParameterArray.length == 3) {
    theme.setQueryParameters(simpleParameterArray[0], simpleParameterArray[1], simpleParameterArray[2]);
  } else if (simpleParameterArray.length == 4) {
    theme.setQueryParameters(simpleParameterArray[0], simpleParameterArray[1], simpleParameterArray[2], simpleParameterArray[3]);
  } else if (simpleParameterArray.length == 5) {
    theme.setQueryParameters(simpleParameterArray[0], simpleParameterArray[1], simpleParameterArray[2], simpleParameterArray[3], simpleParameterArray[4]);
  }
  
  theme.setInfoWindowStyle("MVInfoWindowStyle2");
  this.themeObject = theme;
  this.setBringToTopOnMouseOver(this.bringToTopOnMouseOver);
  this.setVisible(this.visible);
  this.setEnableInfoWindow(this.enableInfoWindow);
  theme.setClickable(false);
  
  if (this.customInfoWindowFunction != null) {
    this.themeObject.addEventListener("mouse_right_click", this.customInfoWindowFunction);
  }
  
  this.mapviewObject.addThemeBasedFOI(theme);

  return this;  
}

DynamicTheme.prototype.setVisible = function(visible) {
  if ((this.themeObject != null) && (visible != null))
    this.themeObject.setVisible(visible);
  this.visible = visible;
}

DynamicTheme.prototype.setEnableInfoWindow = function(enable) {
  if ((this.themeObject != null) && (enable != null))
    this.themeObject.enableInfoWindow(enable);
  this.enableInfoWindow = enable;
}

DynamicTheme.prototype.setBringToTopOnMouseOver = function(enable) {
  if ((this.themeObject != null) && (enable != null)) 
    this.themeObject.setBringToTopOnMouseOver(enable);
  this.bringToTopOnMouseOver = enable;
}

DynamicTheme.prototype.gotoThemeBounds = function() {
  if (this.themeObject != null) {
    this.refreshRequester = "gotoBounds";
    this.themeObject.refresh(true);
  }
}

DynamicTheme.prototype.addEventListener = function(event_name, callback) {
  if (this.themeObject != null) 
    this.themeObject.addEventListener(event_name, callback);
}

DynamicTheme.prototype.removeThemeBasedFOI = function() {
  if (this.themeObject != null) 
    this.mapviewObject.removeThemeBasedFOI(this.themeObject);
}


