$(document).ready(function(){
	s7.init();
});

var s7 = {
	
	init : function(){
		s7.center_gallery();
		s7.fancybox.news();
		s7.side_gallery();
		
		s7.loadAjax();
		
		s7.fancybox.pics();
		s7.gMaps();

	},
	
	loadAjax : function(){
		return false;
		for(i=0; i<pages.length; i++){
			if($('#ajax_'+pages[i]).length){
				$.ajax({
					url: 'ajax/'+pages[i]+'.php',
					context : $('#ajax_'+pages[i]),
					success: function(data){
						// just create the cachefile
					}
				});
			}
		}
	},
	
	fancybox : {
		
		news : function(){
			$(".news_item a.link.video").fancybox({
				'width'		: 640,
				'height'	: 385,
				'type'		: 'iframe',
				'centerOnScroll' : true
			});
			$(".news_item a.link.photo").fancybox({
				'centerOnScroll' : true
			});
			$(".news_item a.link.iframe").fancybox({
				'width'		: 800,
				'height'	: 600,
				'type'		: 'iframe',
				'centerOnScroll' : true
			});
			/*
			$(".news_item a.link.facebook").fancybox({
				'width'		: 982,
				'height'	: 420,
				'type'		: 'iframe',
				'centerOnScroll' : true
			});
			*/
		},
		
		pics : function(){
			if(!$('#pics_gallery').length) return false;
			
			$("#pics_gallery .album a").fancybox({
				'centerOnScroll' : true
			});
			
		}
		
	},
	
	side_gallery : function(){
		if(!$('#side_slider').length) return false;
		
		// shuffle & rotate:
		$('#side_slider img').each(function(){
			angle = -15+Math.floor(Math.random()*30);
			$(this).rotate(angle);
		})
		
		randomElements = $('#side_slider img').get().sort(function(){ 
			return Math.round(Math.random())-0.5
		})
		
		$(randomElements).each(function(){
			$(this).prependTo($('#side_slider'));
		});
	
		$('.pics a.handle').attr({
			'href' : $('#side_slider img:last').attr('rel'),
			'title' : $('#side_slider img:last').attr('title')
		});
		
		$('.pics a.handle').fancybox({
			'centerOnScroll' : true
		});
	
		setInterval ( 's7.side_gallery_do()', 4000 );
	
	},
	
	side_gallery_do : function(){
		speed = 1000;
		
		$('#side_slider img')
			.stop(false,false)
			.css({ left: 0, top: 0})
		
		$('#side_slider img:last')
			.animate({
				left: 240,
				top: -100,
			}, speed, function(){
				$(this).prependTo($('#side_slider'))
				$('.pics a.handle').attr({
					'href' : $('#side_slider img:last').attr('rel'),
					'title' : $('#side_slider img:last').attr('title')
				});
			})
			.delay(200)
			.animate({
				left: 0,
				top: -0,
			}, speed, function(){
				
			})
	},
	
	center_gallery : function(){
        $('#home_slider').cycle();
		
	},
	gMaps : function(){
		if(!$('#map_canvas').length) return false;
		
		var latlng = new google.maps.LatLng(51.498498, 3.610554);
		var myOptions = {
			zoom: 15,
			center: latlng,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
		
		var marker = new google.maps.Marker({
			position: latlng, 
			map: map,
			title: "Hello World!"
		});
	}
	
}

//http://maps.google.nl/maps?q=Seventy+Seven,+Markt,+Middelburg&hl=nl&ll=51.498498,3.610554&spn=0.010566,0.033023&sll=52.469397,5.509644&sspn=5.46268,16.907959&t=h&z=16
