$(document).ready(function() {
	
	$('.promo .branches .msg').show().css('display', '');

	$('.promo .branches .msg .t_block A').click(function() {
		$(this).parents('.msg').hide().animate({opacity: 1}, 300, function(){ $(this).css('opacity','').css('display', '')});
	});
	
	$('INPUT[defaultval]').inputHint();
	$('.search FORM').submit(function() {
		var input = $(this).find('INPUT:text');
		if(input.attr('defaultval')==input.val()) input.val('');
	});
	
	
	$('.feedback FORM').submit(function() {
		var b = true;
		$(this).find('INPUT[mandatory], TEXTAREA[mandatory]').each(function() {
			if(!$(this).val()) b = false;
		})
		if(!b) {
			alert('Bitte fullen Sie das Forumlarfeld unbedingt aus');
			return false;
		}
	});
	
	
	$('#contacts-block .list1 LI A').each(function(i) {
		$(this).click(function() {
			$(this).addClass('on').parent().siblings().find('A').removeClass('on');
			$('#contacts-block .txt').hide()
			$('#contacts-block .txt:eq('+i+')').show();
			
			Set_Cookie( 'contacts_active_num', i, 0, '/' );
			
			return false;
		})
	});
	
	i = Get_Cookie( 'contacts_active_num' );
	if( i && i != null ) {
		$('#contacts-block .list1 LI:eq('+i+') A').trigger('click');
	}
	
	$('.promo').scrollingPromoBlock();
	$('.imgBlock2').embeddedGallery();
	
	
	$('.catalog .header .rBlock A').live('click', function() {
		mode = $(this).parent().attr('class').substring(3);
		$(this).parent().siblings().find('SPAN').replaceWith('<a href="#" title=""></a>')
		$(this).replaceWith('<span></span>')
		$('#list-content').load('./?set-mode='+mode, function() {
			InitLogoFader();
		});
		return false;
	});	
	
	$('.index .catalog .header A').live('click', function() {
		mode = $(this).parent().prev().length + 1;
		
		tmp = $(this).parent().siblings().removeClass('on').html()
		$(this).parent().siblings().html('<a href="#" title="#">'+tmp+'</a>');
		
		$(this).parent().addClass('on');
		$(this).replaceWith($(this).html())
		
		$('.index .catalog .list1').load('./?set-mode='+mode);
		
		return false;
	});
	
	InitLogoFader();
	

});


function InitLogoFader() {
	//preload grayscale images
	$('.catalog .list2 .company A IMG[rel]').each(function(i) {
		var img = new Image();
		img.src = $(this).attr('rel');
	});
	
	$('.catalog .list2 .company A').hover(
		function() {
			var supplier_id = $(this).attr('rel');
			$(this).parent().prevAll('.txt').find('UL LI:not(.all):not(.header1)').stop().css('opacity', 1);
			$(this).parent().prevAll('.txt').find('UL LI:not(.all):not(.header1) A[rel!='+supplier_id+']').parent().fadeTo('fast', 0.2)//css('opacity', 0.2);
		},
		function() {
			$(this).parent().prevAll('.txt').find('UL LI:not(.all):not(.header1)').stop().fadeTo('fast', 1);
		}
	);
	
	$('.catalog .list2 .txt UL LI A[rel]').hover(
		function() {
			var supplier_id = $(this).attr('rel');
			$(this).parent().parent().parent().nextAll('.company').find('A[rel!='+supplier_id+'] IMG').each(function() {
				$(this).data('color_src', $(this).attr('src'));
				$(this).attr('src', $(this).attr('rel')).stop().fadeTo('fast', 0.5);
			})
		},
		function() {
			var supplier_id = $(this).attr('rel');
			$(this).parent().parent().parent().nextAll('.company').find('A[rel!='+supplier_id+'] IMG').each(function() {
				$(this).attr('src', $(this).data('color_src')).stop().fadeTo('fast', 1);
			})
		}
	);
}

