var sendGA = function(name){
	_gaq.push(['_trackPageview', '/' + name]);
	
	(function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
};

$(document).ready(
	
	function() {
		$('#top').flash({
				swf: baseurl +'/images/banners/topbanner.swf',
				width: 949,
				height: 173,
				allowscriptaccess: 'always'
		});
		
		//$('#top').html('<a href="http://www.rocks-n-rivers.nl/"><img src="'+baseurl+'/images/banners/flashbanner.jpg"></a>');
		
		$('#bottomflash').flash({
				swf: flashbottom,
				width: 700,
				height: 110
		});
		
		$('.detail_video').each(function(){
			var vidid = $(this).find("a").attr('href');
			$(this).flash({
			
				swf: 'http://vimeo.com/moogaloop.swf?clip_id='+ vidid +'&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1',
				width: 344,
				height: 193
			});
		});
		
	$('#nav > li').mouseout(
			function () {
				//alert('mouseout');
				
		  	$('#nav > li').each(function(){
					this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
					});
		  }
		);
		
		$('#nav > li').mouseover(
		
			function () {
				$('#nav > li').each(function(){
					this.className=this.className.replace(new RegExp(" sfhover\\b"), "");

					});
		  	this.className+=" sfhover";
		  }
		);

		
		//adviesform
		var adviesform_init = function(){
		  var doeldata = {
		  bedrijven : ["Bedrijfsuitje","Teamdag", "Teamtraining", "Vergaderarrangement","Incentive","Eco Events"],
		  scholen : ["Schoolsurvivaldag", "Survivalkamp", "Eco survivaldag"],
		  particulieren : ["Groepsactiviteiten NL", "Buitensport Activiteiten Ardennen", "Groepshuizen Ardennen","Maatwerk speciale doelgroepen"]
		  };
		  

			$(".groeptype").click(function(){
				
				//sync forms
				$(".groeptype").val($(this).fieldValue());
				var options = doeldata[$(this).fieldValue()];
				
				if(options)
				{
						var html_options = '';
						for(var i = 0;i<options.length;i++)
						{
							html_options += '<option value="'+options[i]+'">'+options[i]+'</option>';
						}
						
						$(".dependgroeptype").css('display','block');
						$(".doel").html(html_options);
						$(this).blur();
				}
			});
			
			$(".doel").change(function(){
				
				$(".doel").val($(this).fieldValue());
			});
			
			//initial data
			var options = doeldata[$(".groeptype").fieldValue()];
				
				if(options)
				{
					var html_options = "";
					for(var i = 0;i<options.length;i++)
					{
						html_options += '<option value="'+options[i]+'">'+options[i]+'</option>';
					}
					$(".doel").html(html_options);
				}
		};
		
		
		//get array of images
		var images = new Array();
		$('.overlaypic').each(function(){
					images[images.length] = $(this);
		});
		
				
			
		$('.aanvraagformulier_link').click(function(){
			var gourl = baseurl + '/overlay/aanvraagformulier.php?programmaid='+id;
			$("body").overlay({scroll:false,boxwidth:600,boxheight:400,boxtop:100,contenturl:  gourl,closeimage: baseurl+'/images/close.gif',loadingimage: baseurl+'/images/ajax-loader.gif',boxbackgroundcolor:  '#FFFFFF'});
			sendGA('formulier_informeer_beschikbaarheid');
			return false;
			}
		);
		
		$('.aanvraagformulier_link_allin').live('click',function(event){
			event.preventDefault();
			var allinid = $(this).attr('href').replace('#','');

			$('#closeimg').trigger('click');
			var gourl = baseurl + '/overlay/allin_aanvraagformulier.php?allinid='+allinid;
			$("body").overlay({scroll:false,boxwidth:600,boxheight:400,boxtop:100,contenturl:  gourl,closeimage: baseurl+'/images/close.gif',loadingimage: baseurl+'/images/ajax-loader.gif',boxbackgroundcolor:  '#FFFFFF'});
			sendGA('formulier_informeer_beschikbaarheid_allin');
			return false;
			}
		);
		
		$('#uitgebreid_adviesform_link').click(function(){
			var urlparams = $('#adviesform').formSerialize();
			//alert(urlparams);
			var gourl = baseurl + '/overlay/uitgebreid_aanvraag_formulier.php?'+urlparams;
			$("body").overlay({scroll:false,onloadhandler:adviesform_init,boxtop:100,boxwidth:600,boxheight:400,contenturl:  gourl,closeimage: baseurl+'/images/close.gif',loadingimage: baseurl+'/images/ajax-loader.gif',boxbackgroundcolor:  '#FFFFFF'});
			sendGA('formulier_persoonlijk_advies_uitgebreid');
			
			return false;
			}
		);
		
		
		$('#share').click(function(){
			var urlparams = location.href;
			//alert(urlparams);
			var gourl = baseurl + '/overlay/shareform.php?link='+urlparams;
			$("body").overlay({scroll:false,onloadhandler:function(){},boxtop:100,boxwidth:600,boxheight:400,contenturl:  gourl,closeimage: baseurl+'/images/close.gif',loadingimage: baseurl+'/images/ajax-loader.gif',boxbackgroundcolor:  '#FFFFFF'});
			return false;
			}
		);
		
		$('#share').hover(function() {
					$(this).css('cursor','pointer');
					}, function() {

					$(this).css('cursor','auto');
		});
		
		$('.overlaypic').hover(function() {
					$(this).css('cursor','pointer');
					var currentimg = $(this).attr('src');
			
					$('.overlaypic_big').attr('src',currentimg.replace("th_",""));
					}, function() {

					$(this).css('cursor','auto');
		});
		
		$('.overlaypic_video').hover(function() {
					$(this).css('cursor','pointer');
					}, function() {

					$(this).css('cursor','auto');
		}).click(function(){
				$('#youtubeframe').attr('src','http://www.youtube.com/embed/' + $(this).attr('data-embed') + "?wmode=transparent");
		});
		
		$('.aanvraagformulier_link').hover(function() {
					$(this).css('cursor','pointer');
					}, function() {

					$(this).css('cursor','auto');
		});
		
		/*$('#tellafriend').css('display', 'none');*/
		
		$('.allin').click(function(event) {
					event.preventDefault();
					var href = $(this).attr('href');
					var id = href.replace('#','');
					var urlparams = id;
					//alert(urlparams);
					var gourl = baseurl + '/overlay/allin.php?allinid='+urlparams;
					$("body").overlay({scroll:false,onloadhandler:function(){},boxtop:100,boxwidth:600,boxheight:400,contenturl:  gourl,closeimage: baseurl+'/images/close.gif',loadingimage: baseurl+'/images/ajax-loader.gif',boxbackgroundcolor:  '#FFFFFF'});
					return false;
		});
		
		adviesform_init();
		//$('#youtubeframe').css('z-index',50);
		//$('#youtubeframe').css('z-index')
	}
);
