function changeGallery (categoryId, uid){
    var macAjaxGalleryScript = 'http://'+window.location.host+'/typo/?eID=mac-ajax-gallery';
    $.post(macAjaxGalleryScript, { catId: categoryId, uid: uid}, function(data){
        if (document.getElementById('mac-ajax-gallery-pictures')){
            document.getElementById('mac-ajax-gallery-pictures').innerHTML = data;
        }else{
            console.log('id mac-ajax-gallery-pictures not founded!');
        }
    });
}

function changeThumbs(changeDirection){
    
    disableEnableLoader('block');
    
    var macAjaxGalleryScript = 'http://'+window.location.host+'/typo/?eID=mac-ajax-gallery';
    var directionId          = changeDirection == 'thumbPrev' ? prevThumbId : nextThumbId;
    $.post(macAjaxGalleryScript, { catId: category_id, changeDirection: changeDirection, directionId: directionId}, function(res){
        if (document.getElementById('mac-ajax-gallery-preview') && res.previewContent){
            document.getElementById('mac-ajax-gallery-preview').innerHTML = res.previewContent;
        }
        if (document.getElementById('mac-ajax-gallery-picture-description') && res.picDescriptions){
            document.getElementById('mac-ajax-gallery-picture-description').innerHTML = res.picDescriptions;
        }
        
        if (res.contentJs){
            thumbsArray = new Array();            
            contentJs = res.contentJs
            for (gal_i=0; gal_i<contentJs.length; gal_i++){
                thumbsArray.push(contentJs[gal_i]);
            }
        }

        if (res.prevThumbId){
            prevThumbId = res.prevThumbId;
            nextThumbId = res.nextThumbId;
        }
        buildGalleryBlocks();
        disableEnableLoader('none');
    }, "json");
}

function disableEnableLoader(loaderStyle){
    document.getElementById('mac-ajax-gallery-loader').style.display = loaderStyle;
}

function showPreviewDescription(descIndex){
    if (hasThumbNavi){
        descIndex = prevThumbId + descIndex - 1;
    }else{
        descIndex = prevThumbId + descIndex;
    }
    
    // description object
    if (document.getElementById(previewDescStr+descIndex)){
		    objSliderBlock = document.getElementById(previewDescStr+descIndex);
		    $(objSliderBlock).fadeIn("slow");
    }
    // close all descriptions blocks
    closeAllPreviewDescriptions(descIndex);		
}

function closeAllPreviewDescriptions(currentId){
    if (hasThumbNavi){
        tmpI = 1;
    }else{
        tmpI = 0;
    }
    
	for (i=prevThumbId; i <= (prevThumbId+nThumbs-tmpI); i++){
		if (i == currentId){
			continue;
		}
		if (document.getElementById(previewDescStr+i)){
			objSliderBlock = document.getElementById(previewDescStr+i);
			$(objSliderBlock).hide();
		}
	}
}

function disableEnableThumbNavis(effectType){
    if (hasThumbNavi){
        if (effectType == 'disable'){
            $(document.getElementById('mac-ajax-gallery-thumbnavi-prev')).fadeOut("slow");
            $(document.getElementById('mac-ajax-gallery-thumbnavi-next')).fadeOut("slow");
        }else{
            $(document.getElementById('mac-ajax-gallery-thumbnavi-prev')).fadeIn("slow");
            $(document.getElementById('mac-ajax-gallery-thumbnavi-next')).fadeIn("slow");
        }
    }
}