var alertBox = null;
Event.observe(window, 'load', function()
{
	externalLinks();
	startList();
});

function externalLinks()
{
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i < anchors.length; i++)
	{
		var anchor = anchors[i];
	   	if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
	   	{
			anchor.setAttribute("target","_blank");
		}
	}
}

function showAlert(title, text, no_buttons)
{
	alertBox = new lightbox();
	lboxHtml = '<form id="frm-recommend" method="post">' +
  				'<h1>' + title + '</h1>' +
				'<p>' + text + '</p>';
	if(no_buttons != true)
	{
		lboxHtml += '<p class="buttons center">' +
		            '<input type="button" class="button btn-next" name="close" value="Zamknij" onclick="return closeAlert();" /></p>';
	}
  	lboxHtml += '<div class="frm-close"><a class="lbAction" rel="deactivate" href="javascript:;"><span>Zamknij</span></a></div></form>';
	alertBox.alert(lboxHtml);
	return false;
}

function showErrorAlert(title, text, no_buttons)
{
	alertBox = new lightbox();
	lboxHtml = '<form id="frm-recommend" method="post" action="' + siteurl + '">' +
  				'<h1>' + title + '</h1>' +
				'<p>' + text + '</p>';
	if(no_buttons != true)
	{
		lboxHtml += '<p class="buttons center">' +
		            '<input type="submit" class="button btn-next" name="close" value="Zamknij" /></p>';
	}
  	//lboxHtml += '<div class="frm-close"><a class="lbAction" rel="deactivate" href="javascript:;"><span>Zamknij</span></a></div>';
  	lboxHtml += '</form>';
	alertBox.alert(lboxHtml);
	return false;
}

function showAlertBox(title, html)
{

	alertBox = new lightbox();
	
	lboxHtml = '<form id="frm-recommend" method="post">' +
  				'<h1>' + title + '</h1>' + html +
				'<div class="frm-close"><a class="lbAction" rel="deactivate" href="javascript:;"><span>Zamknij</span></a></div></form>';
	
	alertBox.alert(lboxHtml);
	
	return false;
}


function closeAlert()
{
    alertBox.deactivate();
    return false;
}

var tabbedContent =
{
	init:function()
	{
		tabs = document.getElementsByClassName('tabbedContent');
		if(tabs.length > 0)
		{
			// hide all but the first tab
			for(i = 0; i < tabs.length; i++)
			{
				tabs[i].hide();
			}
			urlAnchor = document.location.href.substr(document.location.href.lastIndexOf('#') + 1);
			if($(urlAnchor) && $(urlAnchor).className == 'tabbedContent')
			{
				this.switchTab(urlAnchor);
			}
			else
			{
			    // no anchor in url - show the first tab
			    this.switchTab(tabs[0].id);
			}
		}

		// BUG: automatyczne przydzielanie onclick�w, nie dzia�a
		tabLinks = document.getElementsByClassName('tabbedContentLink');
		for(i = 0; i < tabLinks.length; i++)
		{
		    Event.observe(tabLinks[i], 'click', tabbedContent.linkClick.bindAsEventListener(tabLinks[i]));
		    tabLinks[i].onclick = function(){return false;};
		}
	},
	linkClick:function(event)
	{
	    el = Event.element(event);
		targetTab = el.href.substr(el.href.lastIndexOf('#') + 1);
		return tabbedContent.switchTab(targetTab);
	},
	switchTab:function(tabId)
	{
        tabs = document.getElementsByClassName('tabbedContent');
		if(tabs.length > 0)
		{
			// hide all tabs first
			for(i = 0; i < tabs.length; i++)
			{
				tabs[i].hide();
			}
		}
        $(tabId).show();

		tabAnchor = '#' + tabId;
		tabLinks = document.getElementsByClassName('tabbedContentLink');
		for(i = 0; i < tabLinks.length; i++)
		{
		    tabLinks[i].parentNode.parentNode.removeClassName('active');
			if(tabLinks[i].href.indexOf(tabAnchor) != -1)
			{
                tabLinks[i].parentNode.parentNode.addClassName('active');
			}
		}
        return false;
	}
}

