
function swap_button($menu) {
	$mcn = $menu.className;
	for($each in $menu.childNodes) {
		if($menu.childNodes[$each].nodeName && $menu.childNodes[$each].nodeName.toLowerCase() == 'a') {
			$link = $menu.childNodes[$each];
			$lcn = $link.className;
		}
	}
	if($mcn == 'menu_buttons') {
		$mcn = 'menu_buttons_aktiv';
		$lcn = 'menu_link_aktiv';
	}
	else {
		$mcn = 'menu_buttons';
		$lcn = 'menu_link';
	}

	$menu.className = $mcn;
	if(typeof($link) != 'undefined') {
		$link.className = $lcn;
	}
}

function swap_image($img,$src,$index) {
	if(document.getElementById($img)) {
		document.getElementById($img).src = $src;
	}

	if(typeof($index) != 'undefined' && !(parseInt($index) == Number.NaN)) {
		window.fotoakt = 1 + parseInt($index);

		if(document.getElementById($img + '_text')) {
			document.getElementById($img + '_text').innerHTML = window.fototext[(window.fotoakt - 1)];
		}
	}
	
	document.getElementById('fotonum').innerHTML = window.fotoakt + ' / ' + window.fotoids.length;
}

function getGalleryThumbs(index, bigBild, thumb) {
	return '<div class="float">\
				<table cellpadding="0" cellspacing="0" border="0" class="galerie_table">\
					<tr>\
						<td align="center"><a href="' + window.backlink + '/' + window.galerieseite + '-' + window.galerieid + '-' + window.seiteakt + '-' + (index + 1) + '" onclick="swap_image(\'bigbild\',\'' + bigBild + '\',\'' + index + '\'); this.blur(); return false;">\
						<img src="' + thumb + '" border="0" alt="" /></a></td>\
					</tr>\
				</table>\
			</div>';
}

function flip_galerie($dir,$div) {
	$galerie_div = document.getElementById($div);

	if($galerie_div) {
		$prev1 = document.getElementById('topprev');
		$prev2 = document.getElementById('botprev');
		$next1 = document.getElementById('topnext');
		$next2 = document.getElementById('botnext');

		$prev1.style.visibility = 'visible';
		$prev2.style.visibility = 'visible';
		$next1.style.visibility = 'visible';
		$next2.style.visibility = 'visible';

		if($dir < 1) {
			$dir = -1;
		}
		else {
			$dir = 1;
		}

		window.seiteakt += $dir;
		if(window.seiteakt < 1) {
			$prev1.style.visibility = 'hidden';
			$prev2.style.visibility = 'hidden';
		}
		if(window.seiteakt + 1 >= Math.ceil(window.fotoids.length / window.maxfotos)) {
			$next1.style.visibility = 'hidden';
			$next2.style.visibility = 'hidden';
		}

		$galerie = '';
		for($i = window.seiteakt * window.maxfotos; $i < (window.seiteakt + 1) * window.maxfotos; $i++) {
			if(typeof(window.auftragsid[$i]) != 'undefined') {
				$gid = window.galerieid.toString();
				$nid = window.auftragsid[$i].toString();

				$imgpath = window.imgpath.replace($gid,$nid);
				$imgpath = $imgpath.replace($gid.substr($gid.length - 3),$nid.substr($nid.length - 3));

				$thumb   = $imgpath + window.fototyp[$i] + window.fotoids[$i] + '.JPG';
				$bigbild = $imgpath + 'F' + window.fotoids[$i] + '.JPG';

				$galerie += getGalleryThumbs($i, $bigbild, $thumb);
				/*$galerie += '<div class="image_preview">';
				$galerie += '<div class="shadowcorner_top"></div>';
				$galerie += '<div class="shadowcorner_bottom"></div>';
				$galerie += '<div class="shadowcorner_left"></div>';
				$galerie += '<div class="shadow_side"></div>';
				$galerie += '<div class="shadow_bottom"></div>';
				$galerie += '<div class="thumb_verlauf">';
				$galerie += '<div class="thumb_bg">';
				$galerie += '<table  cellpadding="0" cellspacing="0" border="0" class="image_preview_table">';
				$galerie += '<tr>';
				$galerie += '<td align="center"><a href="' + window.backlink + '/' + window.galerieseite + '-' + window.galerieid + '-' + window.seiteakt + '-' + ($i + 1) + '" onclick="swap_image(\'bigbild\',\'' + $bigbild + '\',\'' + $i + '\'); this.blur(); return false;"><img src="' + $thumb + '" border="0" alt="" /></a></td>';
				$galerie += '</tr>';
				$galerie += '</table>';
				$galerie += '</div></div></div>';*/
				
			}
			else {
				//$galerie += '<div class="galerie_table_filler"></div>';
			}
		}

		$galerie_div.innerHTML = $galerie;
	}
}

