function loadGoogleMap() {					  
	var latlng = new google.maps.LatLng(40.37839381408929, -111.81110143661499);
	var myOptions = {
		zoom: 15,
		center: latlng,
		disableDefaultUI: true,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var image = new google.maps.MarkerImage(
		'http://www.risermedia.com/wp-content/themes/riser/images/marker-images/marker-new.png', 
		new google.maps.Size(43,51),
		new google.maps.Point(0,0),
		new google.maps.Point(22,43)
	);
	
	/*var shadow = new google.maps.MarkerImage(
		'/wp-content/themes/riser/images/marker-images/shadow.png',
		new google.maps.Size(48,36),
		new google.maps.Point(0,0),
		new google.maps.Point(13,36)
	);*/
	
	var shape = {
	  coord: [25,0,28,1,31,2,32,3,34,4,35,5,36,6,37,7,38,8,39,9,39,10,40,11,40,12,41,13,41,14,41,15,42,16,42,17,42,18,42,19,42,20,42,21,42,22,42,23,42,24,42,25,42,26,42,27,41,28,41,29,41,30,40,31,40,32,39,33,38,34,38,35,37,36,36,37,35,38,33,39,32,40,30,41,28,42,27,43,26,44,25,45,25,46,24,47,23,48,23,49,22,50,22,50,21,49,21,48,20,47,19,46,19,45,18,44,17,43,14,42,12,41,10,40,8,39,7,38,6,37,5,36,4,35,3,34,3,33,2,32,2,31,1,30,1,29,1,28,0,27,0,26,0,25,0,24,0,23,0,22,0,21,0,20,0,19,0,18,0,17,0,16,0,15,1,14,1,13,2,12,2,11,3,10,3,9,4,8,5,7,6,6,7,5,8,4,10,3,11,2,14,1,17,0,25,0],
	  type: 'poly'
	};

	var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	var marker = new google.maps.Marker({
			draggable: false,
			raiseOnDrag: false,
			icon: image,
			shape: shape,
			position: latlng, 
			map: map, 
			title:"RiserMedia"
	});
	
	google.maps.event.addListener(marker, 'click', function() {
		window.open('http://maps.google.com/?q=Riser%20Media%2C%20West%2050%20North%2C%20American%20Fork', '_blank');
	});

}

var directionDisplay;
var directionsService = new google.maps.DirectionsService();

function calcRoute() {
	var start = document.getElementById("start").value;
	var end = "40.37839381408929, -111.81110143661499";
	var request = {
		origin:start,
		destination:end,
		travelMode: google.maps.DirectionsTravelMode.DRIVING
	};
	
	directionsService.route(request, function(response, status) {
		if (status == google.maps.DirectionsStatus.OK) {
			directionsDisplay.setDirections(response);
		}
	});
}

function loadContactGoogleMap() {					  
	var latlng = new google.maps.LatLng(40.37839381408929, -111.81110143661499);
	directionsDisplay = new google.maps.DirectionsRenderer();
	var myOptions = {
		zoom: 7,
		center: new google.maps.LatLng(40.599356, -111.816101),
		disableDefaultUI: true,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var image = new google.maps.MarkerImage(
		'/wp-content/themes/riser/images/marker-images/marker-new.png',
		new google.maps.Size(43,51),
		new google.maps.Point(0,0),
		new google.maps.Point(22,51)
	);

	/*var shadow = new google.maps.MarkerImage(
		'/wp-content/themes/riser/images/marker-images/riser-shadow.png',
		new google.maps.Size(100,44),
		new google.maps.Point(0,0),
		new google.maps.Point(57,44)
	);*/
	
	var baloonContent = '<div id="baloon">'+
    					'<h4>RiserMedia</h4>'+
    					/*'<p>477 West 50 North<br/>American Fork, UT 84003<br/>(801) 492-1903</p>'+*/
    					'<form action="/contact" onsubmit="calcRoute();return false;" >'+
    					'<input id="start" type="text" value="" />'+
    					'<input type="submit" value="Get directions" id="get-directions" /></form>'+
    					'</div>';
	
	var infowindow = new google.maps.InfoWindow({
	    content: baloonContent
	});

	var shape = {
	  coord: [25,0,28,1,31,2,32,3,34,4,35,5,36,6,37,7,38,8,39,9,39,10,40,11,40,12,41,13,41,14,41,15,42,16,42,17,42,18,42,19,42,20,42,21,42,22,42,23,42,24,42,25,42,26,42,27,41,28,41,29,41,30,40,31,40,32,39,33,38,34,38,35,37,36,36,37,35,38,33,39,32,40,30,41,28,42,27,43,26,44,25,45,25,46,24,47,23,48,23,49,22,50,22,50,21,49,21,48,20,47,19,46,19,45,18,44,17,43,14,42,12,41,10,40,8,39,7,38,6,37,5,36,4,35,3,34,3,33,2,32,2,31,1,30,1,29,1,28,0,27,0,26,0,25,0,24,0,23,0,22,0,21,0,20,0,19,0,18,0,17,0,16,0,15,1,14,1,13,2,12,2,11,3,10,3,9,4,8,5,7,6,6,7,5,8,4,10,3,11,2,14,1,17,0,25,0],
	  type: 'poly'
	};
	
	
	var map = new google.maps.Map(document.getElementById("contact-map"), myOptions);
	directionsDisplay.setMap(map);
	
	var marker = new google.maps.Marker({
		draggable: false,
		raiseOnDrag: false,
		icon: image,
		shape: shape,
		position: latlng, 
		map: map, 
		title:"RiserMedia"
	});
	
	google.maps.event.addListener(marker, 'click', function() {
	  //infowindow.open(map,marker);
		window.open('http://maps.google.com/?q=Riser%20Media%2C%20West%2050%20North%2C%20American%20Fork', '_blank');
	});
}

//the shake function for bobble-head animation
jQuery.fn.shake = function(intShakes, intDistance, intDuration, easing){
	var easing = (jQuery.easing.def && easing) ? easing : 'swing';
	
	return this.each(function(){
		var origLeft = parseInt($(this).css('marginLeft'), 10);
		var origTop = parseInt($(this).css('marginTop'), 10);
		
		for(var x = 1; x <= intShakes; x++){
			$(this)
				.animate({ 'marginLeft': origLeft - (intDistance * -1) + 'px'}, (intDuration / intShakes) / 4, easing)
				.animate({ 'marginTop': origTop - (intDistance * -1) + 'px'}, (intDuration / intShakes) / 4, easing)
				.animate({ 'marginLeft': origLeft + intDistance + 'px' }, (intDuration / intShakes) / 2, easing)
				.animate({ 'marginTop': origTop + intDistance + 'px' }, (intDuration / intShakes) / 2, easing)
				.animate({ 'marginLeft': origLeft + 'px' }, (intDuration / intShakes) / 4, easing)
				.animate({ 'marginTop': origTop + 'px' }, (intDuration / intShakes) / 4, easing)
				.animate({ 'marginLeft': origLeft + (intDistance * -1) + 'px'}, (intDuration / intShakes) / 4, easing)
				.animate({ 'marginTop': origTop + (intDistance * -1) + 'px'}, (intDuration / intShakes) / 4, easing)
				.animate({ 'marginLeft': origLeft + 'px' }, (intDuration / intShakes) / 2, easing)
				.animate({ 'marginTop': origTop + 'px' }, (intDuration / intShakes) / 2, easing)
				.animate({ 'marginLeft': origLeft + 'px' }, (intDuration / intShakes) / 4, easing)
				.animate({ 'marginTop': origTop + 'px' }, (intDuration / intShakes) / 4, easing);

		}
	});
};

$(document).ready(function(){
	loadGoogleMap();
	
	 $('#arw_next')
	.mouseenter(function(){
		$(this)
		.stop()
		.animate({right: 0}, {duration:100, easing: 'easeInOutSine'});
	})
	.mouseleave(function(){
		$(this)
		.stop()
		.animate({right: -4}, {duration:100, easing: 'easeInOutSine'});		
	});
    
    $('#arw_prev')
	.mouseenter(function(){
		$(this)
		.stop()
		.animate({left: 0}, {duration:100, easing: 'easeInOutSine'});
	})
	.mouseleave(function(){
		$(this)
		.stop()
		.animate({left: -4}, {duration:100, easing: 'easeInOutSine'});		
	});
	    
	//loadContactGoogleMap();
	//hide some google map controls
	$('#map_canvas > div > div').css('display', 'none');
	$('#map_canvas > div > div:first-child').css('display', 'block');
	
	//  Initialize the header blockfader
	$('.header-phrase').nivoSlider({
		effect:'boxRandom', // Specify sets like: 'fold,fade,sliceDown'
		boxCols: 14, // For box animations
		boxRows: 3, // For box animations
		animSpeed:400, // Slide transition speed
		pauseTime:1000, // How long each slide will show
		directionNav:true, // Next & Prev navigation
		directionNavHide:false, // Only show on hover
		controlNav:false, // 1,2,3... navigation
		keyboardNav:false, // Use left & right arrows
		manualAdvance:true, // Force manual transitions
		captionOpacity:0.8, // Universal caption opacity
		nextText: '' // Next directionNav text
	});
	
	//  Initialize the footer blockfader
	$('.footer-phrase').nivoSlider({
		effect:'boxRandom', // Specify sets like: 'fold,fade,sliceDown'
		boxCols: 10, // For box animations
		boxRows: 5, // For box animations
		animSpeed:400, // Slide transition speed
		pauseTime:1000, // How long each slide will show
		directionNav:true, // Next & Prev navigation
		directionNavHide:false, // Only show on hover
		controlNav:false, // 1,2,3... navigation
		keyboardNav:false, // Use left & right arrows
		manualAdvance:true, // Force manual transitions
		captionOpacity:0.8, // Universal caption opacity
		nextText: '' // Next directionNav text
	});
	
		
	//display the slideout only when window is scrolled
	$(window).bind('scroll', function(){
			
			//$('#rfp-slideout').css('top', '200px');
						
			if ($(this).scrollTop() > 10) {
				if($("#rfp-slideout").hasClass('hidden')) {			
												
					setTimeout(function(){
						$("#rfp-slideout")
															.animate({top: 200}, {queue: false, duration: 250, easing: 'linear'})
															.show()
															.removeClass('hidden');
					}, 250);
															
																		
				}
			} else {
				$("#rfp-slideout").hide('fast');
					setTimeout( function(){
							$("#rfp-slideout").addClass('hidden').css('top', '0px');
						}, 200);
						
					}			
						
			});
			
			// bind click events on the slideout div on the right hand side
			$('.slideout-arrows').live('click', function(){
				if($('#rfp-slideout').hasClass('closed')){
					$('#rfp-slideout').removeClass('closed')
														.animate({width: '182'}, 250);
													
				} else {
					$('#rfp-slideout').addClass('closed')
														.animate({width: '16'}, 250);
													
				}		
				
			});
	//hide the RFP slideout on mouse leave
	$('#rfp-slideout').mouseleave(function() {
		if($('#rfp-slideout').width() == 182)	{
			$('#rfp-slideout').animate({width: '16'}, 250)
												.addClass('closed');
		}
	});
	
	//custom bobble head animation
	$(function() {
			$(".bobble-head-doll").hover(
				function() {
						//call the animation on hover
						//the funcion parameters are (in this order): number of repeats, offset, time of animation, easing effect
						$('.doll-head').shake(20, 1, 1000, 'swing');
				}					
			);
			
			$(".bobble-head-doll").mouseleave(
				//stop the animation on mouse leave
				function() {
					$('.doll-head').stop(true, true)
						.css('margin-top', '0px')
						.css('margin-left', '0px');
					
			});
	});
		
});
