/* VARIABLES */
var urlVars = [];

/* LISTENERS */
$(document).ready(function() {
	ieFixes();
	setUrlVars();
	selectorForm();
	$(document).pngFix();
	slideNews();
	setIngredientsLink();
	setSmallProductList();
	$('body#splash').height($(window).height());
	setFullSize();
});
$(window).resize(function() {
	$('body#splash').height($(window).height());
	setFullSize();
});

/* FUNCTIONS */
function setFullSize(){
	var flash_container = $('#flash_container');
	if(flash_container.hasClass('auto_size_max')){
		var height = $(window).height() - $('#top').height() + 10;
		flash_container.height(height);
	}
}

function popupOpenen(url,naam,breedte,hoogte,scrollbars) {
	service = window.open(url,naam,"status=yes,menubar=no,toolbar=no,resizeable=no,scrollbars="+scrollbars+",width="+breedte+",height="+hoogte);
	service.focus();
}
function popsm(url,w) {
	if(!w) { w = 825; }
	popupOpenen(url,"popPage",w,550,"yes");
}
function ieFixes() {
	$('#frames #vip>span').addClass('ie');
	$('#comp>img').addClass('ie');
	$('#detail>img').addClass('ie');
	$('#comp>img').addClass('ie');
	$('#detail #ingredients div li:first-child').addClass('first-child');
}
function setUrlVars() {
	var hash;
	var hashes = window.location.href.slice(
			window.location.href.indexOf('?') + 1).split('&');
	for ( var i = 0; i < hashes.length; i++) {
		hash = hashes[i].split('=');
		urlVars.push(hash[0]);
		urlVars[hash[0]] = hash[1];
	}
}
function slideNews() {
	var lis = $('#news ul li');
	var n = lis.length;
	var h = $('#news ul li:first').height();
	slideLoop(lis, n, h);
}
function slideLoop(lis, n, h) {
	$(document).everyTime(4000, function(i) {
		lis.css('position', 'relative');
		if (i == n) {
			lis.animate( {
				bottom : 0
			}, 'slow');
			slideLoop(lis, n, h);
		} else {
			var b = i * h;
			lis.animate( {
				bottom : b
			});
		}
	}, n);
}
function selectorForm() {
	$('.filter2 label:odd').addClass('odd');
	$('.filter2 label:even').addClass('even');

	var defVal = $("#so").val();
	if(!defVal) { defVal = 3; }
	if ($.inArray('slide', urlVars) >= 0) {
		defVal = parseInt(urlVars['slide'])
	}
	$('.filter1 #slider').slider( {
		min : 1,
		max : 5,
		animate : true,
		value : defVal,
		stop : function(event, slider) {
			var val = slider.value;
			var slide = $('<input/>', {
				id : 'slide',
				name : 'slide',
				value : val,
				type : "text"
			});
			slide.val(val);
			slide.appendTo('.filter1');
			$('#selector form:first').submit();
		}

	});
	$('#poductlist li').each(function() {
		var li = $(this);
		var img = li.find('img:first');
		img.load(function() {
			var img = $(this);
			var li = img.parent('li');
			var left = 0 - ((img.width() - li.width()) / 2);
			img.css( {
				left : left
			});
		});
		var left = 0 - ((img.width() - li.width()) / 2);
		img.css( {
			left : left
		});
	});
}
function setSmallProductList() {
	$('#ex li').each(function() {
		var li = $(this);
		var img = li.find('img:first');
		img.load(function() {
			var img = $(this);
			var li = img.parent('li');
			var left = 0 - ((img.width() - li.width()) / 2);
			img.css( {
				left : left
			});
		});
		var left = 0 - ((img.width() - li.width()) / 2);
		img.css( {
			left : left
		});
	});
}
function setIngredientsLink() {
	var ing = $('#ingredients');
	var det = $('#detail');
	var link = $('#detail #desc a.more');
	var close = ing.find('a.close');
	link.removeAttr('href').css( {
		cursor : 'pointer',
		textDecoration : 'underline'
	}).click(function() {
		var link = $(this);
		if (link.hasClass('open')) {
			hideIngredients(ing, det, link);
		} else {
			showIngredients(ing, det, link);
		}
	});
	close.removeAttr('href').css( {
		cursor : 'pointer',
		textDecoration : 'underline'
	}).click(function() {
		hideIngredients(ing, det, link);
	});
}
function showIngredients(ing, det, link) {
	var h = ing.height() + det.height() + 40;
	var ingOffset = ing.offset().top;
	link.addClass('open');
	ing.hide(0);
	$('html,body').animate( {
		scrollTop : ingOffset
	}, 'slow');
	det.animate( {
		height : h
	}, 'fast', 'linear', function() {
		ing.fadeIn('normal');
	});
}
function hideIngredients(ing, det, link) {
	var h = det.height() - (ing.height() + 40);
	link.removeClass('open');
	ing.fadeOut('fast');
	det.animate( {
		height : h
	}, 'normal');
}

jQuery(document).ready(function() {
$('div#campagnes #campbox a img').each(function(){
	var img =  $(this);
	img.hover(function(){
		img.animate({
			marginTop: -25,
			marginBottom: -6,
			marginLeft: -70,
			marginRight: 70,
			height: 300
		},250);
	},function(){
		img.animate({
			marginTop: 0,
			marginBottom: 0,
			marginLeft: 0,
			marginRight: 0,
			height: 265
		},250);
	});
});
});