/*
var winobj = {
  fx: function(ev) {
	ev.returnValue = "You have unsaved information.";
  },
};
winobj.bfx = winobj.fx.bindAsEventListener(winobj);
Event.observe(window, 'beforeunload', winobj.bfx);
*/

function updatePlaylist(container){
	postTEST = Sortable.serialize(container.id);

	//alert(postTEST);
	var errFunc = function(t) {
		alert('Error ' + t.status + ' -- ' + t.statusText);
	}

	var handlerFunc = function(t) {
		showPlayer();
		
	}
	new Ajax.Request('http://www.myflashfetish.com/mfftube/vplaylist-asset.php?action=update', {method:'post',  postBody:postTEST, onSuccess:handlerFunc, onFailure:errFunc});
	

}
		function addV(ida, idb, title, dur){
				
							var errFunc = function(t) {
								alert('Error ' + t.status + ' -- ' + t.statusText);
										
							}

							var handlerFunc = function(t) {
								var respID = t.responseText;
								if(respID == 'invalid'){
									alert('Error, please try another video');
								} else if (respID == 'duplicate'){
									alert('You already have this video on your playlist');
								} else {
									var li = new Element('li', { id: 'al_'+ respID });
									
									var div1link = new Element('a', {'class': 'close'}).observe('click', closeHandler.bindAsEventListener(this));
									var img1 = new Element('img', {'class': 'img', src: 'http://img.youtube.com/vi/'+idb+'/1.jpg'});
									img1.setStyle({ cursor: 'move'});	
									
									li.appendChild(div1link);
									li.appendChild(img1);
									$('videoFloat').appendChild(li);
									li.style.display = 'none';
									Sortable.destroy('videoFloat');
									Sortable.create('videoFloat',{tag:'li',constraint:false, handle:'img', onUpdate:updatePlaylist});
									$(li).appear({duration: .5});
									
									
									showPlayer();
								}
								
							}

						new Ajax.Request('http://www.myflashfetish.com/mfftube/vplaylist-asset.php?action=add', {method:'post',  parameters:'vid='+ida+'&vidr='+idb+'&title='+title+'&dur='+dur, onSuccess:handlerFunc, onFailure:errFunc});	

		}
		function closeV(what, id){ 
				Element.remove(what);
					Sortable.destroy('videoFloat');
					Sortable.create('videoFloat',{tag:'li',constraint:false, handle:'img', onUpdate:updatePlaylist});
					
			var handlerFunc = function(t) {
				showPlayer();
				
			}
			
			new Ajax.Request('http://www.myflashfetish.com/mfftube/vplaylist-asset.php', {method:'get',  parameters:'action=remove&vid='+id, onSuccess:handlerFunc});
		}