var Imgi = new Array();                                                                     
var advert_mem = '';
var active_mem = '';
var heightKeeper = 1;
var toID = null;
function searchAction(){
	if(document.getElementById('find_input').value == '') return false;
	else return true;		
}                                                                      
                                   
function preload(url) {                                               
   if (document.images) {                                             
      var i = Imgi.length;                                            
      Imgi[i] = new Image();                                                            
      Imgi[i].src = url;                                              
   }                                                                  
}     
preload('img/advert_bg.gif');
preload('img/anuluj_button.gif');
preload('img/ok_button.gif');
preload('img/menu_hover_video.jpg');
preload('img/menu_hover_foto.jpg');
preload('img/menu_hover_forum.jpg');
preload('img/menu_hover_lupa.jpg');
preload('img/menu_hover_tort.jpg');
preload('img/menu_hover_blog.jpg');
preload('img/menu_hover_sonda.jpg');
preload('img/menu_hover_wiadomosci.jpg');
preload('img/menu_hover_newsy.jpg');
preload('img/menu_hover_rider.jpg');
preload('img/menu_hover_elka.jpg');
preload('img/menu_hover_kaskdeska.jpg');
preload('img/menu_hover_gondola.jpg');
preload('img/menu_hover_widelec.jpg');
preload('img/menu_hover_lozko.jpg');
preload('img/menu_hover_mapa.jpg');
preload('img/menu_hover_gora.jpg');
preload('img/box_sign_alert_bg.gif');

function menu(type){

	if(advert_mem == '')	advert_mem = document.getElementById('menu_advert_clear').innerHTML;
	
	if(heightKeeper){ 
		var advertHeight = document.getElementById("menu_advert_clear").offsetHeight-7;	
		heightKeeper = 0;
	}else var advertHeight = 0;

	switch (type){ 
	
	case 2:
	active_mem = '<li style="margin-left: 40px;"><a class="menu_hover_lupa" href="users.html" onmouseover="advertMenu(\'on\');" onmouseout="advertMenu(\'off\');">Szukaj</a></li> <li><a class="menu_hover_tort" href="bthusers.html" onmouseover="advertMenu(\'on\');" onmouseout="advertMenu(\'off\');">Urodziny</a></li>';
	break;

	case 3:
	active_mem = '<li style="margin-left: 137px;"><a class="menu_hover_foto" href="allfotos.html" onmouseover="advertMenu(\'on\');" onmouseout="advertMenu(\'off\');">Foto</a></li> <li><a class="menu_hover_video" href="allvideo.html" onmouseover="advertMenu(\'on\');" onmouseout="advertMenu(\'off\');">Video</a></li>';
	break;
	
	case 4:
	active_mem = '<li style="margin-left: 220px;"><a class="menu_hover_forum" href="forum.html" onmouseover="advertMenu(\'on\');" onmouseout="advertMenu(\'off\');">Forum</a></li> <li><a class="menu_hover_blog" href="allblogs.html" onmouseover="advertMenu(\'on\');" onmouseout="advertMenu(\'off\');">Blogi</a></li> <li><a class="menu_hover_sonda" href="probes.html" onmouseover="advertMenu(\'on\');" onmouseout="advertMenu(\'off\');">Sondy</a></li>';
	break;

	case 5:
	active_mem = '<li style="margin-left: 277px;"><a class="menu_hover_wiadomosci" href="tidings.html" onmouseover="advertMenu(\'on\');" onmouseout="advertMenu(\'off\');">Wiadomośći</a></li> <li><a class="menu_hover_newsy" href="newnews.html" onmouseover="advertMenu(\'on\');" onmouseout="advertMenu(\'off\');">Newsy użytkowników</a></li>';
	break;

case 6:
	active_mem = '<li style="margin-left: 27px;"><a class="menu_hover_rider" href="http://przewodnik.space4u.pl/szukaj?selection=5&region=&location=&begin=&end=&words=&db=0&page=1" onmouseover="advertMenu(\'on\');" onmouseout="advertMenu(\'off\');">Snowparki</a></li> <li><a class="menu_hover_elka" href="http://przewodnik.space4u.pl/szukaj?selection=4&region=&location=&begin=&end=&words=&db=0&page=1" onmouseover="advertMenu(\'on\');" onmouseout="advertMenu(\'off\');">Szkoły</a></li> <li><a class="menu_hover_kaskdeska" href="http://przewodnik.space4u.pl/szukaj?selection=3&region=&location=&begin=&end=&words=&db=0&page=1" onmouseover="advertMenu(\'on\');" onmouseout="advertMenu(\'off\');">Wypożyczalnie</a></li> <li><a class="menu_hover_gondola" href="http://przewodnik.space4u.pl/szukaj?selection=2&region=&location=&begin=&end=&words=&db=0&page=1" onmouseover="advertMenu(\'on\');" onmouseout="advertMenu(\'off\');">Miejscówki</a></li> <li><a class="menu_hover_widelec" href="http://przewodnik.space4u.pl/szukaj?selection=1&region=&location=&begin=&end=&words=&db=0&page=1" onmouseover="advertMenu(\'on\');" onmouseout="advertMenu(\'off\');">Wyżywienie</a></li> <li><a class="menu_hover_lozko" href="http://przewodnik.space4u.pl/szukaj?selection=0&region=&location=&begin=&end=&words=&db=0&page=1" onmouseover="advertMenu(\'on\');" onmouseout="advertMenu(\'off\');">Noclegi</a></li>';
	break;
	}
//	active_mem = '<li><a class="menu_hover_video" href="allvideo" >Video</a></li> <li><a class="menu_hover_foto" href="allfotos">Foto</a></li>';
	if(advertHeight > 114-7){ 
		document.getElementById("menu_advert_clear").style.height = (advertHeight)+'px';
	}
	document.getElementById('menu_advert_clear').innerHTML = '<div id="menu_advert"><div id="menu_hover"><ul id="menu_advert_content"><li>' + active_mem + '</li></ul></div></div>';

//	alert('dasds');
}

