// JavaScript Document

$().ready(function() {

// print page

	$(".pageprint").click(function(){
		window.print();
	});


//productinfotoggle


$("div.productinfo").hide();

$(".productinfopanotoggle").click(function(){

	var infolink = $(this);
	var infobox = $("#" + this.rel);
	var infoboxdisplay = $("#" + this.rel).css("display");

	var productinfourl = "/ajax/product-info.php?info=" + this.rel;


	if ( infoboxdisplay == 'none' ){

		infobox.slideDown(500);
		//alert("yea");
		infobox.html("<iframe style='height: 300px; width: 450px' width=450 height=300 border=0 frameborder=0 src='" + productinfourl + "'></iframe>");


	};

	if ( infoboxdisplay == 'block' ){
		infobox.slideUp(500);
	};
	return false;
});



$(".productinfotoggle").click(function(){

	var infolink = $(this);
	var infobox = $("#" + this.rel);
	var infoboxdisplay = $("#" + this.rel).css("display");

	var productinfourl = "/ajax/product-info.php?info=" + this.rel;


	if ( infoboxdisplay == 'none' ){
			$.ajax({
			  type: "GET",
			  url: productinfourl,
			  dataType: "html",
			  beforeSend: function(){
					infolink.after("<span class='productinfotoggleloader'><img src='/img/ajax-loader-small.gif' /></span>");
			  },
			  success: function(productinfo) {
					infobox.html(productinfo);

			  },
			  complete: function(){
					infobox.slideDown(500);
					$(".productinfotoggleloader").remove();
			  }
			});

	};

	if ( infoboxdisplay == 'block' ){
		infobox.slideUp(500);
	};
	return false;
});





// infotoggle

	$(".infotoggle")
		.livequery('click', function(){
			$("#" + this.rel).animate(
			{
			  height: 'toggle',
			  opacity: 'toggle'
			}, 400);
			return false;
			});

// info

	$("div.info").hide();

// clickshow
	$(".clickshow").click(function(){
			$("#" + this.rel).animate({
			  opacity: 'show'
			}, 400);
			$(this).hide();
			return false;
	 });

// clickhide
	$(".clickhide").click(function(){
			$("#" + this.rel).animate({
			  opacity: 'hide'
			}, 400);
			return false;
	 });


// Kalender show hide all

	$(".showall").click(function(){
			$("div.infocontainer").animate({
			  height: 'show', opacity: 'show'
			}, 400);
			return false;
	 });

	$(".hideall").click(function(){
			$("div.infocontainer").animate({
			  height: 'hide', opacity: 'hide'
			}, 400);
			return false;
	 });





// Streckenkarte resize


        $('img#eventmap').click(function() {
			$("div#eventmapbig").animate({
			  height: 'toggle', opacity: 'toggle'
			}, 400);
        });


        $('div#eventmapbig span.close').click(function() {
			$("div#eventmapbig").animate({
			  height: 'toggle', opacity: 'toggle'
			}, 400);
        });


// Streckenkarte drag


		$('#eventmapbig').jqDrag('h4');
		$('#eventmapbig').jqDrag('img');



// Scroll interne Links

        $('a.internal[href*=#]').click(function() {
          if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
          && location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target
            || $('[name=' + this.hash.slice(1) +']');
            if ($target.length) {
              var targetOffset = $target.offset().top;
              $('html,body').animate({scrollTop: targetOffset}, 1000);
             return false;
            }
          }
        });



// accordion #side-main-navigation

        $('div#side-main-navigation> ul').hide();
        //$('div#side-main-navigation> ul:eq(0)').show();
        $('div#side-main-navigation> h3').click(function() {
          $(this).next('ul:hidden').slideDown(400)
          .siblings('ul:visible').slideUp(400);
		  return false;
        });


// newsticker

		$("#newsticker").newsticker();



// formnotes

	$("span.autohelp").hide();
	$("input").focus(function(){
			$("#" + this.name + "note").animate({
			  opacity: 'show'
			}, 400);
	 });
	$("input").blur(function(){
			$("#" + this.name + "note").animate({
			  opacity: 'hide'
			}, 400);
	 });


//paymentoptions

	$("div.hide").hide();
	$("#payment input[type=radio]").click(function(){
			$("div.hide").hide();
			$("#" + this.value + "data").animate({
			  opacity: 'show'
			}, 400);

	 });



//warenkorb fadeinout

	$("div.fadeinout").hide();
	$('div.fadeinout').animate({opacity: 'show'}, 1200).animate({opacity: 1.0}, 3000).animate({opacity: 0}, 1200);



// checkboxen alle/keine



	var checkboxToggle = false; // or true if they are checked on load
	 $('a.checkboxToggle').click(function() {
		$("#" + this.rel + " input[type=checkbox]").attr("checked",!checkboxToggle);
		checkboxToggle = !checkboxToggle;
		return false;
	 });


});	// ready function end



