isReady=0

tspinner='<img src="gfx/spinner_transparent.gif" width="16" height="16" />'
	
$(function() {
	isReady=1
	resizeME()	   
});



function centerSpinner() {
	
	var h=$(window).height()
	var w=$(window).width()
	var s=$(window).scrollTop()
		
	var x=Math.round((w-16)/2)
	var y=Math.round((h-16)/2)+s
	$("#spinner").css({'left':x, 'top':y,'display':'block'})
							
}


function centerOverlayImage() {
	
	var h=$(window).height()
	var w=$(window).width()
	var s=$(window).scrollTop()
	
	var ow=$('#theoverlay').width()
	var oh=$('#theoverlay').height()
	
	if (ow!=0 && ow!=null) {
		
		var x=Math.round((w-ow)/2)
		var y=Math.round((h-oh)/2)+s
		$("#theoverlay").css({'left':x, 'top':y})
		$("#theoverlay").fadeIn(200)
	}						
}

function nextOverlayImage(t) {
	
	var temp=$(t).attr('src')
	i=temp.replace("/big/","/small/")
	var pos=getPosition(i, CURRENT_OVERLAY_SERIE)
	
	pos++
	if (pos>=CURRENT_OVERLAY_SERIE.length) {
		hide_overlay()
	} else {
		//$("#theoverlay").css({'visibility':'hidden'})
		
		$("#theoverlay").fadeOut(400, function() {
	
			var h='<img style="cursor:pointer" onclick="nextOverlayImage(this)" onload="overlayImageLoaded()" src="'+(CURRENT_OVERLAY_SERIE[pos].replace("/small/","/big/"))+'">'
			
			
			if (CURRENT_OVERLAY_SERIE==WORKS) {
				h+= '<div class="imagetitles">'
				h+= $('#work'+pos).html()
				h+= '</div>'
			}
				
			$('#theoverlay').html(h)
			
		})
		
		centerSpinner()
	}
	
}

function getPosition(el, arr) {
	
	var pos=0
	for (var i=0; i<arr.length; i++) {
		if (el==arr[i]) {
			pos=i
			break
		}
	}
	return pos
	
}



function resizeME() {
	
	if (isReady) {
		
		if (!$('#thegray').is(':hidden')) {
			resizeGray()
			centerOverlayImage()
		}
		
		var s=$('.spirals')
		var h=$(window).height()
		var w=$(window).width()
		var pageh=Math.round($(document).height())
	
		if (pageh==0) {
			pageh=h+600
		}
		
		var pagew=Math.round($(document).width())
	
		if (pagew==0) {
			pagew=w
		}
		
		
		for (i=0; i<s.length; i++) {
			var elw=$(s[i]).width()
			var newx=Math.round(Math.random()*(pagew-elw))
			var newy=Math.round(Math.random()*(pageh-elw))
			$(s[i]).css({'top':newy,'left':newx})
		}
	
	}
	
}



function makeTheGray() {
	
	$('#thegray').html('')
	
	if (isIE) {
		$('embed').css('visibility', 'hidden')
	}
	resizeGray()

}

function resizeGray() {
	
	var h=$(window).height()
	var w=$(window).width()
	
	var pageh=Math.round($(document).height())
	if (pageh==0) {
		pageh=h+600
	}

	$("#thegray").css({'opacity':0, 'height':pageh, 'width':w, 'display':'block'})
	$("#thegray").animate({'opacity':0.95},500)
}

function hide_thegray() {
	hide_overlay()	
}

function hide_overlay() {
	
	if (isIE) {
		$('embed').css('visibility', 'visible')
	}

	$("#theoverlay").css({'display':'none'})
	$("#thegray").animate({'opacity':0},500, function() { $("#thegray").css('display', 'none') })

}