var content_element_a = [
	'div.content-text-app-left',
	'div.content-text-right',
	'div.content-text-left',
	'div.content-text-content-app-left-inner',
	'div.content-text-app-left-inner',
	'div.content-text-app-right',
	'div.content-text-left-inner'
];
 
 $(document).ready(function() {

	/* Clear empty content boxes for ie7 and lower */
	
	$.each(content_element_a, function(index) {
		if($(content_element_a[index]).length)
			if(!$(content_element_a[index]).html().length)
				$(content_element_a[index]).hide();
	});
	
	/* Social media icons dropdown */
	$('div.content-header-social > ul > li').hover(
		function() { 
			$(this).siblings().css({'opacity': '0.5'});
			$(this).stop().animate({'margin-top' :'-10px'}, 300);
		},
		function() { 
			$(this).siblings().css({'opacity': '1'});
			$(this).stop().animate({'margin-top' :'-30px'}, 300); 	
	});
	
	/* Menu add Parent class on sub menu (level 1) */
	$('ul.menu > li > ul').children('li').each(function(){
		$(this).find('ul').addClass('parent');
	})
	
	/* age validation  center*/
	if($('div.content-validator').length)
	{
		$('div.content-validator').center();
		setOverlay();
	}
	
	/* Beer video */
	$('a.beer_video').click(function(){
		setBeerVideo(this);
		return false;
	}) 
	
	$('div.content-streamer-movie-close > a').click(function(){
		closeBeerVideo();
		return false;
	});		
	
	/* Menu */
	$('ul.menu').superfish({
		animation: {height:'show'},
		delay: 300,
		autoArrows : false,
		dropShadows: false 
	});
	
	/* Slider bottle navigation center */
	if($('#streamer-navigation > div').length)
		setSliderNavigationCenter();
	
	/* Slider */
    $('#streamer').jcarousel({
    	wrap: 'circular',
    	auto: 8,
    	scroll: 1,
    	visible: 1,
    	easing: 'easeInOutQuart',
    	animation: 1200,
        buttonNextHTML: null,
        buttonPrevHTML: null, 
        itemFallbackDimension: 1245,	
    	initCallback: streamer_initCallback,  
    	itemLastOutCallback: {
    		onBeforeAnimation: setStreamNavHidden,
    		onAfterAnimation: setStreamNav
    	}
    });  
    
    /* Lightbox */
	$('a.light-box').lightBox({
	
		overlayBgColor: '#86a4d8',
		overlayOpacity: 0.9,
		imageLoading: '/ENGINE/IMAGES/DELIRIUM/WEBSITE/lightbox/lightbox-ico-loading.gif',
		imageBtnClose: '/ENGINE/IMAGES/DELIRIUM/WEBSITE/lightbox/lightbox-btn-close.gif',
		imageBtnPrev: '/ENGINE/IMAGES/DELIRIUM/WEBSITE/lightbox/lightbox-btn-prev.gif',
		imageBtnNext: '/ENGINE/IMAGES/DELIRIUM/WEBSITE/lightbox/lightbox-btn-next.gif',
		txtImage: 'Afbeelding',
		txtOf: 'van'
	});     
    
    /* Feature gallery */  
    $('div.content-middle-streamer-item').show();
 	$("#feature-streamer").featureCarousel({});	
 	
 	$('ul.content-faq > li:first > ul').show();
 	
  	/* FAQ list */
	$('ul.content-faq > li > a').click(function(){
		blockActionClose();
		$(this).addClass('active');
		$(this).siblings('ul').slideDown(300);
		return false;
	}); 
	
	/* Downloads movie */
	$('div.content-publication-right > a.video_trigger , div.content-publication-left > a.video_trigger').click(function(){
		number_i = $(this).attr('rel').replace('download_video_trigger_','');
		movie_element_s = '#download_video_' + number_i;
		if($(movie_element_s).is(':visible'))
		{
			$('div.content-publication-right > a.video_open').show();
			$('div.content-publication-right > a.video_close').hide();
			$(movie_element_s).slideUp(200);
		}
		else
		{
			$('div.content-publication-right > a.video_open').hide();
			$('div.content-publication-right > a.video_close').show();			
			$(movie_element_s).slideDown(600);
		}
		
		return false;
	});
});

function setStreamNav(carousel, item, idx, state)
{
	$('#streamer-navigation > div').fadeIn('fast');	
	$('div.content-streamer-more').fadeIn('fast');	
}

function setStreamNavHidden(carousel, item, idx, state)
{
	$('#streamer-navigation > div').fadeOut('fast');
	$('div.content-streamer-more').fadeOut('fast');			
}