/* functions:
 * drag / resize
 * http://dev.iceburg.net/jquery/jqDnR/
 */

(function($){
$.fn.jqDrag=function(h){return i(this,h,'d');};
$.fn.jqResize=function(h){return i(this,h,'r');};
$.jqDnR={dnr:{},e:0,
drag:function(v){
 if(M.k == 'd')E.css({left:M.X+v.pageX-M.pX,top:M.Y+v.pageY-M.pY});
 else E.css({width:Math.max(v.pageX-M.pX+M.W,0),height:Math.max(v.pageY-M.pY+M.H,0)});
  return false;},
stop:function(){E.css('opacity',M.o);$().unbind('mousemove',J.drag).unbind('mouseup',J.stop);}
};
var J=$.jqDnR,M=J.dnr,E=J.e,
i=function(e,h,k){return e.each(function(){h=(h)?$(h,e):e;
 h.bind('mousedown',{e:e,k:k},function(v){var d=v.data,p={};E=d.e;
 // attempt utilization of dimensions plugin to fix IE issues
 if(E.css('position') != 'relative'){try{E.position(p);}catch(e){}}
 M={X:p.left||f('left')||0,Y:p.top||f('top')||0,W:f('width')||E[0].scrollWidth||0,H:f('height')||E[0].scrollHeight||0,pX:v.pageX,pY:v.pageY,k:d.k,o:E.css('opacity')};
 E.css({opacity:0.8});$().mousemove($.jqDnR.drag).mouseup($.jqDnR.stop);
 return false;
 });
});},
f=function(k){return parseInt(E.css(k))||false;};
})(jQuery);







/*
 * A basic news ticker.
 *
 * @name     newsticker (or newsTicker)
 * @param    delay      Delay (in milliseconds) between iterations. Default 4 seconds (4000ms)
 * @author   Sam Collett (http://www.texotela.co.uk)
 * @example  $("#news").newsticker(); // or $("#news").newsTicker(5000);
 *
 */

(function($) {

$.fn.newsTicker = $.fn.newsticker = function(delay)
{
	delay = delay || 4000;
	initTicker = function(el)
	{
		stopTicker(el);
		el.items = $("a", el);
		// hide all items (except first one)
		el.items.not(":eq(0)").hide().end();
		// current item
		el.currentitem = 0;
		startTicker(el);
	};
	startTicker = function(el)
	{
		el.tickfn = setInterval(function() { doTick(el) }, delay)
	};
	stopTicker = function(el)
	{
		clearInterval(el.tickfn);
	};
	pauseTicker = function(el)
	{
		el.pause = true;
	};
	resumeTicker = function(el)
	{
		el.pause = false;
	};
	doTick = function(el)
	{
		// don't run if paused
		if(el.pause) return;
		// pause until animation has finished
		el.pause = true;
		// hide current item
		$(el.items[el.currentitem]).fadeOut("slow",
			function()
			{
				$(this).hide();
				// move to next item and show
				el.currentitem = ++el.currentitem % (el.items.size());
				$(el.items[el.currentitem]).fadeIn("slow",
					function()
					{
						el.pause = false;
					}
				);
			}
		);
	};
	this.each(
		function()
		{
			if(this.nodeName.toLowerCase()!= "div") return;
			initTicker(this);
		}
	)
	.addClass("newsticker")
	.hover(
		function()
		{
			// pause if hovered over
			pauseTicker(this);
		},
		function()
		{
			// resume when not hovered over
			resumeTicker(this);
		}
	);
	return this;
};

})(jQuery);





// NON JQUERY
// products rechnen

function rechnen(ziel, operator)
{
  var zahlFeld = document.getElementById(ziel);
  var wert     = zahlFeld.value;

  if(operator == '-' && wert > 1)
  {
    zahlFeld.value--;
  }
  else if(operator == '+')
  {
    zahlFeld.value++;
  }
}

