var activatePrettyPhoto = false;
var resizeThumbs = false;
var resizeNewsThumbs = false;
var selectedMenu = "";
	
$(window).load(function () {
	
	//imgSizer.collate();
	
	//Resise all the galleries thumbs
	if (resizeThumbs){
		$(".galleries li a img").width(function(){ if ($(this).width()<$(this).height()) return 100; else return $(this).width(); });
		$(".galleries li a img").height(function(){ if ($(this).width()>$(this).height()) return 100; else return $(this).height(); });
		$(".galleries li a").css("opacity","0.8");
		$(".galleries li a").hover(
			function(){ 
				$(this).animate({opacity:'1.0'},80);		
			},
			function(){
				$(this).animate({opacity:'0.8'},80);		
			}
		);
	}
	
	//Resize latest news thumbs
	/*if (resizeNewsThumbs){
		$(".fotoNewsSmall img").width(function(){
					var newWidth=80;
					if ($(this).width()<$(this).height())
						{ newWidth=80; $(this).height(80*$(this).height()/$(this).width()); }
					else
						newWidth=$(this).width();
						
					return newWidth;
					});
		
		$(".fotoNewsSmall img").height(function(){
					var newHeight=80;
					if ($(this).width()>$(this).height())
						{ newHeight=80; $(this).width(80*$(this).width()/$(this).height()); }
					else
						newHeight=$(this).height();
					return newHeight;
					});
		
		$(".fotoNewsSmall img").css("left",function(){ return -($(this).width()-80)/2; });
		$(".fotoNewsSmall img").css("top",function(){ return -($(this).height()-80)/2; });
	}*/
	
});


$(function(){
	
	//Activate PrettyPhoto
	if (activatePrettyPhoto)
		$("a[rel^='prettyPhoto']").prettyPhoto({theme: 'light_rounded'});
	
	
	//MENU
	$(".mainmenu ul li").hover(
		
		function(){ 
			//slide down button
			if (!($(this).attr("class").indexOf('current') != -1) && (!($(this).parent().attr("class")=='children') && !($(this).parent().attr("class")=='sub-menu')) )
			{
				$(this).children("a").animate({marginTop: '10px'},80,function() {
																	$(this).find("span.leftcorner").attr('class','leftcornerH'); 
																	$(this).find("span.middle").attr('class','middleH'); 
																	$(this).find("span.rightcorner").attr('class','rightcornerH'); 
																}
				);//animate
			}
			//open submenu if any
			$(this).children("ul").css("display","block");
			$(this).children("ul").css("opacity","0.0");
			$(this).children("ul").animate({
				opacity: 1.0,
    			top: '+=15'
			},200); 			
		},
		function(){
			//slide up button
			if (!($(this).attr("class").indexOf('current') != -1) && (!($(this).parent().attr("class")=='children') && !($(this).parent().attr("class")=='sub-menu')) )
			{
				$(this).find("a span.leftcornerH").attr('class','leftcorner');
				$(this).find("a span.middleH").attr('class','middle');
				$(this).find("a span.rightcornerH").attr('class','rightcorner');
				$(this).children("a").animate({marginTop: '0px'},50,function() {
																	$(this).find("span.leftcornerH").attr('class','leftcorner'); 
																	$(this).find("span.middleH").attr('class','middle'); 
																	$(this).find("span.rightcornerH").attr('class','rightcorner'); 
																});
			}
			//close submenu if any
			$(this).children("ul").animate({
				opacity: 0.0,
    			top: '-=15'
			},100,function() { $(this).css("display","none");} ); 			
		}
	);	
	
	
	//Set selected menu
	$("#"+selectedMenu).attr('class','current');
	
	//HOME IMAGE
	//var photoHomeWidth = $("#photoHomeContainer").width()-20;
	//$("#photoHome img").height("200px");
	
});





var imgSizer = {
	Config : {
		imgCache : []
		,spacer : "/path/to/your/spacer.gif"
	}

	,collate : function(aScope) {
		var isOldIE = (document.all && !window.opera && !window.XDomainRequest) ? 1 : 0;
		if (isOldIE && document.getElementsByTagName) {
			var c = imgSizer;
			var imgCache = c.Config.imgCache;

			var images = (aScope && aScope.length) ? aScope : document.getElementsByTagName("img");
			for (var i = 0; i < images.length; i++) {
				images[i].origWidth = images[i].offsetWidth;
				images[i].origHeight = images[i].offsetHeight;

				imgCache.push(images[i]);
				c.ieAlpha(images[i]);
				images[i].style.width = "100%";
			}

			if (imgCache.length) {
				c.resize(function() {
					for (var i = 0; i < imgCache.length; i++) {
						var ratio = (imgCache[i].offsetWidth / imgCache[i].origWidth);
						imgCache[i].style.height = (imgCache[i].origHeight * ratio) + "px";
					}
				});
			}
		}
	}

	,ieAlpha : function(img) {
		var c = imgSizer;
		if (img.oldSrc) {
			img.src = img.oldSrc;
		}
		var src = img.src;
		img.style.width = img.offsetWidth + "px";
		img.style.height = img.offsetHeight + "px";
		img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')"
		img.oldSrc = src;
		img.src = c.Config.spacer;
	}

	// Ghettomodified version of Simon Willison's addLoadEvent() -- http://simonwillison.net/2004/May/26/addLoadEvent/
	,resize : function(func) {
		var oldonresize = window.onresize;
		if (typeof window.onresize != 'function') {
			window.onresize = func;
		} else {
			window.onresize = function() {
				if (oldonresize) {
					oldonresize();
				}
				func();
			}
		}
	}
}
