/*
	LoungeRoom Online Solutions: www.loungeroom.nl
*/


function initialize() {
	
	$(document).ready(function(){
		$(document).pngFix();
		overall(0);
		
 	});
	
	
}

function init_home(vv) {
	panel_init(0);
}
function init_product(vv) {
	$('a.lightbox').lightBox({
		overlayBgColor: '#FFF',
		overlayOpacity: 0.6,
		containerResizeSpeed: 350
	});
}

var panel_open;
var panel_opened;
var panel_interval;
function panel_init(foo) {
	set_panel_interval();
	$("#panel h4").mouseover(function(e) {
		panel_open = $("#panel .items h4").index(this);
		panel_opened = $("#panel .items h4").index($('.open'));
		panel_effect(panel_opened,panel_open,1);
		set_panel_interval();
	});
}
function set_panel_interval() {
	clearInterval(panel_interval);
	panel_interval = setInterval("panel_switch(0);",3000);
}
function panel_switch(foo) {
	panel_num = $("#panel div.images img").length;
	panel_opened = $("#panel .images img").index($('.show'));
	
	panel_open = panel_opened;
	panel_open++;
	if(panel_open >= panel_num) { panel_open = 0; }
	panel_effect(panel_opened,panel_open,500);
}
function panel_effect(was_open,to_open,speed) {
	if(speed < 10) {
		$("#panel .items h4").removeClass("open");
		$("#panel .images img").hide().removeClass("show");
		$("#panel .items h4:eq("+to_open+")").addClass("open");
		$("#panel .images img:eq("+to_open+")").show().addClass("show");
	} else {
		$("#panel .items h4").removeClass("open");
		$("#panel .images img:not("+was_open+")").hide();
		$("#panel .images img:eq("+was_open+")").fadeOut(speed, function() {
			$(this).removeClass("show");
			$("#panel .items h4:eq("+to_open+")").addClass("open");
			$("#panel .images img:eq("+to_open+")").fadeIn(speed*2, function() {
				$(this).addClass("show");
			});
		});
	}
}

var fl;
var itemheight;
var height;
var hoesnel;
var opened;

function up_slideShow(v) {
	num = $("#slideContents").children().length;
	up_show(0);
	
	itemheight = 110;
	height = num*itemheight;
	hoesnel = 4000;
	fl = setInterval("up_flash();",hoesnel);
	$("#slideContents").mouseover(function(o) {
		clearInterval(fl);
	});
	$("#slideContents").mouseout(function(o) {
		clearInterval(fl);
		fl = setInterval("up_flash();",hoesnel);
	});
}

function up_show(val) {
	opened = val;
	naar = val*itemheight;
	naar = "-"+naar+"px";
	//$("#selectedContents").children().eq(val).animate({ 
	//alert(naar);
	$("#selectedContents").animate({ 
		top: naar
	}, 1500, function(f) {
		
	});
}
function up_rewind() {
	clearInterval(fl);
	$("#slideContents").animate({ 
		top: '0px' 
	}, 4500, function(f) {
		opened = 0;
		fl = setInterval("up_flash();",hoesnel);
	});
}
function up_flash() {
	nowOpen = opened+1;
	teller = num-1;
	if(opened >= teller) {
		up_rewind();
	} else {
		up_show(nowOpen);
	}	
}

slideopened = new Array();
numopened = new Array();
slideinterval = new Array();
function left_slideShow(d,v) {
	numopened[d] = $(".slideContents.i"+d).children().length;
	left_show(d,0);
	hoesnel = 5000;
	
	slideinterval[d] = setInterval("left_flash('"+d+"');",hoesnel);
	$(".slideContents.i"+d).mouseover(function(o) {
		clearInterval(slideinterval[d]);
	});
	$(".slideContents.i"+d).mouseout(function(o) {
		clearInterval(slideinterval[d]);
		slideinterval[d] = setInterval("left_flash('"+d+"');",hoesnel);
	});
}

function left_show(d,val) {
	$(".slideContents.i"+d).children().eq(val).animate({ 
		left: '0px'
	}, 1500, function(f) {
		slideopened[d] = val;
	});
}
function left_flash(d) {
	$(".slideContents.i"+d).children().eq(slideopened[d]).animate({ 
		left: '-400px' 
	}, 1500, function(f) {
		$(this).css({ left: '400px'});
	});

	nowOpen = slideopened[d]+1;
	teller = numopened[d]-1;
	if(slideopened[d] >= teller) {
		nowOpen=0;
	}
	left_show(d,nowOpen);
}


function overall() {
	$("h2.opener a").click(function(e) {
		e.preventDefault();
		$("h2.opener").show();
		$("div.select").hide();
		$(this).parent().hide();
		$("#"+$(this).attr("rel")).show();
	});
	$(".BaseLeft").click(function() {
		$("div.select").hide();
		$("h2.opener").show();
	});
	$(".close").click(function(e) {
		e.preventDefault();
		$("div.select").hide();
		$("h2.opener").show();
	});
	
	
	$(".link").click(function(e) {
		window.location=$(this).attr("rel");
	});
   
	// wishlist
	wishinited=false;
	$("a.wish").click(function(e) {
		if(wishinited==false) {
			e.preventDefault();
			wishinited=true;
			statusOn();
			
			productid = $(this).attr("rel");
			$.get('/ajax/wishlist.php?ajax=true', { add: productid }, function(data) {
				$("#write_shortlist").html(data);
				statusOff();
				wishinited=false;
			});
		}
	}); // end wishlist
	
	// VENSTER sluiten
	$('.clickandclose').click(function(e) {
		e.preventDefault();
		$('.large').addClass('hide');
		$('.container').html('').addClass('hide').removeClass('bestellen').removeClass('image');
	});

	// verwijder uit snelkeuze
	$("a.remove").click(function(e) {
		e.preventDefault();
		statusOn();
		
		productid = $(this).attr("rel");
		$(this).parent().parent().remove();
		$.get('/ajax/wishlist.php?ajax=true', { remove: productid }, function(data) {
			statusOff();
			//$("#write_shortlist").html(data);
			$("#shortlist .row:odd").removeClass('noteven').addClass('even');
			$("#shortlist .row:even").removeClass('even').addClass('noteven');
			num_short = $("#shortlist .product_wishlist").children().length;
			if(num_short == 0) {
				statusOn();
				$.get('/ajax/wishlist.php?ajax=true', function(data) {
					$("#write_shortlist").html(data);
					statusOff();
				});
			}
		});
	}); // end verwijder uit snelkeuze

}

function popup(url, w, h, name) {
	window.open(url,name,'height='+h+', width='+w+', menubar=no, status=yes, scrollbars=yes, resizable=yes, toolbar=yes, location=no');		
}

function startAnimate(empty) {
	$("#"+empty).html('<img src="/assets/images/ajax_diap.gif" alt="" />');
}
function stopAnimate(empty) {
	$("#"+empty).html('');
}

function startAnimate2(empty) {
	$("#"+empty).html('<div align="center"><img src="/assets/images/squares.gif" alt="" /></div>');
}
function statusOn(empty) {
	$("#status").html('<img src="/assets/images/ajax_diap.gif" alt="" />');
}
function statusOff(empty) {
	window.setTimeout('$("#status").html("");',500);
}
function addToList(additto,add) {
	$("#"+additto).prepend(add);
}


