

function showTooltip( o, content) {
	var obj = $(o);
	var tooltip = $('#tooltip');
	tooltip.css({left: obj.offset().left - 40, top: obj.offset().top - 68})
	tooltip.find('td.text').html( content );
	tooltip.fadeIn('fast');
}

function hideTooltip() {
	$('#tooltip').fadeOut('fast');
}

var previousNr = 0;
function showFloor( o, nr ) {
	$(o).parents("table.floor-navy").find("td.active").removeClass("active");
	if (previousNr && previousNr != nr) {
		$('#floor-'+previousNr).hide();
	}
	$('#floor-'+nr).fadeIn();
	previousNr = nr;
	$(o).parent().parent().addClass('active');
	return false;
}
function moveRombs() {
	$('#footer div.romb-5-right').css('top', '-110px');
	$('#footer div.romb-1-left').css('top', '-230px');
}

function _noBubbling( e ) {
	e = _fixE( e ); /* For IE */
	if (!e.cancelBubble) e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
	return false;
}
function _fixE( e ) {
	//if (is_ie) e = event;
	if (!e) var e = window.event;
	return e;
}

function viewport() {
    this.windowX = (document.documentElement && document.documentElement.clientWidth) || window.innerWidth || self.innerWidth || document.body.clientWidth;
    this.windowY = (document.documentElement && document.documentElement.clientHeight) || window.innerHeight || self.innerHeight || document.body.clientHeight;
    this.scrollX = (document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft;
    this.scrollY = (document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop;
    this.pageX = (document.documentElement && document.documentElement.scrollWidth) ? document.documentElement.scrollWidth : (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidth;
    this.pageY = (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
}


var currentPhotoIndex = -1;
function showPhoto(o, e) {
	var src = (typeof o == 'object') ? o.href : o;
	var image = new Image();

	_noBubbling(e);

	image.onload = function() {
		var view = new viewport();
		var newTop = Math.round((view.windowY - image.height) / 2 + view.scrollY);
		if (newTop < 0) newTop = 0;

		$('#float-layer-inner').html('<img id="sss" src="'+src+'" alt="" />').click(function(e) {
			_noBubbling(e);
		});

		$('#layer-bg').css({height: (view.pageY > view.windowY) ? view.pageY + 'px': view.windowY + 'px'});
		$('#layer-bg').show();
		$('#float-layer').css({top: newTop + 'px'}).fadeIn('fast');
		document.onclick = function() {
			$('#float-layer').hide();
			document.onclick = null;
			$('#layer-bg').hide();
		};

		currentPhotoIndex = getPhotoIndex( src );
		if (currentPhotoIndex > -1) {
			var buttonTop = Math.round(image.height / 2 - 5);
			$('#layer-next').css({ 'margin-top': buttonTop + 'px' }).show();
			$('#layer-prev').css({ 'margin-top': buttonTop + 'px' }).show();
		}

	}
	image.onerror = function() {
		//null
	}
	image.src = src;
	return false;
}

function showNext( e ) {

	if (currentPhotoIndex > -1) {
		//_noBubbling( e );
		currentPhotoIndex++;
		if (currentPhotoIndex >= photos.length) {
			currentPhotoIndex = 0;
		}
		showPhoto( photos[currentPhotoIndex], e );
	}

}

function showPrev( e ) {

	if (currentPhotoIndex > -1) {
		//_noBubbling( e );
		currentPhotoIndex--;
		if (currentPhotoIndex < 0 ) {
			currentPhotoIndex = photos.length - 1;
		}
		showPhoto( photos[currentPhotoIndex], e );
	}

}

function getPhotoIndex( url ) {

	if (typeof photos == 'undefined') return -1;
	var imgSrc = url.split("/");
	imgSrc = imgSrc[ imgSrc.length - 1];
	if (!photos.length) return -1;
	for (var i = 0; i < photos.length; i++) {
		var check = photos[i].split("/");
		check = check[ check.length - 1];
		if (check == imgSrc)
			return i;
	}
	return -1;

}

function close() {
	$('#float-layer').hide();
	document.onclick = null;
	$('#layer-bg').hide();
}

function clipOut( id , steps, step, callback) {

	if (typeof callback == 'function') {
		document.clipOutCallback = callback;
		callback = 1;
	} else if (typeof callback == 'undefined' || callback == null) {
		document.clipOutCallback = null;
		callback = 0;
	}

	var o = document.getElementById( id );
	if (!step) step = 1;
	if (!steps) steps = 20;

	var procMin = 1 / (steps * 2) * step;
	var procMax = 1 - procMin;

	if (step >= steps) {
		if (callback) {
			document.clipOutCallback();
		}
		o.style.display = 'none';
		o.style.clip = 'rect(auto,auto,auto,auto)';
		clearTimeout( timeout );
		timeout = 0;
	} else {
		o.style.clip = "rect("+Math.round(procMin * o.offsetHeight)+"px, "+Math.round(procMax * o.offsetWidth)+"px, "+Math.round(procMax * o.offsetHeight)+"px, "+Math.round(procMin * o.offsetWidth)+"px)";
		step++;
		timeout = setTimeout("clipOut( '"+id+"' , "+steps+", "+step+", "+callback+")", 10);
	}

}