﻿// ImageZoom - Begin

function OpenPictureLayer(divImageZoom, ImageID, ImageTagID, pfad) {
    d = document.getElementById(divImageZoom);
    d.style.visibility = 'visible';

    var flashvars = {};
    var params = {};
    params.menu = "false";
    params.quality = "high";
    var attributes = {};
    swfobject.embedSWF("/flash/imagezoom/ProCompImageZoom.swf?ImagePath=/ImageZoom/" + ImageID + "/", "FlashImageZoomLayer", "810px", "400px", "9.0.0", false, flashvars, params, attributes);
    if (document.images[ImageTagID] == '[object]') document.images[ImageTagID].src = pfad;
}
function ClosePictureLayer(divImageZoom, FlashImageZoomLayer) {

    d = document.getElementById(divImageZoom);
    d.style.visibility = 'hidden';

    e = document.getElementById(FlashImageZoomLayer);
    e.style.visibility = 'hidden';
}

// ImageZoom - End

function OpenExternLayer(name) {

    d = document.getElementById(name);
    d.style.visibility = 'visible';
    sW = screen.width;
    sH = screen.height;
    oW = d.offsetWidth;
    oH = d.offsetHeight;

    d.style.left = '100px'; //sW / 2 - oW / 2 + 'px';
    d.style.top = '400px'; //sH / 2 - oH / 2 + 'px';
}

function CloseExternLayer(name) {
    d = document.getElementById(name);
    d.style.visibility = 'hidden';
}

function OpenExternLayerNewsletter(name) {

    d = document.getElementById(name);
    d.style.visibility = 'visible';
    sW = screen.width;
    sH = screen.height;
    oW = d.offsetWidth;
    oH = d.offsetHeight;

    d.style.left = '100px'; //sW / 2 - oW / 2 + 'px';
    d.style.top = '0px'; //sH / 2 - oH / 2 + 'px';
}

function OpenExternLayerUnvalidArticle(name) {

	d = document.getElementById(name);
	d.style.visibility = 'visible';
	sW = screen.width;
	sH = screen.height;
	oW = d.offsetWidth;
	oH = d.offsetHeight;

	d.style.left = '0px'; //sW / 2 - oW / 2 + 'px';
	d.style.top = '200px'; //sH / 2 - oH / 2 + 'px';
}

