/* 
 * Javascript
*/
(function($){
	
	$(document).ready(function(){
		
		$('input#email').textReplace({text:"your email address"});
		$('input#zip').textReplace({text:"your zip code"});
		
		if($.jcarousel) {
			$('#carousel').jcarousel({
				scroll:1,
				easing:'easeInOutCubic',
				auto:10,
				wrap:'circular'
			});
		}
		
		function monitorcarousel_initCallback(carousel) {
			$('.monitor-control a').bind('click', function() {
				carousel.scroll($.jcarousel.intval($(this).text()));
				return false;
			});
			
			carousel.clip.hover(function() {
				carousel.stopAuto();
			}, function() {
				carousel.startAuto();
			});
	    }
		if($.jcarousel) {
		$('#monitor-carousel').jcarousel({
			scroll:1,
			easing:'easeInOutCubic',
			auto:5,
			wrap:'both',
			initCallback: monitorcarousel_initCallback,
			itemVisibleInCallback: {
				onBeforeAnimation: function(carousel) {
					var index = carousel.first - 1;
					if($('.monitor-control a').hasClass('active')) {
						$('.monitor-control a').removeClass('active');
					}
					$('.monitor-control a').eq(index).addClass('active');
				}
			}
		});}
		
		$("#left .youtube_video").each(function(i) {
			var video = $(this).text().replace(/^[^v]+v.(.{11}).*/,"$1");
			$(this).text("");
			$(this).flash({
				swf: 'http://youtube.com/v/' + video,
				flashvars: {rel:0},
				width:290,
				height:190
			});
		});
		
	});
	
	$.fn.textReplace = function(options) {
	    var defaults = {
	    	text: "enter text"
	    };
	    var options = $.extend(defaults, options);
	    return this.each(function() {
	    	var obj = $(this);
	    	if(obj.val() == '') {
	    		obj.val(options.text);
	    	} else {
	    		options.text = obj.val();
	    	}
	    	obj.bind({
	    		focus: function() {
	    			if(obj.val() == options.text) { obj.val(""); }
	    		},
	    		focusout: function() {
	    			if(obj.val() == "") { obj.val(options.text); }
	    		}
	    	});
	    });
	};

})(jQuery);

