//******************************************************************************
//***************************CK LOADER******************************************
var CURCK = {};
var CKEDITOR_BASEPATH = '/_js/ckeditor_3.2.1/';
var CKEDITOR = {};
$(function(){
    CKEDITOR.replace = function(a1,a2){
        smartCK(a1,a2);
    }
});
function smartCK(a1,a2)
{
    CKEDITOR.replace = undefined;
    CKEDITOR = undefined;
    //delete CKEDITOR;
    $.ajaxSetup({async: false, cache: true});
    $.getScript("/_js/ckeditor_3.2.1/ckeditor.js",function(){
        $.getScript("/_js/ckeditor_3.2.1/config.js", function(){
            $.ajaxSetup({async: true});
            CURCK = CKEDITOR.replace(a1,a2);
        });
    });
}
//******************************************************************************
//***************************PRETTY PHOTO***************************************
$(function(){
    $.fn.prettyPhoto = function(){
        smartpretyfoto($(this), "prettyPhoto");
       
    };
    $.fn.megareload = function(options){
        pr_foto($(this), "megareaload" ,options);
        
    };
});

function smartpretyfoto(obj, type, options)
{
    $.fn.megareload = $.fn.prettyPhoto = undefined;
    
    $.ajaxSetup({async: false, cache: true});
    $.getScript("/_js/pretty_photo/jquery.prettyPhoto.js",function(){
            $.ajaxSetup({async: true});
            
            if(type == "megareaload"){
                $(obj).megareload(options);
            }else{
                $(obj).prettyPhoto();
            }
    });
}
//******************************************************************************
//***************************UI DATA PICKER*************************************
$(function(){
    $.fn.datepicker = function(options){
        smartdatepicker($(this), options);
    };
});

function smartdatepicker(obj, options)
{
    $.fn.datepicker = undefined;
    $.ajaxSetup({async: false, cache: true});
    $.getScript("/_js/UI/lib/ui.datepicker.js",function(){
            $.ajaxSetup({async: true});
            $(obj).datepicker(options);
    });
}
//******************************************************************************
//***************************UI TABS********************************************
//ui.tabs.js
$(function(){
    $.fn.tabs = function(options){
        smarttabs($(this), options);
    };
});
function smarttabs(obj, options)
{
    $.fn.tabs = undefined;
    $.ajaxSetup({async: false, cache: true});
    $.getScript("/_js/UI/lib/ui.tabs.js",function(){
            $.ajaxSetup({async: true});
            $(obj).tabs(options);
    });
}
//******************************************************************************
//***************************AUTOCOMPLERE***************************************
// /_js/jquery.autocomplete.js
$(function(){
    $.fn.autocomplete = function(op1,op2){
        smartautocompl($(this), op1, op2);
    };
});
function smartautocompl(obj, op1, op2)
{
    $.fn.autocomplete = undefined;
    $.ajaxSetup({async: false, cache: true});
    $.getScript("/_js/jquery.autocomplete.js",function(){
            $.ajaxSetup({async: true});
            $(this).autocomplete(op1,op2);
    });
}
//******************************************************************************
//***************************JCROP**********************************************
//_js/img_resize/jquery.Jcrop.min.js
$(function(){
    $.fn.Jcrop = function(options){
        smartjcrop($(this), options);
        
    };
});
function smartjcrop(obj, options)
{
    $.fn.Jcrop = undefined;
    $.ajaxSetup({async: false, cache: true});
    $.getScript("/_js/img_resize/jquery.Jcrop.min.js",function(){
            $.ajaxSetup({async: true});
            $(obj).Jcrop(options);
    });
}

//******************************************************************************
//***************************SWF UPLOAD*****************************************
// /_js/swfupload/swfupload.js
// /_js/swfupload/jquery.swfupload.js
$(function(){
    $.fn.swfupload = function(options){
        smartSWFUPLOAD($(this), options);
    };
});
function smartSWFUPLOAD(obj, options)
{
    $.fn.swfupload = undefined;
    $.ajaxSetup({async: false, cache: true});
    $.getScript("/_js/swfupload/swfupload.js",function(){
        $.getScript("/_js/swfupload/jquery.swfupload.js",function(){
            $.ajaxSetup({async: true});
            $(obj).swfupload(options);
        });
    });
}