var curr = 0;

var prod_a = false;
var proc_a = false;

function menuProdukty(param){
    if(param==0){
        $("a[rel=produkty]").click(function(evt){
                if(!prod_a){
				prod_a = true;
				proc_a = false;
				evt.preventDefault();
                //$("div#rotator").hide();
                //$("div#claim").hide();
                //$("div.denmat_award").hide();
				$("div.menu").children("ul").children("li").children("a").removeClass("active");
                $(this).addClass("active");
				$("ul#sub_procedury").slideUp("fast");
				$("ul#sub_produkty").slideDown("fast");
				
				}
        });
    }
    else{
        $("a[rel=produkty]").click(function(evt){
				if(!prod_a){
				prod_a = true;
				proc_a = false;
                evt.preventDefault();
               // $("div.current").hide();
                $("div.menu").children("ul").children("li").children("a").removeClass("active");
                $("body").addClass("denmat_main");
                $("div.content").addClass("content_denmat");
                $(this).addClass("active");
				$("ul#sub_procedury").slideUp("fast");
                $("ul#sub_produkty").slideDown("fast");
				
				}
        });
    }
}

function menuProcedury(param){
    if(param==0){
        $("a[rel=procedury]").click(function(evt){
				if(!proc_a){
				proc_a = true;
                evt.preventDefault();
                //$("div#rotator").hide();
                //$("div#claim").hide();
               // $("div.denmat_award").hide();
				$("div.menu").children("ul").children("li").children("a").removeClass("active");
                $(this).addClass("active");
				$("ul#sub_produkty").slideUp("fast");
				$("ul#sub_procedury").slideDown("fast");
				prod_a = false;
				}
        });
    }
    else{
        $("a[rel=procedury]").click(function(evt){
                if(!proc_a){
				proc_a = true;
				prod_a = false;
				evt.preventDefault();
               // $("div.current").hide();
                $("div.menu").children("ul").children("li").children("a").removeClass("active");
                $("body").addClass("denmat_main");
                $("div.content").addClass("content_denmat");
                $(this).addClass("active");
				$("ul#sub_produkty").slideUp("fast");
                $("ul#sub_procedury").slideDown("fast");
				}
        });
    }
}

function resize(){
    $(document).ready(function(){
        var $items = $(".products_denmat li a");
        var maxHeight=0;
        
        $.each($items,function(index, item){
            var h = $(item).height();
            if(h>maxHeight) maxHeight = h;
        });
        $items.height(maxHeight);
    });
}


var Rotator = {
    defaultTime: 4000,
    time: 0,
    count: 0,
    elements: null,
    container: null,
    current: 0,
    timer: null,
    
    setup: function(el, time){
        if(time>0)
        {
            Rotator.time=time;
        }
        else{
            Rotator.time = Rotator.defaultTime;
        }
        Rotator.container = $(el);
        Rotator.elements = $(el).children('div');
        Rotator.count = Rotator.elements.length;
        Rotator.start();
    },
    
    start: function(){
        Rotator.timer = setTimeout(Rotator.rotate, Rotator.time);
    },
    
    rotate: function(){
        try{
        next = ( (Rotator.current+1) > Rotator.count-1 )?0:Rotator.current + 1;
        Rotator.elements.eq(Rotator.current).fadeOut();
        Rotator.elements.eq(next).fadeIn();
        Rotator.current = next;
        Rotator.timer = setTimeout(Rotator.rotate, Rotator.time);
        }
        catch(e){
        }
    }
    
};

var Kulki = {
    elementy: null,
    
    init: function(){
        Kulki.elementy = $('#kuleczki .kulka');
        Kulki.elementy.find('img').bind('mouseenter', Kulki.inflate);
        Kulki.elementy.bind('mouseleave', Kulki.burst);
        Kulki.elementy.find('.dymek').css(
            {
                'display': 'none'
            }
        );
        
        $('#kuleczki').bind('click', Kulki.goTo);
        Kulki.elementy.mouseleave();

    },   // koniec init
    
    inflate: function(e){
        e.stopPropagation();

        $dymek = $(this).parents('.kulka').find('.dymek');
        
        $(this).parent('.kulka').data('popStart', e.timeStamp);
        
        if($(this).is(':animated'))
        {
            $(this).stop(true);
            $dymek.stop(true);
        }
        
        
        $(this).animate(
            {
                'width': '85px',
                'height': '85px',
                'margin-top': '145px'
            },
            {
                duration: 400
            }
        );
       
        $dymek.css(
            {
                'display': 'block'
            }
            );
        $dymek.animate(
            {
                'bottom': '95px'
            },
            {
                'duration': 300
            }
        );
    },
    
    burst: function(e){
        e.stopPropagation();
        $obrazek = $(this).find('img');
        $dymek = $(this).find('.dymek');           
        
        elapsedTime = e.timeStamp - $(this).data('popStart');
        
        if(elapsedTime < 250 )
        {
            $obrazek.stop(true);
            $dymek.stop(true);
        }
        
      
        $obrazek.animate(
            {
                'width': '60px',
                'height': '60px',
                'margin-top': '190px'
            },
            {
                duration: 400,
                'complete': function(){
                   // $(this).dequeue();
                }
            }
       );



        $dymek.animate(
            {
                'bottom': '90px'
            },
            {
                'duration': 100,
                'complete': function(){
                    $(this).css({'display': 'none', 'bottom': '55px'});
                }
            }
        ); 
    },
    
    goTo: function(e)
    {
        if($(e.target).hasClass('kulka') || $(e.target).is('#kuleczki'))
        {
            location.href = $('#rotator').children('div:visible').find('a').attr('href');
        }
    }      
};


