function startQuote(time, name, count){
	setTimeout("blendQuote('2', '"+count+"', '"+name+"', '"+time+"')", time); 
}

function blendQuote(id, count, name, time){
	var old_id = parseInt(id)-1;
	var new_id = id;
	if(old_id < 1){
		old_id = count;
	}
	var old_pic = document.getElementById(name+"_"+old_id);
	var new_pic = document.getElementById(name+"_"+new_id);
	
	old_pic.style.zIndex = 1;
	new_pic.style.zIndex = 2;

	var fade = new Fx.Style(new_pic.getAttribute('id'), 'opacity', {duration: 1000}).start(0,1);

	//setTimeout("opacity('"+new_pic.getAttribute('id')+"', 0, 100, 700)", 0);
	setTimeout("changeOpac(0, '"+old_pic.getAttribute('id')+"')", 1);

	var next_id = parseInt(id)+1;
	if(next_id > count){
		next_id = 1;
	}
	setTimeout("blendQuote('"+next_id+"', '"+count+"', '"+name+"', '"+time+"')", time); 
}


function startSlide(time, name, count){
	setTimeout("blendIn('2', '"+count+"', '"+name+"', '"+time+"')", time); 
}

function blendIn(id, count, name, time){
	var old_id = parseInt(id)-1;
	var new_id = id;
	if(old_id < 1){
		old_id = count;
	}
	var old_pic = document.getElementById(name+"_"+old_id);
	var new_pic = document.getElementById(name+"_"+new_id);
	
	old_pic.style.zIndex = 1;
	new_pic.style.zIndex = 2;

	var fade = new Fx.Style(new_pic.getAttribute('id'), 'opacity', {duration: 1000}).start(0,1);

	//setTimeout("opacity('"+new_pic.getAttribute('id')+"', 0, 100, 700)", 0);
	setTimeout("changeOpac(0, '"+old_pic.getAttribute('id')+"')", 1300);

	var next_id = parseInt(id)+1;
	if(next_id > count){
		next_id = 1;
	}
	setTimeout("blendIn('"+next_id+"', '"+count+"', '"+name+"', '"+time+"')", time); 
}


function opacity(id, opacStart, opacEnd, millisec) {
	var obj = document.getElementById(id);
    var speed = Math.round(millisec / 100);
    var timer = 10;

    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
        	if(obj.opacity > i){
        		i = opacEnd - 1;
        	}
        	else{
				setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            	timer++;
 	    		if(i == opacEnd){
 	    			setTimeout("hideObject('" + id + "')",(timer * speed));
        		}
        	}
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

function changeOpac(opacity, id) {
    try{
      var object = document.getElementById(id).style;
      object.opacity = (opacity / 100);
      object.MozOpacity = (opacity / 100);
      object.KhtmlOpacity = (opacity / 100);
      object.filter = "alpha(opacity=" + opacity + ")";
    }
    catch(e){}
}  

function hideObject(obj_id){
  var obj = document.getElementById(obj_id);

  obj.style.opacity = 1;
  obj.style.MozOpacity = 1;
  obj.style.KhtmlOpacity = 1;
  obj.style.filter = 'alpha(opacity=100)';
  obj.style.visibility = 'hidden'; 
}






var expanded = false;
var expanding = false;

function showOverlay(id){
	if(expanding || expanded){
		return;
	}
	var overlay = document.getElementById(id);
	overlay.style.display = 'block';
	expanding = true;

	setTimeout("resizeContent('"+id+"', 0, 145, 0, 250, 220)", 1);
	setTimeout("doAfterExpand('"+id+"')", 281);
}

function doAfterExpand(id){
	var overlay = document.getElementById(id);
	var overlayText = document.getElementById(id + '-text');
	var overlayListener = document.getElementById(id + '-listener');
	
	overlay.style.overflow = 'auto';
	overlayText.style.display = 'block';
	expanded = true;
	expanding = false;
}

function hideOverlay(id){
	if(expanded && !expanding){
		var overlay = document.getElementById(id);
		var overlayText = document.getElementById(id + '-text');
		var overlayListener = document.getElementById(id + '-listener');

		overlay.style.display = 'none';
		overlay.style.overflow = 'hidden';
		overlayText.style.display = 'none';
		overlay.style.height = '0px';
		overlay.style.width = '0px';
		
		setTimeout("doAfterHide()", 281);
	}
}

function doAfterHide(){
	expanded = false;
}

/************************ EXPANDING OBJECTS ************************/

function resizeContent(id, heightStart, heightEnd, widthStart, widthEnd, millisec) {
	var obj = document.getElementById(id);
    var speed = Math.round(millisec / 100);
    var timer = 0;
    
    while(heightStart != heightEnd || widthStart != widthEnd){
    	if(heightStart == heightEnd){
    	}
    	else if(heightStart < heightEnd){
    		heightStart = heightStart + 2;
    		if(heightStart > heightEnd){
    			heightStart = heightEnd;
    		}
    	}
    	else if(heightStart > heightEnd){
    		heightStart = heightStart - 2;
    		if(heightStart < heightEnd){
    			heightStart = heightEnd;
    		}
    	}
    	if(widthStart == widthEnd){
    	}
    	else if(widthStart < widthEnd){
    		widthStart = widthStart + 2;
    		if(widthStart > widthEnd){
    			widthStart = widthEnd;
    		}
    	}
    	else if(widthStart > widthEnd){
    		widthStart = widthStart - 2;
    		if(widthStart < widthEnd){
    			widthStart = widthEnd;
    		}
    	}
    	setTimeout("changeContentSize('" + id + "','" + heightStart + "', '" + widthStart + "')",(timer * speed));
    	timer++;
    }
}

function changeContentSize(id, height, width) {
    try{
      var object = document.getElementById(id).style;
      object.width = width + 'px';
	  object.height = height + 'px';
    }
    catch(e){}
}



/************************ FLASH PLAYER ************************/

function play(file, artist, song) {
	var f = document.getElementById("flashPlayer");
	changeText(file, artist, song);
	f.SetVariable("player:jsUrl", file)
	f.SetVariable("player:jsPlay", "");
}

function changeText(file, artist, song){
	var text = document.getElementById("song-text");
	var span1 = document.createElement("span");	
	var span2 = document.createElement("span");
	var span3 = document.createElement("span");
	var span4 = document.createElement("span");
	var div = document.createElement("div");
	var a = document.createElement("a");
	
	div.setAttribute("id", "song-text");
	span1.setAttribute("style", "font-weight:bold;");
	span3.setAttribute("style", "font-weight:bold;");
	a.setAttribute("href", file);
	span1.appendChild(document.createTextNode(song));
	span2.appendChild(document.createTextNode(" von "));
	span3.appendChild(document.createTextNode(artist + ". "));
	span4.appendChild(document.createTextNode(" zum Download."));
	a.appendChild(document.createTextNode("Hier"));
	
	var parent = text.parentNode;
	parent.removeChild(text);		
	parent.appendChild(div);
	div.appendChild(span1);
	div.appendChild(span2);
	div.appendChild(span3);
	div.appendChild(a);
	div.appendChild(span4);
}

function pause() {
	document.getElementById("flashPlayer").SetVariable("player:jsPause", "");
}

function stop() {
	document.getElementById("flashPlayer").SetVariable("player:jsStop", "");
}

function volume(n) {
	document.getElementById("flashPlayer").SetVariable("player:jsVolume", n);
}
