var jsonrpc;
window.onload = function () {
    jsonrpc = new JSONRpcClient("JSON-RPC");
    JSONRpcClient.max_req_active = 5;
    GuardianUtil.default_page = 'splash';
    GuardianFacebookConnector.init();
    GuardianLogin.login_onstartup();
    GuardianHeader.initSearchBox();
    GuardianFooter.init();
    
    GuardianAudience.url_audience = '../contacts/index.jsp?type=AUDIENCE';
    var video_list;
    if ($("#galleryContainer").length > 0) {
        GetAllVideosInChannel(1, 3, "");
    }
    if ($("#guardian_VideoList").length > 0 && !($("#guardian_myvideos").length > 0)) {
        GuardianVideoList.getShuffleVideoList();
    }
    if ($("#guardian_SpaceList").length > 0) {
    	GuardianSpaceList.spaceTitleElement='.meta_title_space a';
    	GuardianSpaceList.order='ORDER_ADDED';
        GuardianSpaceList.init();
    }
    if ($("#guardian_Featured_SpaceList").length > 0) {
   		GuardianSpaceList.featured = true;
    	GuardianSpaceList.spaceListElement = "#guardian_Featured_SpaceList";
    	GuardianSpaceList.spaceTitleElement='.meta_title_space a';
    	GuardianSpaceList.paginationElement="#guardian_Featured_SpaceList .pagination";
        GuardianSpaceList.init();
    }
    if ($("#guardian_SearchList").length > 0) {
   		 GuardianSearchList.noresult_page = 'space.page';
	   	GuardianSearchList.clipType = 'UGVideoSmall';
  		GuardianSearchList.noresult_newspace = true;
       		 GuardianSearchList.getSearchList();
    }
    if ($("#guardian_RecommendedList").length > 0) {
        GuardianRecommendedList.getRecommendedList();
    }
    if ($("#videoPlayer").length > 0) {
        GuardianVideoPlayer.fillVideoPlayer();
    }
    if ($("#guardian_YourSpaces").length > 0) {
        GuardianSpaceList.getSpaceListByAccount();
    }
    if ($("#embedSpace").length > 0) {
        GuardianWidgetConfiguration.init();
    }
    if ($(".content_space").length > 0) {
        GuardianSpacePage.profileElement = ".content_space .profile";
        GuardianSpacePage.playerElement = ".content_space #video_box";
        GuardianSpacePage.commentElement = ".content_space .comments";
        GuardianSpacePage.relatedElement = ".content_space .related";
        GuardianSpacePage.subscribeElement = ".content_space .space_properties #subscribe_link";
        GuardianSpacePage.spaceVideoListElement = ".content_space .list";
        GuardianSpacePage.page_size = 8;
        GuardianSpacePage.rel_page_size = 10;
        GuardianSpacePage.videoLink = "space.page";
        GuardianSpacePage.backgroundSubscribe="#007bcc";
        GuardianSpacePage.borderSubscribe="1px solid #ccc";
        GuardianSpacePage.init();
    }
    if ($(".content_homeSpace").length > 0) {
        GuardianSpacePage.profileElement = ".content_homeSpace .profile";
        GuardianSpacePage.relatedElement = ".box_video_ads .four_video_list";
        GuardianSpacePage.advBoxElement = ".box_video_ads .four_ads_list";
        GuardianSpacePage.spaceVideoListElement = ".content_homeSpace .list";
        GuardianSpacePage.page_size = 10;
        GuardianSpacePage.rel_page_size = 4;
        GuardianSpacePage.videoLink = "space.page";
        GuardianSpacePage.init();
    }
    if ($("#guardian_confirmMail").length > 0) {
        GuardianAccount.confirmMail();
    }
    if ($("#guardian_confirmDigest").length > 0) {
        GuardianDigest.confirmDigest();
    }
    if ($(".box_join").length > 0) {
        GuardianAccount.init();
    }
    if ($(".box_digest").length > 0 && $('#digest_form').length > 0) {
        GuardianDigest.init();
    }
	if ($(".box_digest").length > 0 && $('#buy_form').length > 0) {
		GuardianDigest.login_join_callback_page = 'buy';
        GuardianMioBox.init();
    }
    if ($(".box_import").length > 0) {
        GuardianImportVideo.init();
    }
    if ($(".list_spacename").length > 0) {
        GuardianSpaceName.init();
    }
    if ($(".box_upload").length > 0) {
        GuardianUploadVideo.init();
    }
    if ($("#prof_info").length > 0 && $("#prof_info_fb").length > 0) {
		GuardianProfile.spaces_name_1='Channels';
        GuardianProfile.init();
    }
    if ($(".box_friends_list").length > 0){
    	GuardianManageFriends.init();
    }
    if ($("#prof_edit").length > 0 && $("#prof_edit_fb").length > 0) {
    	GuardianProfileEdit.no_account_page="/";
        GuardianProfileEdit.init();
    }
    if ($(".splash_search").length > 0 && $(".splash_search").length > 0) {
        GuardianSplash.init();
    }
    if ($("#forgotPassword").length > 0) {
        $("#forgotPassword").css("width", "540px");
    }
    if ($("#guardian_DropboxConfiguration").length > 0) {
        GuardianDropboxConfiguration.init();
    }
};
function loadjscssfile(filename, filetype) {
    if (filetype == "js") {
        var fileref = document.createElement("script");
        fileref.setAttribute("type", "text/javascript");
        fileref.setAttribute("src", filename);
    } else { if (filetype == "css") {
            var fileref = document.createElement("link");
            fileref.setAttribute("rel", "stylesheet");
            fileref.setAttribute("type", "text/css");
            fileref.setAttribute("href", filename);
        }
    }
    if (typeof fileref != "undefined") {
        document.getElementsByTagName("head")[0].appendChild(fileref);
    }
}

