// JavaScript Document
$(document).ready(function(){
   // Your code here
   //Preload
   	$.preload( ".gallery-element a");
	$.preload( ".product a");
	$.preload( ".archiv a");
	$.preload(".section_list div a div");
	
	// Creating custom :external selector
$.expr[':'].external = function(obj){
    return !obj.href.match(/^mailto\:/)
            && (obj.hostname != location.hostname);
};

// Add 'external' CSS class to all external links
$('a:external').attr("target","_blank");
	
	//Facebook
$("#facebook").mouseenter(function () {
$(this).children().children("img").attr("src","http://www.lustenauer-senf.com/images/facebook_logo_bunt.png");									
									
});
$("#facebook").mouseleave(function () {
$(this).children().children("img").attr("src","http://www.lustenauer-senf.com/images/facebook_logo_sw.png");																		
});


	
	//Container-Ding
	
$(".singlediv").each(function() {
	var opacity = parseFloat($(this).css("opacity"));
	var rand = Math.random();
	opacity = opacity + (rand - 0.3)/30.0;
	if(opacity<0)
	opacity = 0;
	if(opacity > 0.4)
	opacity = 0.4;
    $(this).fadeTo(0,opacity);
  });

	//Veränderung in der Zeit
	var refreshDiv = setInterval(function()
{
	$(".singlediv").each(function() {
	var opacity = parseFloat($(this).css("opacity"));
	var rand = Math.random();
	opacity = opacity + (rand - 0.5)/30.0;
	if(opacity<0)
	opacity = 0;
	if(opacity > 0.4)
	opacity = 0.4;
    $(this).fadeTo("slow",opacity);
  });
}, 2000);
		
	//Offset setzen
	var imgoffset = $(".gallery-element:first").offset();
	
	/*//Menü
	//Mousenter
	$(".section_list div a div").mouseenter(function () {		
var src = $(this).css("background-image");
var src1 = src.substring(src.lastIndexOf('/'), src.lastIndexOf('.'));
var src2 = '"http://vorschau.lustenauer-senf.com/images' + src1 + '.png"';
$(this).empty();
$(this).prepend('<img id="hoverimage" src=' + src2 + '/>');
});
	//Mouseleave
		$(".section_list div a div").mouseleave(function () {
$(this).empty();
});*/
		
	
	
	//Box
	$(".gallery-element").click(function () {
var source = $(this).children("a").attr("href");
$("div#bildbox #close").slideUp(0);
$("div#bildbox").fadeTo(0,0);
$("#bildbox img#bild").attr("src",source);
imgoffset = $(this).offset();
$("div#bildbox").offset(imgoffset);
$("div#bildbox").css('zIndex', 200);
$("div#bildbox").fadeTo("fast", 1);
$("div#bildbox #close").slideDown("fast");
imgoffset = $(this).offset();
$("div#bildbox").offset(imgoffset);

return false;
});
	
		//Schließen bei Klick
	$("#bildbox").click(function () {
	$(this).children("#close").slideUp("fast");							  
	$(this).fadeTo("fast",0);
	$(this).css('zIndex', 2);
								});
	
	//Archiv
$(".archiv").click(function () {
var source = $(this).children("a").attr("href");
var text = $(this).children(".product-information").html();
var plink = $(this).children(".pdf-link").html();
/*imgoffset = $(this).offset();*/
$("#archiv #close p#text").text(text);
$("#archiv #close p#link a").attr("href",plink);
$("archiv").fadeTo(0,0);
$("#archiv #close").slideUp(0);
$("#archiv img#bild").attr("src",source);
/*$("#archiv").offset({left: imgoffset.left, top: imgoffset.top});*/
$("#archiv").css('zIndex', 200);
$("#archiv").fadeTo("fast", 1);
$("#archiv .content").jScrollPane();
$("#archiv .content")[0].scrollTo(0);
$("#archiv #close").slideDown("fast");							  

return false;
});
	
		//Schließen bei Klick
	$("#archiv img").click(function () {
	$("#archiv #close").slideUp("fast");							  
	$("#archiv").fadeTo("fast",0);
	$("#archiv").css('zIndex', 2);
								});
	
	//Product-Info
	$(".product").click(function () {
var image = $(this).children("a").attr("href");
var headline = $(this).children(".gallery-element-description").html();
var text = $(this).children(".product-information").html();
imgoffset = $(this).offset();

$("#single-product").offset(imgoffset);
$("#single-product img#product-image").attr("src",image);
$("#single-product-description h2").text(headline);
$("#producttxt").text(text);
$("div#single-product").css('zIndex', 9);
$("div#single-product").fadeTo("fast", 1);
imgoffset = $(this).offset();
$("#single-product").offset(imgoffset);
//Scrollable
$('#single-product-description').jScrollPane();
$('#single-product-description')[0].scrollTo(0);



return false;
										  });
	
	//Schließen bei Klick
	$("img#product-image,img#closingx").click(function () {
	$("div#single-product").fadeTo("fast",0);
	$("div#single-product").css('zIndex', 2);
								});
   
      //Gallery - Fade und Aufklappen
   $(".gallery-element,,.product,.archiv").fadeTo('fast', 0.4); //alle Elemente am Anfang transparent
   

	//Mousenter
	$(".gallery-element,.product,.archiv").mouseenter(function () {
$(this).fadeTo("fast", 1);
$(this).children(".gallery-element-description").slideDown("fast");
$(this).children(".gallery-element-description").fadeTo("slow",1);
});
	//Mouseleave
		$(".gallery-element,.product,.archiv").mouseleave(function () {
$(this).fadeTo("slow", 0.4);
$(this).children(".gallery-element-description").slideUp("fast");
});
   
      //Listen-Anweiseungen   
    $(".entry-content:first").slideDown('fast'); //erstes Listenelement wird aufgeklappt
	$(".entry:first .entry-gallery").slideDown('fast'); //erstes Listenelement wird aufgeklappt
	$(".entry-content:first .slideup .h2entry:first").slideDown('fast'); //erstes Listenelement wird aufgeklappt
	$(".entry-content:first h2:first").addClass("active");

   $("h1:first").css('color',"#CCC");
   $("h1:first").css('border-bottom-color',"#CCC");
   	$("h1:first").addClass("active");
   $(".entry-content:first").css('color',"#CCC");
/* var height = $(".entry-content:first").children(".scrollable").css('height');
	 height = parseFloat(height);
	 if(height > 402)
	 {
	 $(".entry-content:first").children(".scrollable").css('height',"402px");
	 $(".entry-content:first").children(".scrollable").jScrollPane();
	 }*/

   
   
   //Mouseenter der H1-Dinger
   //Mousenter
	$("h1").mouseenter(function () {
$(this).css('color',"#CCC");
$(this).css('border-bottom-color',"#CCC");
});
	$("h1").mouseleave(function () {
	if($(this).hasClass("active"))
	{}
	else
	{
$(this).css('color',"#999");
   $(this).css('border-bottom-color',"#999");
	}
});
   
   //Auf- und Zuklappen der Einträge
   	  $("h2").click(function () {
	
		$(this).siblings(".active").removeClass("active");
		$(this).addClass("active");
		$(this).siblings().next(".h2entry").slideUp('fast');
		$(this).next(".h2entry").slideToggle('fast');
							  
							  });
	     	  $("h3").click(function () {
		$("h3.active").removeClass("active");
		$(this).addClass("active");
		$(this).siblings().next(".h3entry").slideUp('fast');
		$(this).next(".h3entry").slideToggle('fast');
							  
							  });
			  
			  
			  
   //Auf- und Zuklappen H1
	  $("h1").click(function () {
	 $(this).parent().parent().children(".entry-content, .entry-gallery").slideToggle('fast', function() {
    // Animation complete.
  });
	
	  //Boxen schließen
	$("#bildbox").fadeTo("fast",0);
	$("#bildbox").css('zIndex', 2);
	$("#single-product").fadeTo("fast",0);
	$("#single-product").css('zIndex', 2);
	$("#archiv").fadeTo("fast",0);
	$("#archiv").css('zIndex', 2);
	 //Klassen tauschen
	 $("h1.active").css('color',"#999");
	 $("h1.active").css('border-bottom-color',"#999");
	 $("h1.active").removeClass("active");
	 $(this).addClass("active");
	 //Andere Reiter schließen
	 $(this).parent().parent().siblings().css('color',"#999"); //andere Einträge
	 $(this).siblings().css('color',"#CCC"); //Eintrag
	 $(this).css('color',"#CCC");
	 /*$(this).parent().parent().siblings().appendTo($('.page'));*/
	 $(this).parent().parent().siblings().children(".entry-content").slideUp('fast');
	 $(this).parent().parent().siblings().children(".entry-gallery").slideUp('fast');
	 $(".gallery-element-description").slideUp("fast");
	 
	/*  var height = $(this).parent().parent().children(".entry-content").children(".scrollable").css('height');
	 height = parseFloat(height);
	 if(height > 402)
	 {
	 $(this).parent().parent().children(".entry-content").children(".scrollable").css('height',"402px");
	 $(this).parent().parent().children(".entry-content").children(".scrollable").jScrollPane();
	 $(this).parent().parent().children(".entry-content").children(".scrollable")[0].scrollTo(0);
	 }*/



	
  });
	  

	  });

					
							   

						
	 
	  

