//$('.grdList table tbody tr.grdList_detail').hide();
$(document).ready( function() {

	if (jQuery.browser.msie) {
		var client = parseInt(jQuery.browser.version);
		
	} else {
		var client = "";
	}
	
	// init
	//
	
	

	$('.grdList th').each( function(i) {
									
									
									$(this).width($(this).width());
									
									
									
									});
	
	// clickrow
	
	//$('.grdList tr:not(.grdList_detail)').click(function(){
		//alert('test');
	//})
	
	
//	$('.we_grundrisse img').click( function() {
	$('.grdList tr:not(.grdList_detail)').click( function() {

//		if ($(this).parent().parent().attr('class') == 'grd on') {
		if ($(this).attr('class') == 'grd on') {
			
			// this one off
			$('.grd.on').removeAttr('class');
			$('.grdList_detail.on').hide().attr('class', 'grdList_detail');
			
		} else {
			// old ones off
			$('.grd.on').removeAttr('class');
			$('.grdList_detail.on').hide().attr('class', 'grdList_detail');
			
			// current one one
			// id = $(this).parent().parent().attr('id');
			id = $(this).attr('id');
			// $(this).parent().parent().attr('class', 'grd on');
			$(this).attr('class', 'grd on');
			targetId = '#' + id + '_detail';
			$(targetId).fadeIn().attr('class', 'grdList_detail on');
			
			// current-one-zooms
			zoom = eval('zoomUrls_' + id);
			lb = eval(' lightboxUrls_' + id);
			
			// current-ones-count
			if(zoom.length == 1) addGrdClass = ' grdCenter';
			else addGrdClass = '';
			
			
			
			// test if has been zoomed before
			targetIdToTest = '#' + id + '_detail div.zoomed';
		
			if ($(targetIdToTest).eq(0).attr('class') == null) {
				
				targetIdToInsert = '#' + id + '_detail td';
				
				jQuery.each(zoom, function(i, val) {
	
					uidThis = id + '_' + i;
					last = $(targetIdToInsert).append('<div class="zoomed '+addGrdClass+'" id="' + uidThis + '">' + this + '</div>');
					uidThisjq = '#' + uidThis;
					
					$(uidThisjq).click( function() {
	
						$('.lightbox').remove();
						$('body').prepend('<div class="lightbox"><div class="lbInner"></div>' + lb[i] + '<p>schließen/close</p></div>');
						mLeft = 0;
						mTop = 0;
						mLeft = $('.lightbox').width() * 0.5 + $('.lightbox img').width() * 0.5 + 10;
						mTop = $('.lightbox').height() * 0.5 - $('.lightbox img').height() * 0.5;
						stylevalue = "margin-top:" + mTop + "px; " + "margin-left:" + mLeft + "px;";
						$('.lightbox p').attr("style", stylevalue);
						mLeft = $('.lightbox').width() * 0.5 - $('.lightbox img').width() * 0.5;
						stylevalue = "margin-top:" + mTop + "px; " + "margin-left:" + mLeft + "px;";
						$('.lightbox').show();
						$('.lightbox img').attr("style", stylevalue);
						
						$('.lightbox .lbInner').fadeIn('slow', function() {
	
							$('.lightbox img').show();
							$('.lightbox p').show();
						});
						
						$('.lightbox').click( function() {
	
							$('.lightbox p').hide();
							$(this).children('img').hide();
							$('.lightbox').fadeOut('fast');
						});
					});
				});
			}
		
		}
	});
	
	
	

});
