/* jQuery */

/* hover image */
function hoverImg(triggerClass,imageId) {
	jQuery("."+triggerClass).hover(
		function() {
		jQuery("#"+imageId).stop().fadeTo(100, 0);
		},
		function() {
		jQuery("#"+imageId).stop().fadeTo(350, 1);
	});
};

/* Smooth scroll */
jQuery(document).ready(function() {
  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');

  jQuery('a[href^=#]').each(function() {
	var thisPath = filterPath(this.pathname) || locationPath;
	if (  locationPath == thisPath
	&& (location.hostname == this.hostname || !this.hostname)
	&& this.hash.replace(/#/,'') ) {
	  var jQuerytarget = jQuery(this.hash), target = this.hash;
	  if (target) {
		var targetOffset = jQuerytarget.offset().top;
		jQuery(this).click(function(event) {
		  event.preventDefault();
		  jQuery(scrollElem).animate({scrollTop: targetOffset}, 400, function() {
			location.hash = target;
		  });
		});
	  }
	}
  });

  // use the first element that is "scrollable"
  function scrollableElement(els) {
	for (var i = 0, argLength = arguments.length; i <argLength; i++) {
	  var el = arguments[i],
		  jQueryscrollElement = jQuery(el);
  if (jQueryscrollElement.scrollTop()> 0) {
		return el;
  } else {
		jQueryscrollElement.scrollTop(1);
		var isScrollable = jQueryscrollElement.scrollTop()> 0;
		jQueryscrollElement.scrollTop(0);
	if (isScrollable) {
		  return el;
		}
	  }
	}
	return [];
  }

});

/* base */

/* warning message */
function hideElement(elementId){
	if (document.getElementById(elementId)) {
		var toHide = document.getElementById(elementId);
		toHide.style.visibility = "hidden";
	}
}
			
function removeElement(parentDiv, childDiv){
	if (document.getElementById(childDiv)) {     
		var child = document.getElementById(childDiv);
		var parent = document.getElementById(parentDiv);
		parent.removeChild(child);
	}
}
			
window.onload = setTimeout("hideElement('hideMe')",12000);
			
/* parallax background */
function calcParallax(tileheight, speedratio, scrollposition) {
  //    by Brett Taylor http://inner.geek.nz/
  //    originally published at http://inner.geek.nz/javascript/parallax/
  //    usable under terms of CC-BY 3.0 licence
  //    http://creativecommons.org/licenses/by/3.0/
  return ((tileheight) - (Math.floor(scrollposition / speedratio) % (tileheight+1)));
}

window.onload = function() {

  window.onscroll = function() {
	var posX = (document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : window.pageXOffset;
	var posY = (document.documentElement.scrollTop) ? document.documentElement.scrollTop : window.pageYOffset;
				
	var bg1 = document.body;
	var bg1parallax = calcParallax(942, 2, -posY)-942;
	bg1.style.backgroundPosition = "center " + bg1parallax + "px"; 

	var bg2 = document.getElementById('whole');
	var bg2parallax = calcParallax(942, 2, -posY)-942;
	bg2.style.backgroundPosition = "center " + bg2parallax + "px"; 
  }
}
