$(document).ready(function() {
	/*
	 * Apply text-shadow
	 */
	if($("#book-btn").length){
		applyShadow("book-btn", "#df9600", 2, 35);
	}
	if($("#book-mindretext").length){
		applyShadow("book-mindretext", "#df9600", 18, 29);
	}
	if($("#book-mindretext-bla").length){
		applyShadow("book-mindretext-bla", "#333", 18, 29);
	}	
	if($("#book-mindretext-galleri").length){
		applyShadow("book-mindretext-galleri", "#df9600", 15, 29);
	}	
	if($("#send-btn").length){
		applyShadow("send-btn", "#df9600", 15, 22);
	}
	if($("#dot1").length){
		applyShadow("dot1", "#df9600", -3, -1);
	}
	if($("#dot2").length){
		applyShadow("dot2", "#df9600", -3, -1);
	}
	if($("#dot3").length){
		applyShadow("dot3", "#df9600", -3, -1);
	}
	if($("#dot4").length){
		applyShadow("dot4", "#df9600", -3, -1);
	}
	
	
	
	/*
	 * Tooltip
	 */	
	$("#header .tip-trigger").tooltip({
	   offset: [50, 0],
	   relative: true,
	   effect: 'slide'
	}).click(function() { return false; });
		
	
	
	/*
	 * Image gallery
	 */
	if($("#image-gallery").length){		
		// Show first image
		var currentImg = $(".gallery-images img:first-child").attr("id");
		$(".gallery-images #"+currentImg).fadeTo(100, 1);
		$(".gallery-thumbnails #"+currentImg+"-thumb img").fadeTo(100, 0.6);
		$(".gallery-thumbnails #"+currentImg+"-thumb").children(".icon").hide();
		$(".gallery-thumbnails #"+currentImg+"-thumb").addClass("selected");
		
		// Hover functions
		$(".gallery-thumbnails a").hover(function(){
			if(!$(this).hasClass("selected")){
				$(this).children("img").fadeTo(100, 0.6);
			}
		}, function (){
			if(!$(this).hasClass("selected")){
				$(this).children("img").fadeTo(100, 1);
			}
		});
		
		
		
		$(".gallery-thumbnails a").click(function(){
			if(!$(this).hasClass("selected")){
				id = $(this).attr("id");
				id = id.substring(0, id.length-6);	
				$(".gallery-thumbnails #"+currentImg+"-thumb").removeClass("selected");
				$(".gallery-thumbnails #"+currentImg+"-thumb").children("img").fadeTo(100, 1);
				$(".gallery-thumbnails #"+currentImg+"-thumb").children(".icon").show();
					
				$(".gallery-images #"+currentImg).fadeTo(100, 0, function(){
					$(".gallery-images #"+currentImg).hide();
					currentImg = id;
					$(".gallery-thumbnails #"+currentImg+"-thumb").addClass("selected");
					$(".gallery-images #"+currentImg).fadeTo(100, 1);
					$(".gallery-thumbnails #"+currentImg+"-thumb").children(".icon").hide();
				});
			}
		});
	}
});



/*
 * applyShadow()
 * - function that applys textshadow.
 */
function applyShadow(targetElement, shadowColor, shadowTop, shadowLeft) {
  if (typeof(targetElement) != 'object') {
    targetElement = document.getElementById(targetElement);
  }
  var value = targetElement.firstChild.nodeValue;
  targetElement.style.position = 'relative';
  targetElement.style.zIndex = 1;
    
  var newEl = document.createElement('span');
  newEl.appendChild(document.createTextNode(value));
  newEl.className = 'shadowed';
  newEl.style.color = shadowColor;
  newEl.style.position = 'absolute';
  newEl.style.left = shadowLeft + 'px';
  newEl.style.top = shadowTop + 'px';
  newEl.style.zIndex = -1;
  
  targetElement.appendChild(newEl);
}