function advert(){
	if(active_mem == ''){
//	document.getElementById('menu_advert').style.background = 'url();';	
	document.getElementById("menu_advert_clear").style.height = 'auto';
//	alert(advert_mem);
//	if(advert_mem != '<div id="OpenXdest" style="padding-top: 4px; padding-left: 120px;"></div>' && advert_mem !='<DIV id="OpenXdest" style="padding-top: 4px; padding-left: 120px;"></DIV>') document.getElementById('menu_advert_clear').innerHTML = advert_mem;
//	else 
	if(document.getElementById('preOpenX')){
		if(document.getElementById('preOpenX').innerHTML)
			document.getElementById('menu_advert_clear').innerHTML = '<div id="OpenXdest" style="padding-top: 4px; padding-left: 120px;">'+document.getElementById('preOpenX').innerHTML+'</div>';
	}	
	else{
		if(advert_mem != '') document.getElementById('menu_advert_clear').innerHTML = advert_mem;
		else document.getElementById('menu_advert_clear').innerHTML = '<div id="OpenXdest" style="padding-top: 4px; padding-left: 120px;">'+openx(65)+'</div>';
		}
	heightKeeper = 1;
	}
	
}

function Delay(){
	active_mem = '';
	clearTimeout(toID);
	toID = setTimeout("advert()",2000);
	
}
function advertMenu(action){
	
	if(action == 'on') active_mem = document.getElementById('menu_advert_clear').innerHTML;
	else {
		active_mem = '';
		clearTimeout(toID);
		toID = setTimeout("advert()",500);
	}
	
}
function refresh(filepath,id){
	document.getElementById(id).src=filepath+'?'+Math.random()*10000000000000000;	
}
function gotoURL(url){
	var urlpart = document.location.href.split(",");
	var homeurl = '';
	for(i=0;i<urlpart.length-1;i++) homeurl += urlpart[i]+','; 
	document.location.href = homeurl+url;
	return false;	
}

	
	var hovertext = function() {

	this.ie = (document.addEventListener) ? false : true;
	this.keepVisible = 0;

	this.init = function() {
		if(!this.ie) {
			window.addEventListener('load', ht.attachSelf, false);
		}
		else {
			window.attachEvent('onload', ht.attachSelf);
		}
	}

	this.attachSelf = function() {
		var elements = new Array('a', 'span', 'div');
		for(key in elements) {
			var temp = document.getElementsByTagName(elements[key]);
			for(var k = 0 ; k < temp.length ; k++){
				if((temp[k].rel == 'hovertext' || temp[k].className.indexOf('hovertext') > -1) && temp[k].title.length > 0) {
					ht.addHover(temp[k]);
				}
			}
		}
	}

	this.addHover = function(obj) {
		if(!this.ie) {
			obj.addEventListener('mouseover', ht.show, false);
			obj.addEventListener('mouseout', ht.hide, false);
		}
		else {
			obj.attachEvent('onmouseover', ht.show);
			obj.attachEvent('onmouseout', ht.hide);
		}

		obj.rel = obj.title;
		obj.title = '';
	}



	this.show = function(evt) {
		ht.hideDo();
		ht.keepVisible = true;
		var ie = (document.addEventListener) ? false : true;
		if(ie) {
			var cal = evt.srcElement;
		}
		else {
			var cal = this;
		}

		var div = document.createElement('DIV');
		div.id = 'hovertext';


		var span = document.createElement('SPAN');
		span.className = 'hoverarrow';
		div.appendChild(span);

		var p = document.createElement('P');
		p.innerHTML = cal.rel;
		div.appendChild(p);

		div.style.top = (((ie) ? (cal.offsetTop + cal.offsetHeight) : cal.offsetTop) + 20) + 'px';


		document.body.appendChild(div);

		if(ht.maxWidth && div.scrollWidth > ht.maxWidth) {
			div.style.width = ht.maxWidth + 'px';
		}

		if(document.body.clientWidth > div.scrollWidth + cal.offsetLeft + 100) {
			if(ie) {
				var pos = findPos(cal);
				div.style.left = pos[0] + 'px';
			}
			else div.style.left = (cal.offsetLeft) + 'px';
		}
		else {
			div.style.right = (document.body.clientWidth - cal.offsetLeft + ((ie) ? -10 : 0)) + 'px';
			span.className +=' hoverarrowRight';
		}

		if(ie) {
			var st = document.documentElement.scrollTop;
			var sh = document.documentElement.clientHeight;
		}
		else {
			var st = (window.scrollY) ? window.scrollY : document.documentElement.scrollTop;
			var sh = self.innerHeight;
		}
		if(div.offsetTop > st + sh - 20) {
			div.style.top = parseInt(div.style.top) - 20 - div.scrollHeight + 'px';
			span.className += ' hoverarrowBottom';
		}

		if(ie) {
			div.attachEvent('onmouseover', ht.keep);
			div.attachEvent('onmouseout', ht.hide);
		}
		else {
			div.addEventListener('mouseover', ht.keep, false);
			div.addEventListener('mouseout', ht.hide, false);
		}
	}

	this.hide = function() {
		ht.keepVisible = 0;
		setTimeout(ht.hideDo, 500);
	}

	this.hideDo = function() {
		if(ht.keepVisible == 0 && document.getElementById('hovertext')) {
			document.body.removeChild(document.getElementById('hovertext'));
			ht.keepVisible = 0;
		}
	}

	this.keep = function() {
		ht.keepVisible = 1;
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

var ht = new hovertext();
		ht.maxWidth = 350;
		ht.init();
