﻿
$(document).ready(function(){

$('.product-teaser').each(function(){
	/*
	var next =$(this).next('.product-teaser');
if(!next.length){
	 return;
	}
	var nh=next.height();
	var ch=$(this).height();
	if(nh>ch){
		$(this).height(nh);
	}else{
		next.height(ch);	
	}*/
  //alert($(this).parent().parent().height());
  $(this).height( $(this).parent().height()-20 );
});
/////////////////////////////////////////////////////////////////////////

$(window).resize(function(){
	content_resize();	
});

var window_resizing = false;
function content_resize(){
//	if(window_resizing) return false;
	window_resizing=true;
	var ww = $(window).width();
	if(ww<1000){
		$('#header').width(1000);	
		$('#toolbar').width(1000);	
		$('#main').width(1000);	
		$('#footer').width(1000);	
	}else{
		$('#header').css('width','100%');	
		$('#toolbar').css('width','100%');
		$('#main').css('width','100%');
		$('#footer').css('width','100%');
	}
	var wh = $(window).height();
	$('#content-text').css('height','');
	$('#main').css('height','');
	if($('#page').height()<wh){
		$('#main').height(wh-(document.body.filters?318:318));
	}
	$('#content-text').height($('#main').height()-50);
	
	window_resizing=false;
}

content_resize();
/////////////////////////////////////////////////////////////////////////
var animtime=100;

function topmenu_deactivate(){
	$('#navtop .submenu.active').removeClass('active').slideUp(animtime);
	$('#navtop a.active').removeClass('active');
}
	var list=$('#navleft');
	var top=$('#navleft .level-1');

function sidebar_deactivate(){
		top.find('div div div.active').removeClass('active').slideUp(animtime);
		top.find('div div.active').removeClass('active').slideUp(animtime);
		top.find('div.active').removeClass('active').slideUp(animtime);
		top.find('a.active').removeClass('active');
		
}
$('body').click(function(){
	sidebar_deactivate();
	topmenu_deactivate();
});

$('#header').hover(function(){
	topmenu_deactivate();
	sidebar_deactivate();
},function(){
});
	
top.find('div').prev('a').addClass('has-children');
	
	
//TOP LEVEL ITEMS
list.children('a').each(function(){
	var e=$(this).next('div');
	if(e[0]){
		$(this).children('span:last-child').click(function(){
			var s=$(this).parent();
			var e=$(this).parent().next('div');
			if(e.is(':visible')){
				s.removeClass('expanded');
				e.slideUp(animtime, content_resize);
				
			}else{
				s.addClass('expanded');
				e.slideDown(animtime, content_resize);
				
			}
			return false;
		});
		$(this).addClass('top');
	}
});
	
	
	var current_item=list.children('.current');
	if(current_item.length){
		var first_subitems=current_item.next('div');
		if(first_subitems.length){
			current_item.click();
		}
	}else{
		var first_item=list.children('a:eq(0)');
		var first_subitems=first_item.next('div');
		if(first_subitems.length){
			first_item.click();
		}
	}
	
	
	list.children('a').hover(function(){
		topmenu_deactivate();
		sidebar_deactivate();
	},function(){
		});


	top.children('a').hover(function(){
		topmenu_deactivate();
		var e=$(this).next('div');
		top.find('div div div.active').removeClass('active').slideUp(animtime);
		top.find('div div.active').removeClass('active').slideUp(animtime);
		top.find('div.active').not(e).removeClass('active').slideUp(animtime);
		top.find('a.active').removeClass('active');
		$(this).addClass('active');

		if(!e.length) return;
		if(!e.is('.active')){

      e.css('left',e.parent().width()+2);
			e.css('margin-top',-e.prev().height()-18);
			/*

			if(!e[0].childwidthprocessed){
				e[0].childwidthprocessed=1;
				var maxw=0;
				if(e.children("a").length>1){
				e.children("a").each(function(){
					var w = $(this).width();
					if(w > maxw){
						maxw=w;
					}	
				});	
				e.children("a").css('width',(maxw-30)+'px');	
				}
			}				*/

			e.css('visibility','visible')
				.slideDown(animtime)
				.addClass('active');
		}
	},function(){
		});
	
	$('#navleft .level-2 a').hover(function(){
			var e=$(this).next('div');
			var p=$(this).parent();

			p.find('div div div.active').removeClass('active').slideUp(animtime);
			p.find('div div.active').removeClass('active').slideUp(animtime);
			p.find('div.active').not(e).removeClass('active').slideUp(animtime);
			p.find('a.active').removeClass('active');
			$(this).addClass('active');
			
			if(!e.length) return;
			
			if(!e.is('.active')){
				
        e.css('left',e.parent().width()+2);
				e.css('margin-top',-e.prev().height()-18);
				/* 

				if(!e[0].childwidthprocessed){
					e[0].childwidthprocessed=1;
					var maxw=0;
					if(e.children("a").length>1){
					e.children("a").each(function(){
						var w = $(this).width();
						if(w > maxw){
							maxw=w;
						}	
					});	
					e.children("a").css('width',(maxw-30)+'px');	
					}
				}
        */
				
				e.css('visibility','visible');
				e.addClass('active').slideDown(animtime,function(){
				

				});
			}
		},function(){
		});

	$('#navleft .level-2').hover(function(){
  },function(){
		topmenu_deactivate();
		sidebar_deactivate();
	});
	$('#navtop .submenu').hover(function(){
  },function(){
		topmenu_deactivate();
		sidebar_deactivate();
	});


	$('#navtop .submenu').addClass('collapsed');

	$('#navtop .topmenu > a').hover(function(){
		sidebar_deactivate();
		var e=$(this).next('.submenu');
		
		var top=$(this).parents('#navtop');
		
		var index=top.find('.topmenu > a').index(this);
		
		top
			.find('.submenu')
			.not(':eq('+index+')')
			.filter('.active')
			.removeClass('active')
			.slideUp(animtime);

		top.find('a.active').removeClass('active');
		
		$(this).addClass('active');
	
		if(!e.is('.active')){
/*
			if(!$(this)[0].childwidthprocessed){
					
				var maxw=0;
				e.children("a").each(function(){
					var w = $(this).width();
					if(w > maxw){
						maxw=w;	
					}	
				});	
				if(maxw){
					
					if(!$(this)[0].childwidthprocessed){
					$(this)[0].childwidthprocessed=1;
					e.children('a').width(maxw-(navigator.appVersion.indexOf('MSIE 7')>0?0:40));
					}else{
						e.children("a").css('width',(maxw)+'px');	
					}
				}
			}*/

			e.css('visibility', 'visible')
				.slideDown(animtime)
				.addClass('active');
		}

	},function(){
		});

		
});