function CloseExternLayerNewsletter(name) {
    d = document.getElementById(name);
    d.style.visibility = 'hidden';
   }

   function TabPanelParameters(tabPrefix, panelPrefix, tabCount, enableTimers) {
   	this.tabOverTimer = undefined;
   	this.tabOutTimer = undefined;
   	this.panelOutTimer = undefined;
   	this.fixedPanelId = undefined;
   	this.displayedPanelId = undefined;
   	this.tabCount = tabCount;
   	this.tabPrefix = tabPrefix;
   	this.panelPrefix = panelPrefix;
   	this.enableTimers = enableTimers,
    this.timerDelay = 1000;
   	this.onSelectedIndexChanged = undefined;

   	this.merge = function (parameters) {
   		this.mergeProperty(parameters, 'tabCount');
   		this.mergeProperty(parameters, 'tabPrefix');
   		this.mergeProperty(parameters, 'panelPrefix');
   		this.mergeProperty(parameters, 'enableTimers');
   		this.mergeProperty(parameters, 'timerDelay');
   		this.mergeProperty(parameters, 'onSelectedIndexChanged');
   	}

   	this.mergeProperty = function (parameters, propertyName) {
   		//alert(propertyName);
   		var propertyValue = eval('parameters.' + propertyName);
   		if (propertyValue != undefined) {
   			eval('this.' + propertyName + ' = parameters.' + propertyName);
   		}
   	}
   }

   function TabPanel(params) {
   	this.initParams = params;
   	this.p = new TabPanelParameters(); //new TabPanelParameters(tabPrefix, panelPrefix, tabCount, enableTimers);

   	this.initialize = function () {
   		this.p.merge(this.initParams);
   		for (var i = 1; i <= this.p.tabCount; i++) {
   			var tabId = this.p.tabPrefix + i.toString();
   			var panelId = this.p.panelPrefix + i.toString();
   			var instance = this;

   			jQuery('#' + tabId).click(function () { instance.tab_OnClick(this); });
   			jQuery('#' + tabId).mouseover(function () { instance.tab_OnMouseOver(this); });
   			jQuery('#' + tabId).mouseout(function () { instance.tab_OnMouseOut(this); });

   			jQuery('#' + panelId).mouseover(function () { instance.panel_OnMouseOver(); });
   			jQuery('#' + panelId).mouseout(function () { instance.panel_OnMouseOut(); });

   			if (jQuery('#' + panelId).attr('defaultPanel') == 'defaultPanel') {
   				this.p.fixedPanelId = panelId;
   			}

   			var subPanelId = jQuery('#' + panelId).attr('subPanelId');
   			if (subPanelId != undefined && jQuery('#' + subPanelId).attr('subPanelInitialized') == undefined) {
   				jQuery('#' + subPanelId).mouseover(function () { instance.panel_OnMouseOver(); });
   				jQuery('#' + subPanelId).mouseout(function () { instance.panel_OnMouseOut(); });
   				jQuery('#' + subPanelId).attr('subPanelInitialized', 'true');
   			}
   		}

   		if (this.p.fixedPanelId == undefined && this.p.tabCount > 0) {
   			this.showPanel(this.p.panelPrefix + '1', true);
   		}
   		else if (this.p.fixedPanelId != undefined) {
   			this.showPanel(this.p.fixedPanelId, true);
   		}
   	}

   	this.hideAllPanels = function () {
   		for (var i = 1; i <= this.p.tabCount; i++) {
   			jQuery('#' + this.p.panelPrefix + i.toString()).css("display", "none");

   			var subPanelId = jQuery('#' + this.p.panelPrefix + i.toString()).attr('subPanelId');
   			if (subPanelId != undefined) {
   				jQuery('#' + subPanelId).css("display", "none");
   			}
   		}
   	}

   	this.showPanel = function (elementId, fixIt) {
   		var lastSelectedIndex = 0;
   		if (this.p.displayedPanelId != undefined) {
   			lastSelectedIndex = eval(this.p.displayedPanelId.replace(this.p.panelPrefix, ''));
   		}
   		var selectedIndex = eval(elementId.replace(this.p.panelPrefix, ''));

   		this.hideAllPanels();
   		jQuery('#' + elementId).css("display", "block");
   		this.p.displayedPanelId = elementId;

   		var subPanelId = jQuery('#' + elementId).attr('subPanelId');

   		if (subPanelId != undefined) {
   			jQuery('#' + subPanelId).css("display", "block");
   		}

   		if (fixIt) {
   			this.p.fixedPanelId = elementId;
   		}

   		this.clearMouseOutTimers();

   		if (this.p.onSelectedIndexChanged != undefined) {
   			this.p.onSelectedIndexChanged(lastSelectedIndex, selectedIndex);
   		}
   	}

   	this.clearMouseOutTimers = function () {
   		if (this.p.panelOutTimer != undefined) {
   			clearTimeout(this.p.panelOutTimer);
   			this.p.panelOutTimer = undefined;
   		}

   		if (this.p.tabOutTimer != undefined) {
   			clearTimeout(this.p.tabOutTimer);
   			this.p.tabOutTimer = undefined;
   		}
   	}

   	this.tab_OnClick = function (element) {
   		var i = element.id.replace(this.p.tabPrefix, '');
   		this.showPanel(this.p.panelPrefix + i, true);
   	}

   	this.tab_OnMouseOver = function (element) {
   		var i = element.id.replace(this.p.tabPrefix, '');
   		var instance = this;

   		if (this.p.enableTimers) {
   			this.p.tabOverTimer = setTimeout(function () { instance.showPanel(instance.p.panelPrefix + i, false) }, this.p.timerDelay);
   		}

   		this.clearMouseOutTimers();
   	}

   	this.tab_OnMouseOut = function (element) {
   		var i = element.id.replace(this.p.tabPrefix, '');
   		var instance = this;
   		clearTimeout(this.p.tabOverTimer);

   		if (this.p.fixedPanelId != this.p.panelPrefix + i) {
   			if (this.p.enableTimers) {
   				this.p.tabOutTimer = setTimeout(function () { instance.showPanel(instance.p.fixedPanelId, false) }, this.p.timerDelay);
   			}
   		}
   	}

   	this.panel_OnMouseOut = function () {
   		var instance = this;

   		if (this.p.enableTimers) {
   			this.p.panelOutTimer = setTimeout(function () { instance.showPanel(instance.p.fixedPanelId, false) }, this.p.timerDelay);
   		}
   	}

   	this.panel_OnMouseOver = function () {
   		this.clearMouseOutTimers();
   	}
   }

