var jsonrpc;

window.onload = function() {
 	
 	jsonrpc = new JSONRpcClient("JSON-RPC");
	//!!!!IMPORTANT!!!!!!
 	JSONRpcClient.max_req_active = 5;
 	
 	ClearSpringController.spacePage = "viewSpace.page";
 	
 	GuardianFacebookConnector.init();
 	
 	//Login Form
 	GuardianLogin.login_onstartup();
    GuardianHeader.search_page = 'space.page?spacename=';
    GuardianHeader.initSearchBox();
    GuardianFooter.init();
 
 	//Guardian Video List
    var video_list;
    
	var args = GuardianUtil.getArgs();
	    
    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.getSpaceList();
        GuardianAds.advBoxElement ="#content_all .four_ads_list";
        GuardianAds.advListSize = 4;
        GuardianAds.keywords = GuardianAds.readChannelName();
        GuardianAds.getAdvItems();
   }

   if ($('#guardian_SearchList').length > 0){
	   	GuardianSearchList.noresult_page = 'space.page';
	   	GuardianSearchList.clipType = 'UGVideoSmall';
  		GuardianSearchList.noresult_newspace = true,
  		GuardianSearchList.getSearchList();
   		GuardianAds.advBoxElement ="#content_all .four_ads_list";
        GuardianAds.advListSize = 4;
        var search_par = args['query'];
        GuardianAds.keywords = search_par;
        GuardianAds.getAdvItems();
   }

   if ($('#guardian_RecommendedList').length > 0){
	    GuardianRecommendedList.clipType = 'UGVideoSmall';
 		GuardianRecommendedList.getRecommendedList();
   }
              
   if ($('#videoPlayer').length > 0) 
   	GuardianVideoPlayer.fillVideoPlayer();
   	   
   if ($('#guardian_YourSpaces').length > 0) 
   	GuardianSpaceList.getSpaceListByAccount();
   	
   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.advBoxElement =".content_space .four_ads_list";
        GuardianSpacePage.advSearchBoxElement =".search_ads";
   		GuardianSpacePage.subscribeElement = ".content_space .space_properties #subscribe_link";
    	GuardianSpacePage.spaceVideoListElement = ".content_space .list";
    	GuardianSpacePage.page_size = 4;
        GuardianSpacePage.advListSize = 4;
        GuardianSpacePage.advSearchSize = 4;
   		GuardianSpacePage.rel_page_size = 10;
   		GuardianSpacePage.videoLink = "viewSpace.page";
   		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.subscribeElement = ".content_homeSpace .space_properties #subscribe_link";
		GuardianSpacePage.spaceVideoListElement = ".content_homeSpace .list";
    	GuardianSpacePage.page_size = 10;
   		GuardianSpacePage.rel_page_size = 4;
        GuardianSpacePage.advListSize = 4;
   		GuardianSpacePage.videoLink = "viewSpace.page";
    	GuardianSpacePage.init();
   }
   
   if($('.search_ads').length > 0 ){
    	GuardianSpacePage.advSearchBoxElement =".search_ads";
   }else{
GuardianSpacePage.advSearchBoxElement = null;
}

   
   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)  
		GuardianDigest.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.init();
		
	if($('#prof_edit').length >0 && $('#prof_edit_fb').length>0)
		GuardianProfileEdit.init();
        
        	
	if($('.splash_search').length >0 && $('.splash_search').length>0)
		GuardianSplash.init();
	
	if($('#forgotPassword').length>0){
		$('#forgotPassword').css('width','540px');
	}	
	
	if($('#content_all .btn_staytuned').length>0){
		var search_par = args['query'];
		$('#content_all .btn_staytuned').parent().attr('href','digest.page?passion=' + search_par);
	}
	
	if($('form#contact_form').length>0){
        GuardianSupport.init();
	}
		
	if($('div#content_all div.btn_bookmark').length>0){
		$('div#content_all div.btn_bookmark').parent().jFav();	
	}	
	
	if($('div#content_all a.btn_bookmark').length>0){
		$('div#content_all a.btn_bookmark').jFav();	
	}
} 