function sublistExpand(ex)
{
	sublist = ex.parentNode.getElementsByTagName('ul')[0];
	if(sublist.style.display == 'none')
	{
		Effect.BlindDown(sublist);
		ex.innerHTML = 'ukryj';
	}
	else
	{
		Effect.BlindUp(sublist);
		ex.innerHTML = 'rozwiń';
	}
	return false;
}

function reloadBaner(show, hide)
{

	new Effect.Fade($(hide), {duration: 0.35}) ;
	setTimeout(function ()
  	{
		var e = new Effect.Appear($(show), {duration: 0.35});

  	}, 300);
}

function startList() 
{
	navRoot = $('menu');
	if (navRoot)
	{
    	navEl = navRoot.getElementsByTagName('li');
    	for (i=0; i<navEl.length; i++) 
    	{
    		node = navEl[i];
    		node.onmouseover=function() 
    		{
    			if(document.all)
    			{
    				this.className+=" over";
    			}
    			var list = document.getElementById("menu").childNodes;
    			for(var i = 0; i < list.length; i++)
    			{
    				if(list[i].className)
    					list[i].className = list[i].className.replace('active', 'inact');
    			}
    			
    		}
    		node.onmouseout=function() 
    		{
    			if(document.all)
    			{
    				this.className=this.className.replace(" over", "");
    			}
    			var list = document.getElementById("menu").childNodes;
    			for(var i = 0; i < list.length; i++)
    			{
    				if(list[i].className)
    					list[i].className = list[i].className.replace('inact', 'active');
    			}
    
    		}
    	}
	}
	if (document.all&&document.getElementById) 
	{
		var navRoot = $('searchtabs');
		if(navRoot)
		{
			navEl = navRoot.getElementsByTagName('li');
			for (i=0; i<navEl.length; i++) 
			{
				node = navEl[i];
				node.onmouseover=function() 
				{
					this.className+=" over";
				}
				node.onmouseout=function() 
				{
					this.className=this.className.replace(" over", "");
				}
			}
		}
		var navRoot = $('groupDescContainer');
		if(navRoot)
		{
			navEl = navRoot.getElementsByTagName('span');
			for (i=0; i<navEl.length; i++) 
			{
				node = navEl[i];
				node.onmouseover=function() 
				{
					this.className+=" over";
				}
				node.onmouseout=function() 
				{
					this.className=this.className.replace(" over", "");
				}
			}
		}
		var navRoot = $('dropdownid');
		if(navRoot)
		{
			navEl = navRoot.getElementsByTagName('li');
			for (i=0; i<navEl.length; i++) 
			{
				node = navEl[i];
				if(node.className != 'title' && node.className != 'separator')
				{
					node.onmouseover=function() 
					{
						this.className+=" over";
					}
					node.onmouseout=function() 
					{
						this.className=this.className.replace(" over", "");
					}
				}
			}
		}
		
	}
}

function iFrameResize(obj)
{
	var myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) 
	{
    //Non-IE
    	myHeight = window.innerHeight;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
    //IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{
	    //IE 4 compatible
    	myHeight = document.body.clientHeight;
	}
	myHeight = myHeight - 120;
	obj.style.height = myHeight + 'px';
	//window.alert( 'Height = ' + myHeight );
}

function contactFormSubmit()
{
    $('lbf_email_error').style.display = 'none';
	new Ajax.Request(siteurl + 'kontakt/',
	{
		asynchronous: true,
		method: 'post',
		postBody:
			'ajax=1' + '&send=1' +
			'&f_name=' + encodeURIComponent($F('lbf_name')) +
			'&f_message=' + encodeURIComponent($F('lbf_message')) +
			'&f_mail=' + encodeURIComponent($F('lbf_mail')),
   		onComplete: function(obj) { $('lbf_submit').innerHTML = '<input class="button" type="submit" name="send" value="Wyślij" onclick="contactFormSubmit(); return false;"/>'; if(obj.responseText == '1') {$('lbContactDone').style.display = 'block'; $('lbContactForm').style.display = 'none';} else {$('lbf_email_error').innerHTML = obj.responseText; $('lbf_email_error').style.display = 'block';} },
   		onLoading: function() {$('lbf_submit').innerHTML = '<img src="/i/progressSetup.gif" class="progressSetup" />';}
   	});
	
   	return false;
}