function flip_galerie_gal($dir,$div) {
	$galerie_div = document.getElementById($div);
	
	if($galerie_div) {
		$prev1 = document.getElementById('topprev');
		$prev2 = document.getElementById('botprev');
		$next1 = document.getElementById('topnext');
		$next2 = document.getElementById('botnext');
		
		$prev1.style.visibility = 'visible';
		$prev2.style.visibility = 'visible';
		$next1.style.visibility = 'visible';
		$next2.style.visibility = 'visible';
		
		if($dir < 1) {
			$dir = -1;
		}
		else {
			$dir = 1;
		}
		
		window.seiteakt += $dir;
		if(window.seiteakt < 1) {
			$prev1.style.visibility = 'hidden';
			$prev2.style.visibility = 'hidden';
		}
		if(window.seiteakt + 1 >= Math.ceil(window.fotoids.length / window.maxfotos)) {
			$next1.style.visibility = 'hidden';
			$next2.style.visibility = 'hidden';
		}
		
		$galerie = '';
		for($i = window.seiteakt * window.maxfotos; $i < (window.seiteakt + 1) * window.maxfotos; $i++) {
			if(typeof(window.auftragsid[$i]) != 'undefined') {
				$gid = window.galerieid.toString();
				$nid = window.auftragsid[$i].toString();
				
				$imgpath = window.imgpath.replace($gid,$nid);
				$imgpath = $imgpath.replace($gid.substr($gid.length - 3),$nid.substr($nid.length - 3));
				
				$thumb   = $imgpath + window.fototyp[$i] + window.fotoids[$i] + '.JPG';
				$bigbild = $imgpath + 'F' + window.fotoids[$i] + '.JPG';

				$galerie += getGalleryThumbs($i, $bigbild, $thumb);
				/*$galerie += '<div class="image_preview">';
				$galerie += '<div class="shadowcorner_top"></div>';
				$galerie += '<div class="shadowcorner_bottom"></div>';
				$galerie += '<div class="shadowcorner_left"></div>';
				$galerie += '<div class="shadow_side_gal"></div>';
				$galerie += '<div class="shadow_bottom_gal"></div>';
				$galerie += '<div class="thumb_verlauf">';
				$galerie += '<div class="thumb_bg">';
				$galerie += '<table  cellpadding="0" cellspacing="0" border="0" class="image_preview_table">';
				$galerie += '<tr>';
				$galerie += '<td align="center"><a href="' + window.backlink + '/' + window.galerieseite + '-' + window.galerieid + '-' + window.seiteakt + '-' + ($i + 1) + '" onclick="swap_image(\'bigbild\',\'' + $bigbild + '\',\'' + $i + '\'); this.blur(); return false;"><img src="' + $thumb + '" border="0" alt="" /></a></td>';
				$galerie += '</tr>';
				$galerie += '</table>';
				$galerie += '</div></div></div>';*/
				
			}
			else {
				//$galerie += '<div class="galerie_table_filler"></div>';
			}
		}
		
		$galerie_div.innerHTML = $galerie;
	}
}

