//Symbiosis UI 0.0.2
(function ($) {
    $.symbiosis=function(json){
        if(json!=undefined){
            if(json.url!=undefined) $.symbiosis.url=json.url;
            if(json.path!=undefined) $.symbiosis.path=json.path;
            if(json.mlm!=undefined) $.symbiosis.mlm=json.mlm;
            if(json.language!=undefined) $.symbiosis.language=json.language;
            if(json.language!=undefined&&json.path!=undefined) $.symbiosis.ajax=$.symbiosis.path+'$/'+$.symbiosis.language+'/';
            $.symbiosis.ajaxLoads=0;
            $.symbiosis.ajaxLoadsComplete=0;
        }
        $.ajaxSetup({
            url: $.symbiosis.ajax,
            type: "POST",
            dataType: "json",
            global: true
        });
    }
    $.fn.sym=function(){
        //Processing javascript
        $(this).find('.symbiosis-js').each(function(){            
            name=$(this).attr('title');
            t=true;
            for(key in $.symbiosis.js){
                if($.symbiosis.js[key]==name) t=false;
            }
            if(t||$(this).hasClass('run')){
                $.symbiosis.js.push(name);
                script='<script type="text/javascript" src="'+name+'"></script>';
                last=$('head script:last');
                if(last.length){
                    last.after(script);
                }
                else{
                    $('head').append(script);
                }
            }
            $(this).remove();
        });
        //Processing styles
        $(this).find('.symbiosis-css').each(function(){
            name=$(this).attr('title');
            t=true;
            for(key in $.symbiosis.css){
                if($.symbiosis.css[key]==name) t=false;
            }
            if(t){
                $.symbiosis.css.push(name);
                link='<link rel="stylesheet" href="'+name+'" type="text/css" media="screen" />';
                last=$('head link:last');
                if(last.length){
                    last.after(link);
                }
                else{
                    $('head').append(link);
                }
            }
            $(this).remove();
        });
    }
    
    
    $(document).ready(function(){
        //Classes:
        //Dblclick class
        $('.symbiosis-dblclick')
        .click(function(){
            return false;
        })
        .dblclick(function(){
            window.location=$(this).attr('href');
        });
        $('a').click(function(){
            if($(this).attr('href')=='') return false;
            return true;
        });
        
        $('.symbiosis-hover').hover(function(){
            $(this).addClass('ui-state-hover');
        },function(){
            $(this).removeClass('ui-state-hover');
        });
        
        //Scripts&&CSS:
        $.symbiosis.js=new Array();
        $.symbiosis.css=new Array();
        
        $('script').each(function(){
            $.symbiosis.js.push($(this).attr('src'));
        });
        $('link').each(function(){
            if($(this).attr('rel')=='stylesheet'){
                $.symbiosis.css.push($(this).attr('href'));
            }
        });
        $(document).sym();
    });
})(jQuery);
