// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// 
// Coded by Travis Beckham
// http://www.squidfingers.com | http://www.podlob.com
// If want to use this code, feel free to do so, but please leave this message intact.
//
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// --- version date: 09/29/02 ---------------------------------------------------------

// Utility Functions

var dom = document.getElementById;
var iex = document.all;
var ns4 = document.layers;
var opera= dom&&navigator.userAgent.indexOf("Opera")>0;
var agent = navigator.userAgent.toLowerCase();
var mac = (agent.indexOf("mac")!=-1);
var safari = (mac && (agent.indexOf("safari")!=-1));

var contentMaskHeight = 300;
var scrollSpeed = 16; // scrolling speed
var dragHeight = 19; // Height of scrollbar drag
var trackHeight = 260; // Height of scrollbar track

function getElement(name, nest){
	
	nest = nest ? 'document.'+nest+'.' : '';
	var el = dom ? document.getElementById(name) : iex ? document.all[name] : ns4 ? eval(nest+'document.'+name) : false;
	
	el.css = ns4 ? el : el.style;
	//alert(name + " +" + nest +" -" + el.id  + "  " + parseInt(el.css.top))
	el.getTop = function(){return parseInt(el.css.top) || 0};
	el.getVisibisity = function(){return (el.style.visibility) || 0};
	el.setVisibisity = function(vis){el.style.visibility = vis};
	
	el.setTop = function(y){el.css.top=y};
	el.getHeight = function(){return ns4 ? el.document.height : el.offsetHeight};
	el.getClipHeight = function(){return ns4 ? el.clip.height : el.offsetHeight};
	
	return el;
}
function getMouse(e){
	return iex ? event.clientY : e.pageY;
}
function fixNetscape(){
	if(NS4origWidth != window.innerWidth || NS4origHeight != window.innerHeight){
		window.location.reload();
	}	
}
if(document.layers){
	NS4origWidth = window.innerWidth;
	NS4origHeight = window.innerHeight;
	window.onresize = fixNetscape;
}

// Scroll Drag Functions


function initScroller(){
	
	upObj = getElement('up'); // Reference to the up arrow div
	downObj = getElement('down'); // Reference to the down arrow div
	dragObj = getElement('drag'); // Reference to the scrollbar drag div
	contentMaskObj = getElement('textelemente'); // Reference to the content mask div
	contentObj = getElement('seiten_inhalt','textelemente'); // Reference to the content div
	contentScroll = getElement('scrolling');
	trackTop = dragObj.getTop(); // Scrollbar top contraint
	trackBottom = (trackTop+trackHeight)-dragHeight; // Scrollbar bottom contraint
	//AUSKOMMENTIERT A_R
	//contentMaskHeight = contentMaskObj.getClipHeight();// Height of the div that masks the content div
	
	contentHeight = contentObj.getHeight() + 20; // Height of the content div
	if(safari) contentHeight = contentObj.getHeight() + 200;
	scrollLength = (trackHeight-dragHeight)/(contentHeight-contentMaskHeight); // Height difference between the scrollbar track and the content
	if(!safari){
		if(contentHeight > (contentMaskHeight+40)) contentScroll.setVisibisity("visible");
		else contentScroll.setVisibisity("hidden");
	}
	scrollTimer = null;
	upObj.onmousedown = scrollUp;
	upObj.onmouseup = stopScroll;
	upObj.onmouseout = stopScroll;
	downObj.onmousedown = scrollDown;
	downObj.onmouseup = stopScroll;
	downObj.onmouseout = stopScroll;
	dragObj.onmousedown = startDrag;
	dragObj.ondragstart = function(){return false}; // for ie4.5 compatibility
	if(ns4){
		upObj.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.MOUSEOUT);
		downObj.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.MOUSEOUT);
		dragObj.captureEvents(Event.MOUSEDOWN);
	}
}
function startDrag(e){
	
	if( ((ns4 && e.which!=1) || (iex && event.button!=1)) && !opera){
		return true; // Enables the right mousebutton
	}
	dragStartMouse = getMouse(e); // Holds the starting y mouse position
	dragStartOffset = dragObj.getTop(); // Holds the starting top position of the scrollbar drag
	document.onmousemove = drag;
	document.onmouseup = stopDrag;
	if(ns4) document.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
	return false;
}
function stopDrag(){
	if(ns4) document.releaseEvents(Event.MOUSEMOVE | Event.MOUSEUP);
	document.onmousemove = null;
	document.onmouseup = null;
}
function drag(e){
	var currentMouse = getMouse(e);
	var mouseDifference = currentMouse-dragStartMouse;
	var dragDistance = dragStartOffset+mouseDifference;
	var dragMovement = (dragDistance<trackTop) ? trackTop : (dragDistance>trackBottom) ? trackBottom : dragDistance;
	var contentMovement = (dragMovement-trackTop)*(1/scrollLength);
	dragObj.setTop(dragMovement);
	contentObj.setTop(-contentMovement);
	if(iex){
		return false; // So ie-pc doesn't select the image
	}
}

// Scroll Arrow Functions

function scrollUp(){
	var contentMovement = contentObj.getTop()+scrollSpeed;
	if(contentMovement > 0){
		contentMovement = 0;
	}
	contentObj.setTop(contentMovement);
	updateDrag();
	scrollTimer = window.setTimeout('scrollUp()',25);
	return false;
}
function scrollDown(){
	var contentMovement = contentObj.getTop()-scrollSpeed;
	if(contentMovement < -(contentHeight-contentMaskHeight)){
		contentMovement = -(contentHeight-contentMaskHeight);
	}
	contentObj.setTop(contentMovement);
	updateDrag();
	scrollTimer = window.setTimeout('scrollDown()',25);
	return false;
}
function updateDrag(){
	
	var dragMovement = contentObj.getTop()*((trackHeight-dragHeight)/(contentHeight-contentMaskHeight));
	dragMovement = trackTop-Math.round(dragMovement);
	if(dragMovement < trackTop){
		dragMovement = trackTop;
	}else if(dragMovement > trackBottom){
		dragMovement = trackBottom;
	}
	dragObj.setTop(dragMovement);
}
function stopScroll(){
	if(scrollTimer){
		window.clearTimeout(scrollTimer);
		scrollTimer = null;
	}
}

window.onload = initScroller;

	
	function showHighlightImage(kategorie, nr_cat, nr_img){
		//alert(document.getElementById("catimage").src)
		document.getElementById("catimage").src="fileadmin/funeral_arts/produkte/"+kategorie+"/kollektion_"+nr_cat+"/produkt_"+nr_img+"hl.gif" 
	}
	
		function showNormalImage(){
		//alert(document.getElementById("catimage").src)
		document.getElementById("catimage").src="fileadmin/funeral_arts/produkte/dummy.gif" 
	}
	
	function changeImg(name_div, img_name,hl,nm){
		
		//document.getElementById(name_div).innerHTML =  '<img src="'+img_name+'" width="200" height="258" border="0" alt="" title="" />';
		document.getElementById(name_div).innerHTML =  img_name;
		document.getElementById(hl).className="orange";
		document.getElementById(nm).className="white";
	
	}
	
	
	
