
function showHideDivText(tt,show,hide,dd)
{
	dd2 = document.getElementById(dd);
	if(dd2.style.display=='none'){
		tt.innerHTML = hide;
		dd2.style.display = 'block';
	}else{
		tt.innerHTML = show;
		dd2.style.display = 'none';
	}	
}
function getParamByName(href, name) {
        var match = RegExp('[?&]' + name + '=([^&]*)').exec(href); 
        return match && decodeURIComponent(match[1].replace(/\+/g, ' '));

    }


    $(document).ready(function(){
        // get all items with artitem
        $('.artitem').bind('mousemove', function(e){
            var x = e.layerX || e.clientX;
            var y = e.layerY || e.clientY;
            if ('number' == typeof e.offsetX) { // MSIE
                offset = $(this).offset();
                x = offset.left - 70;
                y = offset.top + 40;
            }
            var href = getParamByName(this.href, 'artikul_id'); 
            
            showInfo('art', href, x, y, this.title);
            this.title = '';
        })
        var timeOut;
        $('.artitem').hover(
            function (){
                var objid = getParamByName(this.href, 'artikul_id');
                var objEl = "popupArtid"+objid;
                // hide all prev
                $('.popubobjArts').hide();
                if(timeOut)
                    clearTimeout(timeOut);
                $('#'+objEl).show();  
            },
            function (){
                var objid = getParamByName(this.href, 'artikul_id');
                var objEl = "popupArtid"+objid;
                timeOut = setTimeout(function(){                                    
                     $('#'+objEl).hide();  
                 }, 
             1500);
            }
        ); 
        function showInfo(type, objid, x, y, title){
            var objEl = "popupArtid"+objid;
            var isNew = false;
            if(!document.getElementById(objEl)){
                $("body").append("<div class='popubobjArts' id='"+objEl+"'></div>");
                $('#'+objEl).bind('mouseout', function(e){ 
                    setTimeout(function(){                                    
                         $('#'+objEl).hide();  
                    }, 1500)
                });
                isNew = true;
            }
            var el = $('#'+objEl); 
            el.css('top', y+10);
            el.css('display', 'block');
            el.css('left', x+10);
            if(isNew){
                el.append("<div class='popupArtsTitle'>"+title+"</div>");
                el.append("<div class='popupArtsContent'>Загрузка...</div>");          
                // make ajax call and get from server info
                el2 = $('#' + objEl + ' .popupArtsContent');
                getInfoFromServer(el2, type, objid);
            }                        
        }
        function getInfoFromServer($el, type, objid){
            // make ajax call
            
            $.ajax({
                  url: "/arts/?ajax=1&type="+type+"&objid="+objid,
                  context: $el,
                  success: function(a,b){ 
                      if(b=='success'){
                          $(this).html(a);
                      }else{
                           $(this).html('ошибка при загрузке данных');
                      } 
                  }
            });
        }
        
    }); 
