///////////////////////////
//   CUSTOM JAVASCRIPT   //
///////////////////////////

//   Homepage slider   //

$(window).load(function() {
    $('ul#homepage_slider').nivoSlider({
        effect: 'fade',
		animSpeed: 1500,
		pauseTime: 10000,
		beforeChange: function(){
			fadeNivoElements('fade', 1500);
        }
    });
});

function fadeNivoElements(element, delay) {
	var currentSlide = $('ul#homepage_slider').data('nivo:vars').currentSlide;
	var nextSlide = ($('ul#homepage_slider').data('nivo:vars').currentSlide + 1) % $('ul#homepage_slider').data('nivo:vars').totalSlides;
	$("ul").find("[data-slide='fade" + nextSlide +"']").fadeIn(delay);
	$("ul").find("[data-slide='fade" + currentSlide +"']").fadeOut(delay);
}

//   PrettyPhoto activation   //

$(document).ready(function(){
	$(".gallery:first a[rel^='prettyPhoto']").prettyPhoto({animation_speed:'normal',theme:'light_rounded',slideshow:3000, autoplay_slideshow: false});
	$(".gallery:gt(0) a[rel^='prettyPhoto']").prettyPhoto({animation_speed:'fast',theme:'light_rounded', slideshow:10000});

	
	//$("#custom_content a[rel^='prettyPhoto']:first").prettyPhoto({
	//	custom_markup: '<div id="map_canvas" style="width:260px; height:265px"></div>',
	//	changepicturecallback: function(){ initialize(); }
	//});

	//$("#custom_content a[rel^='prettyPhoto']:last").prettyPhoto({
	//	custom_markup: '<div id="bsap_1237859" class="bsarocks bsap_d49a0984d0f377271ccbf01a33f2b6d6" style="height:260px"></div><div id="bsap_1251710" class="bsarocks bsap_d49a0984d0f377271ccbf01a33f2b6d6"></div>',
	//	changepicturecallback: function(){ _bsap.exec(); }
	//});
	
	if(typeof(openAfterFormError) != "undefined"){
		if(openAfterFormError){
		//if($(".mc_error_msg").html()){
		//	if($(".mc_error_msg").html() != ''){	
			$.prettyPhoto.open('#newsletter', '', '');
		//	}
		//}
		}
	}
	$('.background').zlayer({mass:3,force:'push',canvas:'#container'});
});
