
// remap jQuery to $
(function($){

// FOOTER PAGE SCROLL
	  function filterPath(string) {
	  return string
	 .replace(/^\//,'')
	 .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
	 .replace(/\/$/,'');
	  }
	  var locationPath = filterPath(location.pathname);
	  var scrollElem = scrollableElement('html', 'body');
	  $('a[href*=#]').each(function() {
	 var thisPath = filterPath(this.pathname) || locationPath;
	 if (  locationPath == thisPath
	 && (location.hostname == this.hostname || !this.hostname)
	 && this.hash.replace(/#/,'') ) {
	   var $target = $(this.hash), target = this.hash;
	   if (target) {
	  var targetOffset = $target.offset().top;
	  $(this).click(function(event) {
	    event.preventDefault();
	    $(scrollElem).animate({scrollTop: targetOffset}, 400, function() {
	   location.hash = target;
	    });
	  });
	   }
	 }
	  });
	  function scrollableElement(els) {
	 for (var i = 0, argLength = arguments.length; i <argLength; i++) {
	   var el = arguments[i],
	    $scrollElement = $(el);
	   if ($scrollElement.scrollTop()> 0) {
	  return el;
	   } else {
	  $scrollElement.scrollTop(1);
	  var isScrollable = $scrollElement.scrollTop()> 0;
	  $scrollElement.scrollTop(0);
	  if (isScrollable) {
	    return el;
	  }
	   }
	 }
	 return [];
	 }

 
$("#slider").easySlider({
numericId: "slider_control",
nextId: "slider_next",
prevId: "slider_prev",
auto:			true,
pause:			7000,
speed:			400,
});




 
 
 // TABBED CONTENT

	var TabbedContent = {
		init: function() {	
			$(".tab_item").click(function() {
			
				var background = $(this).parent().find(".moving_bg");
				
				$(background).stop().animate({
					left: $(this).position()['left']
				}, {
					duration: 300
				});
				
				TabbedContent.slideContent($(this));
				
			});
		},
		
		slideContent: function(obj) {
			
			var margin = $(obj).parent().parent().find(".slide_content").width();
			margin = margin * ($(obj).prevAll().size() - 1);
			margin = margin * -1;
			
			$(obj).parent().parent().find(".tabslider").stop().animate({
				marginLeft: margin + "px"
			}, {
				duration: 300
			});
		}
	}

	TabbedContent.init();
	Shadowbox.init();
	
	$("#contactform").validate({
			submitHandler: function(form) {
				$.post('yritys/index.php#formwrapper', $("#contactform").serialize(), function(data) {
				$('#formwrapper').html("<div id='success_js'><h3>Kiitos yhteydenotostasi!</h3><p>Vastaamme viestiisi mahdollisimman pian.</p></div>");
				});	
			}
	});
	
	$("#catalogueform").validate({
			submitHandler: function(form) {
				$.post('kuvastot/index.php#formwrapper', $("#catalogueform").serialize(), function(data) {
				$('#formwrapper').html("<div id='success_js'><h3>Kiitos tilauksesta!</h3><p>Lähetämme kuvastot postitse mahdollisimman pian.</p></div>");
				});	
			}
	});
	
	
	jQuery("a[href^='http:']").not("[href*='cultivor.com']").attr('target','_blank'); 

})(this.jQuery);







