var pano = '';
var loadSound = false;
var helpOut = false;

$(document).ready(function() {
    
    $("#vids").click(function() {
        $("#tourlinks").slideUp("fast");
        $("#vidlinks").slideDown("fast");
    });
    $("#vt").click(function() {
        $("#vidlinks").slideUp("fast");
        $("#tourlinks").slideDown("fast");
    });
    
    //Hygiene Bay clicked
    $("#entry").click(function() {
        //Show Loading Graphic
        document.getElementById('flash').style.backgroundImage = "url(images/loadcabana.png)";
        //Load Pano
        $("#flash").html('<embed width="565" height="424" type="application/x-shockwave-flash" wmode="transparent" src="entry.swf" pluginspage="http://www.adobe.com/go/getflashplayer" FlashVars="externalinterface=1"/>');
        //Keep track of which pano is loaded
        pano = 'entry';
        //Clear the links and then set entry as current pano in menu bar
        clearLinks('#entry');
        loadAudio();
    });
    //Hover states
    
    $("#checkin").click(function() {
        document.getElementById('flash').style.backgroundImage = "url(images/loadcheckin.png)";
        $("#flash").html('<embed width="565" height="424" type="application/x-shockwave-flash" wmode="transparent" src="checkin.swf" pluginspage="http://www.adobe.com/go/getflashplayer" FlashVars="externalinterface=1"/>');
        pano = 'checkin';
        clearLinks('#checkin');
        loadAudio();
    });
    $("#checkin").hover(function() {
        $(this).fadeTo("fast", .6);    
    }, 
    function() {
        if (pano != 'checkin') {
            $(this).fadeTo("fast", 1);
        }
    });
    
    
    $("#waiting").click(function() {
        document.getElementById('flash').style.backgroundImage = "url(images/loadwaiting.png)";
        $("#flash").html('<embed width="565" height="424" type="application/x-shockwave-flash" wmode="transparent" src="waiting.swf" pluginspage="http://www.adobe.com/go/getflashplayer" FlashVars="externalinterface=1"/>');
        pano = 'waiting';
        clearLinks('#waiting');
        loadAudio();
    });
    $("#waiting").hover(function() {
        $(this).fadeTo("fast", .6);    
    }, 
    function() {
        if (pano != 'waiting') {
            $(this).fadeTo("fast", 1);
        }
    });
    
    $("#private").click(function() {
        document.getElementById('flash').style.backgroundImage = "url(images/loadrooms.jpg)";
        $("#flash").html('<embed width="565" height="424" type="application/x-shockwave-flash" wmode="transparent" src="private.swf" pluginspage="http://www.adobe.com/go/getflashplayer" FlashVars="externalinterface=1"/>');
        pano = 'private';
        clearLinks('#private');
        loadAudio();
    });
    $("#private").hover(function() {
        $(this).fadeTo("fast", .6);    
    }, 
    function() {
        if (pano != 'private') {
            $(this).fadeTo("fast", 1);
        }
    });
    
    $("#bays").click(function() {
        document.getElementById('flash').style.backgroundImage = "url(images/loadbays.png)";
        $("#flash").html('<embed width="565" height="424" type="application/x-shockwave-flash" wmode="transparent" src="bays.swf" pluginspage="http://www.adobe.com/go/getflashplayer" FlashVars="externalinterface=1"/>');
        pano = 'bays';
        clearLinks('#bays');
        loadAudio();
    });
    $("#bays").hover(function() {
        $(this).fadeTo("fast", .6);    
    }, 
    function() {
        if (pano != 'bays') {
            $(this).fadeTo("fast", 1);
        }
    });
    
    $("#checkout").click(function() {
        document.getElementById('flash').style.backgroundImage = "url(images/loadcheckout.png)";
        $("#flash").html('<embed width="565" height="424" type="application/x-shockwave-flash" wmode="transparent" src="checkout.swf" pluginspage="http://www.adobe.com/go/getflashplayer" FlashVars="externalinterface=1"/>');
        pano = 'checkout';
        clearLinks('#checkout');
        loadAudio();
    });
    $("#checkout").hover(function() {
        $(this).fadeTo("fast", .6);    
    }, 
    function() {
        if (pano != 'checkout') {
            $(this).fadeTo("fast", 1);
        }
    });
    
    $("#exterior").click(function() {
        document.getElementById('flash').style.backgroundImage = "url(images/loadcheckout.png)";
        $("#flash").html('<embed width="565" height="424" type="application/x-shockwave-flash" wmode="transparent" src="exterior.swf" pluginspage="http://www.adobe.com/go/getflashplayer" FlashVars="externalinterface=1"/>');
        pano = 'exterior';
        clearLinks('#checkout');
        loadAudio();
    });
    $("#exterior").hover(function() {
        $(this).fadeTo("fast", .6);    
    }, 
    function() {
        if (pano != 'exterior') {
            $(this).fadeTo("fast", 1);
        }
    });
    
    $("#close").click(function() {
        showHelp();
    });
    
    $("#drana").click(function() {
        $("#sound").html("");
        loadSound = false;
        $("#flash").html('<embed width="565" height="424" type="application/x-shockwave-flash" wmode="transparent" src="drana.swf" pluginspage="http://www.adobe.com/go/getflashplayer" FlashVars="NSvideo=drana.flv"/>');
    });
    $("#drana").hover(function() {
        $(this).fadeTo("fast", .6);    
    }, 
    function() {
        $(this).fadeTo("fast", 1);
    });
    $("#spanish").click(function() {
        $("#sound").html("");
        loadSound = false;
        $("#flash").html('<embed width="565" height="424" type="application/x-shockwave-flash" wmode="transparent" src="drana.swf" pluginspage="http://www.adobe.com/go/getflashplayer" FlashVars="NSvideo=spanish.flv"/>');
    });
    $("#spanish").hover(function() {
        $(this).fadeTo("fast", .6);    
    }, 
    function() {
        $(this).fadeTo("fast", 1);
    });
    
    $("#hygene").click(function() {
        $("#sound").html("");
        loadSound = false;
        $("#flash").html('<embed width="565" height="424" type="application/x-shockwave-flash" wmode="transparent" src="drana.swf" pluginspage="http://www.adobe.com/go/getflashplayer" FlashVars="NSvideo=hygene.flv"/>');
    });
    $("#hygene").hover(function() {
        $(this).fadeTo("fast", .6);    
    }, 
    function() {
        $(this).fadeTo("fast", 1);
    }); 
});

    function clearLinks(pano) {
        $("#entry").fadeTo("fast", 1);
        $("#checkin").fadeTo("fast", 1);
        $("#waiting").fadeTo("fast", 1);
        $("#bays").fadeTo("fast", 1);
        $("#checkout").fadeTo("fast", 1);
        $("#private").fadeTo("fast", 1);
        
        $(pano).fadeTo("fast", .6);
    }
    
function showHelp() {
    if (helpOut == false) {
        helpmenu = document.getElementById('help');
        $("#flash").hide();
        content = document.getElementById('content');
        helpmenu.style.display = "block";
        $("#help").css("top", content.offsetTop);    
        helpOut = true;
    }
    else {
        $("#help").hide();
        $("#flash").show();
        helpOut = false;
    }
}

function loadAudio() {
    if (loadSound == false) {
        $("#sound").html('<embed width="565" height="30" type="application/x-shockwave-flash" src="audio.swf" pluginspage="http://www.adobe.com/go/getflashplayer" FlashVars="externalinterface=1"/>');
    }
    loadSound = true;
}

function clear() {
    $("#flash").html("");
}