function swap_big($img,$dir) {
	if($dir < 0) {
		if(document.getElementById($img)) {
			$nextimg = window.fotoakt - 2;
	
			if(typeof(window.fotoids[$nextimg]) == 'undefined') {
				$nextimg = window.fotoids.length - 1;
	
				window.seiteakt = Math.ceil(window.fotoids.length / window.maxfotos);
				flip_galerie(-1,'galthumbs');
			}
			$FotoID = window.fotoids[$nextimg];
	
			$gid = window.galerieid.toString();
			$nid = window.auftragsid[$nextimg].toString();
	
			$imgpath = window.imgpath.replace($gid,$nid);
			$imgpath = $imgpath.replace($gid.substr($gid.length - 3),$nid.substr($nid.length - 3));
	
			document.getElementById($img).src = $imgpath + 'F' + $FotoID + '.JPG';
			window.fotoakt = parseInt($nextimg) + 1;

			if(document.getElementById($img + '_text')) {
				document.getElementById($img + '_text').innerHTML = window.fototext[(window.fotoakt - 1)];
			}

			if(window.fotoakt < (window.seiteakt * window.maxfotos) + 1) {
				flip_galerie(-1,'galthumbs');
			}
		}
	}
	else {
		if(document.getElementById($img)) {
			$nextimg = window.fotoakt;
	
			if(typeof(window.fotoids[$nextimg]) == 'undefined') {
				$nextimg = 0;
	
				window.seiteakt = -1;
				flip_galerie(1,'galthumbs');
			}
			$FotoID = window.fotoids[$nextimg];
	
			$gid = window.galerieid.toString();
			$nid = window.auftragsid[$nextimg].toString();
	
			$imgpath = window.imgpath.replace($gid,$nid);
			$imgpath = $imgpath.replace($gid.substr($gid.length - 3),$nid.substr($nid.length - 3));
	
			document.getElementById($img).src = $imgpath + 'F' + $FotoID + '.JPG';
			window.fotoakt = parseInt($nextimg) + 1;
	
			if(document.getElementById($img + '_text')) {
				document.getElementById($img + '_text').innerHTML = window.fototext[(window.fotoakt - 1)];
			}

			if(window.fotoakt > window.seiteakt * window.maxfotos + window.maxfotos) {
				flip_galerie(1,'galthumbs');
			}
		}
	}

	document.getElementById('fotonum').innerHTML = window.fotoakt + ' / ' + window.fotoids.length;
}
function swap_big_gal($img,$dir) {
	if($dir < 0) {
		if(document.getElementById($img)) {
			$nextimg = window.fotoakt - 2;
			
			if(typeof(window.fotoids[$nextimg]) == 'undefined') {
				$nextimg = window.fotoids.length - 1;
				
				window.seiteakt = Math.ceil(window.fotoids.length / window.maxfotos);
				flip_galerie_gal(-1,'galthumbs');
			}
			$FotoID = window.fotoids[$nextimg];
			
			$gid = window.galerieid.toString();
			$nid = window.auftragsid[$nextimg].toString();
			
			$imgpath = window.imgpath.replace($gid,$nid);
			$imgpath = $imgpath.replace($gid.substr($gid.length - 3),$nid.substr($nid.length - 3));
			
			document.getElementById($img).src = $imgpath + 'F' + $FotoID + '.JPG';
			window.fotoakt = parseInt($nextimg) + 1;
			
			if(document.getElementById($img + '_text')) {
				document.getElementById($img + '_text').innerHTML = window.fototext[(window.fotoakt - 1)];
			}
			
			if(window.fotoakt < (window.seiteakt * window.maxfotos) + 1) {
				flip_galerie_gal(-1,'galthumbs');
			}
		}
	}
	else {
		if(document.getElementById($img)) {
			$nextimg = window.fotoakt;
			
			if(typeof(window.fotoids[$nextimg]) == 'undefined') {
				$nextimg = 0;
				
				window.seiteakt = -1;
				flip_galerie_gal(1,'galthumbs');
			}
			$FotoID = window.fotoids[$nextimg];
			
			$gid = window.galerieid.toString();
			$nid = window.auftragsid[$nextimg].toString();
			
			$imgpath = window.imgpath.replace($gid,$nid);
			$imgpath = $imgpath.replace($gid.substr($gid.length - 3),$nid.substr($nid.length - 3));
			
			document.getElementById($img).src = $imgpath + 'F' + $FotoID + '.JPG';
			window.fotoakt = parseInt($nextimg) + 1;
			
			if(document.getElementById($img + '_text')) {
				document.getElementById($img + '_text').innerHTML = window.fototext[(window.fotoakt - 1)];
			}
			
			if(window.fotoakt > window.seiteakt * window.maxfotos + window.maxfotos) {
				flip_galerie_gal(1,'galthumbs');
			}
		}
	}
	
	document.getElementById('fotonum').innerHTML = window.fotoakt + ' / ' + window.fotoids.length;
}

