window.onload = function() {

	new Effect.BlindUp('completed',{duration: 0});
	new Effect.BlindUp('progress',{duration: 0});
	 
	$('uploadbtn').onclick = function() {
		new Effect.toggle('upload','blind');
		new Effect.toggle('progress','blind');
		new Effect.toggle('shareBox','blind');
		AIM.submit($('uploadfrm'), {
			'onStart': function(){
				$('completed').innerHTML = "started";
				return true;
			},
			'onComplete': function(response) {
				$('completed').innerHTML = response;
				new Effect.toggle('progress','blind');
				new Effect.toggle('completed','blind');
				if($('imgNum')){
					curNum = $('imgNum').innerHTML;
					$('imgNum').innerHTML = parseFloat(curNum) + 1;
				}
			}
      })
   };
	
   restart = function() {
		new Effect.toggle('upload','blind');
		new Effect.toggle('completed','blind');
		new Effect.toggle('shareBox','blind');
   };
   
   if($('loginbtn')){
		$('loginbtn').onclick = function() {
			AIM.submit($('loginfrm'), {
				'onStart': function(){
					$('loginbtn').innerHTML = "PLEASE WAIT...";
					return true;
				},
				'onComplete': function(response) {
					if(response == 'error'){
						$('login').innerHTML = "<strong>Invalid Username or Password</strong>! <a href='javascript: tryLoginAgain();'>Please Try Again</a>.";
					}else{
						$('login').innerHTML = response;
						$('nav').innerHTML = "<a href='index.php'>UPLOAD A PHOTO</a>&nbsp;&nbsp;<a href='photos.php'>MY PHOTOS</a>&nbsp;&nbsp;<a href='slideshows.php'>SLIDESHOWS</a>";
					}
				}
			})
		}
	}
   
};

var totalImageCount = 1;
var maxImageCount = 5;
function addMoreImages(upload_type){
	var block_id = $("imgfiles");
	if(totalImageCount < maxImageCount) {
		var file_id  = ("file-" + totalImageCount);
		var file_div = document.createElement("p");
		file_div.setAttribute("id", file_id);
		file_div.innerHTML += "<input name=\'imgfile[]\' type=\'file\' id=\'imgfile\' size=\'30\' />";
		block_id.appendChild(file_div);
		totalImageCount++;
	}else{
		alert("You can only add a max of "+maxImageCount+" files to each upload.");
	}
}
