/* function to fix the -10000 pixel limit of jquery.animate */
$.fx.prototype.cur = function(){
    if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
      return this.elem[ this.prop ];
    }
    var r = parseFloat( jQuery.css( this.elem, this.prop ) );
    return typeof r == 'undefined' ? 0 : r;
}

$(function(){
    init();
});

function init() {
    assignLinks();
    mCustomScrollbars();
    $("a[rel=gallery]").fancybox();
}

function assignLinks () {
    $('.topmenu a, #content a').not('a[rel=gallery]').not('a[href^=http]').each(function(){
        if ( !$(this).hasClass('assigned') )
            $(this).attr('href', "javascript:textLoad('"+this.href+"');").addClass('assigned');
    });
}

var loading = false;

function textLoad ( href ) {
    if ( loading ) return;

//    textToggle(false, function() {
//        $('#content').load(href+' #content', {}, function(){
//            loading = false;
//            init();
//            textToggle(true);
//        } );
//    } );

    textToggle(false, function () {
        loading = false;
        textToggle(true);
        $('#content').html('<img style="border: none; margin: 185px 0 0 230px;" src="/html/images/loading.gif">');
        init();
        $('#content').load(href+' #content', {}, init );
    });
//    loading = false;

}

function textToggle ( turn_on, callback ) {

    if ( !callback ) callback = function(){
        loading = false;
        $('#mcs_container').removeClass('low');
    }

    if ( loading ) return;
    loading = true;
    
    $('#mcs_container').addClass('low');
    if ( turn_on ) {
        $('#text').animate({'left':'0px'}, 300, 'linear', callback );
    } else {
        $('#text').animate({'left':'-1000px'}, 500, 'linear', callback );
    }
}

function mCustomScrollbars(){
	/*
	malihu custom scrollbar function parameters:
	1) scroll type (values: "vertical" or "horizontal")
	2) scroll easing amount (0 for no easing)
	3) scroll easing type
	4) extra bottom scrolling space for vertical scroll type only (minimum value: 1)
	5) scrollbar height/width adjustment (values: "auto" or "fixed")
	6) mouse-wheel support (values: "yes" or "no")
	7) scrolling via buttons support (values: "yes" or "no")
	8) buttons scrolling speed (values: 1-20, 1 being the slowest)
	*/
	$("#mcs_container").mCustomScrollbar("vertical",300,"easeOutCirc",1.1,"auto","yes","yes",15);
}


//$(function(){
//        $('.topmenu a').each(function(){
//                $(this).attr('onclick', 'return false;');
//                alert ( this.href );
//            }).click(function(){
//                textToggle(false);
//                $('#text').load(this.href+' #content');
//                textToggle(true);
//                return false;
//            });
//        });

