var _menu_min_height = 435;//pxfunction getDocHeight(substract_height) {    var D = document;    var max = Math.max(		Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),		$(document).height(),		$(window).height(),        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),        Math.max(D.body.clientHeight, D.documentElement.clientHeight),		$('#content').height(),		$('body').height(),        /* For opera: */        D.documentElement.clientHeight    );	if(!isNaN(substract_height) && max>substract_height) {		max -= substract_height;			}	return max;}function heightFilter(h){	if(h>=_menu_min_height)		return h;	else		return _menu_min_height;}function addToFav() {	if(window.sidebar){		window.sidebar.addPanel(document.title, this.location,"");	}	else{		window.external.AddFavorite(this.location,document.title);	}}function menuscroll(substract_height) {	var height = getDocHeight(substract_height);	$('#wrap').css('height',height+'px');	var vph = window.innerHeight ? window.innerHeight : $(window).height();	$('#menu').css('height',heightFilter(vph)+'px');	if(vph>_menu_min_height) {		$(window).scroll(function () {			if(typeof(window.pageYOffset)=='number') {			   pageY=window.pageYOffset;			} else {			   pageY=document.documentElement.scrollTop;			}			if(pageY<0)				pageY=0;		   $('#menu').stop();			$('#menu').animate({				marginTop: pageY + 'px'			}, 1000);		});	}}$(function(){	/*$('#f-1,#f-2,#f-3,#f-4').hover(function(){		$(this).children().fadeIn();	},function(){		$(this).children().fadeOut();	});*/	$('#f-1').click(function(){		$('#lb_f1').modal();	});	$('#f-2').click(function(){		$('#lb_f2').modal();	});	$('#f-3').click(function(){		addToFav();	});	$('#f-4').click(function(){		window.open("http://www.facebook.com/share.php?u="+$('#here').html()+"&t="+$('#title').html());//__product.Product.name);	});	menuscroll(0);	$('.clickclear').each(function(){		$(this).data('cc-i-val',this.value);	}).click(function(){		if(this.value==$(this).data('cc-i-val'))			this.value='';	});//	$('#tb-basket').click(function(){//		bs_click('basket');//		return false;//	});	$('#tb-storage').click(function(){		show_storage();		return false;	});	$('.mtb-single').live('click',function(){		mtb(this, 'Single');	});	$('.mtb-group').live('click',function(){		mtb(this, 'Group');	});	$('.storage-delete').live('click',function(){		var product_id = $(this).attr('id').replace('storage-delete-', '');		var obj = JSON.parse($.cookie('berndson_storage'));		var deleted = false;		for(var i=0;i<obj.length&&!deleted;i++) {			if(obj[i].id==product_id) {				deleted=true;				obj.splice(i,1);			}		}		if(deleted) {			$.cookie('berndson_storage',JSON.stringify(obj), {expires: 365, path:'/'});			$(this).parent().parent().parent().fadeOut();		}	});	$('.bar').click(function(){		var c =$(this).parent().find('.bar-content');		var b =$(this).parent().find('.bar-expand');//		var bg = c.css('background');//		c.css('background','transparent');		if(c.css('display')=='none') {			$(b).addClass('expanded');			if(isNaN($(b).data('expand_height'))) {				var before_height = getDocHeight(false);			}			var that = $(b);			c.slideDown(400,function(){				if(isNaN(that.data('expand_height'))) {					var after_height = getDocHeight(false);					that.data('expand_height',parseInt(after_height-before_height));				}				menuscroll(0);			});			fleXenv.initByClass("flexcroll");		} else {			$(b).removeClass('expanded');			var that = $(b);			c.slideUp(400,function(){				menuscroll(that.data('expand_height'));			});		}		if(b.id == 'trainer-expand') {			$.cookie('berndson_expanded',$(b).hasClass('expanded'));		}	});	$("a.fancybox").fancybox();	if($('#trainer-expand').length==1 && $.cookie('berndson_expanded')=='true') {		$('#trainer-expand').trigger('click');	}		if($('#board-expand').length==1 && $.cookie('board_expanded')=='true') {		$('#board-expand').trigger('click');	}	/*	$('.bar-expand').click(function(){		var c =$(this).parent().parent().find('.bar-content');//		var bg = c.css('background');//		c.css('background','transparent');		if(c.css('display')=='none') {			$(this).addClass('expanded');			if(isNaN($(this).data('expand_height'))) {				var before_height = getDocHeight(false);			}			var that = $(this);			c.slideDown(400,function(){				if(isNaN(that.data('expand_height'))) {					var after_height = getDocHeight(false);					that.data('expand_height',parseInt(after_height-before_height));				}				menuscroll(0);			});			fleXenv.initByClass("flexcroll");		} else {			$(this).removeClass('expanded');			var that = $(this);			c.slideUp(400,function(){				menuscroll(that.data('expand_height'));			});		}		if(this.id == 'trainer-expand') {			$.cookie('berndson_expanded',$(this).hasClass('expanded'));		}	});	$("a.fancybox").fancybox();	if($('#trainer-expand').length==1 && $.cookie('berndson_expanded')=='true') {		$('#trainer-expand').trigger('click');	}	*/});function show_storage() {	$.post('/products/get_list',{data:$.cookie('berndson_storage')},function(data){		$('#lb_storage').html(data);		$('#lb_storage').modal();		fleXenv.fleXcrollMain("storage-items");//		$('.lb-close').click(function(){//			$.modal.close();//		});	});}function mtb(xobj,type) {	var product_id = $(xobj).attr('id').replace('mtb-'+type+'-', '');	var obj = JSON.parse($.cookie('berndson_storage'));	var deleted = false;	var found;	for(var i=0;i<obj.length&&!deleted;i++) {		if(obj[i].id==product_id) {			deleted=true;			found=obj[i];			obj.splice(i,1);		}	}	if(deleted) {		$.cookie('berndson_storage',JSON.stringify(obj), {expires: 365, path:'/'});		var add = {id:product_id,type:type,category_id:found.category_id,ammount:'1'};		var basket = JSON.parse($.cookie('berndson_basket'));		var added = false;		if(basket)			for(var i=0;i<basket.length&&!added;i++) {				if(basket[i].type==add.type && basket[i].id==add.id) {					added=true;					var newa = parseInt(basket[i].ammount)+1;					basket[i].ammount=newa+'';					$.cookie('berndson_basket',JSON.stringify(basket), {expires: 365, path:'/'});				}			}		if(!added) {			if($.cookie('berndson_basket')==null) {				$.cookie('berndson_basket',JSON.stringify([add]), {expires: 365, path:'/'});			} else {				var obj1 = JSON.parse($.cookie('berndson_basket'));				obj1[obj1.length]=add;				$.cookie('berndson_basket',JSON.stringify(obj1), {expires: 365, path:'/'});			}		}		$(xobj).parent().parent().parent().parent().fadeOut();	}}
