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 = {
				'04':'lkjpn_kosice.htm',
				'05':'w8pye_poprad.htm',
				'06':'g1xtm_humenne.htm',
				'82':'k7rgo_bratislava.htm',
				'83':'k7rgo_bratislava.htm',
				'84':'k7rgo_bratislava.htm',
				'98':'mrcwr_lucenec.htm',
				'99':'y5wge_velky_krtis.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);
   }); 

	
})
