var GY = (function(parent, $){
	
	var self = parent || {};

	self.init = function() {
		
		// search
		this.search.init('#searchform');
		this.placeholder.init('input#s');
		
		// megabig
		if($('body.home').length > 0 && !this.mobile()) {
			this.megabig.init('.slides', window.slides);
		}
		
		this.expandCollapse('a.ec-trigger', 'ul.ec');
		this.externals('a[rel=external]');
		
		$('.slideshow').slideshow();
		
		// map
		if($('#map').length > 0 && GY.map) {
			if(window.lat && window.lng) {
				//console.log('what?');
				this.map.init('map', {
					lat: window.lat,
					lng: window.lng,
					zoom: 5
				});
			} else {
				this.map.init('map');
			}
			
		}
		
	};
	
	self.mobile = function() {
		var iphone = (navigator.platform.indexOf('iPhone')>=0) ? true : false,
			ipad = (navigator.platform.indexOf('iPad')>=0) ? true : false,
			android = (navigator.userAgent.indexOf('Android')>=0) ? true : false;
		
		if(iphone || ipad || android) {
			return true;
		} else {
			return false;
		}
	};
	
	self.expandCollapse = function(trigger, target, options) {
		
		trigger = $(trigger); 
		target = $(target);
		
		trigger.bind('click', function(e) {
			e.preventDefault();
			target.toggle(150, function(e) {
				($(this).is(':visible')) ? trigger.find('span').html('-') : trigger.find('span').html('+');
			});
		});
		
	};
	
	self.externals = function(triggers) {
		$(triggers).attr('target', '_blank');
	};
	
	return parent;
	
})(GY || {}, jQuery);

jQuery(function() {
    GY.init();
});
