/*<![CDATA[*/
$(document).ready(function(){
	/* example 1 */
	var button = $('#button1'), interval;
	var desiredaction = document.getElementById("desiredaction").value;
	
	if(!desiredaction)
		desiredaction = '?mod=CMS&cms_ui=news';
		
	new AjaxUpload(button,{
		action: desiredaction, 
		name: 'userfile',
		onSubmit : function(file, ext){		
			button.text('Uploading');
			
			// If you want to allow uploading only 1 file at time,
			// you can disable upload button
			this.disable();
			
			// Uploding -> Uploading. -> Uploading...
			interval = window.setInterval(function(){
				var text = button.text();
				if (text.length < 13){
					button.text(text + '.');					
				} else {
					button.text('Uploading');				
				}
			}, 200);
		},
		onComplete: function(file, response){
			button.html("<input type=submit value=\'Lisää uusi tiedosto\'>");
			window.clearInterval(interval);
			this.enable();
			// add file to the list
			$('<li></li>').appendTo('#filelist').text(file);
		}
	});
});

function jqvisit(address)
{
	$.get(address);
}

function focusspot()
{
	var ele = document.getElementById('focusfield');
	ele.focus();
}

function cropPicture(targetfile,resultfile)
{
	window.open("?mod=CMS&cms_ui=imagecropper&ic_targetfile="+targetfile+"&ic_resultfile="+resultfile+"&again=No", "Kuvanmuokkaus", "status = 1, height = 600, width = 800, resizable = 1" );
}

function linkHelper()
{
	window.open("?mod=CMS&cms_ui=addlink","Linkkihelppaaja","status = 1, height=200, width=800, resizable=1");
}

function lightHelper()
{
	window.open("?mod=CMS&cms_ui=addLight","Lis&auml;&auml; Valaisin","status = 1,height=200, width=800, resizable=1");
}

function touchfile(targetfile)
{
	//alert("Toiminto ei ole vielä valmis");
	var addr = "?mod=CMS&cms_ui=news&news_ui=touchfile&news_uival="+targetfile;
	jqvisit(addr);
	location.reload(true);
}

function removeFile(filename,id)
{
	$("#filelist #"+id).remove();
	var addr = "?mod=CMS&cms_ui=news&news_ui=delete&news_uival="+filename;
	//alert(addr);
	jqvisit(addr);
}



/*]]>*/
