




jQuery.noConflict();

var plauditAnalytics = (function() {
	
	function isPageTrackerLoaded() {
		return typeof(_gaq) != "undefined" && _gaq != null;
	};
	
	return {
		trackPage: function(url) {
			if ( url.substring(0,1) != '/' )
				url = '/' + url;
			if ( isPageTrackerLoaded() ) {
				_gaq.push(['_trackPageview', url]);
			} else if ( typeof(console) != "undefined" ) {
				console.log("Google Analytics not loaded. Trying to track page: " + url);
			}
		},
		trackEvent: function(category, action, opt_label, opt_value) {
			if ( isPageTrackerLoaded() ) {
				_gaq.push(['_trackEvent', category, action, opt_label, opt_value]);
			} else if ( typeof(console) != "undefined" ) {
				console.log("Google Analytics not loaded. Trying to track event with category '" + category +"', action '" + action +"', opt_label '" + opt_label +"', and opt_value '" + opt_value +"'.");
			}
		}
	};
})();

var Cookie = {
	get: function(key) {
		var keyEQ = key + "=";
		var ca = document.cookie.split(';');
		for( var i=0;i < ca.length;i++ ) {
			var c = ca[i];
			while ( c.charAt(0) == ' ' ) {
				c = c.substring( 1, c.length );
			}
			if ( c.indexOf(keyEQ) == 0 ) {
				return c.substring( keyEQ.length,c.length );
			}
		}
		return null;
	},
	set: function(key, value, ttl) {
		var expires = "";
		if ( ttl ) {
			expires = "; expires=" + Cookie.hoursToExpireDate( ttl );
		}
		return document.cookie = key + "=" + value + expires + "; path=/";
		
	},
	unset: function( key ) {
		if (Cookie.get(key)) Cookie.set(key, '', 'Thu, 01-Jan-70 00:00:01 GMT');
	},
	hoursToExpireDate: function(ttl) {
		if (parseInt(ttl) == 'NaN' ) return '';
		else {
			var now = new Date();
			now.setTime(now.getTime() + (parseInt(ttl) * 60 * 60 * 1000));
			return now.toGMTString();			
		}
	}
};



var plauditSite = (function($){
	
	
	
	var defaultMethods = function(){
		$("body").addClass("jsEnabled");
		$("tr:odd").addClass("odd");
		$(".searchForm input#query").focus(function(){ $(this).select(); });
		$("a[href^=\"http://\"]").attr("target", "_blank");
		$("a[href^=\"https://\"]").attr("target", "_blank");
		$("a[href=\"$.pdf\"]").attr("target", "_blank");
		$("#navigation li.hasChildren").hover(
			function(){
				$(this).addClass("hover");
			}, function(){
				$(this).removeClass("hover");
			}
		);
	}();
	
	var customElements = {
			
		init: function(){
			this.onlineReview();
			this.faq();
			this.googleMaps();
			this.videoOverlay();
			this.homepageSlideDown();
			this.carousel();
		}
		,onlineReview: function(){
			$("#review-link a").click(function(){
				plauditAnalytics.trackEvent("Post an online review","Click",$(this).attr("href"));
			});
		}
		
		,faq: function(){
			// FAQ Setup
			var hash = location.hash;
			
			// If there is a hash open up that answer
			if ( hash ) { 
				$(hash)
					.addClass("open")
					.children(".answer")
					.show();
				$(hash).data("lastToggle1", 1); // jQuery toggle method uses the jquery data method internally and we are faking the value here
			}
		
			$("#faq li").toggle(
				function(){
					$(this).addClass("open");
					$(this).children(".answer").slideDown();
				}, function(){
					$(this).removeClass("open").removeAttr("class");
					$(this).children(".answer").hide();
				}
			);
			
			$("#faq li a").click(function(e){
				e.stopPropagation();
			});
		}
		,googleMaps: function(){
			
			if( $("#map").length !== 0 ){ // Test if the Map div exists
				 var latlng = new google.maps.LatLng(45.094147,-93.745545);
				 var mapCenter = new google.maps.LatLng(45.049723,-93.593903);
				 var mapOptions = {
				      zoom: 9,
				      center: mapCenter,
				      mapTypeControl: false,
				      mapTypeId: google.maps.MapTypeId.ROADMAP
				};
				var map = new google.maps.Map(document.getElementById("map"), mapOptions);
			    var marker = new google.maps.Marker({
			        position: latlng, 
			        map: map,
			        title:"WH Security"
			    });  
			    
			    var infoWindowContent = '<h4>WH Security</h4>'+
			    '<p style="text-align: left;">6800 Electric Drive<br/>'+
			    'Rockford, MN 55373</p>';
			    
			    var infoWindow = new google.maps.InfoWindow({
			    	content: infoWindowContent
			    });
			    
			    google.maps.event.addListener(marker, 'click', function(){
			    	infoWindow.open(map,marker)
			    });
			}
		}
		,videoOverlay: function(){
			var options = {
				animationSpeed: 'normal',
				allowresize: false,
				showTitle: false,
				theme: 'light_rounded'	
			};
			
			$("a[rel^='lightbox']").prettyPhoto(options);
		}
		,homepageSlideDown: function(){
			var messageArea = $("#message-area");
			var isSlideDownDisabled = Cookie.get("disableSlideDown");
			
			if ( isSlideDownDisabled === null){
				
				Cookie.set("disableSlideDown",true);
				
				if ( $("body").hasClass("homepage") ){
					if ( $.support.opacity ){
						messageArea.slideDown();
					} else {
						messageArea.show();
					}
					
					messageArea.find(".close").click(function(){
						if ( parseInt(jQuery.browser.version) == 6){
							window.location.reload();
						} else {
							messageArea.hide();
						}
					});
				}
			}
				
		}
		,carousel: function(){
			if ($('#carousel-wrap').length==0) return;
			$('#carousel-wrap').parent().append('<div class="carousel-controls"><a id="carousel-l" class="control-l" href="#">Prev</a><a id="carousel-r" class="control-r" href="#">Next</a><span id="carousel-paginate"></span>');
			$('#carousel').cycle({
			     fx:     'fade'
			    ,pager:  '#carousel-paginate'
			    ,next:   '#carousel-r' 
			    ,prev:   '#carousel-l' 
			   	,containerResize: 0
			    ,timeout: 5000
				,delay:  1000
			    ,speed:  700
		        ,speedIn:  1000 
		        ,speedOut: 500
			});
		} // END carousel()
		
		
	};
	
	customElements.init();
	



	
		


})(jQuery);


