/************************* JQUERY ONLOAD ACTIONS *****************************/

jQuery(document).ready(function() {
	var resourceTypeIDs = Array();
	resourceTypeIDs['audio'] = 1;
	resourceTypeIDs['image'] = 2;
	resourceTypeIDs['pdf'] = 3;
	resourceTypeIDs['excel'] = 4;
	resourceTypeIDs['video'] = 5;
	resourceTypeIDs['website'] = 6;
	resourceTypeIDs['word'] = 7;
	
	// FAVORITES EVENT BINDINGS
	var bindMoreLessBehaviors = function(scope) {
		$jQ('#moreFavoriteUsers').click(function(){
			//getFavoriteUsers();
			$jQ('#lessFavoriteUsers').removeClass('hide');
			$jQ('#moreFavoriteUsers').addClass('hide');
			$jQ('.favoriteUsersExtra').removeClass("hide");
		});
		$jQ('#moreFavoriteAudio').click(function(){
			//getFavoriteAudio();
			$jQ('#lessFavoriteAudio').removeClass('hide');
			$jQ('#moreFavoriteAudio').addClass('hide');
			$jQ('.favoriteAudioExtra').removeClass("hide");
		});
		$jQ('#moreFavoriteVideo').click(function(){
			//getFavoriteVideo();
			$jQ('#lessFavoriteVideo').removeClass('hide');
			$jQ('#moreFavoriteVideo').addClass('hide');
			$jQ('.favoriteVideoExtra').removeClass("hide");
		});
		$jQ('#moreFavoriteImages').click(function(){
			//getFavoriteImages();
			$jQ('#lessFavoriteImages').removeClass('hide');
			$jQ('#moreFavoriteImages').addClass('hide');
			$jQ('.favoriteImagesExtra').removeClass("hide");
		});
		$jQ('#moreFavoriteDocs').click(function(){
			//getFavoriteDocs();
			$jQ('#lessFavoriteDocs').removeClass('hide');
			$jQ('#moreFavoriteDocs').addClass('hide');
			$jQ('.favoriteDocsExtra').removeClass("hide");
		});
	    $jQ('#moreFavoriteWebsites').click(function(){
			//getFavoriteWebsites();
			$jQ('#lessFavoriteWebsites').removeClass('hide');
			$jQ('#moreFavoriteWebsites').addClass('hide');
			$jQ('.favoriteWebsitesExtra').removeClass("hide");
		});
		
	    $jQ('#lessFavoriteUsers').click(function(){
			$jQ('#lessFavoriteUsers').addClass('hide');
			$jQ('#moreFavoriteUsers').removeClass('hide');
			$jQ('.favoriteUsersExtra').addClass("hide");
	    });
	    $jQ('#lessFavoriteAudio').click(function(){
			$jQ('#lessFavoriteAudio').addClass('hide');
			$jQ('#moreFavoriteAudio').removeClass('hide');
			$jQ('.favoriteAudioExtra').addClass("hide");
	    });
	    $jQ('#lessFavoriteVideo').click(function(){
			$jQ('#lessFavoriteVideo').addClass('hide');
			$jQ('#moreFavoriteVideo').removeClass('hide');
			$jQ('.favoriteVideoExtra').addClass("hide");
	    });
	    $jQ('#lessFavoriteImages').click(function(){
			$jQ('#lessFavoriteImages').addClass('hide');
			$jQ('#moreFavoriteImages').removeClass('hide');
			$jQ('.favoriteImagesExtra').addClass("hide");
	    });
	    $jQ('#lessFavoriteDocs').click(function(){
			$jQ('#lessFavoriteDocs').addClass('hide');
			$jQ('#moreFavoriteDocs').removeClass('hide');
			$jQ('.favoriteDocsExtra').addClass("hide");
	    });
	    $jQ('#lessFavoriteWebsites').click(function(){
			$jQ('#lessFavoriteWebsites').addClass('hide');
			$jQ('#moreFavoriteWebsites').removeClass('hide');
			$jQ('.favoriteWebsitesExtra').addClass("hide");
	    });	
	}  // END MORELESS BEHAVIORS
	
	// Now bind the Events
	bindMoreLessBehaviors();
});

/********************** DYNAMIC DATA FUNCTIONS **********************/
function getUserID() {
    return $jQ('#u7s7e7r7i7d').attr("innerHTML");   
}

// GET Orgs FROM USER FAVORITES AND UPDATE FAVORITE ORGS TAB CONTENT
function getFavoriteOrgs() {
		$jQ.post("../includes/ajax/favorite-orgs.php",{
			  userID: getCurrentUser()
			},function(data){
			 $jQ("div#favoriteOrgList").html(data) ;
		});
}

// GET Users FROM USER FAVORITES AND UPDATE FAVORITE USERS TAB CONTENT
function getFavoriteUsers() {
	_userID = getUserID();

	$jQ.post("../includes/ajax/favorite-users.php",{
		  userID: _userID
		},function(data){
		 $jQ("div#favoriteUserList").html(data) ;
	});
}

