

/*zalozky v obsahu*/
function whichTab( eprf , tprf , lst , dflt )
{
	var hsh = window.location.hash;
	var hst = '#' + tprf;
	if( hsh.length > hst.length && hsh.substring( 0 , hst.length ) == hst )
	{
		var nnn = hsh.substring( hst.length );
		if( lst.indexOf( ',' + nnn + ',' ) >= 0 )
			return eprf + nnn;
	}
	return eprf + dflt;
}

function setTabs(tabsId, contentId, activeTabId, activeContentId)
{
	var content = document.getElementById(contentId);

	/* skryti obsahu */
	if (content != null)
	{
		var nodes = content.childNodes;

		if (nodes != null)
		{
			for(var i = 0; i < nodes.length; i++)
			{
				if (nodes[i].nodeType == 1)
				{
					nodes[i].style.display = 'none';
				}
			}
		}
	}

	/* nastaveni neaktivity zalozek */
	var tabs = document.getElementById(tabsId);
	if (tabs != null)
	{
		var nodes = tabs.getElementsByTagName('li');

		if (nodes != null)
		{
			for(var i = 0; i < nodes.length; i++)
			{
				if ( !i )
					nodes[i].className = 'first';
				else
					nodes[i].className = '';
			}
		}

	}

	/* zobrazeni obsahu pod aktivni zalozkou */
	var activeContent = document.getElementById(activeContentId);
	if (activeContent != null)
	{
		activeContent.style.display = 'block';
	}

	/* nastaveni stylu vybrane zalozky */
	var activeTab = document.getElementById(activeTabId);
	if (activeTab != null)
	{
		if ( activeTabId == 'tt1') 
			activeTab.className = 'first-active';
		else 
			activeTab.className = 'active';
	}

	return true;
}

function IsTable(node)
{
	if (node.tagName != null && node.className != null &&
		node.tagName.toLowerCase() == "table" &&
		node.className.toLowerCase() == "norm")
	{
		return true;
	}
	return false;
}

function SetTables()
{
	var root = document.getElementById('mayor');

	if (root != null)
	{
		for(var index = 0; index < root.childNodes.length; index++)
		{
			if ( IsTable(root.childNodes[index]) )
			{
				tbbg = document.createElement('div');
				tbbg.className = 'tbbg';
				tbbgbtm = document.createElement('div');
				tbbgbtm.className = 'tbbgbtm';
				tbbgtop = document.createElement('div');
				tbbgtop.className = 'tbbgtop';

				table = root.childNodes[index].cloneNode(true);

				tbbgtop.appendChild(table);
				tbbgbtm.appendChild(tbbgtop);
				tbbg.appendChild(tbbgbtm);

				root.childNodes[index].parentNode.replaceChild(tbbg, root.childNodes[index]);
			}
		}
	}

	return true;
}

function postProcess()
{
	SetTables();
	ieLinks();
}

window.onload = postProcess;

/* tooltip */
var tooltip=function(){
	var id = 'tt';
	var top = 10;
	var left = 10;
	var maxw = 325;
	var speed = 10;
	var timer = 20;
	var endalpha = 100;
	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';
			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'}
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u + top) + '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);
		}
	};
}();

function filterEnter(key){
	var k=key.keyCode||key.which;
	return k!=13;
}

$(document).ready(function(){

	$('#rc-cart-collapse-text').click(function(event) {

		if ( $('#rc-cart table').is(':visible') )
		{
			event.preventDefault();

			$('.rc-cart-info').show();
			$('#rc-cart table').hide();
			$('#rc-cart-collapse-text a').text('Expand');

			$.cookie('rc-cart-expand', '0');
		}
		else
		{
			event.preventDefault();

			$('.rc-cart-info').hide();
			$('#rc-cart table').show();
			$('#rc-cart-collapse-text a').text('Collapse');

			$.cookie('rc-cart-expand', '1');
		}

	});

	$('#rc-checkout-shippingHandle').click(function(event) {

		if ( $('#rc-checkout-shipping').is(':visible') )
		{
			$('#rc-checkout-shipping').slideUp('slow');
			$.cookie('avg_rc_cart_shipping', '0');
		}
		else
		{
			$('#rc-checkout-shipping').slideDown('slow');
			$.cookie('avg_rc_cart_shipping', '1');
		}

	});

});


