function initLinks()
{
	
	if (!document.getElementsByTagName){return;}
	var anchors = document.getElementsByTagName("a");

	// loop through all anchor tags
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];

		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "lightbox")){
			// anchor.onclick = function () {showLightbox(this); return false;}
		} else {
            if (anchor.href.indexOf('.pdf') != -1 || anchor.href.indexOf('.PDF') != -1) {
                anchor.setAttribute('target', '_blank');
                anchor.className = 'link_pdf';
            }
            if (anchor.href.indexOf('.doc') != -1 || anchor.href.indexOf('.DOC') != -1) {
                anchor.setAttribute('target', '_blank');
                anchor.className = 'link_doc';
            }
            if (anchor.href.indexOf('.rtf') != -1 || anchor.href.indexOf('.RTF') != -1) {
                anchor.setAttribute('target', '_blank');
                anchor.className = 'link_doc';
            }
            if (anchor.href.indexOf('.zip') != -1 || anchor.href.indexOf('.ZIP') != -1) {
                anchor.setAttribute('target', '_blank');
                anchor.className = 'link_zip';
            }
            if (anchor.href.indexOf('.rar') != -1 || anchor.href.indexOf('.RAR') != -1) {
                anchor.setAttribute('target', '_blank');
                anchor.className = 'link_zip';
            }
		}
	}
}

window.addEvent('domready', function() {

		if (document.getElementById('login_container') != undefined) {
			header_log = new Fx.Slide("login_container", {
					duration: 1300, 
					transition: Fx.Transitions.Quint.easeOut
			});
			header_log.hide(); 
		}

		var subnavi = $$('#navlist a');
		subnavi.each(function(element) {
 			
 			var subfx = new Fx.Styles(element, {duration:400, wait:false});
 			
 			subfx.start({
				'opacity': 1
			});
 			
			element.addEvent('mouseenter', function(){
				subfx.start({
					'opacity': 0.01
				});
			});
 	
			element.addEvent('mouseleave', function(){
				subfx.start({
					'opacity': 1
				});
			});
 		});	


	/* BIGSLIDER */
	if (document.getElementById('bigslidercontainer')) {

		$('bigsliderleftmov').addEvent('click',function(){
			leftx = document.getElementById('bigsliderinnercontent');
			x = leftx.style.left.toInt();
			if(x == "" || isNaN(x)){
				x = 0;
			}

			$('bigsliderinnercontent').effect('left',{ duration: 800, transition: Fx.Transitions.Quart.easeInOut, wait:true }).start(x, x + 624 );
		});

		$('bigsliderrightmov').addEvent('click',function(){
			rightx = document.getElementById('bigsliderinnercontent');
			x = rightx.style.left.toInt();
			if(x == "" || isNaN(x)){
				x = 0;
			}
			$('bigsliderinnercontent').effect('left',{ duration: 800, transition: Fx.Transitions.Quart.easeInOut, wait:true }).start(x, x - 624 )

		});
		
		/* Tipps on the Images */

		var Tipp1 = new Tips($$('.tippImg'), {
			initialize:function(){
				this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
			},
			maxTitleChars	: 150,
			onShow: function(toolTip) {this.fx.start(0.8);},
			onHide: function(toolTip) {this.fx.start(0);}
		});
	}
	
	/* SMALLSLIDER */

/*
	if (document.getElementById('smallslidercontainer')) {

		$('smallsliderleftmov').addEvent('click',function(){
			leftx = document.getElementById('smallsliderinnercontent');
			x = leftx.style.left.toInt();
			if(x == "" || isNaN(x)){
				x = 0;
			}

			$('smallsliderinnercontent').effect('left',{ duration: 500, transition: Fx.Transitions.Quart.easeInOut, wait:true }).start(x, x - 177 );
		});

		$('smallsliderrightmov').addEvent('click',function(){
			rightx = document.getElementById('smallsliderinnercontent');
			x = rightx.style.left.toInt();
			if(x == "" || isNaN(x)){
				x = 0;
			}
			$('smallsliderinnercontent').effect('left',{ duration: 500, transition: Fx.Transitions.Quart.easeInOut, wait:true }).start(x, x + 177 )

		});
		
		var Tipp2 = new Tips($$('.tippImg'), {
			initialize:function(){
				this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
			},
			onShow: function(toolTip) {this.fx.start(1);},
			onHide: function(toolTip) {this.fx.start(0);}
		});
	}
*/	
	
	if (document.getElementById('form_comment') != undefined) {
		com_form = new Fx.Slide("form_comment", {
				duration: 1300, 
				transition: Fx.Transitions.Quint.easeOut
		});
		com_form.hide(); 
	}
	
	/* Initialize accordion if needed */
	if (document.getElementById('accordion')) {
			var accordion = new Accordion('h4.atStart', 'div.atStart', {
				opacity: false
			}, $('accordion'));
	}	


	/* Start smooth-gal if needed */

	if (document.getElementById('myGallery')) {
		myGallery = new gallery($('myGallery'), {
			timed: false,
			showCarousel: false,
			showArrows: false
		});
	}

	/* Result Slider if needed */

	if (document.getElementById('result_slider')) {
		var slider = new noobSlide({
			box: $('slidebox'),
			items: $ES('div.in_cont','slidebox'),
			size: 320,
			fxOptions: {
				duration: 600,
				transition: Fx.Transitions.Quart.easeInOut,
				wait: false
			},
			buttons: {
				previous: $('prev'),
				next: $('next')
			}
		});
	}
	/* Result Slider2 if needed */

	if (document.getElementById('result_slider3')) {
		var slider2 = new noobSlide({
			box: $('slidebox3'),
			items: $ES('div.in_cont3','slidebox3'),
			size: 320,
			fxOptions: {
				duration: 600,
				transition: Fx.Transitions.Quart.easeInOut,
				wait: false
			},
			buttons: {
				previous: $('prev'),
				next: $('next')
			}
		});
	}

	/* Index (Lexikon) Slider if needed */

	if (document.getElementById('index_slider')) {
		var slider = new noobSlide({
			box: $('slidebox2'),
			items: $ES('div.in_cont','slidebox'),
			handles: $ES('span','shandles'),
			size: 310,
			onWalk: function(currentItem,currentHandle){
				//style for handles
				this.handles.removeClass('active');
				$$(currentHandle,this.handles[this.currentIndex]).addClass('active');
			},
			fxOptions: {
				duration: 600,
				transition: Fx.Transitions.Quart.easeInOut,
				wait: false
			}
		});
	}
	
	initLinks();
	
});



