
var bigHotelImages = function(){
    var imgSelector='', posX, posY, forImage;
    var timeout=false;
    var IEShadowDelta = 42, deltaX = 20, deltaY = 10, delay=0, fadingSpeed=0;
    var structure = '<div id="cloudImg" style="top:0;left:0;display:none"><div class="rShadow"><div class="imgContainer"></div></div><div class="bShadow"></div><div class="rbShadow"></div></div>';

    this.setDelay = function(d){
        delay = d;
    }
    this.setFadingSpeed = function(fs){
        fadingSpeed = fs;
    }
    
    this.run = function(){
		//var x=0

        $('body')
        .append( structure ) ;
		
        $(imgSelector).each(function(){
			$(this)
				.mouseover(
					function( event ){

                        posX = event.pageX
                        posY = event.pageY
                        
                        //if (forImage!=this) {
    
                            forImage = this;
                            $('#cloudImg .imgContainer')
                                .html('<img src="'+(this.src.replace(/\/booking_thumbs.{0,3}\//,'/booking_thumbs_gr/'))+'"/>' + ($(this).data('html')?$(this).data('html'):''))
                            $('.imgContainer img').load( fixWidthForIE7 );
                        //}
                        
                        
                        if (delay==0){
                            open();
                        } else {
                            if (!timeout){
                                timeout = setTimeout(
                                    function(){
                                        if (timeout) {
                                            open();
                                        }
                                        timeout=false
                                    }, delay );
                            }
                        }
                        //fixWidthForIE7( );
                    }
				).mouseout(
					function( ){
                        timeout=false;
                        close();
					}
				).mousemove(
					function( event ){
                        posX = event.pageX;
                        posY = event.pageY;                        
                        setCloudPosition( );
					}
				)
		});
		
		function setCloudPosition(){
            var x = posX + deltaX;
            var y = posY + deltaY;
            var ob = $('#cloudImg');
            
            var maxY = window.pageYOffset+window.innerHeight;
            var maxX = window.pageXOffset+window.innerWidth;
            if (!maxX) {
                var d = document.documentElement;
                var maxY = d.scrollTop + d.offsetHeight;
                var maxX = d.scrollLeft + d.offsetWidth;
            }
           
            var h = ob.height();
            if (y+h>maxY) {
                y = maxY - h - deltaY;
            }
            var w = ob.width();
            
            if ( x + w > maxX) {
                x = x - w - deltaX;
            }
			ob.css( {left: x+'px', top: y +'px' })			
		}
		
		function fixWidthForIE7(){
			setCloudPosition();
            
			// wyjdź gdy przeglądarka inna niż IE7
			if ( navigator.appVersion.search('MSIE 7.0')==-1 && navigator.appVersion.search('MSIE 8.0')==-1 ) {
                return;
            }
			// specjalnie dla ie7
			// trzeba na "twardo" ustalić szerokość DIVA, bo 100% nie działa
			var w = ($('div#cloudImg img') ) .width();

            if (w>0) {
                $('.bShadow, #cloudImg' ).width( w + IEShadowDelta );
            }
		}
    }
    
    this.open = function(){
        if (fadingSpeed==0 ) {
            $('#cloudImg').show();
        } else {
            $('#cloudImg').fadeIn(fadingSpeed);
        }
    }
    var open = this.open;
    
    this.close = function(){
        if (fadingSpeed==0 ) {
            $('#cloudImg').hide();
        } else {
            $('#cloudImg').fadeOut(fadingSpeed);
        }
    }
    var close = this.close;
    
    this.setImgSelector = function( i ){
        imgSelector = i;
    }
    this.setIEShadowDelta = function( d ){
        IEShadowDelta = d;
    }
    this.setDeltaX = function( d ){
        deltaX = d;
    }
    this.setDeltaY = function( d ){
        deltaY = d;
    }
    this.setStructure = function( s ){
        structure = s;
    }
}
