/*

© 2010, maxpress UNTERNEHMENSGRUPPE (www.maxpress.de)

*/

function findPos(obj) {                                                                                                                                                                                                            

	var curleft = curtop = 0;                                                                                                                                                                                                        
                                                                                                                                                                                                                                   
	if (obj.offsetParent) {                                                                                                                                                                                                          
                                                                                                                                                                                                                                   
		do {                                                                                                                                                                                                                             
			curleft += obj.offsetLeft;                                                                                                                                                                                                   
			curtop += obj.offsetTop;                                                                                                                                                                                                     
                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                   
		} while (obj = obj.offsetParent);    
	}                                                                                                                                                                                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                   
	return [curleft,curtop];                                                                                                                                                                                                         
}                       


$(function() {
	

  $('area').mouseover(
    function () {
    	
    	var _bLayerSet = Boolean(false) ;
    	
    	if ( $('body div.layer').css('display') ) {
    		_bLayerSet = true ;
    	}
    	
      var _offset = $('img#main_pic').offset() ;
                      
      var _aCoords = $(this).attr('coords').split(',') ; 
      
      var _iLeft   = parseInt(_offset.left) + parseInt(_aCoords[0]) ;
      var _iTop    = parseInt(_offset.top)  + parseInt(_aCoords[1]) ;
      
      var _iHeight = _aCoords[3] - _aCoords[1] ;
      var _iWidth  = _aCoords[2] - _aCoords[0] ;

			if ( _bLayerSet ) {   
				$('body div.layer_over div.content').html( $(this).attr('alt') + ', <a class="lightbox" href="' + $(this).attr('href') + '" title="' + $(this).attr('alt') + '">Grundriss</a>' ) ;   
      }
      else {
      	$('body').append('<div class="layer">&nbsp;</div><div class="layer_over"><div class="content">' +  $(this).attr('alt') + ', <a class="lightbox" href="' + $(this).attr('href') + '" title="' + $(this).attr('alt') + '">Grundriss</a></div><div class="arrow"><img alt="" border="0" height="10" src="images/spacer.gif" width="11" /></div></div>') ;
      }
      $('body div.layer').css( 'top', _iTop ) ;
      $('body div.layer').css( 'left', _iLeft ) ;
      $('body div.layer').width( _iWidth ) ;
      $('body div.layer').height( _iHeight ) ;
      $('body div.layer_over').css( 'top', _iTop - $('body div.layer_over').height() + 10 ) ;
      $('body div.layer_over').css( 'left', _iWidth + _iLeft - 10) ;

			if ( ! _bLayerSet ) {
      	$('body div.layer').fadeTo( 'fast', 0.4, function() {
      		
      
      		$('body div.layer_over').show('fast') ;  
      	}) ;
      }
		  $('body div.layer_over a.lightbox').lightBox() ;
      
    }
  );

  $('div#box_content a.lightbox').lightBox() ;
  
  $('td a.lightbox').hover( 
    function () { 
      $(this).parent().css( 'background', '#9cbfdc' ) ;
    },
    function () { 
      $(this).parent().css( 'background', 'transparent' ) ;
    }
  );

}) ;


