function hiploadNew(){
	
	$('#twittload-overlay, #twittload-box,#twittloadFinal-overlay, #twittloadFinal-box').hide();
	$("#Hipload-Final").slideDown();
	$("#Hipload-Result").slideUp();
	
}

function hiploadStart(a,b,c,d,e){
/*

Four arguments are sent to the function: 
event: The event object. 
queueID: The unique identifier of the file that was cancelled. 
fileObj: An object containing details about the file that was selecte
 name – The name of the file 
 filepath – The path on the server to the uploaded file 
 size – The size in bytes of the file 
 creationDate – The date the file was created 
 modificationDate – The last date the file was modified 
 type – The file extension beginning with a '.' 
response: The data sent back from the server. 
data: Details about the file queue. 
 fileCount – The total number of files left in the queue 
 speed – The average speed of the file upload in KB/s 

*/
	
	$("#uploadStatusMessage").html('<strong>TwittLoading... </strong> Please wait...');
	$("#twitterAfterLogged").hide();
	var d2 = d.split('|'); 
	
	
	// prepare final link for download and remove
	var MainLink = websiteUrl+d2[0];
	var RemoveLink = websiteUrl+'remove/'+d2[1]+'/'+d2[0];
		

	
	// post Twitter Message
	jQuery.ajax({
	 type: "POST",
	 url: "index.php",
	 data: "twitterAction=upload&twitterMessage="+encodeURIComponent($("#twitterMessage").val())
	 +"&twitterUpload="+encodeURIComponent(d2[2]),
	 success: function(data){
			  if(data == "OK"){
				  // twitter was posted well.
				  $("#uploadStatusMessage").html('<h2>Congratulations - File Twitted!</h2>Your file is uploaded and status updated, now and you can share it with your friends!').show();
				  
				  $("#twitterAfterLogged").html('<a href="http://twitter.com/'+$("#tLoggedAs").html()+'">View your status &raquo;</a><a href="index.php?twitter=logout" class="logout">Logout</a>').show();
									 
				
			  } else {
				  // some error, twitter was not posted.
				  $("#uploadStatusMessage").html('<h2>ERROR - File uploaded, but not Twitted!</h2>Your file is uploaded, however Twitter status was not updated. Please verify your login username and password and try again later!').show();
				  
				  $("#twitterAfterLogged").html('');
				  
			  }
		}
	});
		
				
	$("#fileLink").val(MainLink);
	$("#htmlLink").val('<a href="'+MainLink+'">'+MainLink+'</a>');
	$("#forumLink").val('[URL='+MainLink+']'+MainLink+'[/URL]');
	$("#removeLink").val(RemoveLink);
	
	$("#twitterMessage").val("");

	$('#Hipload-Result').show();

	var maskHeight = $(document).height();  
	var maskWidth = $(window).width();
	
	// calculate the values for center alignment
	var dialogTop = 100;// (maskHeight/2.5) - ($('#dialog-box').height());  
	var dialogLeft = (maskWidth/2) - (700/2); 
	
	// assign values to the overlay and dialog box
	$('#twittloadFinal-overlay').css({height:maskHeight, width:maskWidth}).fadeIn();
	$('#twittloadFinal-box').css({top:dialogTop, left:dialogLeft}).show();
	

}

$(document).ready(function() {
				



	$('#fileInput').fileUpload({
		'uploader':'swf/uploader.swf',
		'script':'upload.php',
		'cancelImg':'img/cancel.png',
		'folder':'uploads',	
		'sizeLimit':'500000',
		//'buttonImg':'img/browse-files.png',
		'wmode':'transparent',
		'buttonText':'Twitt a File!',
		//'multi':true,
		'auto':true,
		'onComplete':function(a,b,c,d,e){hiploadStart(a,b,c,d,e)}

	});

});

$(document).ready(function () {

	// if user clicked on button, the overlay layer or the dialogbox, close the dialog	
	$('a.btn-ok, #dialog-overlay, #dialog-box').click(function () {		
		$('#dialog-overlay, #dialog-box').hide();		
		return false;
	});
	
	// if user resize the window, call the same function again
	// to make sure the overlay fills the screen and dialogbox aligned to center	
	$(window).resize(function () {
		
		//only do it if the dialog box is not hidden
		if (!$('#dialog-box').is(':hidden')) popup();			
	});	
	
	
});

//Popup dialog
function popup(message) {
		
	// get the screen height and width  
	var maskHeight = $(document).height();  
	var maskWidth = $(window).width();
	
	// calculate the values for center alignment
	var dialogTop =  220;//;maskHeight/2.5) - ($('#dialog-box').height());  
	var dialogLeft = (maskWidth/2) - ($('#dialog-box').width()/2); 
	
	// assign values to the overlay and dialog box
	$('#dialog-overlay').css({height:maskHeight, width:maskWidth}).show();
	$('#dialog-box').css({top:dialogTop, left:dialogLeft}).show();
	
	// display the message
	$('#dialog-message').html(message);
			
}
