$(function() {
$('#slideshow').cycle({ 
    prev:   '#prev', 
    next:   '#next', 
    timeout: 8000 
});
});

// Lightbox_me
$(function() {
	$('#open-lbx-versandkosten').click(function() {
		$('#lbx-versandkosten').lightbox_me({centered: true, onLoad: function() { $('#lbx-versandkosten').find('input:first').focus()}});
		return false;
	});
	
	$('#open-aktion-window').click(function() {
		$('#aktion-window').lightbox_me({centered: true, onLoad: function() { $('#aktion-info').find('input:first').focus()}});
		return false;
	});
});



/*
Image preview script - Alen Grakalic
*/
 
this.imagePreview = function(){	
		xOffset = 10;
		yOffset = 10;

	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Vorschau' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

// starting the script on page load
$(document).ready(function(){
	imagePreview();
});



// 29.07.2011
// equal height rows (for the SIT catfilter view)
// http://css-tricks.com/examples/EqualHeightsInRows

$(document).ready(function() {

// these are (ruh-roh) globals. You could wrap in an
  // immediately-Invoked Function Expression (IIFE) if you wanted to...
  var currentTallest = 0,
	  currentRowStart = 0,
	  rowDivs = new Array();
  
  function setConformingHeight(el, newHeight) {
		  // set the height to something new, but remember the original height in case things change
		  el.data("originalHeight", (el.data("originalHeight") == undefined) ? (el.height()) : (el.data("originalHeight")));
		  el.height(newHeight);
  }
  
  function getOriginalHeight(el) {
		  // if the height has changed, send the originalHeight
		  return (el.data("originalHeight") == undefined) ? (el.height()) : (el.data("originalHeight"));
  }
  
  function columnConform() {
  
		  // find the tallest DIV in the row, and set the heights of all of the DIVs to match it.
		  $('#catfilterwrap div > ul').each(function() {
		  
				  // "caching"
				  var $el = $(this);
				  
				  var topPosition = $el.position().top;
  
				  if (currentRowStart != topPosition) {
  
						  // we just came to a new row.  Set all the heights on the completed row
						  for(currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) setConformingHeight(rowDivs[currentDiv], currentTallest);
  
						  // set the variables for the new row
						  rowDivs.length = 0; // empty the array
						  currentRowStart = topPosition;
						  currentTallest = getOriginalHeight($el);
						  rowDivs.push($el);
  
				  } else {
  
						  // another div on the current row.  Add it to the list and check if it's taller
						  rowDivs.push($el);
						  currentTallest = (currentTallest < getOriginalHeight($el)) ? (getOriginalHeight($el)) : (currentTallest);
  
				  }
				  // do the last row
				  for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) setConformingHeight(rowDivs[currentDiv], currentTallest);
  
		  });
  
  }
  
  
  $(window).resize(function() {
		  columnConform();
  });
  
  // Dom Ready
  // You might also want to wait until window.onload if images are the things that
  // are unequalizing the blocks
  $(function() {
		  columnConform();
  });

 });
