var tooltip=function(){
	var imgDir = '/js/src/tooltip/';
	var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 322;
	var speed = 10;
	var timer = 20;
	var endalpha = 90;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';

            if(v=="fotoindex" || v=="orez" || v=="ramecek")
            {
				t.style.visibility = 'hidden';
				b.style.visibility = 'hidden';

                if(v=="fotoindex")
                {
                    c.style.width = '160px';
                    c.style.height = '120px';
                    c.style.backgroundImage='url('+ imgDir +'tt-fotoindex.png)';
                    c.innerHTML='<p style=\"line-height: 1; padding: 10px 0 8px 0; text-align: center;\">UKÁZKA FOTOINDEXU</p>';
                }
                else if(v=="orez")
                {
                    c.style.width = '322px';
                    c.style.height = '201px';
                    c.style.backgroundImage='url('+ imgDir +'tt-orez.png)';
                    c.innerHTML='<p style=\"line-height: 1; padding: 15px 20px 8px 20px;\">Váš digitální fotoaparát ukládá fotografie standardně ve formátu 4:3. Při využití  fotografického papíru např. 10x15 by Vaše fotografie vypadaly takto:</p><p style=\"float: left; width: 159px; line-height: 1; text-align: center;\"><strong style=\"line-height: 1.3\">OŘEZ</strong><br />ANO</p><p style=\"float: left; display: inline; width: 159px; line-height: 1; text-align: center; margin: 0 0 0 4px;\"><strong style=\"line-height: 1.3\">OŘEZ</strong><br />NE</p><p style=\"float: left; width: 159px; line-height: 1; text-align: center; padding: 90px 0 0 0;\">Oříznutá fotografie<br />bez bílého okraje</p><p style=\"float: left; width: 159px; line-height: 1; text-align: center; padding: 90px 0 0 0; margin: 0 0 0 4px;\">Kompletní fotografie<br />s bílými okraji</p>';
                }
                else if(v=="ramecek")
                {
                    c.style.width = '296px';
                    c.style.height = '143px';
                    c.style.backgroundImage='url('+ imgDir +'tt-ramecek.png)';
                    c.innerHTML='<p style=\"float: left; display: inline; width: 117px; line-height: 1; text-align: center; padding: 12px 0 0 0; margin: 0 0 0 21px;\"><strong style=\"line-height: 1.3\">RÁMEČEK</strong><br />ANO</p><p style=\"float: left; display: inline; width: 117px; line-height: 1; text-align: center; padding: 12px 0 0 0; margin: 0 0 0 21px;\"><strong style=\"line-height: 1.3\">RÁMEČEK</strong><br />NE</p>';
                }

                c.style.padding = '0';
            }
			else
            {
				t.style.visibility = 'visible';
				b.style.visibility = 'visible';

                if (typeof document.body.style.maxHeight != "undefined") {
                    c.style.width = '276px';
                } else {
                    c.style.width = '276px';
                }

                c.style.height = 'auto';
                c.style.backgroundImage='url('+ imgDir +'tt-content.png)';
                c.style.padding = '6px 12px';
                c.innerHTML = v;
            }

			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
        pos:function(e){
        // For IE6 compatibity - nick 22/08/2008 11:32
        var u = 0, l = 0;
        if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        u = window.pageYOffset;
        l = window.pageXOffset;
        } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        u = document.body.scrollTop;
        l = document.body.scrollLeft;
        } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        u = document.documentElement.scrollTop;
        l = document.documentElement.scrollLeft;
        }

        u = ie ? event.clientY + u : e.pageY;
        l = ie ? event.clientX + l : e.pageX;
        tt.style.top = (u - h) + 'px';
        tt.style.left = (l + left) + 'px';
        },
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();
