
		$(document).ready(function() {


			function positionMenuSub() {

				$('.menusubItem').each(function() {
					var menusubItemId = $(this).attr('id');
					var headLeft = $('#header').offset().left;				
					var menuMainItemWidth = $('#header a[rel="'+ menusubItemId +'"]').width();									
					var menuItemLeft = $('#header a[rel="'+ menusubItemId +'"]').offset().left;
					var menuItemWidth = $('ul',this).width();
					menuItemMoveTo = (menuItemLeft - headLeft) - (menuItemWidth / 2) + (menuMainItemWidth / 2);				
					if (menuItemMoveTo < 12) {
						menuItemMoveTo = 12;
					}
					$(this).css('margin-left', menuItemMoveTo);					
				})
			}
			positionMenuSub()

			if ($('.menusubItem li.selected a').length == 0) {
				$('#menuSub').addClass('borderBottomNone');
			}
			var collectionShow = false;
			var parentRel;
			var selectedLink;
			var parentLink;
			if ($('#header li.selected a').length > 0) {
				selectedLink = $('#header li.selected a');
				parentLink = selectedLink; 
				if ( $(selectedLink).attr('href').substr(0,14) == 'collection.asp' ) {				
					collectionShow = true;
				}
				else {
					parentRel = $('#' + $(selectedLink).attr('rel'));
				}
			}

			$('#header ul a').click(function(event) {

				var sameLinkClick = false;
				if (parentLink !== undefined) {
					if (parentLink.html() == $(this).html()) {				
						sameLinkClick = true;										
					}			
				}
				
				if (sameLinkClick == false) {
					changeMenu($(this))			
				}
				
				if (selectedLink !== undefined) {
					$(document).stopTime();
					// Wait x second and then go back to previous menu
					$(document).oneTime(5000, function() {
						if (parentLink !== undefined) {
							changeMenu($(selectedLink ,'#header'));
						}					
					});
				}
				return false;										
			});



			var liMax = 0
			$('#filterForm .filter ul').each(function() {
				if ($(this).children('li').length > liMax) {
					liMax = $(this).children('li').length;
				}
			})
			var filtersHeight = liMax * 20; 
			$('#filters').height(filtersHeight - 20)


			function changeMenu(object) {

				if (selectedLink !== undefined) {			
					if ($(object).html() !== $(selectedLink).html()) {
						$(object).parent().addClass('active');						
						$(selectedLink).parent().addClass('blur');																		
						$(parentLink).parent().removeClass('active');																								
					}				
					else {
						$(selectedLink).parent().removeClass('blur');	
						$(parentLink).parent().removeClass('active');												
					}
				}

				$('#menuSub').stop()
				if ( $(object).attr('href').substr(0,14) == 'collection.asp' ) {

					if (parentRel == undefined) {
						if (collectionShow == false) {
							$('#menuSub').removeClass('borderBottomNone')													
							$('#menuSub').height(0)
							$('#catalog #main').animate({ top : 230 }, 500, function() {});							
							$('#menuSub').animate({ height: filtersHeight }, 500, function() {
								$('#filters').fadeIn(500);
							});
							collectionShow = true;													
						}				
					}
					else {
						if (parentRel.length > 0) { 
							$('ul', parentRel).fadeOut(500, function() {	
								$('#menuSub').removeClass('borderBottomNone')														
								$('#menuSub').height(20);
								$('#catalog #main').animate({ top : 230 }, 500, function() {});							
								$('#menuSub').animate({ height : filtersHeight }, 500, function() {
									$('#filters').fadeIn(500);
								});
								collectionShow = true;							
							});
						}
						else {
							$('#menuSub').removeClass('borderBottomNone')														
							$('#menuSub').height(0);
							$('#catalog #main').animate({ top : 230 }, 500, function() {});
							$('#menuSub').animate({ height : filtersHeight }, 500, function() {
								$('#filters').fadeIn(500);
							});
							collectionShow = true;													
						}
					}
				}
				else {

					menuSubRel = '#'+ $(object).attr('rel');

					if ($(menuSubRel).length == 0) {
						if ($(object).attr('href') !== $(selectedLink).attr('href')) {
							document.location = object.attr('href')
							return false;												
						}
					}

					if (collectionShow == true) {

						collectionShow = false;

						$('#filters').fadeOut(300, function() {

							$('#menuSub').height(150)
							if ($(menuSubRel).length == 0) {
								$('#menuSub').animate({ height : 0 }, 200, function() {
									$('#menuSub').addClass('borderBottomNone')
								});							
							}
							else {
								$('#menuSub').removeClass('borderBottomNone')							
								$('#catalog #main').animate({ top : 100 }, 500, function() {});								
								$('#menuSub').animate({ height : 20	}, 200, function() {
									$('ul', menuSubRel).fadeIn(200);						
								});
							}
						});
					}
					else {
						if ($(parentRel).length == 0) {
							$('#menuSub').removeClass('borderBottomNone')													
							$('#menuSub').animate({ height : 20	}, 200, function() {
								$('ul', menuSubRel).fadeIn(200);						
							});							
						}
						else {
							if (parentRel == undefined) {

								$('#menuSub').height(0);
								$('ul', menuSubRel).show();								
								$('#menuSub').animate({ height : 20	}, 200);											
							}
							else {
								
								if ($(menuSubRel).length == 0) {

									$('ul', parentRel).fadeOut(function() {
										$('#menuSub').animate({ height : 0 }, 200, function() {
											$('#menuSub').addClass('borderBottomNone')
										});							
									});										
								}
								else {
									$('#menuSub').removeClass('borderBottomNone')															
									$('#menuSub').height(20);
									$('ul', parentRel).fadeOut(function() {
										$('ul', menuSubRel).fadeIn(300);
									});
								}								
								

							}
						}
					}

					parentRel = $(menuSubRel);				
				}	

				parentLink = $(object)							
				return false;														
			}
			



			/*
			$('#articleInfo #retailerCity').change(function() {
				$.ajax({
					type: 'GET',
					url: 'articleRetailersAjax.asp?articleId='+ $('#articleId').val() +'&retailerCity='+ $('#retailerCity').val(),
					success: function(data) {
						$('#articleInfo #list').html(data)
					}
				});						
			});


			$('#findastore #retailerCity').change(function() {
				$(this).parent().parent('form').submit();
			});
			$('#findastore #retailerButtonSearch').hide();
			*/



			$.jGoogleAnalytics('UA-2673616-3');

		});


		