var $selectors = {},
	$browser = {},
	$state = {},
	site = {
	
		_debug: function infscr_debug() {
			return window.console && console.log.call(console, arguments);
		},
		
		_init: {
			about: function() {
			
				if (!$('#slideshow').length) { return false; }
				
				var $slideshowImg = $('#slideshow').find('img');
				
				$('#slideshow').cycle({
					fx: 'scrollUp',
					speed: '750',
					easing: 'easeInOutQuint',
					timeout: 0,
					pager: '#slideshow-nav',
					pagerAnchorBuilder: function(idx, slide) {
						return '#slideshow-nav a:eq(' + idx + ')';
					},
					after: function(currSlideElement, nextSlideElement, options, forwardFlag) {
						var thisNum = $slideshowImg.index($(nextSlideElement)) + 1;
						_gaq.push(['_trackEvent', 'About', thisNum]);
					}
				});
				
				
			},
			
			contact: function() {
			
				var myLatlng = new google.maps.LatLng(51.52409829559966, -0.07583141326904297),
		            myOptions = {
		                zoom: 17,
		                maxZoom: 18,
		                minZoom: 14,
		                draggable: true,
		                center: myLatlng,
		                navigationControlOptions: { style: google.maps.NavigationControlStyle.SMALL },
		                mapTypeId: google.maps.MapTypeId.TERRAIN,
		                mapTypeControl: false,
		                streetViewControl: false,
		                zoomControl: true
		            },
		            map = new google.maps.Map(document.getElementById("map"), myOptions),
		            infoWindow = infoWindow = new google.maps.InfoWindow({
		                content: '',
		                maxWidth: 400
		            }),
		            sunsStyles = [
		              {
		                  featureType: "all",
		                  elementType: "all"
		
		              }, {
		                  featureType: "administrative",
		                  elementType: "labels",
		                  stylers: [
		                  { visibility: "off" }
		                ]
		              }, {
		                  featureType: "landscape",
		                  elementType: "geometry",
		                  stylers: [
		                  { hue: '#cc0000' },
		                  { saturation: -97 },
		                  { lightness: 20 },
		                  { gamma: 0 },
		                  { invert_lightness: false }
		                ]
		              }, {
		                  featureType: "landscape",
		                  elementType: "labels",
		                  
		              }, {
		                  featureType: "poi",
		                  elementType: "all",
		                  stylers: [
		                  { visibility: "off" }
		                ]
		              }, {
		                  featureType: "road.highway",
		                  elementType: "all",
		                  stylers: [
		                  { visibility: "simplified" },
		                  { saturation: -99 },
		                  { lightness: 99 }
		                  ]
		                  
		              }, {
		                  featureType: "road.arterial",
		                  elementType: "all",
		                  stylers: [
		                  { visibility: "simplified" },
		                  { saturation: -99 },
		                  { lightness: 99 }
		                  ]
		                  
		              }, {
		                  featureType: "transit.station.bus",
		                  elementType: "all",
		                  stylers: [
		                  { visibility: "off" }
		                  ]
		              }, {
		                  featureType: "transit.line",
		                  elementType: "all",
		                  stylers: [
		                  { visibility: "off" }
		                  ]
		              }, {
		                  featureType: "water",
		                  elementType: "labels",
		                  stylers: [
		                  { visibility: "off" }
		                ]
		              }, {
		                  featureType: "water",
		                  elementType: "geometry",
		                  stylers: [
		                  { lightness: 100 },
		                  { saturation: 100 },
		                  { gamma: 10 }
		                ]
		              }
		            ],
		            sunsMapType = new google.maps.StyledMapType(sunsStyles, myOptions);
		
		        map.mapTypes.set('billionsuns', sunsMapType);
		        map.setMapTypeId('billionsuns');
		        
		        var image = new google.maps.MarkerImage(
		                    '/wp-content/themes/hostem/css/images/marker.png',
		                    new google.maps.Size(105, 20),
		                    new google.maps.Point(0, 0),
		                    new google.maps.Point(0, 0)
		                ),
	            marker = new google.maps.Marker({
	                position: new google.maps.LatLng(51.52458392293138, -0.07585287094116211),
	                map: map,
	                icon: image
	            });
			
			},
			
			
			lookbook: function() {
			
				if (!$('#slideshow').length) { return false; }
				
				$('#slideshow').cycle({
					fx: 'scrollHorz',
					speed: '950',
					easing: 'easeInQuint',
					timeout: 0,
					prev: '#prev-slide',
					next: '#next-slide',
					after: function(currSlideElement, nextSlideElement, options, forwardFlag) {
						var thisDirection = (!!forwardFlag) ? 'next' : 'previous';
						_gaq.push(['_trackPageview', window.location.pathname]);
						_gaq.push(['_trackEvent', 'Lookbook', thisDirection]);
					}
				});
			
			},
			
			blog: function() {
				
				if (!$('#single-back').length) { return false };
				
				$('#post-container').find('article').find('a[href$=jpg],a[href$=jpeg],a[href$=png],a[href$=gif]').fancybox();
				
				// Twitter social tracking
                twttr.events.bind('tweet', function(e) {
                    if (e) {
                        var targetUrl;
                        if (e.target && e.target.nodeName == 'IFRAME') {
                            targetUrl = extractParamFromUri(e.target.src, 'url');
                        }
                        _gaq.push(['_trackSocial', 'twitter', 'tweet', targetUrl]);
                    }
                });

                // Facebook social tracking
                if (FB) {
					FB.Event.subscribe('edge.create', function(targetUrl) {
                    	_gaq.push(['_trackSocial', 'facebook', 'like', targetUrl]);
                	});
				}
			}
		}
	
	};
	

$(document).ready(function() {
	
	
	/* Define selectors
    ---------------------------------------------- */
	
	$selectors.window = $(window);
	$selectors.html = $('html');
	$selectors.body = $('body');
	$selectors.bodyID = $selectors.body.attr('id');
	
	
	/* Define browser stuff
    ---------------------------------------------- */
	
	$browser.hasHistory = Modernizr.history;
	$browser.placeholder = Modernizr.input.placeholder;
	$browser.chrome = $selectors.html.hasClass('chrome');
	$browser.oldie = ($selectors.html.hasClass('ie') && !$selectors.html.hasClass('ie9'));
	
	
	var timeout = setTimeout('doneLoading()',900);
	
	
	/* Start everything
    ---------------------------------------------- */
	
	if (!!site._init[document.body.id]) {
		site._init[document.body.id]();
	};
	
	
	/* Keyboard navigation
    ---------------------------------------------- */
	
	$(document).bind('keydown',keyDown);

});


function keyDown(e) {
	
	var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
	switch (key) {
		case 27: // escape
			if ($state.fancybox) closeFancybox();
		break;
		
		case 37: // left
			if ($state.fancybox) $.fancybox.prev();
			$('#slideshow').cycle('prev');
		break;
		
		case 39: // right
			if ($state.fancybox) $.fancybox.next();
			$('#slideshow').cycle('next');
		break;
	};

};

function doneLoading() {
	$selectors.body.removeClass('loading');
}
