var meoss = {
    curr_idcategory : null,
    
    ajHTML: function(args) {
        mdig.aj(args, 'html');
    },

    ajJSON: function(args) {
        mdig.aj(args, 'json');
    },

    // Makes an Ajax HTML request with sensible defaults    
    aj: function(args, dataType) {
        // On some parameters we test against undefined as the caller might
        // pass null values on purpose
        $.ajax({
            type:       args.type || 'POST',
            dataType:   dataType,
            url:        args.url,
            data:       (args.data !== undefined ? args.data : null),
            timeout:    30000,
            success:    args.success,
            beforeSend: args.beforeSend,
            error:      (args.error !== undefined ? args.error : mdig._ajError)
        });
    },

    // Service functions
    _ajError : function() {
        alert("Error in Ajax call.\n\nThis might be due to a network error. Please reload the page and try again.");
    },

	
	slider_setup : function() {
		$("#slider").easySlider({
			auto: true,
            continuous: true 
		});
		
		        
        $("#slider .miniatura").show();
	},
    
    categories_setup : function(args) {
        //meoss.cat_list_uri = args.list_uri;
        meoss.curr_idcategory = args.curr_idcategory;
        
        // Bind click events to categories with children
        $("#mm a.haschildcats").click(function() {
            $(this).siblings("ul").toggle(200);
            return false;
        });
        
        // Show all parents of current category
        //alert(meoss.curr_idcategory);
	//console.warn($("#mm span.category_id:contains(" + meoss.curr_idcategory + ")"));
        $("#mm span.category_id").each(function() {
            if ( $(this).text() === meoss.curr_idcategory ) {
                $(this).parents("ul").show();
            }
	});
//:contains(" + meoss.curr_idcategory + ")").parents("ul").show();
    }
	
};

//encrypt mail
function UnCryptMailto( s )
    {
        var n = 0;
        var r = "";
        for( var i = 0; i < s.length; i++)
        {
            n = s.charCodeAt( i );
            if( n >= 8364 )
            {
                n = 128;
            }
            r += String.fromCharCode( n - 1 );
        }
        return r;
    }

    function linkTo_UnCryptMailto( s )
    {
        location.href=UnCryptMailto( s );
    }
    
	function clearText(thefield){
	if (thefield.defaultValue==thefield.value)
	thefield.value = ""
}


$(function(){
    // Login box
    var $ltrig_cnt = $("#login_trigger").parent().parent().parent();
    
    var $lbox = $("#login_box");
    $lbox.css("left", $ltrig_cnt.position().left)
    $lbox.css("top", $ltrig_cnt.position().top + $ltrig_cnt.height()+1);
    $(window).resize(function() {
        $lbox.css("left", $ltrig_cnt.position().left)
        $lbox.css("top", $ltrig_cnt.position().top + $ltrig_cnt.height()+1);
    });
    $("#login_trigger").click(function() {
        $lbox.toggle();
        return false;
    });

    $(".miniatura").hover(function () {
      $(this).css({'background-image' : 'url(images/bgminiatura_hover.png)'});
    }, function () {
        var cssObj = {
            'background-image' : 'url(images/bgminiatura.png)'
        }
        $(this).css(cssObj);
    });


    // fancybox
    $("a[rel=zoom]").fancybox({
					'titlePosition'		: 'outside',
				'overlayColor'		: '#000',
				'overlayOpacity'	: 0.7,
        'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'titlePosition' 	: 'over',
	'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
	    return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
	}
    });
	
/*-----------------------------------------------------------------------------------*/
/*	Image Hover
/*-----------------------------------------------------------------------------------*/

	$('#gallery img').hover( function() { 
		$(this).stop().animate({opacity : 0.5 }, 200);
	}, function () {
		$(this).stop().animate({opacity : 1 }, 200);
	});
	
/*-----------------------------------------------------------------------------------*/
/*	tooltip
$(".tTip").simpletip();
/*-----------------------------------------------------------------------------------*/
	

	
});


