// WaitBox
function getElem(ename) {
	if (document.all) return document.all[ename];
	if (document.getElementById) return document.getElementById(ename);
}
function waitingBox(ref) {
	var elem = getElem('waitbox2');
	if (!ref || ref.indexOf('javascript')<0) {
		clickfirst = false;
		document.body.style.cursor = 'wait';
		var ie6 = (document.all && !window.opera && !window.XMLHttpRequest) ? true : false;
		elem.style.zIndex='999';
		var height = 0;
		var width = 0;
		if (ie6) {
			var elements = document.body.getElementsByTagName('select');
			for (var i = 0; i < elements.length; i++) {
				elements[i].disabled='disabled';
			}
		}
		if (!window.opera) {
			height = document.body.clientHeight;
		} else {
			height = document.documentElement.clientHeight;
		}
		elem.style.margin='0';
		elem.style.height=height+'px';
		elem.style.visibility='visible';
	}
}
// supraheader lang dropdown
var t1,r1;
function clangT(){clearTimeout(t1);}
function langT(){clangT();t1 = setTimeout('langClose();', 2000);}
function langOpen(){jQuery('#sh-LangsItems').slideDown('fast');}
function langOifH(){clangT();if(jQuery('#sh-LangsItems').is(':hidden')){langOpen();}}
function langClose(){jQuery('#sh-LangsItems').slideUp('fast');}
function langToggle(event){if(this == event.target){if(jQuery('#sh-LangsItems').is(':hidden')){langOpen();}else{langClose();}}}
var langDropdown = {init : function(){
	jQuery('#sh-LangsCaption').bind('click', langToggle).bind('mouseover', langOifH).bind('mouseout', langT);
	jQuery('.sh-LangsItems-Insert').bind('mouseover', clangT).bind('mouseout', langT);
}}
// submenu expander and collapser
var t2,r2;
function submenuSubExpand(){clearTimeout(t2);jQuery('#submenuMore').hide();jQuery('#submenuLinksSub').removeClass('submenuLinksSubHide').hide().slideDown('fast');}
function submenuSubCollapse(){jQuery('#submenuLinksSub').slideUp('fast');jQuery('#submenuMore').show();}
function submenuExpand(){submenuSubCollapse();jQuery('#submenuWrapper').slideDown('fast');if(jQuery('#submenuButtonMore').is(':visible')){t2 = setTimeout('submenuSubExpand()', 1000);}}
function submenuCollapse(){clearTimeout(t2);submenuSubCollapse();jQuery('#submenuWrapper').slideUp('fast');}
var submenuExpander = {init : function(){
	jQuery('#submenuExpander').click(function(event){if(this == event.target){if(jQuery('#submenuWrapper').is(':hidden')){submenuExpand();}else{submenuCollapse();}}});
	jQuery('#submenuButtonMore').click(function(event){if(this == event.target){submenuSubExpand();}});
	jQuery('#submenuButtonClose').click(function(event){if(this == event.target){submenuCollapse();}});
}}
// help expander and collapser
function helpExpand(item){item.find('.divHelpInsert').slideDown('fast');item.find('.helpBottom').show();}
function helpCollapse(item){item.find('.divHelpInsert').slideUp('fast');item.find('.helpBottom').hide();}
function helpToggle(item){if(item.find('.divHelpInsert').is(':hidden')){helpExpand(item);}else{helpCollapse(item);}}
var helpExpander = {init : function(){
	jQuery('.helpButton').click(function(event){if(this == event.target){helpToggle(jQuery(this).parent());}});
	jQuery('.helpButtonClose').click(function(event){if(this == event.target){helpCollapse(jQuery(this).parent().parent().parent());}});
}}
// onload
jQuery(function(){
	//jQuery.preload( [ 'stehlik/logo/stehlik-group_logo_h__var1-grey__supra-header-h29', 'plus', 'minus' ], {
	//	base:'/fileadmin/templates/images/',
	//	ext:'.gif'
	//});
	//jQuery.fn.canvasSwap.defaults.suffix = '_over';
	//jQuery.fn.canvasSwap.defaults.ie6_support = true;
	//jQuery('img.canvasswap').canvasSwap();
	helpExpander.init();jQuery('.divHelpInsert').hide();jQuery('.helpBottom').removeClass('nv').hide();
	submenuExpander.init();jQuery('#submenuWrapper').removeClass('submenuWrapperHide').hide();
	langDropdown.init();jQuery('#sh-LangsCaption').addClass('sh-LangsCaption');jQuery('#sh-LangsItems').addClass('sh-LangsItems').hide();
});
// scroll-to-top
var scrollToTop = {
	setting : {startLine: 100, scrollTo: 0, scrollDuration: 1000, fadeDuration: [500, 100]},
	controlHTML : '<img src="/fileadmin/templates/images/icons/up.png" style="width:48px; height:48px" />',
	controlattrs : {offsetx: 5, offsety: 5},
	anchorKeyword : '#top',
	state : {isVisible: false, shouldVisible: false},
	scrollUp : function(){
		if (!this.cssFixedSupport){
			this.jQControl.css({opacity:0});
		}
		var dest = isNaN(this.setting.scrollTo) ? this.setting.scrollTo : parseInt(this.setting.scrollTo);
		if (typeof dest == 'string' && jQuery('#' + dest).length == 1){
			dest = jQuery('#' + dest).offset().top;
		}else{dest=0;}
		this.jQBody.animate({scrollTop: dest}, this.setting.scrollDuration);
	},
	keepFixed : function(){
		var jQWindow = jQuery(window);
		var controlx = jQWindow.scrollLeft() + jQWindow.width() - this.jQControl.width() - this.controlattrs.offsetx;
		var controly = jQWindow.scrollTop() + jQWindow.height() - this.jQControl.height() - this.controlattrs.offsety;
		this.jQControl.css({left: controlx + 'px', top: controly + 'px'});
	},
	toggleControl : function(){
		var scrollTop2 = jQuery(window).scrollTop();
		if (!this.cssFixedSupport) {this.keepFixed();}
		this.state.shouldVisible = (scrollTop2 >= this.setting.startLine) ? true : false;
		if (this.state.shouldVisible && !this.state.isVisible){
			this.jQControl.stop().animate({opacity:1}, this.setting.fadeDuration[0]);
			this.state.isVisible = true;
		}
		else if (this.state.shouldVisible == false && this.state.isVisible){
			this.jQControl.stop().animate({opacity:0}, this.setting.fadeDuration[1]);
			this.state.isVisible = false;
		}
	}
}
jQuery(function(){
	var mainObj = scrollToTop;
	var iebrws = document.all;
	mainObj.cssFixedSupport = !iebrws || (iebrws && document.compatMode == 'CSS1Compat' && window.XMLHttpRequest);
	mainObj.jQBody=(window.opera) ? (document.compatMode == 'CSS1Compat' ? jQuery('html') : jQuery('body')) : jQuery('html,body');
	mainObj.jQControl=jQuery('<div id="topcontrol">' + mainObj.controlHTML + '</div>')
		.css({position: (mainObj.cssFixedSupport ? 'fixed' : 'absolute'), bottom: mainObj.controlattrs.offsety, right: mainObj.controlattrs.offsetx, opacity: 0, cursor: 'pointer'})
		.attr({title: 'Scroll Back to Top'})
		.click(function(){mainObj.scrollUp(); return false;})
		.appendTo('body');
	if (document.all && !window.XMLHttpRequest && mainObj.jQControl.text() != ''){
		mainObj.jQControl.css({width: mainObj.jQControl.width()});
	}
	mainObj.toggleControl();
	jQuery('a[href="' + mainObj.anchorKeyword +'"]').click(function(){mainObj.scrollUp();return false;});
	jQuery(window).bind('scroll resize', function(e){mainObj.toggleControl();});
});
/*
jQuery(function(){
	jQuery('area').cluetip({
		cluetipClass: 'jtip',
		arrows: true,
		dropShadow: false,
		hoverIntent: false,
		sticky: true,
		mouseOutClose: true,
		closePosition: 'title'
	});
	jQuery('xxx').cluetip({
		attribute: 'alt',
		hoverIntent: {
			sensitivity: 1,
			interval: 750,
			timeout: 750
		}
	});
});
*/
