$(document).ready(function() {

		function mod(num, base){
					var n = num % base;
					return n < 0 ? n + base : n;
		};

		function loadingFadeIn(ev) {
				$('#loader').fadeOut();
        var width = $('#image').width();
        $('table#footer').attr('style', 'width: ' + width +'px');
				$('#image').fadeIn('normal', function() {
						$('div.more_info').attr('style', 'width: ' + width +'px');
						$('div#serie').attr('style', 'width: '+ width + 'px');
						$('div#serie p').show();
						//$('table#footer').show();

						if  ($('div.more_info p').html() != '')  $('td.nav_info a').show();
						});
		};


    $('#image').fadeIn('normal', function() {}).bind("contextmenu",function(e){
	    return false;
        });

    $('td.nav_info a').hover(
        function() {
            $('div.more_info').fadeIn('fast');
        },
        function() {
            $('div.more_info').fadeOut('fast');
        }).click(function(e) { e.preventDefault(); })

//    $('td.nav a').click(function(e) {
//        var str = this.href.split('/');
//        //e.preventDefault();
//        $('div#serie p').hide();
//        $('td.nav_info a').hide();
//        //$('table#footer').hide();
//        $('#image').fadeOut('fast', function() {
//
//            var count = $('#nav_status').html().split('|')[1];
//						$.ajax({
//							url: '/json/portfolio/' + str[4] + "/" + str[5],
//							dataType: 'json',
//							cache: false,
//						 	success: function(data) {
//                var im = data[0].fields;
//                $('#image').attr('src', '/static/' + im.image);
//                $('#nav_status').html(str[5] +"|"+ count);
//                var url = "/portfolio/" + str[4] + "/";
//
//                $('#prev').get(0).href = url + (mod(str[5] - 2, parseInt(count)) + 1);
//                $('#next').get(0).href = url + (str[5] % count + 1);
//
//                var title = im.title ? '<span class="title">' + im.title + '</span><br/>' : '';
//
//                $('div.more_info p').html(title + im.info.replace('\r\n', '<br />'));
//
//                if (im.serie != null) {
//                    $.getJSON('/json/serie/' + im.serie, function(data) {
//                        var sr = data[0].fields;
//                        $('div#serie p').html(sr.name);
//                        });
//                 }
//                 else {
//                        $('div#serie p').html('');
//                 }
// 							}
//          	});
//  			});
//				$('#image').load(loadingFadeIn);
//				$('#loader').fadeIn();
//				return false;
//		});
});

