//Symbiosis UI 0.0.9
(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.design!=undefined) $.symbiosis.design=json.design;
            if(json.code!=undefined) $.symbiosis.code=json.code;
            if(json.language!=undefined){
                $.symbiosis.ajax=$.symbiosis.url+'$/'+$.symbiosis.language;
            }
            if(json.init!=undefined) $.symbiosis.init=json.init;
            $.symbiosis.ajaxLoads=0;
            $.symbiosis.ajaxLoadsComplete=0;
            $.symbiosis.funcs={};
        }
        $.ajaxSetup({
            url: $.symbiosis.ajax,
            type: "POST",
            dataType: "json",
            global: true
        });
    }
    $.fn.sym=function(){
        $(this).find('a.external').click(function(){
            window.open($(this).attr('href'));
            return false;
        });
        //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);
                if($.browser.msie){
                    document.createStyleSheet(name);
                }
                else{
                    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();
        });
        if($.symbiosis.init!=undefined){
            $.fn.symbiosis_init=$.symbiosis.init;
            $(this).symbiosis_init();
        }
    }
    $(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'));
            }
        });
        
        
        if(location.hash){
            title=location.hash.substring(1, location.hash.length);
            $('.symbiosis-accordion .'+title+' .content').show().addClass('opened');
        }
        
        $('.symbiosis-accordion .element .title').click(function(){
            var content=$(this).parent().find('.content');
            if(content.hasClass('opened')){
                content.slideUp().removeClass('opened');
                location.hash='closed';
                return false;
            }
            else{
                $(this).parent().parent().find('.opened').slideUp().removeClass('opened');
                content.slideDown().addClass('opened');
                return true;
            }
        });
        $(document).sym();
    });
})(jQuery);
