function addEventSimple(obj,evt,fn) {
	if (obj.addEventListener)
		obj.addEventListener(evt,fn,false);
	else if (obj.attachEvent)
		obj.attachEvent('on'+evt,fn);
}
function removeEventSimple(obj,evt,fn) {
	if (obj.removeEventListener)
		obj.removeEventListener(evt,fn,false);
	else if (obj.detachEvent)
		obj.detachEvent('on'+evt,fn);
}

resizeElements = function(){
	widthElement = 100 / Math.round( worksCollection.offsetWidth / 306 + 1 );
	$('#worksCollect .workCollectionElement').each(function(){
		this.style.width = widthElement + "%";
	});
}

$(document).ready(function(){
	worksCollection = document.getElementById('worksCollect');
	resizeElements();
	$('#worksCollect .workCollectionElement img').hover(function(){
		$(this).animate({opacity: 0.5}, { duration: 300, queue: false });
	}, function(){
		$(this).animate({opacity: 1}, { duration: 300, queue: false });
	});
	$('#worksCollect .workCollectionElement a:not([rel=flash])').nyroModal();
	$('#worksCollect .workCollectionElement a[rel=flash]').each(function(){
		var script = $(this).find('script');
		if( script.length ){
			var params = undefined;
			eval(script[0].innerHTML);
			$(this).nyroModal(params);
		}else{
			$(this).nyroModal();
		}
	});
	
	addEventSimple(window, 'resize', resizeElements);
});