(function($){
	$(document).ready(function(){
		$('#block-locale-language h2').toggle(showLanguages,hideLanguages);
		var open = false;
		colorMenu();
		if($('.view-q-a').length){
			$('.view-q-a .view-content').accordion({active:false, collapsible:true, autoHeight: false});
		}
		if($('.press-overview').length){
			$('.press-overview').hover(function(){
				$(this).find('a img').fadeIn();
			},function(){
				$(this).find('a img').fadeOut();
			});
		}
		$('.auto-clear').each(function(){
			$(this).data('con',$(this).val()).click(function(){
				if($(this).val() == $(this).data('con')){
					$(this).val('');
				}
			}).blur(function(){
				if($(this).val() == ''){
					$(this).val($(this).data('con'));
				}
			});
		});
		$('#block-block-3 h2').click(function(){
			$('#press-form').slideDown();
		});
		$('#views-exposed-form-Store-locator-new-page').each(function(){
			$(this).find('.form-item-distance-country').insertBefore($(this).find('.form-item-distance-postal-code'));
			$(this).find('.form-item-distance-country option').each(function(){
				if($.inArray($(this).attr('value'),['au','at','be','ca','cy','dk','fi','fr','gf','de','gr','hk','it','kz','nl','no','pl','pt','ru','sg','es','se','ch','ae','gb','us'])==-1){
					$(this).remove();
				}
			});
			$(this).find('.form-item-distance-search-distance').hide();
			$(this).find('.form-item-distance-search-units').hide();
		});
		$('.language-switcher-locale-session .en a').attr('href','/?l=en');
		if($('.menu-mlid-631.active').length || $('.menu-mlid-637.active').length){
			$('.view-categories .view-content').css('height',0);
			$('.view-categories').append('<div class="small-info"></div>');
			$('.view-categories .info-item').hide();
			$('.view-categories .info-item').each(function(){
				$(this).css({position:'absolute',top:0});
				var con = $('<div></div>').addClass('info-item-small');
				con.append('<img src="'+$(this).find('img').attr('src')+'"/>');
				con.append('<p>'+$(this).find('h2').html()+'</p>');
				con.click(showSelection);
				$('.view-categories .small-info').append(con);
			});
		}
		if($('.menu-mlid-636.active').length){
			var con = $('<div class="list"></div>');
			$('.view-categories .views-row').each(function(){
				con.append('<h2>'+$(this).find('.info-item-title').html()+'</h2>');
				con.append('<div class="content">'+$(this).find('p').parent().html()+'</div>');
			});
			$('.view-categories').html(con);
			$('.view-categories .list').accordion({active:false, collapsible:true, autoHeight: false});
		}
		if($('.rotate-images').length){
			$('.rotate-images .rotate:not(:first)').hide();
			var curRotate = 1;
			setInterval(function(){
				$('.rotate-images .rotate:not(:eq('+curRotate+'))').fadeOut(2000);
				$('.rotate-images .rotate:eq('+curRotate+')').fadeIn(2000);
				curRotate++;
				curRotate %= $('.rotate-images .rotate').length;
			},6000);
		}
	});
	function showSelection(){
		if(open==true){
			$('.view-categories .info-item:eq('+$(this).index()+')').fadeIn();
			$('.view-categories .info-item:not(:eq('+$(this).index()+'))').fadeOut();
		}else{
			$('.view-categories .view-content').animate({height:390},1000);
			$('.view-categories .info-item:eq('+$(this).index()+')').delay(1000).fadeIn();
		}
		open = true;
	}
	function showLanguages(){
		$('#block-locale-language .content').animate({'top':300},500);
	}
	function hideLanguages(){
		$('#block-locale-language .content').animate({'top':-400},500);
	}
	function colorMenu(){
		var num = 1;
		$('#main-menu a').each(function(){
			$(this).addClass('color-'+num++);
		});
	}
})(jQuery);;

