$(document).ready(function(){

function changeWidth(first) {
    var width = $(window).width();

    if (width <= 1110) {
	noLinks = $('.images a.bigger').size() == 0;
	$('.images img').each(
	    function() {
		$(this).css('width', '240px')
		if ( noLinks == true) {
		    var src=$(this).attr('src');
		    $(this).wrap('<a class="bigger" href="' + src + '" />');
		}
	    }
	);
	$('.images').css('width', '240px');
    } else if (width <= 1600) {
	noLinks = $('.images a.bigger').size() == 0;

	$('.images img').each(
	    function() {
		$(this).css('width', '480px');
		if (noLinks == true) {
		    var src=$(this).attr('src');
		    $(this).wrap('<a class="bigger" href="' + src + '" />');
		}
	    }
	);
	$('.images').css('width', '480px');
    } else if (first == false) {
	$('.images img').css('width', '960px');
	$('.images a.bigger').each(
	    function() {
		$(this).replaceWith( $(this).contents() );
	    }
	);
	$('.images').css('width', '960px');
    }
}

changeWidth(true);
$(window).bind("resize", function(){
    changeWidth(false);
});


// Menu
$(".mainmenu").hover(
    function() {
	// hide items in active menu
	$("ul.menu li.selected").siblings("li").animate({
	    opacity:"1"
	}, {
	    queue:false,
	    duration:200
	} );

	// hide inactive menus
//	$("ul.menu").each(function(){
//	    if ( $(this).children("li.selected").size() == 0 && !$("li.item1").hasClass("active") ) $(this).animate({
//		    opacity:"1"
//		}, {
//		    queue:false,
//		    duration:200
//		} );
//	});
    },
    function() {
	$("ul.menu li.selected").siblings("li").animate({
	    opacity:"0"
	}, {
	    queue:false,
	    duration:200
	} );

//	$("ul.menu").each(function(){
//	    if ( $(this).children("li.selected").size() == 0 ) $(this).animate({
//		    opacity:"0"
//		}, {
//		    queue:false,
//		    duration:200
//		} );
//	});
    }
    );

});

//addLoadEvent(function() {
//	imgSizer.collate();
//});
//
//function addLoadEvent(func) {
//	var oldonload = window.onload;
//	if (typeof window.onload != 'function') {
//		window.onload = func;
//	} else {
//		window.onload = function() {
//			if (oldonload) {
//				oldonload();
//			}
//			func();
//		}
//	}
//}
