$.postJSON = function(url, data, func) { $.post(url+(url.indexOf("?") == -1 ? "?" : "&")+"callback=?", data, func, "json"); }

var gecom = {}

gecom.baseurl = '/';

gecom.adjust_menu = function(){
	var items = $('#menu').find('li.nav-item');
	
	items.each(function(i, item){
		var sub = $(item).find('.sub');
		
		if(sub.length){
			sub.show();
			var col1 = $(sub).find('.col_1').outerWidth();
			var col2 = $(sub).find('.col_2').outerWidth();
			sub.hide();
			sub.width(col1 + col2 + 105);
			
			$(item).hover(function(){
				
				if($.browser.msie){
					sub.show().css('opacity', '1')
							  .css('filter', '');
				}else{
					sub.show()
					   .stop(true, true)
					   .animate({
							'left': '-40px',
							'opacity': '1',
							'filter': ''
						},300);
				}
			}, function(){
				if(!$.browser.msie){
					sub.stop(true, true)
					   .animate({
							'left': '-50px',
							'opacity': '0',
							'filter': ''
						},300);
					setTimeout(function(){sub.hide()}, 300);
				}else{
					sub.hide();
				}
			});
		}
	});
}

gecom.load_gallery = function(obj, path){
	
	var options = {
        continuous: true,
        counterType: "skip"
    };
	
	$.postJSON(gecom.baseurl + "bin/ajax.php?action=files",obj, function (j){
			$.each(j, function(i, res){
				if(res.status == 'ok'){
					
					var array = [];
					
					//for(var i = 0 in res.msg){
					
					for(var i = 0; i < res.msg.length; i++){
						var image = {
					        player: "img",
					        content: gecom.baseurl + 'upload/' + path + '/' + res.msg[i]
					    };
						array.push(image);
					}				    
					Shadowbox.open(array, options);
					
				}else{
					var html = {
						player: 'html',
						title: 'Error',
						content: '<div id="image_error">Errore nel caricamento delle immagini!</div>'
					}
					
					//Shadowbox.open(html, options);
				}
			});
		})
}

