var closetimer = 0;
var sel_init = 0;
	
function tabs_open(tabsname){
	$("#button_" + tabsname).addClass("active");
	$("#tabs_" + tabsname).css('display','block');
}

function tabs_close(tabsname){
	$("#button_" + tabsname).removeClass("active");
	$("#tabs_" + tabsname).css('display','none');
}
	
function jm_close(){
	$("#oferta_a").hide();
	$("#oferta_e").hide();
}
	
function jm_open(timeout){
	closetimer = window.setTimeout(jm_close, timeout);
}
	
function jm_cancel(){
	if(closetimer){
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}
	
jQuery(document).ready(function(){
	
	$('marquee').marquee('pointer').mouseover(function () {
        $(this).trigger('stop');
    }).mouseout(function () {
        $(this).trigger('start');
    });


        $(".select").click(function(){
	    $('.items').hide();
            if(sel_init == 0){
                var items = $(this).find('.items');
                items.show();
                items.css('left', $(this).offset().left - 30);
                items.css('top', $(this).offset().top - 20);
                sel_init++;
            }
        });

        $(".spcselect").click(function(){
            $('.items').hide();
	    if(sel_init == 0){
                var items = $(this).find('.items');
                items.show();
                items.css('left', $(this).offset().left - 100);
                items.css('top', $(this).offset().top - 20);
                sel_init++;
            }
        });

        $(".items").click(function(){
            $(this).hide();
            sel_init--;
        });

        $("html").click(function(){
            if(sel_init == 0){
                $('.items').hide();
            } else { sel_init--; }
        });

	$('#jump_to_category').change(function(){
		if(this.value){
			location.href = 'katalog_'+this.value+'.htm';
		}
	});

	$('#oddzialy').submit(function(){
		var codeMap = {
				'00':'uhert_warszawa.htm',
				'01':'uhert_warszawa.htm',
				'02':'uhert_warszawa.htm',
				'03':'uhert_warszawa.htm',
				'04':'uhert_warszawa.htm',
				'05':'uhert_warszawa.htm',
				'06':'uhert_warszawa.htm',
				'07':'uhert_warszawa.htm',
				'08':'uhert_warszawa.htm',	
				'10':'tll1_olsztyn.htm',
				'11':'tll1_olsztyn.htm',
				'12':'tll1_olsztyn.htm',	
				'14':'tll1_olsztyn.htm',
				'15':'edp2q_bialystok.htm',
				'16':'edp2q_bialystok.htm',
				'17':'edp2q_bialystok.htm',			
				'19':'tll1_olsztyn.htm',
				'20':'hm1ff_lublin.htm',			
				'22':'hm1ff_lublin.htm',
				'23':'hm1ff_lublin.htm',
				'25':'9h5gj_kielce.htm',
				'26':'g1xtm_radom.htm',		
				'29':'mew4z_czestochowa.htm',
				'30':'pftt_krakow.htm',
				'31':'pftt_krakow.htm',
				'32':'pftt_krakow.htm',
				'33':'pftt_krakow.htm',				
				'35':'vs7zq_rzeszow.htm',
				'36':'vs7zq_rzeszow.htm',				
				'38':'vs7zq_rzeszow.htm',
				'39':'vs7zq_rzeszow.htm',
				'40':'ecocv_katowice.htm',
				'41':'ecocv_katowice.htm',
				'42':'mew4z_czestochowa.htm',
				'43':'malic_bielsko_biala.htm',				
				'46':'mew4z_czestochowa.htm',
				'47':'w8pye_gliwice.htm',
				'48':'w8pye_gliwice.htm',				
				'50':'yybid_wroclaw.htm',
				'51':'yybid_wroclaw.htm',
				'52':'yybid_wroclaw.htm',
				'53':'yybid_wroclaw.htm',
				'54':'yybid_wroclaw.htm',
				'55':'yybid_wroclaw.htm',
				'56':'yybid_wroclaw.htm',
				'57':'yybid_wroclaw.htm',
				'58':'yybid_wroclaw.htm',
				'59':'yybid_wroclaw.htm',
				'60':'q0p5i_poznan.htm',
				'61':'q0p5i_poznan.htm',
				'62':'q0p5i_poznan.htm',
				'63':'gvncn_kalisz.htm',
				'64':'q0p5i_poznan.htm',
				'65':'iddh_zielona_gora.htm',				
				'67':'iddh_zielona_gora.htm',
				'68':'iddh_zielona_gora.htm',
				'69':'cev2t_gorzow_wielkopolski.htm',
				'70':'fpugc_szczecin.htm',
				'71':'fpugc_szczecin.htm',
				'72':'fpugc_szczecin.htm',
				'73':'fpugc_szczecin.htm',				
				'75':'ea8oy_koszalin.htm',				
				'77':'ea8oy_koszalin.htm',				
				'80':'xxoex_gdansk.htm',
				'81':'w0h8b_gdynia.htm',				
				'85':'9j2g_bydgoszcz.htm',								
				'90':'j4oww_lodz.htm',
				'91':'j4oww_lodz.htm',
				'92':'j4oww_lodz.htm',
				'93':'j4oww_lodz.htm',
				'94':'j4oww_lodz.htm',
				'95':'j4oww_lodz.htm',				
				'97':'j4oww_lodz.htm',
				'99':'j4oww_lodz.htm'	
				};
		
		var code = $('#zip_code').attr('value');
		if (code.length > 1 ){
			var id = code.substring(0,2);
			if ( codeMap[id] != undefined){
				location.href = codeMap[id];
			}
			else{
				location.href = 'najblizsze_oddzialy.htm?kod='+code;
			}
		}
		return false;
	});

	$('.outlets_list').change(function(){
		if(this.value){
			location.href = this.value;
		}
	});

	$("#button_product").click(function(){
		tabs_close('solution');
		tabs_close('reference');
		tabs_open('product');
		
	});

	$("#button_solution").click(function(){
		tabs_close('product');
		tabs_close('reference');
		tabs_open('solution');
		
	});

	$("#button_reference").click(function(){
		tabs_close('product');
		tabs_close('solution');
		tabs_open('reference');
	});
	
	$("#oferta_a").mouseover(function(e){
		jm_cancel();		
	});

	$("#oferta_e").mouseover(function(e){
		jm_cancel();
	});
	
	$("#oferta_e").mouseout(function(e){
		jm_open(1000);
	});

   $("#oferta").mouseover(function(e){
           
       	var mPos = $('#navi').offset();
       	var mWidth = $('#navi').outerWidth();
       
       	var eWidth = $('#oferta_e').outerWidth();
		var fPos = (mPos.left + mWidth) - eWidth;

		var pos = $('#oferta').offset();    
        var width = $('#oferta').outerWidth();
       	
        var left = fPos;
        var top = pos.top;

        $("#oferta_a").css("top", (top+32) + 'px');
      	$("#oferta_a").css("left", (pos.left+(width/2)-23) + 'px');      	
      	$("#oferta_a").show();
      
     	$("#oferta_e").css("top", (top+32) + 'px');
      	$("#oferta_e").css("left", fPos + 'px');
      	$("#oferta_e").show();

      	jm_open(2000);
   }); 

	
})

function showCountryList(whichLayer)
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}