function swap_video($div,$vid) {
	$video  = '<object width="590" height="480">';
	$video += '<param name="movie" value="/flash/player_basicweb.swf" />';
	$video += '<param name="FlashVars" value="videoid=' + $vid + '" />';
	$video += '<param name="allowFullScreen" value="true" />';
	$video += '<param name="allowscriptaccess" value="always" />';
	$video += '<param name="quality" value="high" />';
	$video += '<embed src="/flash/player_basicweb.swf" quality="high" flashvars="videoid=' + $vid + '"  type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="590" height="480"></embed>';
	$video += '</object>';

	document.getElementById($div).innerHTML = $video;
}


var frame_timer = null;
var is_open = -1;
var breite;
var abstand;

function sidemenu(){
		breite = document.getElementById("sidemenu").offsetWidth;
		abstand = breite * -1;
		clearTimeout(frame_timer);
		if (is_open == 1)
		{
				frame_timer = setTimeout("sidemenu_close()",20);
		}
		else
		{
				frame_timer = setTimeout("sidemenu_open()",20);
		}
		is_open = is_open * -1;
}
function sidemenu_open()
{		
		if (abstand >= -15)
		{
				abstand = 0;
				document.getElementById("sidemenu").style.right = "0px";
		}
		else
		{
				abstand = (abstand + 35);
				document.getElementById("sidemenu").style.right = abstand + "px";
				frame_timer = setTimeout("sidemenu_open()",20);
		}
}
function sidemenu_close()
{

		if (abstand <= - (breite -35)) {
				abstand = breite * -1;
				document.getElementById("sidemenu").style.right = abstand + "px";
		}
				
				
		else
		{
				abstand = abstand -35;
				document.getElementById("sidemenu").style.right = (abstand) + "px";
				frame_timer = setTimeout("sidemenu_close()",20);
		}


}


	
	function galerieTouchstart(element,e) {
		if (!e) {
			e = window.event;
		}
		var coords = [];
		if (e.touches && e.touches.length) { 	/* iPhone */
			coords[0] = e.touches[0].clientX;
			coords[1] = e.touches[0].clientY;
		} else { 				/* all others */
			coords[0] = e.clientX;
			coords[1] = e.clientY;
		}
		galerie.startCoords = coords;
		galerie.endCoords = coords;
		element.onclick = "";
		
	}		
	function galerieTouchmove(e) {
		if (!e) {
			e = window.event;
		}
		var coords = [];
		if (e.touches && e.touches.length) { 	/* iPhone */
			coords[0] = e.touches[0].clientX;
			coords[1] = e.touches[0].clientY;
		} else { 				/* all others */
			coords[0] = e.clientX;
			coords[1] = e.clientY;
		}
		galerie.endCoords = coords;
	}
	function galerieTouchend(e) {
		var differenz = galerie.startCoords[0] - galerie.endCoords[0];
		var differenz_height = galerie.startCoords[1] - galerie.endCoords[1];
		
		if (differenz_height < 50 && differenz_height > -50 ) {
			if (differenz > 15 || differenz < -15) {		
				if (galerie.startCoords[0] > galerie.endCoords[0]){
					galerie.next();
				}
				else {
					galerie.prev();
				}
			}
			galerie.endCoords = null;
		}
	}	
