/*
 * Site.js
 */
Site = {
		banner: function(){
			var fade_speed = 500;
			var delay_time = 3500;
			
			$('#slideshow').cycle({
				speed:       fade_speed,
				timeout:     delay_time,
				delay:       0, 
				pager:      '#nav',
				pagerEvent: 'click',
				pauseOnPagerHover: true,
				pagerAnchorBuilder: function(idx, slide) {
					return '#recentimages li:eq(' + idx + ')';
				} 
			});
			$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) {
				$(pager).find('li').removeClass('selected').filter('li:eq('+currSlideIndex+')').addClass('selected');
			};			
		},
		banner_buttons: function (){ // Banner Button Effect
		    $('#recentimages li').append('<div class="hover"></div>');  
		    $('#recentimages li').hover(  
		        function() {  
		            $(this).children('div').fadeIn('500');   
		        },   
		        function() {  
		            $(this).children('div').fadeOut('500');      
		        }).click(function () {
		            $('#recentimages li').removeClass('selected');
		            $(this).addClass('selected');
		            return false;
		        });
	
		    $('#recentimages_details li').append('<div class="hover_details"></div>');  
		    $('#recentimages_details li').hover(  
		        function() {  
		            $(this).children('div').fadeIn('500');   
		        },   
		        function() {  
		            $(this).children('div').fadeOut('500');      
		        }).click(function () {
		            $('#recentimages_details li').removeClass('selected');
		            $(this).addClass('selected');
		            return false;
		        });
		},
		slideshow_control: function(){ // Slide show play & pause
			$('#slideshow').hover(  
				function() {
					jQuery('#slideshow').cycle('pause')
				},   
				function() {  
				 	jQuery('#slideshow').cycle('resume')
			});
			$('#slideshow_details').hover(  
				function() {
					jQuery('#slideshow_details').cycle('pause')
				},   
				function() {  
				 	jQuery('#slideshow_details').cycle('resume')
			});
		},
		map: function(address) {
			if ($("#map").length == 1) {
				var map = null;
				var geocoder = null;

				if (GBrowserIsCompatible()) {
					map = new GMap2(document.getElementById("map"));
					geocoder = new GClientGeocoder();
					geocoder.getLatLng(
						address,
						function(point) {
							map.setCenter(point);
							map.setZoom(11);
							map.setMapType(G_NORMAL_MAP);
							map.addControl(new GSmallMapControl());
			
							var marker = new GMarker(point);
							map.addOverlay(marker);
						}
					);
				}
			}
		},		
		init: function(){
			Site.banner_buttons();
			Site.slideshow_control(); 
			Site.banner();
			if ($("#map").length == 1) {
				Site.map(address);
			}			
		}
}


$(document).ready(Site.init);
