jQuery(window).load(function(){
    var hotspots = new Array();
    var thumbnailBoxes = new Array();
    var hotspotButton = jQuery('.hotspot');
    var thumbnailBox = jQuery('.thumbnailBox');
    var changeImgBoxOpen = false;
    thumbnailBox.each(function(i){
        if(jQuery(this).hasClass("imageChanger")){
            
            jQuery('#ChangeImageBttn').click(function(e){
                e.preventDefault();
                jQuery('#ChangeImageBttn').blur();
                if(!changeImgBoxOpen){
                    jQuery('.imageChanger').fadeIn();

                    thumbnailBox.each(function(){
                        if(!jQuery(this).hasClass('imageChanger')) jQuery(this).fadeOut();
                    });
                    changeImgBoxOpen = true;
                }else{
                    jQuery('.imageChanger').fadeOut();
                    changeImgBoxOpen = false;
                }
            });
        }else{
            thumbnailBoxes[i] = jQuery(this);
            //jQuery(this).css("opacity",0);
        }
    });

    hotspotButton.each(function(i){
        hotspots[i] = jQuery(this);
        hotspotButton.each(function(j){
            jQuery(document).click(function(){
                jQuery(thumbnailBoxes).each(function(){
                    thumbnailBoxes[i].css("z-index","1");
                    thumbnailBoxes[i].fadeOut(500,function(){
                        thumbnailBoxes[i].hide();
                    });
                });
            });            
            jQuery(this).mouseover(function(){
                if(j==i){
                    //thumbnailBoxes[i].css('display','block');
                    thumbnailBoxes[i].css("z-index","9999");
                    thumbnailBoxes[i].fadeIn();
                }else{
                    thumbnailBoxes[i].css("z-index","1");
                    thumbnailBoxes[i].fadeOut();
                }

            });
        });
    });

    // Room image switcher

    var thumbs = new Array();
    var containers = new Array();
    var thumbimgs = jQuery('a.roomThumb');
    var imgContainers = jQuery('.roomImage');

    imgContainers.each(function(i){
        containers[i] = jQuery(this);
        //jQuery(this).css("opacity",0);
    });

    thumbimgs.each(function(i){
        thumbs[i] = jQuery(this);
        jQuery(this).click(function(e){
            e.preventDefault();
            jQuery(containers).each(function(j){
                if(j==i){
                    containers[j].fadeIn(1000);
                    jQuery(".thumbnailBox").each(function(){
                        jQuery(this).fadeOut();
                        changeImgBoxOpen = false;
                    });
                }else{
                    containers[j].fadeOut(1000);
                }
            });
            
        });
    });
    
});