function init() {
	resizeContent();
}


function resizeContent() {
	var leftColumn = document.getElementById('left-column');
	var contentWrap = document.getElementById('content-wrap');
	if(contentWrap && leftColumn) {
		var contentWrapHeight = contentWrap.offsetHeight;
		var leftColumnHeight = leftColumn.offsetHeight;
		if(contentWrapHeight <= (leftColumnHeight + 20) ) {
			contentWrap.style.height = leftColumnHeight + 40 + "px";
		}
	}
}


function popup(url, windowname, width, height, menue, scroller, resizable) {
	var sizeParams = '';
	if(width) {
		sizeParams += 'width=' + width + ',';
	}
	if(height) {
		sizeParams += 'height=' + height + ',';
	}

	newWindow = window.open(url, windowname, sizeParams + 'toolbar=0,location=0,directories=0,status=0,menubar=' + menue + ',scrollbars=' + scroller + ',resizable=' + resizable);
	newWindow.focus();
}

function show(elementId) {
	var element = document.getElementById(elementId);
	if(element) {
		element.style.display = 'block';
	}
}

function hide(elementId) {
	var element = document.getElementById(elementId);
	if(element) {
		element.style.display = 'none';
	}
}

function switchProductImage(number, newHref) {
	// Close all at first
	for(var i=1; i <= 10; i++) {
		hide('product-image-' + i);
	}
	
	// Show the selected image
	show('product-image-' + number);
	
	var zoomlink_1 = document.getElementById('zoomlink_1');
	var zoomlink_2 = document.getElementById('zoomlink_2');
	if(zoomlink_1 && zoomlink_2) {
		zoomlink_1.href = newHref;
		zoomlink_2.href = newHref;
	}
	
	return false;
}

/*
*	TabsController
*/

function tabsController() {
	this.controller = false;
	this.contentDivs = new Array;
	
	this.setController = TC_setController;
	this.setContentDivs = TC_setContentDivs;
	this.setActiveTabIndex = TC_setActiveTabIndex;
	this.initialize = TC_initialize;
	this.showDiv = TC_showDiv;
	this.setSimpleController = TC_setSimpleController;
	this.disableBlur = TC_disableBlur;
	this.checkAnchors = TC_checkAnchors;
}


function TC_setController(controllElement) {
	this.controller = controllElement;
}

function TC_setContentDivs(divs) {
	this.contentDivs = TC_setContentDivs.arguments;
}

function TC_initialize() {
	/*
	 * Hide all Divs, except the first one
	 */
	 for(var i=0; i < this.contentDivs.length; i++) {
	 	var div = document.getElementById(this.contentDivs[i]);
	 	if(div && i > 0) {
	 		div.style.display = 'none';
	 	}
	 }
	 	 
	 /*
	  * Create the Tab-Controller
	  */
 	 var rootElement = document.getElementById(this.controller);
 	 if(rootElement) {
		var as = rootElement.getElementsByTagName('a');
		for(var j=0; j < as.length; j++) {
			var a = as[j];
			if(a.className != 'notab') {
				a.setAttribute('control', this.contentDivs[j]);
				a.setAttribute('number', j);
				
				var owner = this;
				
				a.onclick = function() {
					owner.showDiv(this.getAttribute('control'));
					owner.setActiveTabIndex(this.getAttribute('number'));
					
					// Anpassen des InnerFrames
					if(typeof(resize_iframe) == 'function') {
						resize_iframe();
					}
					
					return false;
				};
			}	
			this.disableBlur(a);
		}
 	 }
 	 
 	 this.checkAnchors();
}

function TC_showDiv(divId) {
	
	/*
	 * Hide all Divs first
	 */
	 for(var i=0; i < this.contentDivs.length; i++) {
	 	var div = document.getElementById(this.contentDivs[i]);
	 	if(div) {
	 		div.style.display = 'none';
	 	}
	 }
	
	var div = document.getElementById(divId);
	if(div) {
		div.style.display = 'block';
	}
}

function TC_setActiveTabIndex(index) {
	var controller = document.getElementById(this.controller);
	if(controller) {
 		var lis = controller.getElementsByTagName('li');
		for(var i=0; i < lis.length; i++) {
			var li = lis[i];
			if(i == index) {
				li.className = 'active';
			} else {
				li.className = '';
		 	}
		}
	}
}

function TC_setSimpleController(id, contentId, index) {
	var rootElement = document.getElementById(id);
	if(rootElement) {
		var as = rootElement.getElementsByTagName('a');
		for(var j=0; j < as.length; j++) {
			var a = as[j];
			var owner = this;
						
			a.onclick = function() {
				owner.showDiv(contentId);
				owner.setActiveTabIndex(index);
				return false;
			};
			
			this.disableBlur(a);

		}
	}
}

function TC_disableBlur(e) {
	e.onfocus = function() {
		this.blur();
	};
}

function TC_checkAnchors() {
	var anchor = window.location.hash;
	if(anchor) {
		anchor = anchor.substr(1);
		for(var i=0; i < this.contentDivs.length; i++) {
			var actDiv = this.contentDivs[i];
			if(actDiv == anchor) {				
				this.showDiv(actDiv);
				this.setActiveTabIndex(i);
				break;
			}
		}
	}
}