$(document).ready(function() {
	
	var e = $("#navigation .nivo-1 ul li");
	e.each(function() {
		if($(this).is('.active')){
			var catid = $(this).attr("id").replace("cat-","");
			var menu = "#menu-"+catid;
			$('#navigation .nivo-2').show();
			$(menu).show();
		}
	});
	
	$('#navigation .nivo-1 ul li').click(function(e) { 
		 var catid = $(this).attr("id").replace("cat-","");
		 var menu = "#menu-"+catid;
		 
		 if($(menu).children().size() > 0) {
			 $('#navigation .nivo-2').show();
			 e.preventDefault();
		 
			 $('.nivo-1 ul li').removeClass('active');
			 $(this).addClass('active');
		   

		   
			 $('.nivo-2 ul').hide();
		   
			 $(menu).show();
			 $(this).addClass('active');
		 }
	});

	//colorbox 
	$("a[rel='colorbox-product']").colorbox();
	$("a[rel='colorbox-pdf']").colorbox({iframe:true, innerWidth:950, innerHeight:550});

	$('.ordering.block.closed').click(function(e) {
		$(this).children('.block-content').slideDown();
		$(this).removeClass('closed');
	});

	// katalog
	$('#input_catalog_page').keypress(function(e){
	var pagenum = $(this).val();
	if(e.which == 13 && pagenum!='') {
		e.preventDefault();
		$.fn.colorbox({href:'/katalog/jpg/'+pagenum+'.html', open:true, iframe:true, innerWidth:640, innerHeight:550, rel:'colorbox-catalog'});
	}
	});
	
	$('#catalog_page_submit').click(function(){
		var pagenum = $('#input_catalog_page').val();
		if(pagenum!='') {
			$.fn.colorbox({href:'/katalog/jpg/'+pagenum+'.html', open:true, iframe:true, innerWidth:640, innerHeight:550, rel:'colorbox-catalog'});
		}
	});
	
	//images
	$('img.product_small_image').click(function() {
		var link = $(this).attr('src');
		$('#product_image').css('background-image','url('+link.replace('img_small','img_medium')+')');
		$('#product_image_link').attr('href',link.replace('img_small','img_big'));
	});
  
  // zaloge
  $('a[href="#zaloge"]').click(function() {
		var koda = $(this).attr('id').replace('link_zaloge_','');
		var url = 'http://mobile.textileurope.de/?s='+koda+'&amp;m=fr&amp;t=0';
		window.open(url, 'zaloga', 'width=480,height=600,location=0,menubar=0,status=0,resizable=1');
		return false;
  });
  
  
});