// GET Images FROM USER FAVORITES AND UPDATE FAVORITE IMAGES TAB CONTENT
function getFavoriteImages() {
	_userID = getUserID();

	$jQ.post("../includes/ajax/favorite-images.php",{
		userID: _userID
	},function(data){
		$jQ("div#favoriteImageList").html(data);
	});
}

// GET Video FROM USER FAVORITES AND UPDATE FAVORITE VIDEO TAB CONTENT
function getFavoriteVideo() {
	_userID = getUserID();

	$jQ.post("../includes/ajax/favorite-video.php",{
		  userID: _userID
		},function(data){
		 $jQ("div#favoriteVideoList").html(data) ;
	});
}

// GET Audio FROM USER FAVORITES AND UPDATE FAVORITE AUDIO TAB CONTENT
function getFavoriteAudio() {
	_userID = getUserID();

	$jQ.post("../includes/ajax/favorite-audio.php",{
		  userID: getCurrentUser()
		},function(data){
		 $jQ("div#favoriteAudioList").html(data) ;
	});
}

// GET Docs FROM USER FAVORITES AND UPDATE FAVORITE DOCS TAB CONTENT
function getFavoriteDocs() {
	_userID = getUserID();

	$jQ.post("../includes/ajax/favorite-docs.php",{
		  userID: getCurrentUser()
		},function(data){
		 $jQ("div#favoriteDocList").html(data) ;
	});
}

// GET Docs FROM USER FAVORITES AND UPDATE FAVORITE DOCS TAB CONTENT
function getFavoriteWebsites() {
	_userID = getUserID();

	$jQ.post("../includes/ajax/favorite-websites.php",{
		  userID: getCurrentUser()
		},function(data){
		 $jQ("div#favoriteWebsiteList").html(data) ;
	});
}

// GET DETAIL FOR RESOURCE AND UPDATE DETAIL POPUP WINDOW
function getResourceDetail(_resourceID, _userID) {
	$jQ.post("../includes/ajax/favorite-resources-detail.php",{
		resourceID: _resourceID,
		userID: _userID
	},function(data){
		$jQ("div#resourceDetailContainer").html(data);
		$jQ("div#resourceDetail").fadeIn('fast');
	});
}

// GET Contacts FROM USER FAVORITES AND UPDATE CONTACTS POPUP WINDOW
function getContacts() {
	_userID = getUserID();

	$jQ.post("../includes/ajax/favorite-contacts.php",{
		  userID: _userID
		},function(data){
		 $jQ("div#contactList").html(data) ;
	});
	$jQ("div#contacts").fadeIn('fast');
}

function getMessageContacts(_messageOutType) {
	_userID = getUserID();
	$jQ.prompt("Getting Contact List");
	
	$jQ.post("../includes/ajax/favorite-contacts.php",{
		  userID: _userID

		},function(data){
		 $jQ("div#messageContactDetail").html(data) ;
	});
	$jQ("div#messageContacts").fadeIn('fast') ;
}

// GET ALL ORGS NOT ALREADY FAVORITES AND UPDATE ADD-ORGS POPUP WINDOW
function getOrgs() {
	_userID = getUserID();

	$jQ.post("../includes/ajax/favorite-orgs-add.php",{
		  userID: _userID
		},function(data){
		 $jQ("div#orgList").html(data) ;
	});
	$jQ("div#searchOrgs").fadeIn('fast');
}

// GET ALL USERS NOT ALREADY FAVORITES AND UPDATE ADD-USERS POPUP WINDOW
function getUsers() {
	_userID = getUserID();

	$jQ.post("../includes/ajax/favorite-users-add.php",{
		  userID: _userID
		},function(data){
		 $jQ("div#userList").html(data) ;
	});
	$jQ("div#searchUsers").fadeIn('fast');
}

// ADDS AN ORGANIZATION TO USER FAVORITES
function addFavoriteOrg(_userID,_orgID) {
		$jQ.post("../includes/ajax/favorite-orgs-add.php",{
			  userID: _userID,
			  orgID: _orgID
			},function(){
			 getFavoriteOrgs();
			 $jQ("div#searchOrgs").fadeOut('fast');
		});
}

// ADDS A USER TO USER FAVORITES
function addFavoriteUser(_userID,_contactID) {
		$jQ.post("../includes/ajax/favorite-users-add.php",{
			  userID: _userID,
			  contactID: _contactID
			},function(){
			 getFavoriteUsers();
			 $jQ("div#searchUsers").fadeOut('fast');
		});
}

function addResourceToFavorites(_userID, _resourceID) {
		$jQ.ajax({ 
			type: "POST", 
			url: "../includes/ajax/favorite-resources-add.php",
			data: "userID="+_userID+"&resourceID="+_resourceID,
			success: function(data) {
				$jQ.prompt(data);
				$jQ("#addToFavorites").attr("innerHTML","");
				$jQ("#myFavoriteResource").removeClass("hide");
			},
			error: function(data) {
				$jQ.prompt(data);
			},
		});
}


