/*
 * Javascript for the media page
 *
 * $Date: 2008-09-10
*/

$(document).ready(function() 
    { 
        
		// Setup Tablesorter jquery extension
		$("#table_medialista").tablesorter({
			sortList: [[0,1]], 					// [column,asc/desc] array of default sort columns.
			sortClassAsc: 'headerSortUp',		// Class name for ascending sorting action to header
			sortClassDesc: 'headerSortDown',	// Class name for descending sorting action to header
			headerClass: 'header',			// Class name for headers (th's)
			widgets: ['zebra'],
			stripingRowClass: ['#table_medialista.even','.odd'],// Class names for striping supplyed as a array.
		});
		
    } //readyFunction
);


function toggleContainer(containerid) {
	
	$("#" + containerid).toggle('fast');
}



// AJAX function that increases the media count.
//Add behaviour for the select_getPersonToEdit dropdown

function increaseDownloadCount(type, id, downloadLink) {
	if(is_int(id) && id > 0) {
		
		var inputData = new Object();
		inputData.id = id;
		inputData.type = type;
		var jsonDataString = JSON.stringify(inputData);
		
		// TODO: Use $.ajax instead in order to see errors!
		
		$.post('ajax_increaseDownloadCount.php', {data: jsonDataString}, 
			function(outputData){ 
				// DEBUG
				//if(outputData.errorMessage && outputData.errorMessage != "") {
				//	alert(outputData.errorMessage);	
				//}
				
				// Redirect user to download
				top.location.href = downloadLink;
			}, 
		"json");					
	}
	
}


function is_int(variable)
{
	return variable.constructor === Number && Math.round(variable, 0) === variable;
}