$(function(){
	var search_default_string = "Suchwort eingeben";
	var gallery_loaded = false;
	$(window).resize(function(){
		if($(window).height()>860){
        	if( gallery_loaded == false){
        		var img = document.createElement('img');
        		img.setAttribute('src','tl_files/bhg_reinholdshain/images/home/hauptbild.jpg');
        		img.setAttribute('alt','Blick in den Baumarkt');
        		$('#gallery').append(img);
        		gallery_loaded = true;
        	}
        	$('#gallery').show(200);
        	$('#home_navigation').css("margin-top", 0);
        	
    	} else {
    		if( gallery_loaded == true) {
    			$('#gallery').hide(200);
    		}
    		// Calculate margin
    		var margin = ($(window).height()-200-490)*0.5;
    		if(margin>-25){
        		$('#home_navigation').css("margin-top", margin);
        	}
    	}
    });
    
    
    
    $("#searchform").simpletip({

   		// Configuration properties
   		content: '	<strong>Nach folgenden Artikelinformationen k&ouml;nnen Sie suchen:</strong>\
   					<br /> \
   					<br /> \
   					<ul style="list-style: disc;">\
                            <li style="margin-left: 20px; float: none; padding: 0;">Artikelnummer</li>\
                            <li style="margin-left: 20px; float: none; padding: 0;">Name</li>\
                            <li style="margin-left: 20px; float: none; padding: 0;">Beschreibung</li>\
                            <li style="margin-left: 20px; float: none; padding: 0;">Lieferant</li>\
                            <li style="margin-left: 20px; float: none; padding: 0;">Scancode</li>\
                        </ul>',
   		fixed: false

	});
            
    
    /*
    $("form").validate({
    	debug: true,
    	rules: {
    	     guest_billing_lastname: "required"
    	}     
    	/*submitHandler: function(form){
    		alert('submit..');
    		//form.submit();*/
    	
    //}); 
	
/*
$("#form1").validate({ 
11	        rules: { 
12	          name: "required",// simple rule, converted to {required:true} 
13	          email: {// compound rule 
14	          required: true, 
15	          email: true 
16	        }, 
17	        url: { 
18	          url: true 
19	        }, 
20	        comment: { 
21	          required: true 
22	        } 
23	        }, 
24	        messages: { 
25	          comment: "Please enter a comment." 
26	        } 
27	      }); 
28	    }); 




*/



	$(document).ready(function() {
		$(window).resize();
		if($('#search').val() == ""){
			$('#search').val(search_default_string);
		}
		
		//$("form.mandatory").hide();
		//$("form").hide();
		
		

	});


	//form validation für Gastbestellung beim Shop
	

	
	$('a[rel=lightbox]').fancybox();
	
	$('#search').focusin(function() {
		if($("#search").val() == search_default_string){
			$('#search').val("");
		}
	});
	
	$('#search').focusout(function() {
		if($('#search').val() == ""){
			$('#search').val(search_default_string);
		}
	});

	$('#searchform').submit(function(event){
		
		if(($('#search').val() == "") || ($('#search').val() == search_default_string) ){
			event.preventDefault();
		}
	});
	
	$("#navigation").find("ul.level_1 li").hover(function() { 
			if(!$(this).find("ul.level_2").is(':visible')){
        		$(this).find("ul.level_2").slideDown(200).show(); //Drop down the subnav on click  
  			}
        }, function(){
       		if($(this).find("ul.level_2").is(':visible')){
            	$(this).parent().find("ul.level_2").slideUp(300); //When the mouse hovers out of the subnav, move it back up  
        	}
        });
        
    
    //############## fŸrs Anzeigen aller Artikel einer Unterkategorie im Sortiment
    // Zugehšriges Template im Webshop: webShop_articlelist_default.tpl
    
    $('a[rel=showAllItems]').click(function(e){
    	
    	e.preventDefault();
    	if($("#rrh_all_articles").is(':visible')){
			$("#rrh_all_articles").slideUp(500); 
		}
		else{
			$("#rrh_all_articles").slideDown(500); 
		}
    });
    
});



