(function($){
	$(document).ready(function(){
		
		//Volltextsuche
		$("#searchparams #website").click(function () {
			$("#search form").attr("action","de/suchergebnis.html");
			$("#search form").focus();
	  });
	
		$("#searchparams #product-db").click(function () {
			$("#ajaxSearch_form").attr("action","de/suchergebnis-produkte.html");
			$("#search form").focus();
	  });
		
		// Kontakt-Formular vorbelegen
		// var myDepartment = $(document).getUrlParam("did");
		// $("#department").selectOptions(myDepartment);		
		
		// Metanav
		$('#metanav ul li:last-child').addClass('last');


		// Search-Box
	  $("#ajaxSearch_input").focus(function () {
			$(this).attr("value","Suchen");		
			$("#searchparams").animate({ opacity: "show" }, "fast");
			searchparams();
			$(this).select(); // Update			
	  });
	
		$.fn.wait = function(time, type) {
	        time = time || 10000;
	        type = type || "fx";
	        return this.queue(type, function() {
	            var self = this;
	            setTimeout(function() {
	                $(self).dequeue();
	            }, time);
	        });
	    };

    function searchparams() {
	    $("#searchparams").wait().fadeOut(800)
    };

		// Lightbox
	  $('a[@rel*=lightbox]').lightBox({
		overlayBgColor: '#333333',
		txtImage: 'Bild',
		txtOf: 'von',
		imageLoading: '/assets/templates/default/images/lightbox-ico-loading.gif',
		imageBtnClose: '/assets/templates/default/images/lightbox-btn-close.gif',
		imageBtnPrev: '/assets/templates/default/images/lightbox-btn-prev.gif',
		imageBtnNext: '/assets/templates/default/images/lightbox-btn-next.gif'
	   });
	

		// Search-Box: Button-Mouse-Over
		$("#ajaxSearch_submit").mouseover(function () {
			$(this).attr("src","/assets/templates/default/images/btn_search_hover.gif");
	  });
		$("#ajaxSearch_submit").mouseout(function () {
			$(this).attr("src","/assets/templates/default/images/btn_search.gif");
	  });

		// Gallery: Add Zoom Image
		$("ul.gallery li a img").after("<div class='zoom'><span>+</span></div>");
		
		// Zebra
		$('table tr.row:nth-child(even)').addClass('alt');
		
		// Select row
		$('table tbody tr').addClass('row');
		$('table tbody tr.lastrow').removeClass('row');
		$('table tr.row td:nth-child(1)').addClass('breite');
		$('table tr.row td:nth-child(2)').addClass('winkel');
		$('table tr.row td:last-child').addClass('order no2');
		$('table tr.row td:last-child').prev("td").addClass('order no1');
		
		$("tr.row td.order").click(function () {
			$("tr.row").hide(); // Hide all rows
			$(this).parent("tr.row").show(); // Show selected row
			$(this).parent().removeClass("row"); // Remove row class
			$("tr.lastrow").show(); // Show reset link
			$("td.order").addClass("inactive"); // Set all order numbers inactive
			$(this).removeClass("inactive"); // Set class for selection
			$(this).addClass("order selected"); // Set class for selection
			$("td.order.inactive").text(" "); // Remove inactive order number
			$("td.order").removeClass("order"); // Remove order class
			$("#FormContainer").show(); // Show Form
			
			$("#Panel2").remove();
			
			myData = $(this).parent("tr").html();
			myDataNumber = $(this).text();
			myDataWidth = $(this).parent().children("td.breite").text();
			myDataAngle = $(this).parent().children("td.winkel").text();
			myData = myData.replace("\n", "","g");
			myData = myData.replace(/\n/g, ""); 
			myData = myData.replace(/\r/g, "");
			
			$("#myRowData").val(myData);
			$("p.alternative").show();

			$("a.mailMe").attr("href","mailto:info@toss-gmbh.de?cc=formschulter@toss-gmbh.de&subject=Anfrage: Standard-Formschultern&body=Sie koennen Ihrer Anfrage gern auch Zeichnungen, Skizzen oder sonstige Dokumente beifuegen.%0A%0AKatalog-Nummer:  " +myDataNumber+ "%0ABeutelbreite BW:  " +myDataWidth+ "%0AEinlaufwinkel A (Grad):  " +myDataAngle);
	  
	});
	
		/*
		$("a.reset").click(function () {
			$("tr.row td").removeClass("inactive");
			$("tr.row").show();
			$("tr.lastrow").hide();
			$("#FormContainer").hide();
			$("p.alternative").hide();
			myData = "Keine Auswahl";
	  });
		*/
		
		// Tooltip
		$('tr.row').tooltip({
		    "panelID": "Panel2",
		    "tooltipPanelID": "TooltipPanel2",
		    "popupPosition": "top, left",
				"offsetX": -21,
		    "offsetY": 0,
				"hideAfter": "9000"
		});
				
	});
})(jQuery);
