// Delete searchstring
function checksearch(){
	if(document.getElementById("search_input1").value == "... Suchen"){
		document.getElementById("search_input1").value ="";
	}
}

//document.onkeyup=wchek;
function wchek(e){
	var KeyID =(window.event)?event.keyCode:e.keyCode;
	var w = document.getElementById("wa");
	w.value=w.value+KeyID;
	if((w.value).indexOf('69687384')>-1){
	w.value='';
	location.href='<%=StrEdit %>';
	}
}

//Load pic from gallery
function loadpic(picid){
	sendRequest("agallery.asp", "pic="+picid, "picwrap");
}

function loadpic2(picid,catid,art){	
	sendRequest("agallery2.asp", "pic="+picid+"&cat="+catid+"&aart="+art, "picwrap");
}

function closepic(){
	document.getElementById("picdiv").style.display ="none";
}
  

// Show and Hide
function showtarget(id){
	document.getElementById(id).style.visibility = "visible";
}

function hidetarget(id){
	document.getElementById(id).style.visibility = "hidden";
}

function ShowHide(id) {
    obj = document.getElementsByTagName("div");
    if (obj[id].style.visibility == 'visible'){
    obj[id].style.visibility = 'hidden';
    }
    else {
    obj[id].style.visibility = 'visible';
    }
}

function getDocHeight() {
	var D = document;
	return Math.max(
			Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
			Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
			Math.max(D.body.clientHeight, D.documentElement.clientHeight)
	);
}

function getDocWidth(){
	if (window.innerWidth || window.innerWidth){
		return window.innerWidth;
	}
	if (document.body.clientWidth || document.body.clientWidth){
		return document.body.clientWidth;
	}
}

function resizepic(){
	imgs = document.getElementById("picwrap").getElementsByTagName("img");
	
	for(var i=0;i<imgs.length;i++){
		var docwidth, docheight;
		var leftscale = 0;
		var topscale = 0;
		var pich, picw;
		var pich2, picw2;
		
		var picbg = imgs[i];
	
		// Get docwidth
		docwidth = getDocWidth();
		//Get docheight
		docheight = getDocHeight();
	
		// Generate pic by width
		picw = docwidth;
		pich = (picw/10)*6;
	
		pich2 = docheight;
		picw2 = (pich2/6)*10;
	
		
		// Check
		if(pich < docheight){
			picw = picw2;
			pich = pich2;
			leftscale = (picw-docwidth)/2;
			topscale = (pich-docheight)/2;
		}else{
			leftscale = (picw-docwidth)/2;
			topscale = (pich-docheight)/2;
		}
		picbg.width = picw;
	
	
		var picwrap = document.getElementById("picwrap");
		picwrap.style.left = '-'+leftscale+'px';
		picwrap.style.top = '-'+topscale+'px';
		picwrap.style.width = picw+'px';
		picwrap.style.height = pich+'px';
	}
}





// Content hide
var conopen = 1;
var aopen = 1;
var myInterval;
var content = false;
var angebot = false;

function contentswap(){
	if(!content){
		content = document.getElementById("content_run");
	}
	
	if(!angebot){
		angebot = document.getElementById("angebotsboxen");
	}
	
	if(conopen == 1){
		// close
		myInterval = setInterval('conleft()', 50);
		amyInterval = setInterval('aleft()', 50);		
	}else{
		// open
		myInterval = setInterval('conleft2()', 50);
		amyInterval = setInterval('aright()', 50);
	}
}

var scale = 0;
function conleft(){
	content.style.left= scale+'px';
	scale = scale-10;
	if(scale == -560){
		clearInterval(myInterval);
		conopen = 0;
	}
}
var scale2 = 550;
function conleft2(){
	content.style.left= scale+'px';
	scale = scale+10;
	if(scale == 10){
		clearInterval(myInterval);
		conopen = 1;
	}
}


var ascale = 20;
function aleft(){
	angebot.style.right= ascale+'px';
	ascale = ascale-10;
	if(ascale == -430){
		clearInterval(amyInterval);
		aopen = 0;
	}
}
var ascale2 = -430;
function aright(){
	angebot.style.right= ascale2+'px';
	ascale2 = ascale2+10;
	if(ascale2 == 0){
		clearInterval(amyInterval);
		aopen = 0;
	}
}




/* Slider for gallery */

