(function(jq){
    jq.fn.angebote_overview = function() { 
        
        var _count_zimmer = jq('#angebote_overview_wrap').children().size() ; 
        
        function resize_angebote_imgs() {  
        
            var zimmerwidth = jq(window).width() / _count_zimmer ; 
            var zimmerheight = jq(window).height() - 63 ; 
            
            var list = jq('#angebote_overview_wrap').find('.angebot_ov_wrap') ;
            var count = 0 ; 
            list.each(function(){
                jq(this).css("left", count * zimmerwidth) ; 
                jq(this).width(zimmerwidth) ; 
                jq(this).height(zimmerheight) ; 
                count++ ; 
                
            }) ; 
            
            list.each( function() {
                var _self = jq(this) ; 
                var imgs = _self.find('img') ;  
                if(zimmerwidth > 0 && zimmerheight > 0)
                {
                    var wrapper_width = 0 ; 
                    var wrapper_height = 0 ; 
                	imgs.each(function(){
                		var imgwidth    = jq(this).width() ;
                		var imgheight   = jq(this).height() ;
                		var widthratio  = zimmerwidth / imgwidth ;
                		var heightratio = zimmerheight / imgheight ;
                		var widthdiff   = heightratio * imgwidth ;
                		var heightdiff  = widthratio * imgheight ;
                		if(heightdiff > zimmerheight) { 
                		    jq(this).css({ width: zimmerwidth+'px', height: heightdiff+'px' }) ; 
                		}
                		else { 
                		    jq(this).css({ width: widthdiff+'px', height: zimmerheight+'px' }) ; 
                		}
                	});
                	                	
                }
            });
		}         
        
        jq(window).resize(function () { 
             resize_angebote_imgs() ; 
        });
        
        resize_angebote_imgs() ; 
        jq(window).resize() ; 
        
        // hover effect
        
        var list = jq('#angebote_overview_wrap').find('.angebot_ov_wrap') ;
        list.each(function() {
            var img = jq(this).find('img') ; 
            var header = jq(this).find('h2') ; 
            img.hover(
                function () {
                    img.css("opacity", 0.6) ; 
                    header.css('color', '#C89514') ; 
                }, 
                function () {
                    img.css("opacity", 1.0) ; 
                    header.css('color', '#2E190F') ; 
                }
            ) ; 
        }) ;
    }
})(jQuery);


