(function($){
	//Resize image on ready or resize
	$.fn.supersize = function() {	
		//Invoke the resizenow() function on document ready
		$(document).ready(function() {
			$('#supersize').resizenow(); 
		});
		//Invoke the resizenow() function on browser resize
		$(window).bind("resize", function() {
    		$('#supersize').resizenow(); 
		});
	};
	//Adjust image size
	$.fn.resizenow = function() {
		//Define starting width and height values for the original image
		var startwidth = 1024;  
		var startheight = 1140;
		//Define image ratio
		var ratio = startheight/startwidth;
		//Gather browser dimensions
		var browserwidth = $(window).width();
		var browserheight = $(window).height();
		//Resize image to proper ratio
		if ((browserheight/browserwidth) > ratio) {
		    $(this).height(browserheight);
		    $(this).width(browserheight / ratio);
		    $(this).children().height(browserheight);
		    $(this).children().width(browserheight / ratio);
		} else {
		    $(this).width(browserwidth);
		    $(this).height(browserwidth * ratio);
		    $(this).children().width(browserwidth);
		    $(this).children().height(browserwidth * ratio);
		}
		//Make sure the image stays center in the window
		$(this).children().css('left', (browserwidth - $(this).width())/2);
		$(this).children().css('top', (browserheight - $(this).height())/2);
	};
})(jQuery);

$(document).ready(function() {
	$("div#supersize").supersize();
});

// navigation stuff

var over = false,timeout = false;

$(document).ready(function() {
	// $('#mainNav > li:has(ul)')
	$('#mainNav > li')
		.mouseover(function() {
			if (timeout) {
				clearTimeout(timeout);
				timeout = false;
			}
			
			over = true;
			
			var li = $(this),
				ul = li.find('> ul');
			
			if (!ul.is(':visible')) {
				li.siblings(':has(ul)').each(function() {
					// $(this).find('> ul').css('display','none');
					$(this).find('> ul').fadeOut(200);
				});
				// li.find('> ul').css('display','block');
				li.find('> ul').fadeIn(200);
			}
		})
		.mouseout(function() {
			over = false;
			timeout = setTimeout('restoreMenu()',500);
		})
		.find('> ul:not(.active)').css('display','none')
		;
	
	$('#mainNav > li > ul')
		.mouseover(function() {
			if (timeout) {
				clearTimeout(timeout);
				timeout = false;
			}

			over = true;
		})
		.mouseout(function() {
			over = false;
			timeout = setTimeout('restoreMenu()',500);
		});
});

function restoreMenu() {
	timeout = false;
	
	if (!over) {
		var ul = $('#mainNav > li > ul:visible');
		if (!ul.hasClass('active')) {
			// ul.css('display','none');
			ul.fadeOut(100);
			// $('#mainNav > li > ul.active').css('display','');
			$('#mainNav > li > ul.active').fadeIn(200);
		}
	}
}

// accordeon

var acc = function() {
	var accSel = 'ul#accordeon',blocked = 0;
	
	return {
		init: function() {
			$(accSel + ' > li > div.tabContent').css('display','none');
			$(accSel + ' > li > h3 > a').click(this.onHeaderClick);
		},
		
		onHeaderClick: function() {
			var 
				li = $(this).parent().parent(),
				active = li.siblings('.active');
			
			if (blocked) {
				return false;
			};
			
			if (!li.is('.active')) {
				blocked++;
				li.find('> div.tabContent').slideDown(400,function() {
					li.addClass('active');
					blocked--;
				});
			} else {
				active = li;
			}
			
			if (active.length) {
				blocked++;
				active.find('> div.tabContent').slideUp(400,function() {
					active.removeClass('active');
					blocked--;
				});
			}
			
			return false;
		}
	};
}();

$(document).ready(jQuery.proxy(acc,'init'));

// image galleries

$(document).ready(function() {
		
	$("a[rel=imgGallery1]").fancybox({
		'titleShow'			: false,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? '&nbsp;' + title : '') + '</span>';
		}
	});
	
	$("a[rel=imgGallery2]").fancybox({
		'titleShow'			: false,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? '&nbsp;' + title : '') + '</span>';
		}
	});
	
	$("a[rel=imgGallery3]").fancybox({
		'titleShow'			: false,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? '&nbsp;' + title : '') + '</span>';
		}
	});

});

// link decryption

var browserName=navigator.appName;var browserVer=parseInt(navigator.appVersion);var version="";var msie4=(browserName=="Microsoft Internet Explorer"&&browserVer>=4);if((browserName=="Netscape"&&browserVer>=3)||msie4||browserName=="Konqueror"||browserName=="Opera"){version="n3";}else{version="n2";}
function decryptCharcode(n,start,end,offset){n=n+offset;if(offset>0&&n>end){n=start+(n-end-1);}else if(offset<0&&n<start){n=end-(start-n-1);}
return String.fromCharCode(n);}
function decryptString(enc,offset){var dec="";var len=enc.length;for(var i=0;i<len;i++){var n=enc.charCodeAt(i);if(n>=0x2B&&n<=0x3A){dec+=decryptCharcode(n,0x2B,0x3A,offset);}else if(n>=0x40&&n<=0x5A){dec+=decryptCharcode(n,0x40,0x5A,offset);}else if(n>=0x61&&n<=0x7A){dec+=decryptCharcode(n,0x61,0x7A,offset);}else{dec+=enc.charAt(i);}}
return dec;}
function linkTo_UnCryptMailto(s){location.href=decryptString(s,-1);}


