/*
This script is copyright (c) 2006 Elliot Swan under the
Creative Commons Attribution-ShareAlike 2.5 license:
http://creativecommons.org/licenses/by-sa/2.5/

More information on this script can be found at:
http://www.elliotswan.com/2006/04/12/move-and-copy/
*/

var Move =	{

  copy	:   function(e, target)	{
	    var eId      = $(e);
	    var copyE    = eId.cloneNode(true);
	    var cLength  = copyE.childNodes.length -1;
	    copyE.id     = e+'-copy';

	    for(var i = 0; cLength >= i;  i++)	{
	    if(copyE.childNodes[i].id) {
	    var cNode   = copyE.childNodes[i];
	    var firstId = cNode.id;
	    cNode.id    = firstId+'-copy'; }
	    }
	    $(target).appendChild(copyE);
	    },
  element:  function(e, target, type)	{
	    var eId =  $(e);
	    if(type == 'move') {
	       $(target).appendChild(eId);
	       $(eId).style.display = "block";
	    }

	    else if(type == 'copy')	{
	       this.copy(e, target);
	    }
	    }
}

function removeThisBox(id) {	
	new Effect.Fade($(id),{to:0.001,afterFinish: function(){$(id).remove()}} );	
	}

function toggleThisBox(id) {	
	new Effect.Fade($(id),{to:0.001,afterFinish: function(){$(id).toggle()}} );	
	}

function hideThisBox(id) {	
	new Effect.Fade($(id),{to:0.001,afterFinish: function(){$(id).hide()}} );	
	}

function removeAllBoxes() {
	
	var elements = $$('.box');
	elements.each(
			function(e) {
				new Effect.Fade(e,{to:0.001,afterFinish: function(){e.remove()}} );
				}
			)
			
    new Effect.Fade($('box_audiobox'),{to:0.001,afterFinish: function(){$('box_audiobox').style.display = 'none'}} );
 
 
 	}


function box_to_the_front(id) {
//	alert($(id).style.zIndex);
	var elements = $$('.box, .singlebox');
	var maxZindex=0;var boxAtTheFront;
	elements.each(
			function(e) {
				if(parseInt(e.style.zIndex)>=maxZindex) {
						maxZindex = parseInt(e.style.zIndex);
						boxAtTheFront = e;
						}
			});
//	if(boxAtTheFront && boxAtTheFront.id!=id) {
//    	alert(maxZindex);
	
    	$(id).style.zIndex = maxZindex + 1;
//		alert($(id).style.zIndex);

//		}
	}

var test;

function disableSelection(target) {

if (typeof target.onselectstart!="undefined") { //IE route
	target.onselectstart=function(){return false}
} else if (typeof target.style.MozUserSelect!="undefined") { //Firefox route
	target.style.MozUserSelect="none"
} else { //All other route (ie: Opera)
	test[target.id] = target.onmousedown;
	target.onmousedown=function(){return false}
}

//target.style.cursor = "default"

}

function enableSelection(target){
/*
if (typeof target.onselectstart!="undefined") //IE route
	target.onselectstart=function(){return true}
else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
	target.style.MozUserSelect="none"
else //All other route (ie: Opera)
	target.onmousedown=function(){return true}
target.style.cursor = "default"
*/
}

function findBox(id) {
	if($(id)) {
		box_to_the_front(id);
		new Effect.Highlight($(id),{duration: 0.5,startcolor:'#ffff00'});
		return false;
		}
	
	return true;
	}

