/**
 * 
 * LD.functions.js
 * (c) LinkDiagnosis.com
 * 
 * 
 * JS function routines
 * [Begin
 **/

if(typeof(LD) == 'undefined') {
    var LD = new Object();
}
 
// is something numeric?
function is_numeric(mixed_var) {
    if (mixed_var === '') {
        return false;
    }
    return !isNaN(mixed_var * 1);
}

// is something within a given array?
function in_array(needle, haystack, argStrict) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: true
 
    var found = false, key, strict = !!argStrict;
 
    for (key in haystack) {
        if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
            found = true;
            break;
        }
    }
 
    return found;
}


// -- Cop [
// top right controller eh
var copIsOn = false;
function whisperUser(msg, dur) {
    $('LD_Cop').innerHTML = msg;
    if(copIsOn) { return; }
    copIsOn = true;
    $('LD_Cop').fancyShow();
    if(!dur) {
        dur = 3000;
    }
    setTimeout(function(){
        $('LD_Cop').fancyHide();
        copIsOn = false;
    }, dur);
}

// -- Cop ]



// -- Captain [
// bottom right controller eh
var captainIsOn = false;
function tellUser(msg, hold) {
    $('LD_Captain').innerHTML = msg;
    if(captainIsOn) { return; }
    captainIsOn = true;
    $('LD_Captain').show();
    
    if(!hold) {
        setTimeout("untellUser();", 10000);
    }
}

function tellUserControl(msg) {
    tellUser('<a href="#" onclick="untellUser(); return false;">[X] Close</a> &gt; ' + msg, true);
}

function untellUser() {
    $('LD_Captain').hide();
    captainIsOn = false;
}

// -- Captain ]



// -- Constable [
// top left controller eh
var constableInterval = null;
function reprimandUser(msg) {
    
    if(!msg) {
        $('LD_Constable').fancyHide();
        clearInterval(constableInterval);
        
        return;
    }
    
    clearInterval(constableInterval);
    
    $('LD_Constable').innerHTML = msg;
    $('LD_Constable').fancyShow();
    
    constableInterval = setInterval("reprimandUser('');", 25000);
}

// -- Constable ]



// -- onload [
// add a domready even catcher for everything contained within this file
window.addEvent('domready', function(){
    // lets extend all elements so they have these
    Element.implement({
        show: function() {
            this.setStyle('display','');
        },
        hide: function() {
            this.setStyle('display','none');
        },
        fancyShow: function() {
            this.fade('in');
        },
        fancyHide: function() {
            this.fade('out');
        },
        flash: function(to,from,reps,prop,dur) {
            
            //defaults
            if(!reps) { reps = 1; }
            if(!prop) { prop = 'background-color'; }
            if(!dur) { dur = 250; }
            
            //create effect
            var effect = new Fx.Tween(this, {
                    duration: dur,
                    link: 'chain'
                })
            
            //do it!
            for(x = 1; x <= reps; x++)
            {
                effect.start(prop,from,to).start(prop,to,from);
            }
        }
    });
    
    // inject our notifyers if they're not president
    if(!$('LD_Cop')) {
        var i1 = new Element('div', {id: 'LD_Cop'});
        i1.set('text', 'Loading...');
        $(document.body).grab(i1);
    }
    if(!$('LD_Captain')) {
        var i2 = new Element('div', {id: 'LD_Captain'});
        i2.set('html', '<a href="#" onclick="window.location.reload();return false;">Refresh</a>');
        $(document.body).grab(i2);
    }
    if(!$('LD_Constable')) {
        var i3 = new Element('div', {id: 'LD_Constable'});
        $(document.body).grab(i3);
    }
    if(!$('LD_Station')) {
        var i4 = new Element('div', {id: 'LD_Station'});
        
        var i6 = new Element('div', {id: 'LD_Station_Close'});
        var i7 = new Element('a');
        i7.setAttribute('href', 'javascript;');
        i7.setAttribute('onclick', 'myLightBox.deactivate();return false;');
        i7.set('html', 'close');
        i6.grab(i7);
        i4.grab(i6);
        
        var i8 = new Element('br');
        i8.setStyle('clear', 'both');
        i4.grab(i8);
        
        var i9 = new Element('div', {id: 'LD_Station_Floor'});
        var i5 = new Element('span', {id: 'LD_Station_Cell'});
        i9.grab(i5);
        i4.grab(i9);
        
        $(document.body).grab(i4);
    }
    
    // hide our notifyers
    $('LD_Cop').fancyHide();
    $('LD_Captain').hide();
    $('LD_Constable').fancyHide();
    $('LD_Station').hide();
    
    
    if(typeof(LD.mb) == 'undefined' && typeof(MultiBox) == 'function') {
        LD.mb = new MultiBox('multibox', {
            descClassName:'multiBoxDesc', 
            useOverlay: true
        });
    }
    
    if((document.location.href+'').indexOf('#', 0) != -1) {
        var scroller = new Fx.Scroll(window, {
            duration  : 10
        }).toTop();
        
        var scroll_to_me = document.location.href.substring(((document.location.href+'').indexOf('#', 0)+1));
        
        var scroller = new Fx.Scroll(window, {
            duration  : 1000,
            onComplete: function() {
                $(scroll_to_me).flash('#fff','#fffea1',10);
            }
        }).toElement(scroll_to_me);
    }
});
// -- onload ]


/**
 * ]End
 **/
