// JavaScript Document

$(document).ready(function() {
	
	$(".tip7").fancybox({
	'showCloseButton'	: false,
	'titlePosition' 		: 'inside'
});
	
	$('div.slide a').fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'fade',
		'speedIn'		:	200, 
		'speedOut'		:	200,
		'autoScale'		:	false,
		'padding'		:	0
	});
	
	$('.rollover').hover(function() {
		if($(this).hasClass("on") == false) {
			var currentImg = $(this).attr('src');
			$(this).attr('src', $(this).attr('hover'));
			$(this).attr('hover', currentImg);
		}
    }, function() {
		if($(this).hasClass("on") == false) {
			var currentImg = $(this).attr('src');
			$(this).attr('src', $(this).attr('hover'));
			$(this).attr('hover', currentImg);
		}
  });
	
	$("div.slideshow div.slide img:first").addClass("first");
	$("div.slideshow div.slide img:last").addClass("last");
	
	$(".rollover:first").each(function( ) {
		$(this).addClass("on");
		var currentImg = $(this).attr('src');
		$(this).attr('src', $(this).attr('hover'));
		$(this).attr('hover', currentImg);
	});
	
	$(".rollover").click(function( ) {
		
		var asdf = $(this).attr("class").split(" ")[0];
		
		var slide = $("div.slideshow div.slide");
		var left = slide.offset( ).left - $("div.slideshow div.slide img." + asdf).offset( ).left - 2; // LEFT BORDER
		
		var lastImage = $("div.slideshow div.slide img:last");
		var contentWidth = ($("div.slideshow div.slide").offset( ).left * -1) + lastImage.offset( ).left + lastImage.width( );
		
		var leftLimit = contentWidth - $("div.slideshow").width( );
		
		if((left * -1) > leftLimit) {
			left = leftLimit * -1;
		}
		
		$("div.slideshow div.slide").animate({
			left: left
		}, 500);
		
		$("img.rollover").each(function( ) {
			if($(this).hasClass("on")) {
				$(this).removeClass("on");
				var currentImg = $(this).attr('src');
				$(this).attr('src', $(this).attr('hover'));
				$(this).attr('hover', currentImg);
			}
		});
		$(this).addClass("on");
		
	});
	
		
	var captionHeight = 0;
	$("ul.thumbnails li p.caption").each(function( ) {
		if($(this).height( ) > captionHeight) captionHeight = $(this).height( );
	});
	$("ul.thumbnails li p.caption").height(captionHeight);
	
	$('p').defuscate( );
	
});

startList = function() {
	if (document.all&&document.getElementById) {
		var navRoot = document.getElementById("contentNavigation");
		if(navRoot) {
			for (var i=0; i < navRoot.childNodes.length; i++) {
				node = navRoot.childNodes[i];
				if (node.nodeName=="LI") {
					node.onmouseover=function() {
						this.className+=" over";
					}
					node.onmouseout=function() {
						this.className=this.className.replace(" over", "");
					}
				}
			}
		}
	}
}
window.onload=startList;