function streamer_initCallback(carousel)
{
    $('#streamer-navigation > div > ul > li > a').bind('click', function() {
        carousel.scroll($.jcarousel.intval($(this).attr('id').replace('streamer_item_','')));
        return false;
    });    
    
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });
    
    $('a.streamer-previous').bind('click', function() {
        carousel.prev();
        return false;
    });
    
    $('a.streamer-next').bind('click', function() {
        carousel.next();
        return false;
    });    

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function setValidation()
{	
	$('div.content-validate-loading').show();
	language_id = $('input[name="language"]:checked').val();
	validate_b_i = $('input[name="validation"]').val();
	
	$('form[name="age_validation_form"]').hide();
    
    language_id = language_id ? language_id : 'nl';
    
	$.ajax
	({
		type: 'POST',
		url: '/delirium/validate/'+language_id,
		data: {
			validate_b: validate_b_i,
			language_s: language_id
		},
		success: function(data)
		{			
			if(data){
				/*$('div.content-validate-loading').hide();
				/$("#overlay").hide();
				$('div.content-validator').hide();
				if($('#intro-video').length)
					setIntroVideo();*/
				location.href= 'http://www.delirium.be/'+language_id;
				//location.href= window.location;
			}
			else
			{
				location.href = 'http://www.google.com';
			}
			
		},
		error: function (XMLHttpRequest, textStatus, errorThrown)
		{}
	});	

}

function setAge(age_b)
{
	if(age_b)
		$('input[name="validation"]').val(1);
	else
		$('input[name="validation"]').val(0);
}

function setProperLangauge(langauge_s)
{
	$('div.validator-language').hide();
	$('div.validator-'+langauge_s).show();
}

function setOverlay()
{
	if(!$("#overlay").length)
	{
		var docHeight = $(document.body).height();
		$("body").append("<div id='overlay'></div>");
		$("#overlay").height(docHeight).css({'opacity' : 0.4, 'position': 'absolute', 'top': 0, 'left': 0, 'background-color': 'black','width': '100%','z-index': '55'});
	}
	else
	{
		$("#overlay").show();
	}
}

function setBeerVideo(object_s)
{
	if(object_s) 
	{
		/* Stop carousel */
		carousel = $('#streamer').data('jcarousel');
		carousel.options.auto = 0;
	
		movie_source_s = $(object_s).attr('href');
		$('div.content-streamer-movie').animate({'margin-top' :'130px'}, 1000,'easeInOutQuart',function(){
			setOverlay();
			$('div.content-streamer-movie').css({'z-index' : '60'});
		});
    	
		jwplayer("streamer-beer").setup({
			flashplayer: "/ENGINE/MOVIES/DELIRIUM/WEBSITE/player.swf",
			file: movie_source_s,
			autostart: true,
			height: 426,
			width: 640,
			skin: false,
			stretching: 'uniform',
			controlbar: '',
			events: {
				onComplete: function() {
					closeBeerVideo()
				}
			}
		});	
	}
}

function closeBeerVideo()
{
	/* Stop carousel */
	carousel = $('#streamer').data('jcarousel');
	$('div.content-streamer-movie').css({'z-index' : '1002'});
	$('div.content-streamer-movie').animate({'margin-top' :'-430px'}, 1000,'easeInOutQuart',function()
	{
		carousel.options.auto = 8;
		$("#overlay").remove(); 
		$('#streamer-beer').html('');	
		$('#streamer-beer').hide();	
		jwplayer().stop();
	});
}

function blockActionClose()
{
	$('ul.content-faq > li a').each(function(){
		$(this).removeClass('active');
	});
	$('ul.content-faq > li ul').each(function(){
		$(this).hide();
	});	
}

function setSliderNavigationCenter()
{
	item_width = $('#streamer-navigation > div > ul > li').width()+1;
	item_count = $('#streamer-navigation > div > ul > li').length;
	total_count = item_width * item_count;
	item_offset = (($('#streamer-navigation > div > ul').width() - total_count) / 2) + 'px';
	$('#streamer-navigation > div > ul > li:first').css({'margin-left': item_offset});
}

function checkContactFormOption(element_o)
{
	if(element_o == 'Je souhaite visiter la brasserie')
		location.href='http://www.delirium.be/pagina/89/visitez_la_brasserie.html';	
	if(element_o == 'I want to request a brewery visit')
		location.href='http://www.delirium.be/pagina/108/brewery_visit.html';
	if(element_o =='over een brouwerij bezoek')
		location.href= 'http://www.delirium.be/pagina/21/brouwerijbezoek.html';	
	if(element_o == 'Su una visita al birrificio')
		location.href='http://www.delirium.be/pagina/131/visita_del_birrificio.html';
	if(element_o == '私は醸造所見学を希望します')
		location.href='http://www.delirium.be/pagina/174/brewery_visit.html';		
	if(element_o == 'я хочу заказать посещение пивоварни')
		location.href='http://www.delirium.be/pagina/199/brewery_visit.html';
	if(element_o == 'Quiero solicitar una visita a la fábrica')
		location.href='http://www.delirium.be/pagina/262/visita_a_la_fabrica.html';		
	
	if(element_o == 'sponsoring' || element_o == 'sponsorship' || element_o == 'sponsorizzazione' || element_o == 'спонсорство' || element_o == 'スポンサー' || element_o == 'patrocinio')
	{
		$('#contact-form-sponsor').show();		
		$('#contact > input[name="__receiver_subject__"]').val('Sponsoring');
	}
	else
		$('#contact > input[name="__receiver_subject__"]').val('Contact');
		
}
