	function activatePlaceholders() 
	{
		var detect = navigator.userAgent.toLowerCase();
		if (detect.indexOf('safari') > 0) return false;
		$('input').each(function(i)
		{
			if ($(this).attr("type") == "text")
			{
				if ($(this).attr("placeholder"))
				{
					$(this).attr("value", $(this).attr("placeholder"));
					
					$(this).focus(function()
					{
						if ($(this).attr("placeholder") == $(this).val())
						{
							$(this).attr("value", "");
						}
					});
					
					$(this).blur(function()
					{
						if ($(this).val().length == 0)
						{
							$(this).attr("value", $(this).attr("placeholder"));
						}
					});
				}
			}
		});
	}
	
	/*function showWork()
	{
		clearTimeout(workTimeout);
		$('#subnav_work').show();
	}
	
	function initHideWork()
	{
		if (mainSection != "work")
		{
			clearTimeout(workTimeout);
			workTimeout = setTimeout("hideWork()", 250);
		}
	}
	
	function hideWork()
	{
		$('#subnav_work').hide();
	}*/
	
	var workTimeout;
	var mouseDownX;
	var mouseDownY;
	var lastX;
	var carouselX;
	var carouselMinX;
	var carouselM;
	var hasMoved;
	var carouselInterval;
	var carouselCount;
	var carouselTweenPositions;
	
	function initCarousel()
	{
		// Carousel
		
		if ($("#carouselinner").length == 0) return;
		
		carouselMinX = 960 - $('#carouselinner').width() + 10;
		
		if (isIE)
		{
			disableSelection(document.body);
		}
		
		// Keyboard support
		$(document).keyup(function(evt)
		{
			switch (evt.keyCode)
			{
				case 37:
					carouselScrollTo(getCurrentItem() - 1);
					break;
				case 39:
					carouselScrollTo(getCurrentItem() + 1);
					break;
			}
		});
		
		$('#carouselinner').mouseover(function(e)
		{
			
		}).mouseout(function(e)
		{
			
		}).mousedown(function(e)
		{
			// clear out the interval if it's still going
			clearInterval(carouselInterval);
			
			var ex = e.pageX;
			var ey = e.pageY;
			mouseDownX = ex;
			mouseDownY = ey;
			lastX = ex;
			carouselX = $(this).position().left;
			hasMoved = false;
			
			$(document).bind('mousemove', trackMouse);
			$(document).bind('mouseup', handleDragUp);
			
		});
		
		// Touch support
		
		$('#carouselinner').bind('touchstart', function(e)
		{
			e.preventDefault();
			
			// clear out the interval if it's still going
			clearInterval(carouselInterval);

			var orig = e.originalEvent;  
			var ex = orig.changedTouches[0].pageX;  
			var ey = orig.changedTouches[0].pageY; 
			
			mouseDownX = ex;
			mouseDownY = ey;
			lastX = ex;
			carouselX = $(this).position().left;
			hasMoved = false;
			
			$(document).bind('touchmove', trackTouch);
			$(document).bind('touchend', handleTouchEnd);
		});
		
		$('#carouselinner ul li').mouseover(function()
		{
			$(this).find('p').each(function()
			{
				$(this).addClass('over');
			});
			
			$(this).find('.background').stop().animate({ opacity: 0.2 }, 500);
		}).mouseout(function()
		{
			$(this).find('p').each(function()
			{
				$(this).removeClass('over');
			});	
			
			$(this).find('.background').stop().animate({ opacity: 0.0 }, 500);
		}).mouseup(function(e)
		{
			if (!hasMoved)
			{
				location.href = $(this).attr('href');
			}
		});
		
		$('#carouselinner ul li').bind('touchend', function (e)
		{
			if (!hasMoved)
			{
				location.href = $(this).attr('href');
			}
		});
		
		carouselCount = $('#carouseldotsinner a').length;
				
		$('#carouseldotsinner a').each(function(index)
		{
			//$(this).attr('href', 'index');
			$(this).click(function(e)
			{
				e.preventDefault();
				carouselScrollTo(index);
			});
		});
		
		$('#carouselarrowleft').click(function(e)
		{
			e.preventDefault();
			carouselScrollTo(getCurrentItem() - 1);
		});
		
		$('#carouselarrowright').click(function(e)
		{
			e.preventDefault();
			carouselScrollTo(getCurrentItem() + 1);
		});
		
		hiliteCurrentItem();
	}
	
	function hiliteCurrentItem()
	{
		var idx = getCurrentItem();
		
		$('#carouseldotsinner a').each(function(index)
		{
			if (index == idx)
			{
				$(this).addClass("selected");
			}
			else
			{
				$(this).removeClass("selected");
			}
		});
	}
	
	function getCurrentItem()
	{
		px = $('#carouselinner').position().left;
		if (px > -50)
		{
			return 0;
		}
		else if (px < carouselMinX + 50)
		{
			return carouselCount - 1;
		}
		else
		{
			px *= -1;
			px -= 167;
			var ix = 1 + Math.round(px/410);
			return ix;
		}
	}
	
	function trackMouse(e)
	{
		var ex = e.pageX;
		var ey = e.pageY;
		
		carouselM = ex - lastX;
		lastX = ex;
		
		var dx = Math.abs(ex - mouseDownX);
		var dy = Math.abs(ey - mouseDownY);
		var e = 4;
		
		if (dx > 4 || dy > 4)
		{
			hasMoved = true;
		}
		
		var diff = ex - mouseDownX;
		
		var px = carouselX + diff;
		if (px > 100) px = 100;
		if (px < carouselMinX - 100) px = carouselMinX - 100;
		$('#carouselinner').css('left', px + 'px');
		hiliteCurrentItem();
	}
	
	function handleDragUp(e)
	{
		$(document).unbind('mousemove', trackMouse);
		$(document).unbind('mouseup', handleDragUp);
				
		carouselX = $('#carouselinner').position().left;
		
		if (carouselX > 0)
		{
			carouselM = -6;
		}
		if (carouselX < carouselMinX)
		{
			carouselM = 6;
		}
		
		carouselInterval = setInterval("carouselGlide()", 20);
		hiliteCurrentItem();
	}
	
	function trackTouch(e)
	{
		e.preventDefault();
		var orig = e.originalEvent;  
		var ex = orig.changedTouches[0].pageX;  
		var ey = orig.changedTouches[0].pageY; 
		
		carouselM = ex - lastX;
		lastX = ex;
		
		var dx = Math.abs(ex - mouseDownX);
		var dy = Math.abs(ey - mouseDownY);
		var e = 4;
		
		if (dx > 4 || dy > 4)
		{
			hasMoved = true;
		}
		
		var diff = ex - mouseDownX;
		
		var px = carouselX + diff;
		if (px > 100) px = 100;
		if (px < carouselMinX - 100) px = carouselMinX - 100;
		$('#carouselinner').css('left', px + 'px');
		hiliteCurrentItem();
	}
	
	function handleTouchEnd(e)
	{
		$(document).unbind('touchmove', trackTouch);
		$(document).unbind('touchend', handleTouchEnd);
		
		carouselX = $('#carouselinner').position().left;
		
		if (carouselX > 0)
		{
			carouselM = -6;
		}
		if (carouselX < carouselMinX)
		{
			carouselM = 6;
		}
		
		carouselInterval = setInterval("carouselGlide()", 20);
		hiliteCurrentItem();
	}	
	
	function carouselGlide()
	{
		var px = carouselX;
		px += Math.round(carouselM);
		carouselM *= 0.95;
		
		if (px > 100)
		{
			px = 100;
			carouselM = -6;
		}
		else if (px < carouselMinX - 100)
		{
			px = carouselMinX - 100 + 6;
			carouselM = 6;
		}
		else if (Math.abs(carouselM) < 1)
		{
			clearInterval(carouselInterval);
		}
		
		carouselX = px;
		$('#carouselinner').css('left', px + 'px');
		hiliteCurrentItem();
	}
	
	function carouselScrollTo(index)
	{
		if (index < 0 || index >= carouselCount) return;
		clearInterval(carouselInterval);
		
		var px = 0;
		
		if (index == carouselCount - 1)
		{
			px = carouselMinX;
		}
		else if (index != 0)
		{
			px = -167 - (index - 1) * 410;
		}
		
		carouselTweenPositions = new Array();
		
		var basex = $('#carouselinner').position().left;
		var diff = px - basex;
		var steps = 16;
		
		for (var i = 0; i < steps; i++)
		{
			var x = i/steps;
			var v = 3*x*x  - 2 * x * x * x;
			carouselTweenPositions.push(Math.round(basex + diff * v));
		}
		
		carouselTweenPositions.push(px);
		
		carouselInterval = setInterval("carouselTween()", 20);
		
	}
	
	function carouselTween()
	{
		$('#carouselinner').css('left', carouselTweenPositions[0] + 'px');
		carouselTweenPositions.splice(0, 1);
		
		if (carouselTweenPositions.length == 0)
		{
			clearInterval(carouselInterval);
		}
		
		hiliteCurrentItem();
	}
	
	/***********************************************
	* Disable Text Selection script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
	* This notice MUST stay intact for legal use
	* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
	
	***********************************************/
	
	function disableSelection(target){
	
	    if (typeof target.onselectstart!="undefined") //IE route
	        target.onselectstart=function(){return false}
	
	    else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
	        target.style.MozUserSelect="none"
	
	    else //All other route (ie: Opera)
	        target.onmousedown=function(){return false}
	
	    target.style.cursor = "default"
	}

	
	/* GOOGLE MAP */
	
	var map;
	var mapControlPath = "/wp-content/themes/rdcom/images/map/";
	var currentMapType = 0;
	
	function initializeMap()
	{
		if ($("#map_canvas").length > 0)
		{
			var latlng = new google.maps.LatLng(37.754264,-122.420848);
			var myOptions = {
				zoom: 12,
				center: latlng,
				mapTypeId: google.maps.MapTypeId.ROADMAP,
				mapTypeControl: false
			};
			map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
			var image = '/wp-content/themes/rdcom/images/map/receivermarker.png';
			var marker = new google.maps.Marker({
				position: latlng,
				map: map,
				icon: image
			});
  
			// To add the marker to the map, call setMap();
			marker.setMap(map);
			
			var contentString = '<div id="content">'+
				'<table cellpadding="0" cellspacing="0" border="0">' +
				'<tr><td><img src="/wp-content/themes/rdcom/images/map/balloonlabel.gif" width="60" height="27" border="0" style="margin-right: 10px;"></td>' +
				'<td><p style="margin: 0 0 4px 0; padding: 0;"><span class="balloontext">RECEIVER DESIGN</span><br>1167 Valencia Street<br>San Francisco, CA 94110<br>(415) 938-RCVR</p><p style="margin: 0; padding: 0;"><a href="http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=1167+Valencia+Street,+San+Francisco,+CA&aq=0&sll=37.754264,-122.420848&sspn=50.291089,96.855469&ie=UTF8&hq=&hnear=1167+Valencia+St,+San+Francisco,+California+94110&z=16" target="_blank">directions</a></p></td></tr></table>'
				'</div>';
			
			var infowindow = new google.maps.InfoWindow({
				content: contentString
			});

			google.maps.event.addListener(marker, 'click', function() 
			{
				infowindow.open(map,marker);
				Cufon.replace('.balloontext', { fontFamily: 'DIN', fontWeight: 500 });
			});
			
			$("#map_control_street").bind("click", function()
			{
				setMapType(0);
			}).hover(
				function() {
					if (currentMapType != 0)
					{
						$(this).attr("src", mapControlPath + "btn_street_1.png");
					}
				},
				function() {
					if (currentMapType != 0)
					{
						$(this).attr("src", mapControlPath + "btn_street_0.png");
					}
				}
			);
			
			$("#map_control_satellite").bind("click", function()
			{
				setMapType(1);
			}).hover(
				function() {
					if (currentMapType != 1)
					{
						$(this).attr("src", mapControlPath + "btn_satellite_1.png");
					}
				},
				function() {
					if (currentMapType != 1)
					{
						$(this).attr("src", mapControlPath + "btn_satellite_0.png");
					}
				}
			);
						
			$("#map_control_terrain").bind("click", function()
			{
				setMapType(2);
			}).hover(
				function() {
					if (currentMapType != 2)
					{
						$(this).attr("src", mapControlPath + "btn_terrain_1.png");
					}
				},
				function() {
					if (currentMapType != 2)
					{
						$(this).attr("src", mapControlPath + "btn_terrain_0.png");
					}
				}
			);
		}
	}
	
	function setMapType(type)
	{
		currentMapType = type;
		
		switch(type)
		{
			case 0:
				map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
				$("#map_control_street").attr("src", mapControlPath + "btn_street_1.png");
				$("#map_control_satellite").attr("src", mapControlPath + "btn_satellite_0.png");
				$("#map_control_terrain").attr("src", mapControlPath + "btn_terrain_0.png");
				break;
			case 1:
				map.setMapTypeId(google.maps.MapTypeId.SATELLITE);
				$("#map_control_street").attr("src", mapControlPath + "btn_street_0.png");
				$("#map_control_satellite").attr("src", mapControlPath + "btn_satellite_1.png");
				$("#map_control_terrain").attr("src", mapControlPath + "btn_terrain_0.png");
				break;
			case 2:
				map.setMapTypeId(google.maps.MapTypeId.TERRAIN);
				$("#map_control_street").attr("src", mapControlPath + "btn_street_0.png");
				$("#map_control_satellite").attr("src", mapControlPath + "btn_satellite_0.png");
				$("#map_control_terrain").attr("src", mapControlPath + "btn_terrain_1.png");
				break;
		}
	}
	
	$(document).ready(function()
	{
		initializeMap();
		
		/*if (mainSection == "work")
		{
			$('#subnav_work').show();
		}
		
		$('#navwork a').mouseover(function()
		{
			showWork();
		}).mouseout(function()
		{
			initHideWork();
		});
		
		$('#subnav_work a').each(function()
		{
			$(this).mouseover(function()
			{
				showWork();
			}).mouseout(function()
			{
				initHideWork();
			});
		});*/
		
		$('.promomodule a, .projectlist a').mouseover(function()
		{
			$(this).find('img').stop().animate({ opacity: 0.8 }, 200);
		}).mouseout(function()
		{
			$(this).find('img').stop().animate({ opacity: 1.0 }, 200);
		});
		
		$('#searchbutton a').bind('click', function()
		{
			$('#search-form').submit();
		});
		
		initCarousel();
		activatePlaceholders();
		
		Cufon.replace('h1, h2, h3, h5', { hover: true, fontFamily: 'DIN', fontWeight: 500 });
		//Cufon.replace('.contentheader p, .contentheaderspaced p', { fontFamily: 'DIN', fontWeight: 200 });
		
		$(".tweet").tweet({
	            username: "receiverdesign",
	            join_text: "auto",
	            count: 6,
	            auto_join_text_default: "",
	            auto_join_text_ed: "",
	            auto_join_text_ing: "",
	            auto_join_text_reply: "",
	            auto_join_text_url: "",
	            loading_text: "loading tweets..."
		});

	});
