/*Megadropdowns*/
(function( jQuery ){
	jQuery.fn.megadropdown = function(){  
		return this.each( function(index) {			
			
			var $this = jQuery(this);			
			jQuery('.dropdowns').append('<div class="dropdown" id="dropdown-'+index+'" style="height:500px;" loaded="false"><div class="inner-dropdown"></div><div class="end-dropdown"></div></div>');
			
			$this.mouseenter( function(){
				
				if (jQuery('#dropdown-' + index).attr("loaded") == "false") 
				{
					// jQuery('#dropdown-' + index + ' > div.inner-dropdown').load('/WebRoot/Store/Shops/Dallmayr/DropDown/temp_dropdown_content_id' + index + '.html', function(response, status, xhr){
                    jQuery('#dropdown-' + index + ' > div.inner-dropdown').load('?ObjectPath=/Shops/Dallmayr/DropDown&ViewAction=ViewMegaDropDown&DropDownIndex=' + index, function(response, status, xhr){
                    
						if (status == "error") {
							// alert(xhr.status + " " + xhr.statusText);
						}
						jQuery('#dropdown-' + index).attr("loaded","true")
					});
				}			
				//if($this.open != true)jQuery('#dropdown-'+index).show();
				setTimeout(function() {
        			$this.showdropdown() ;
     			},200);
				$this.open = true;
				$this.mousein = true;
			}).mouseleave( function(){
				$this.mousein = false;
				setTimeout(function() {
        			$this.hidedropdown() ;
     			},20);
			});
			
			jQuery('#dropdown-' + index).mouseenter( function(){
				$this.mousein = true;
			}).mouseleave( function(){
				$this.mousein = false;
				setTimeout(function() {
        			$this.hidedropdown() ;
     			},20);
			});
			
			$this.hidedropdown = function(){
				if($this.mousein != true)
				{
					jQuery('#dropdown-'+index).css("z-index",20);
					jQuery('#dropdown-'+index).slideUp();
					$this.open = false;
					jQuery('#dropdown-bg').fadeOut('slow');				
				}
			};
			$this.showdropdown = function(){
				if($this.mousein == true)
				{
					jQuery('#dropdown-'+index).css("z-index",index+6);
					jQuery('#dropdown-'+index).slideDown();
					$this.open = false;
					jQuery('#dropdown-bg').fadeIn('fast');
				}
			};
		});	
	};
})( jQuery );

jQuery( document ).ready( function(){
	jQuery('.dropdowns').append('<div id="dropdown-bg" style="top: 10px; background:#F7F2EB; height:'+(jQuery( document ).height()-165)+'px; width:100%; opacity:0.8; z-index:5; position:absolute; "></div>');
	jQuery('#dropdown-bg').hide();
	jQuery('.GeneralLayout').addClass('dropdowns-on');
	jQuery('div.NavBarTop ul.HorizontalDisplay.NavBarElement0 li.NavigationElement').megadropdown();
});

/*jQuery(window).resize(function() {
		if ( jQuery(window).width() <= 1280 ) {
	  		jQuery('.dropdowns .dropdown').each(function(index) {
	  			jQuery(this).css(width, getW);
  			});
		}
});*/

