if (!window.console) {    console = {};    console.log = console.log || function(){};    console.warn = console.warn || function(){};    console.error = console.error || function(){};    console.info = console.info || function(){};}// JavaScript Document$(document).ready(function(){    /** Baux Hovering*/    function resetHover() {        $(".baux").hover(function () {            $(this).css('opacity', 1);            $(this).addClass("hover");            $(this).css("z-index", "10000");        },        function () {                        if (!$(this).hasClass('editing') ) {                $(this).css("z-index", $(this).data('z'));                $(this).removeClass("hover");                $(this).fadeTo("fast", $(this).data('o'));            }        });    }    /** Button Hovering*/    $('.fdbtn').fadeTo("fast", 0.40);    $(".fdbtn").hover(        function () {            $(this).fadeTo("fast", 0.80);        },        function () {            $(this).fadeTo("fast", 0.40);        }        );    /** Link Clicked*/    $('.note a').live('click', function() {        $(this).parents('.edit:first').addClass('clicking');    });    /** Baux Editing*/    // Edit Baux    $(".edit").live("click", function(){        if (!$(this).hasClass('clicking')) {            if (!$(this).hasClass('editing')) {                $(this).addClass('editing');                var baux = $(this);                blockBaux(baux);                                nHeight = baux.find('.note').height();                baux.find('.note').hide();                editor = $('.editor').clone();                baux.find('.note').after(editor);                editor.show();                baux.css('z-index', '89000');                editor.find('input').attr('value', baux.attr('id'));                editor.css('z-index', '90000');                editor.find('textarea').attr("value", baux.data('text'));                editor.find('textarea').height(nHeight);                editor.focus();                editor.autoResize({                    minHeight:112                });            }        } else {            $(this).removeClass('clicking');        }    });    // Close Editing    function closeEditing() {        $('.editing').each(function() {            baux = $(this);                       baux.find('.note').html("");            baux.css('z-index', baux.data('z'));            $(this).fadeTo("fast", $(this).data('o'));            baux.removeClass('editing');            baux.removeClass("hover");            baux.find('.editor').ajaxSubmit({                success: afterBauxEdit,                dataType:'json'            });            baux.find('.editor').remove();        });        killBlauker();    }    function afterBauxEdit(json, statusText) {        baux = $("#"+json.Baux.id);        baux.data('text', json.Baux.note);        baux.find('.note').html(json.Baux.htmlnote);        baux.find('.note').fadeIn('slow');        bauxWrap = baux.find('.bauxWrap');    }    /** Baux Adding*/    // Clear the input field on click    $('.input textarea').click(function(){        if ($(this).attr("value") == "type your notes in this baux") {            $(this).attr({                value: ''            });        }    });    // AutoResize the input field    $('#BauxAddForm').autoResize();    // Submit Input Button Listener    $(".input .submit").live("click", function(){        //var form = $(this).parents('form:first');        $("#BauxAddForm").ajaxSubmit({            success: addNewResponse,            dataType:'json'        });    });    // Add New Baux Callback    function addNewResponse(json, statusText) {        console.log(json);        if (json == undefined) {            force_login();        } else {            baux = printBaux(json.data.bauxes.Baux);            $('.bauxes .input').after(baux);            // Get a Refrence to the new Baux            var baux = $(".live:first");            // Offset the Baux            baux.css("margin-left", -baux.width());            // Show the Baux            baux.show();            // Slide Baux In            baux.animate({                "margin-left": "0"            }, 600 );            resetOpacity("hard");            resetHover();            resetDragable();            $('.input textarea').attr("value", "type your notes in this baux");            $('.input textarea').height(157);            checkBauxCount();        }    }    function force_login() {        goAwaySliders();        $('.loginForm').animate({            left: "10px"        }, 600 );    }        /** Baux Count Check*/function checkBauxCount() {    count = $('.baux').length;    if (count == 4) {        setTimeout("openShare()", 3000);    }}    /** Baux Loading*/    var xhr = null; // Interupt Control    // Loads the bauxes    function getBauxes() {        // Interupt Check        if (window.xhr != null) {            window.xhr.abort();            window.xhr = null;        }        // Sever Call        // Returns: JSON Object of Bauxes        $.getJSON("/bauxes/load", function(json){            $.each(json.data.bauxes, function(i, n){                baux = printBaux(n.Baux);                $('.bauxes .input').after(baux);            });            resetDragable();            resetOpacity("fade");            resetHover();        });    }    function blockBaux(el) {        el.css('z-index', '50000');        $('.blauker').css('z-index', '49000');        $('.blauker').fadeTo("fast", 0.3);    }    function killBlauker() {        $('.blauker').fadeTo("normal", 0.0, function() {            $('.blauker').hide();        });    }    $('.blauker').click(function() {        closeEditing();    });    function printBaux(data) {        baux = $('.emptybaux:last').clone();        baux.attr('id', data.id);        baux.data('text', data.note);        baux.find('.date').html("+ "+data.longdate);        baux.find('.note').html(data.htmlnote);        baux.removeClass('emptybaux');                return baux;    }    // Reset all the bauxes opacitys    function resetOpacity(type) { // Param: fade, hard        var totalBauxes = $(".baux").length;        var currentO = 0.95;        var zindex = 9500;        var totalO = 85;        var step = 0.05;        // Calculate the step        if (totalBauxes > 17) {            // 18 and up            step = (totalO/totalBauxes)/100;        } else {            // 17 or less            step = 0.05;        }        // Animations        var delay = 35; //ms        var currentDelay = 0;                //set opacity of each bauxes        $(".baux").not('.emptybaux').each(function () {            currentO = roundNumber(currentO, 2); // Round Number            // Save Settings            $(this).data("o", currentO);            $(this).data("z", zindex);            // Change Settings            $(this).css("z-index", zindex);            if (type == "fade") {                $(this).delay(currentDelay).fadeTo("normal", currentO); // Fade In            } else if (type == "hard") {                $(this).css("opacity", currentO); //Hard In            }            // Counters            currentDelay = currentDelay+delay;            currentO = currentO-step;            zindex--;        });        // Reset Bright Bauxes        // TODO: Add dynamic Opacity to class name        $(".bright").data("o", .6);        $(".bright").fadeTo("fast", .6);    }    /** Utility Functions*/    // Round Function    function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places        var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);        return newnumber;    }    /** Drag and Drop*/    function resetDragable() {        $(".dragable").draggable({            cursor: 'move',            delay: 300,            snap: true,            zIndex: 90000,            opacity: 0.50,            revert: true,            revertDuration: 0,            start: function(event, ui) {                $('.trashForm').fadeIn();            },            stop: function(event, ui) {                goAwaySliders();            }        });        $(".trashBin").droppable({            accept: '.baux',            //hoverClass: 'highlight',            tolerance:  'pointer',            over: function(event, ui) {                $(this).addClass("onDrag");            },            out: function(event, ui) {                $(this).removeClass("onDrag");            },            drop: function(event, ui) {                $(this).removeClass("onDrag");                                // Baux ID                var id = $(ui.draggable).attr("id");                // Actions                $(ui.draggable).remove();                // Call Delete                $.ajax({                    url: "/bauxes/delete/"+id,                    success: function(){                    //loadOneBaux();                    }                });                // reset O                resetOpacity("hard");                resetHover();                resetDragable();            }        });    }    /** Settings*/    $('#settingsForm').submit(function() {        $('#settingsForm').ajaxSubmit({            success: function(text, statusText) {                if (text != "") {                    $('.aj_message').html(text);                    $('.aj_message').fadeIn().delay(3000).fadeOut();                } else {                   goAwaySliders();                }            },            dataType:'text'        });        return false;    });        /** Password*/    $('#passwordForm').submit(function() {        $('#passwordForm').ajaxSubmit({            success: function(text, statusText) {                if (text != "") {                    $('.aj_message_pass').html(text);                    $('.aj_message_pass').fadeIn().delay(3000).fadeOut();                } else {                   goAwaySliders();                }            },            dataType:'text'        });        return false;    });    /** Fire up the page*/    getBauxes();});
