$(document).ready(function() {
		$(".text_field").focus(function(srcc)
	  {
	      if ($(this).val() == $(this)[0].title)
	      {
	          $(this).removeClass("default_text_active");
	          $(this).val("");
	      }
	  });
	  $(".text_field").blur(function()
	  {
	      if ($(this).val() == "")
	      {
	          $(this).addClass("default_text_active");
	          $(this).val($(this)[0].title);
	      }
	  });
	$(".text_field").blur();
	
});
var Home = {
	initialize: function() {
		$('#featured').nivoSlider({
			effect:'fade',
			directionNav: false,
			animSpeed:500,
			pauseTime:4000,
			captionOpacity: 1
		});
		$("#products ul li a").hover(function() {
			$(this).stop().animate({ 'opacity': 1 });
		}, function() {
			$(this).stop().animate({ 'opacity': 0.5 });
		});
	}
};
var About = {
	initialize: function() {
		$(".tip").tipTip({ delay: 0, defaultPosition: 'top' });
	}
};
var Contact = {
	initialize: function() {
		$("li.call a.call_me").click(function() {
			$("li.call form").toggle("slide");
		});
		
		$("#contact_form").validate({
		    invalidHandler: function(form, validator) {
		      var errors = validator.numberOfInvalids();
		      if (errors) {
		        var message = errors == 1
		          ? 'You missed 1 field. It has been highlighted below.'
		          : 'You missed ' + errors + ' fields. They have been highlighted below.';
		        $("div.error p").text(message);
		      } else {
		        $("div.error").hide();
		      }
		    },
			errorPlacement: function(error, element) { } 
		 });
		
		$(".send").click(function() {
			// validate and process form
			// first hide any error messages
	    $('.call_error').hide();

		  var name = $("input#g_name").val();
			if (name == "" || name == "Your Name") {
	      $("input#g_name").focus();
				alert("Please enter a valid name.")
	      return false;
	    }
			var phone = $("input#g_phone").val();
			if (phone == "" || phone == "Your 11-Digit Phone #") {
	      $("input#g_phone").focus();
				alert("Please enter a valid phone number.")
	      return false;
	    }

			var dataString = 'g_name='+ name + '&g_phone=' + phone;

			$.ajax({
	      type: "POST",
	      url: "call_me.php",
	      data: dataString,
	      success: function() {
	        $("#call_form, .call_me").fadeOut(200);
					$("div.success").delay(200).fadeIn(200);
	      }
	     });
	    return false;
		});
		
		
	}
};
var Services = {
	initialize: function() {
		
		$("div#services_nav ul").tabs("div#services_container > div", { 
			history: true,
			effect: 'fade',
			fadeInSpeed: 300,
			selected: 0
		});
		
		/* $("div.work").hover(function() {
			$(this).addClass("work_hover");
		}, function() {
			$(this).removeClass("work_hover");
		}); */
		
	}
};
var Products = {
	initialize: function() {
		
		$("div#product_list ul").tabs("div#products_container > div", { 
			history: true,
			effect: 'fade',
			fadeInSpeed: 300,
			selected: 0
		});
		
		var api = $("div#product_list ul").data("tabs");
		
		api.onBeforeClick(function(index) {
			$("div#product_list ul li a.current").parent().removeClass("current");
			$(".arrow").remove();
		});
		
		api.onClick(function(index) {
			$("div#product_list ul li a.current").parent().addClass("current").append('<div class="arrow"></div>');
		});
		
		$("div#products_container > div").each(function() {
			
			var this_id = $(this).attr("id");
			
			if($("div#"+this_id+" div.screens").length != 0) { 
				$("div#"+this_id+" div.screens").cycle({ 
				    prev:   '#'+this_id+'_prev', 
				    next:   '#'+this_id+'_next', 
				    timeout: 0,
						speed: 500,
						before: function() { 
							if($(this).attr("class") != "") { 
							  $(this).parent().animate({ height: $(this).css("height") }, 300); 
							} else {
								$(this).parent().animate({ height: '476px' }, 300); 
							} 
						}
				});	
			}
			
		});
		
	}
};
var Portfolio = {
	initialize: function() {
		
		$("a.enlarge").fancybox({
			overlayColor: '#000',
			overlayOpacity: 0.8
		});
		
		$("ul.filters li a").click(function() {
			
			var type = $(this).attr("rel");
			
			$("#portfolio .item").each(function() {

				if(type == "all") {
				 	if($(this).is(':hidden')) {
						$(this).delay(300).fadeIn(300);
					}
				} else {
					if(!$(this).hasClass(type)) {
						$(this).fadeOut(300);
					} else {
						if($(this).is(':hidden')) {
							$(this).delay(300).fadeIn(300);
						}
					}
				}
			});
			
			$("ul.filters li a").removeClass("current");
			$(this).addClass("current");
			
		});
		/*
		$(".item img").lazyload({
		      placeholder : "../images/box.gif",
		      threshold : 50,
					effect : "fadeIn"
		});
		*/
		
		if (/webkit.*mobile/i.test(navigator.userAgent)
			&& "getBoundingClientRect" in document.documentElement) {
			(function ($) {
				$.fn.offsetOld = $.fn.offset;
				$.fn.offset = function () {
					var result = this.offsetOld();
					result.top -= window.scrollY;
					result.left -= window.scrollX;

					return result;
				};
			})(jQuery);
		}
		
	}
};
var Gallery = {
	initialize: function() {
		var totWidth=0;
		var positions = new Array();

		$('#slides .slide').each(function(i){

			positions[i]= totWidth;
			totWidth += $(this).width();
			//totWidth += 800;


			//if(!$(this).width())
			//{
			//	alert("Please, fill in width & height for all your images!");
			//	return false;
			//}

		});

		$('#slides').width(totWidth);

		$('#menu ul li a').click(function(e,keepScroll){

				/* On a thumbnail click */

				$('li.menuItem').removeClass('act').addClass('inact');
				$(this).parent().addClass('act');

				var pos = $(this).parent().prevAll('.menuItem').length;

				$('#slides').stop().fadeOut("fast").animate({marginLeft:-positions[pos]+'px'},0).fadeIn();
				/* Start the sliding animation */

				e.preventDefault();
				/* Prevent the default action of the link */
		});

		$('#menu ul li.menuItem:first').addClass('act').siblings().addClass('inact');
	}
}