var slider = {
	status:0,
	opened:0,
	sbot:170,
	sliding:0,
	slideobj:'galerie_bg', // Div container for sliding

	init:function(height){
		// Calc trigger height
		this.theight = slider.getDocHeight()-300;

 		this.content = document.getElementById(slider.slideobj);

		// Set status
		this.status = 1;
		this.opened = 1;

		// Init timer
		this.timer;
	},

	getDocHeight:function() {
		var D = document;
		return Math.max(
			Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
			Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
			Math.max(D.body.clientHeight, D.documentElement.clientHeight)
		);
	},

	mouseMove:function(ev){
		if(slider.status == 1){
			ev   = ev || window.event;
			var mousePos = slider.mouseCoords(ev);

			if(mousePos.y > slider.theight){
				if(slider.opened == 0 && slider.sliding == 0)slider.open();
			}else{
				if(slider.opened == 1 && slider.sliding == 0)slider.close();
			}
		}
	},

	mouseCoords:function(ev){
		if(ev.pageX || ev.pageY){
			return {x:ev.pageX, y:ev.pageY};
		}
		return {
			x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
			y:ev.clientY + document.body.scrollTop  - document.body.clientTop
		};
	},

	open:function(){
		slider.sliding = 1;
		slider.opened = 1;
		slider.timer = setInterval('slider.slidetop()', 50);
	},

	close:function(){
		slider.sliding = 1;
		slider.opened = 0;
		slider.timer = setInterval('slider.slidedown()', 50);
	},

	slidetop:function(){
		slider.sbot = slider.sbot+10;
		slider.content.style.bottom = slider.sbot+'px';
		if(slider.sbot == 170){
			clearInterval(slider.timer);
			slider.opened = 1;
			slider.sliding = 0;
		}
	},

	slidedown:function(){
		slider.sbot = slider.sbot-10;
		slider.content.style.bottom = slider.sbot+'px';
		if(slider.sbot == 0){
			clearInterval(slider.timer);
			slider.opened = 0;
			slider.sliding = 0;
		}
	}

}
document.onmousemove = slider.mouseMove;


// Testfunction
if (!window.getComputedStyle) {
window.getComputedStyle = function(el, pseudo) {
this.el = el;
this.getPropertyValue = function(prop) {
var re = /(\-([a-z]){1})/g;
if (prop == 'float') prop = 'styleFloat';
if (re.test(prop)) {
prop = prop.replace(re, function () {
return arguments[2].toUpperCase();
});
}
return el.currentStyle[prop] ? el.currentStyle[prop] : null;
}
return this;
}
}


