$(function () {
    $('.bubbleInfo').each(function () {
        var distance = 10;
        var time = 250;
        var shown = false;
        var trigger = $('.trigger', this);
        var info = $('.popup_tip', this).css('opacity', 0);

        var bclose = $('a.closer',this);
        var t=bclose.attr('href');
        bclose.click(function(){
            hideTip();
            clearInterval(tipInterval);
            if(t == 1 || t == 2 || t == 3){
                setCookie('tip'+t,'1','2592000');
            }            
            return false;
        });

        function showTip(){
                info.css({
                    top: -40,
                    left: 0,
                    display: 'block'
                }).animate({
                    top: '-=' + distance + 'px',
                    opacity: 1
                }, time, 'swing', function() {}
                );
        }
        function hideTip(){
                info.animate({
                    top: '-=' + distance + 'px',
                    opacity: 0
                }, time, 'swing', function () {
                    info.css('display', 'none');
                });
        }
        
        var state = false;

        loopTips = function(){
            if(!state){
                showTip();
            }else{
                hideTip();
            }
            state = !state;
        }
        
        var tipInterval = setInterval(loopTips,5000);
        

    });
});

function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}




