jQuery(function($){
	/*
	var getRelativeBottomPos = function(elem){
		var pos = elem.position();
		return pos.top - ($('#visual').height() + $('#head').height() + elem.height()) - $("#primary-widget").height();
	}
		

	$('#sticky-sidebar').css({		
		marginTop: getRelativeBottomPos($('#footer_container'))  
	})
	*/
	var getRelativeBottomPos = function(elem){
		var pos = elem.position();
		var temp = ($('#main').height() - $('#sticky-sidebar').height() - $("#primary-widget").height());
		if(temp < 150){ temp = 50; }
		return temp;
	}
		

	$('#sticky-sidebar').css({		
		marginTop: getRelativeBottomPos($('#footer_container'))  
	})
    
	
	$("#your-ordercount").bind("keyup", function() {
        var count = $("#your-ordercount").val();                                  
        var price = 10; //Preis pro Buch
		var sprice = 2; //Versandkosten pro Paket
		var shipUnit = 4; //Maximale Versandeinheit in Buechern
		if(parseInt(count) > 0){
	   	    var newValue = parseInt(count) * parseInt(price);                                  
		}else{
			var newValue = 0;	
		}
		if(count > shipUnit){
			var totalShipUnits = count / shipUnit;
			totalShipUnits = Math.ceil(totalShipUnits);
		}else{
			totalShipUnits = 1;
		}
		var shipCost = totalShipUnits * sprice;
		$('#buchkosten').val((newValue + shipCost));
		$('#price-shipping').val(shipCost);
		$('#price-books').val(newValue);
    });
	
	var lexiconLinks = $('.lexicon-link'),
		forbiddenTags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'a'];
	if(lexiconLinks.length){
		for(i = 0, l = lexiconLinks.length ; i < l ; i++){
			if($.inArray(lexiconLinks[i].parentNode.tagName.toLowerCase(), forbiddenTags) >= 0){
				$(lexiconLinks[i]).replaceWith($(lexiconLinks[i]).text());
			}
			
		}
	}
	
	/*$('.lexicon-link').each(function(){
		if($(this).parent().get(0).tagName.toLowerCase() != 'p'){
			var txt = $(this).text();
			var elem = $(this).parent();
			$(this).replaceWith(txt);
			
			if(elem.get(0).tagName.toLowerCase() == 'span' && !elem.children('a').text().length && elem.text().length){
				var temp2 = elem.text();
				var temp1 = elem.children('a:first').text(temp2);
				elem.empty();
				elem.append(temp1);
				
			}
		}
	})*/
})