function set_gal(gal_number,thumb_id) {
	myGallery.goTo(gal_number);
	var t_images = 	$$("#jd_thumbnavi img");
	t_images.each(function(element) {
		if (element.id == thumb_id) {
			element.setStyle('border-color', '#444');
		} else {
			element.setStyle('border-color', '#fff');		
		}
	});
}

var myGallery = true;
var header_log = true;
var com_form = true;

/* EDIT */

/** XHConn - Simple XMLHTTP Interface - brad@xkr.us - 2005-01-24             **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function XHConn()
{
  var xmlhttp;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){ if (xmlhttp.readyState == 4) {
        fnDone(xmlhttp); }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}

function kill_comment(weblog_id, entry_id,comment_id) {
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	myConn.connect("http://www.kleindenkmaeler.at/kleinsys/index.php", "GET", "S=0&C=edit&M=change_status&weblog_id="+ weblog_id +"&entry_id="+ entry_id +"&comment_id="+ comment_id +"&current_page=0&status=close", handle_res);
}


handle_res = function(z)  {
	//alert(z.responseText);
	// do a reload if successfull!
	location.reload();

}

function goto_lexi_de() {
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	myConn.connect("http://www.kleindenkmaeler.at/lexikon-suche/de_url_title/", "POST", "title="+ document.bsuche_form.bsuche.value, lexi_page_de);

}

lexi_page_de = function(z)  {
	// do a reload if successfull!
	window.location.href = "http://www.kleindenkmaeler.at/lexikon/" + z.responseText;

}

function goto_lexi_sl() {
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	myConn.connect("http://www.kleindenkmaeler.at/lexikon-suche/sl_url_title/", "POST", "title="+ document.bsuche_form.bsuche.value, lexi_page_sl);

}

lexi_page_sl = function(z)  {
	// do a reload if successfull!
	window.location.href = "http://www.kleindenkmaeler.at/leksikon/" + z.responseText;

}