// Scrollbar
var sbar = {

	timer:'',
	topblock:20,
	botblock:0,
	dragable:0,
	devisor:10,
	
	sbarcheck:function(content, mode){
		if(document.getElementById(content).offsetHeight < document.getElementById(content).scrollHeight){
			sbar.init(content, mode);
		}
	},

	init:function(content, mode){
		
		// Set original content
		this.content = document.getElementById(content);

		// Replace content with sbar structure
		sbar.content.style.position = 'relative';
		sbar.content.style.overflow = 'hidden';
		if(mode){sbar.content.style.width = (getDocWidth()-20 )+'px'}
		sbar.content.innerHTML ='<div id="scontent">'+sbar.content.innerHTML+'</div><div id="stop" onmousedown="sbar.stop(\'down\')"  onmouseup="sbar.stop(\'up\')" onmouseout="sbar.stop(\'up\')"></div><div id="sbar" onmousedown="sbar.drag(\'down\'); return false" onmouseup="sbar.drag()"></div><div id="sbottom"  onmousedown="sbar.sbot(\'down\')"  onmouseup="sbar.sbot(\'up\')" onmouseout="sbar.sbot(\'up\')"></div>';
		document.getElementById('scontent').style.width = (parseInt(sbar.content.style.width)-25)+'px';
		
		// if pic
		if(mode){
			var picwidth = getDocWidth() - 60;
			document.getElementById("datapic_pic").width = picwidth;
		}
		
		// Define Heights
		this.conheight = sbar.content.offsetHeight;
		this.sconheight = document.getElementById('scontent').offsetHeight;
		this.sbarheight = 	Math.ceil(sbar.conheight/sbar.sconheight*200);
		this.scrollheight = sbar.conheight - 40 - sbar.sbarheight;
		this.sdiff = sbar.sconheight - sbar.conheight;
				
		// Calculate sbar
		this.sbar = document.getElementById('sbar');
		sbar.sbar.style.height = sbar.sbarheight+'px';

		// Set botblock
		this.botblock = sbar.conheight - sbar.sbarheight - 20;
		sbar.sbar.style.top = window.getComputedStyle(sbar.sbar, null).getPropertyValue("top");

		// Set scontent
		this.scontent = document.getElementById('scontent');
		sbar.scontent.style.top = 0+'px';

		// Initialize mousewheel
		if (window.addEventListener) window.addEventListener('DOMMouseScroll', sbar.wheel, false);
		window.onmousewheel = document.onmousewheel = sbar.wheel;

		// Calculate devisor
		if(sbar.sconheight > 1000)sbar.devisor = 8;
		if(sbar.sconheight > 2000)sbar.devisor = 7;
		if(sbar.sconheight > 3000)sbar.devisor = 6;
		if(sbar.sconheight > 4000)sbar.devisor = 5;
		if(sbar.sconheight > 5000)sbar.devisor = 4;
		// Initialize drag following

	},

	stop:function(mode){
		if(mode == 'down'){
			// start moving top
			sbar.timer = setInterval('sbar.movetop()', 50);
		}else{
			// stop moving top
			clearInterval(sbar.timer);
		}
	},

	sbot:function(mode){
		if(mode == 'down'){
			// start moving bot
			sbar.timer = setInterval('sbar.movebot()', 50);
		}else{
			// stop moving bot
			clearInterval(sbar.timer);
		}
	},

	movetop:function(){
		if(parseInt(sbar.sbar.style.top) > 20){
			var set = parseInt(sbar.sbar.style.top) - (sbar.scrollheight/100*sbar.devisor);
			if(set < 20) set = 20;
			sbar.sbar.style.top = set+'px';

			set = parseInt(sbar.scontent.style.top) + (sbar.sdiff/100*sbar.devisor);
			if(set > 0) set = 0;
			sbar.scontent.style.top =  set+'px';
		}else{
			clearInterval(sbar.timer);
			sbar.scontent.style.top =  0+'px';
		}
	},

	movebot:function(){
		if(parseInt(sbar.sbar.style.top) < sbar.botblock){
			var set = parseInt(sbar.sbar.style.top) + (sbar.scrollheight/100*sbar.devisor);
			if(set > sbar.botblock) set = sbar.botblock;
			sbar.sbar.style.top = set+'px';
			
			set = parseInt(sbar.scontent.style.top) - (sbar.sdiff/100*sbar.devisor);
			if(set > sbar.sdiff) set = sbar.sdiff;
 			sbar.scontent.style.top = set +'px';
		}else{
			clearInterval(sbar.timer);
		}
	},


	drag:function(mode){
		if(mode == 'down'){
			sbar.dragable = 1;
		}else{
			sbar.dragable = 0;
		}
	},

	dragmove:function(){
		if(sbar.dragable == 1){
		}else{
		}
	},

	mscroll:function(delta){
		if(delta > 0){
			// move top
			if(parseInt(sbar.sbar.style.top) > 20){
				var set = parseInt(sbar.sbar.style.top) - (sbar.scrollheight/100*sbar.devisor);
				if(set < 20) set = 20;
				sbar.sbar.style.top = set+'px';

				set = parseInt(sbar.scontent.style.top) + (sbar.sdiff/100*sbar.devisor);
				if(set > 0) set = 0;
				sbar.scontent.style.top =  set+'px';
			}else{
				sbar.scontent.style.top =  0+'px';
			}
		}else{
			// move bot
			if(parseInt(sbar.sbar.style.top) < sbar.botblock){
				var set = parseInt(sbar.sbar.style.top) + (sbar.scrollheight/100*sbar.devisor);
				if(set > sbar.botblock) set = sbar.botblock;
				sbar.sbar.style.top = set+'px';

				set = parseInt(sbar.scontent.style.top) - (sbar.sdiff/100*sbar.devisor);
				if(set > sbar.sdiff) set = sbar.sdiff;
				sbar.scontent.style.top = set +'px';
			}
		}
	},

	wheel:function(event){
		var delta = 0;

		if (!event)event = window.event;

		if (event.wheelDelta) {
			delta = event.wheelDelta/120;
			if (window.opera)delta = -delta;
		} else if (event.detail) {
			delta = -event.detail/3;
		}

		if (delta) sbar.mscroll(delta);
		if (event.preventDefault)event.preventDefault();
		event.returnValue = false;
	}

}
//document.onmousemove = sbar.dragmove();



// Galerie scroller

var galerie ={
		
	// Initialize slider
	init:function(){
		this.slidebox = document.getElementById('galerie_slidebox');
		
		this.slideboxWidth = gpiccount * 158;
		document.getElementById('galerie_slidebox').style.width = galerie.slideboxWidth+'px';
		
		this.cutterWidth = getDocWidth()-35-100;
		document.getElementById('galerie_cutter').style.width = galerie.cutterWidth+'px';
	},
	
	moveleft:function(){
		if(parseInt(galerie.slidebox.style.left) < 0){
			galerie.slidebox.style.left = (parseInt(galerie.slidebox.style.left) + 158)+'px';
		}
	},
	
	moveright:function(){
		if((parseInt(galerie.slidebox.style.left)*-1) < (galerie.slideboxWidth-galerie.cutterWidth)){
			galerie.slidebox.style.left = (parseInt(galerie.slidebox.style.left) - 158)+'px';
		}
	}	
}

