$(document).ready(function () {
	Cufon.replace('.content h1', { fontFamily: 'Futura Lt BT' });
	Cufon.replace('.data h2', { fontFamily: 'Futura Lt BT' });
	if ($('#tabs')) {
		$('div.tabtitle a').click(function () { 
			if ($('#' + $(this).attr('rel')).parent().hasClass('tshow')) { $('div.tab').removeClass('tshow'); }
			else { $('#' + $(this).attr('rel')).parent().addClass('tshow'); }
			$('#' + $(this).attr('rel')).slideToggle();
		});
		$('#tabs a.stab').click(function () { 
			if ($('#' + $(this).attr('rel')).parent().hasClass('tishow')) { $('div.tabdata').removeClass('tshow'); }
			else { $('#' + $(this).attr('rel')).parent().addClass('tishow'); }
			$('#' + $(this).attr('rel')).slideToggle();
		});
	}
	
	
	if ($('#overshow')) {
		$('a.overshow , a.overshowOpen').click(function () { 
			//$('#' + $(this).attr('rel')).toggle('fast');
			$(this).showpopup($(this));
		});
	}
	
	if ($('a#lightbox')) $('a#lightbox').lightBox();
	
	jQuery('#slider').jcarousel({
		wrap: 'circular',
		scroll: 1,
		animation: 'fast',
		initCallback: mycarousel_initCallback
	});
	$('#homeshow').cycle({ 
		fx:     'fade', 
		slideExpr: 'div.hitem',
		speed:  2000, 
		timeout: 5000, 
		next:   '#hnext', 
		prev:   '#hprev' 
	});
	
	setTimeout(function(){ $(document).showpopup($('a.overshowOpen')); }, 2000);
	

		

	$(".slide ul").each(function(){
	
	var t = setInterval(function(){
	
		$(".slide ul").animate({marginLeft:-166},2000,
			function(){
				//als de animatie klaar is
				$(this).find("li:last").after(
				$(this).find("li:first"));
				//reset margin nadat het linkeritem aangelegd is
				$(this).css({marginLeft:0});
				//$(this).find("LI.active").removeClass('active').next().addClass('active');
				})
		},10000);
		});
	});

$.fn.showpopup = function(e, type) {
	if ($('#' + $(e).attr('rel')).css('display') == 'none') { 
		$('#' + $(e).attr('rel')).fadeIn(1000).css('display', 'block'); 
		if (typeof document.body.style.maxHeight === "undefined") {
			$("body","html").css({height: "100%", width: "100%"});
			$("html").css("overflow","hidden");
			$("body").append("<div id='overlay' onclick='tover_hide()'></div>");
		}else{ if(document.getElementById("overlay") === null){ $("body").append("<div id='overlay' onclick='tover_hide()'></div>"); } }
	}
	else { $('#' + $(e).attr('rel')).css('display', 'none'); }
};

function mycarousel_initCallback(carousel)
{
    carousel.buttonNext.bind('click', function() {
		var active = parseInt($('#slider ul li.active').attr('jcarouselindex'));
        $('#slider ul li').removeClass('active');
		active = active + 1;
		$('#slider ul li.jcarousel-item-' + active).addClass('active');
    });
    carousel.buttonPrev.bind('click', function() {
        var active = parseInt($('#slider ul li.active').attr('jcarouselindex'));
        $('#slider ul li').removeClass('active');
		active = active - 1;
		$('#slider ul li.jcarousel-item-' + active).addClass('active');
    });
};

function tover_hide() { 
	$("#overlay").remove(); 
	$('div.over').css('display', 'none')
}

$.fn.showpopup = function(e, type) {
	if ($('#' + $(e).attr('rel')).css('display') == 'none') { 
		$('#' + $(e).attr('rel')).fadeIn(1000).css('display', 'block'); 
		if (typeof document.body.style.maxHeight === "undefined") {
			$("#wrap2","html").css({height: "100%", width: "100%"});
			$("html").css("overflow","hidden");
			$("#wrap2").append("<div id='overlayh' onclick='tover_hide()'></div>");
		}else{ if(document.getElementById("overlayh") === null){ $("#wrap2").append("<div id='overlayh' onclick='tover_hide()'></div>"); } }
	}
	else { $('#' + $(e).attr('rel')).css('display', 'none'); }
};

function swapImages(){
      var $active = $('.rproduct.slide .active');
      var $next = ($('.rproduct.slide .active').next().length > 0) ? $('.rproduct.slide .active').next() : $('.rproduct.slide img:first');
      $active.fadeOut(function(){
      $active.removeClass('active');
      $next.fadeIn().addClass('active');
      });
    }


$(document).ready(function(){
      setInterval('swapImages()', 5000);
    });

