
$(function () {
	// slash must be included

	var _src = ($.support.cssFloat) ? 'bubble/images/bubble-tail2.png' : 'bubble/images/bubble-tail2.gif',
        _origPopup = $('table.popup');
	$('#TourtheMachine .themachine div.dot p').each(function() {
		var _myHtml = $(this).html(),
			_secondClass = $(this).parent('div').attr('class').split(' ')[1];
		
		$(this).replaceWith('');

		var _clonePopup = _origPopup.clone();

			_clonePopup.find('div.subcontent').html(_myHtml + '<a href="#" class="close"  style="display:block; text-align:center;">Click to close</a>');
            _clonePopup.find('td.bottom img').attr('src', _src);
			_clonePopup.addClass(_secondClass);
		
		$('#TourtheMachine .themachine').append(_clonePopup);
	});
	
	$('#TourtheMachine .themachine div.dot').each(function () {

				
            var distance = 30,
				time = 250,
				hideDelay = 500,
				hideDelayTimer = null,
				beingShown = false,
				shown = false,
				trigger = $('a.ht', this),
				info = $('.popup.'+$(this).attr('class').split(' ')[1]).css({opacity:0, zIndex:999});
			
			/*var _isIe = $.support.cssFloat;
			
			if ( !_isIe ) {
				var _flash = info.find('.popup-contents div.subcontent'),
					_flashPlayer = _flash.html();
			}*/

			var _offset = $(this).position(),
				_top = _offset['top']  - 164,
				_left = _offset['left'] - 140;
			
			info.css({
				top : _top,
				left : _left 
			});
        
            trigger.click(function () {
                if ( info.is(':visible') ) return false;
                
                
            if(jQuery.browser.msie){
              //toggle_visibility();
            }

     
               $('#TourtheMachine div.themachine table.popup:visible').removeClass('active').css({
                    display:'none',
                    opacity: 0
                });

				trigger.addClass('active');
                //if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown) {
                    // don't trigger the animation again
                    return;
                } else {
                    // reset position of info box
                    beingShown = true;

                    info.css({
                        top: _top,
                        left: _left,
                        display: 'block'
                    }).animate({
                        top: '-=' + distance + 'px',
                        opacity: .9
                    }, time, 'swing', function() {
                        beingShown = false;
                    });
                }

                return false;
            });
            
            info.click( function(e) {
                
                if ( !$(e.target).hasClass('close') ) return;
                
                trigger.removeClass('active');
                hideDelayTimer = null;
                info.css({
                    display:'none',
                    opacity: 0
                });
            
                return false;
            }); 
            
            /*
            .blur(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function () {
					trigger.removeClass('active');
                    hideDelayTimer = null;
					info.css({
						display:'none',
						opacity: 0
					});
					shown = false;
				
                }, hideDelay);

                return false;
            }); */
        });

	
});
function toggle_visibility() {

    $(".player").each(function(){

        playerId = $(this).attr('id');

        if(niftyplayer(playerId).getState() == 'playing') {

            //Stop the currently playing player
            niftyplayer(playerId).stop();

            //Hide the div that was playing
           //$("#" + playerId).hide();

        }

    });



}

