// JavaScript Document

$(document).ready(function(){
	
	// Activate lightbox for all <a href> tags, which have a `rel`-property named `lightbox`
	$('a[@rel*=lightbox]').lightBox();
		
	// Activate opacity on the menu
	$(".main_item").css({opacity: .90});
	$(".sub_item").css({opacity: .80});
	$(".subsub_item").css({opacity: .70});
	$(".subsubsub_item").css({opacity: .95});
	
	// Activate smooth scrolling
	anchor.init();
	
	//$.localScroll({easing:'easeInOutSine'});

	// Close all contact tabs
	$(".contact_holder li").find('.foldOut').css('display', 'none');
	// Change all - to +
	if(globalRootPath == ''){
		$(".contact_holder li.expander").css('backgroundImage', 'url(images/layout/icons/expand.jpg)');
	}else{
		$(".contact_holder li.expander").css('backgroundImage', 'url('+ globalRootPath +'/images/layout/icons/expand.jpg)');
	}
	
	// Click event to expand a contact tab
	$(".contact_holder li a").click(expand);
	
	// expand when an anchor is in the url
	var foldOutAnchor = window.location.hash.substring(1);	
	expand(foldOutAnchor);
	
	function expand(target) {
		
		var t = $(this);
				
		if(typeof target == 'string') {
			t = $("#"+foldOutAnchor);
		}
				
		var parentLi = t.parent();
				
		if(parentLi.hasClass('expander')){
			parentLi.find('.foldOut').toggleFade({ speedIn : 800, speedOut : 150 });
			return false;
		}
	
	}
	
	
	
	// Trigger flashbox for all a hrefs who have a relation with flashbox
	$("a[@rel*='flashbox']").click(function(){
												
		$(this).flashBox({width:$(this).attr("width"), height:$(this).attr("height"), loadPath:$(this).attr("href"), title:$(this).attr("title") });
		
		return false;
	});
	
	$("img.colourChange").mouseover(function(){
		
		var path = $(this).attr('src');
		var new_path = createNewPath('in', path);
		
		$(this).attr('src',new_path);
		
	});
	
	$("img.colourChange").mouseout(function(){
		
		var path = $(this).attr('src');
		var new_path = createNewPath('out', path);
				
		$(this).attr('src',new_path);
		
	});
	
	function createNewPath(command, path){
		
		// Get length of string
		var lengthString = path.length;
		var pathWithoutExtention = path.substring(0, (lengthString - 4));
		
		if(command == 'in'){
			var newPath = pathWithoutExtention + '_colour.jpg';
		}else{
			pathWithoutExtention = path.substring(0, (lengthString - 11));
			var newPath = pathWithoutExtention + '.jpg';
		}
		
		return newPath;
	
	}
		
	
});