﻿$(document).ready(function(){
    $("#page-wrapper").addClass("js");
    $(".pointer-wrapper").show();
    $("img.js-stretch", "#map-wrapper").stretch();
    $(".pointer-wrapper:not([class*='active'])").fadeTo(0, 0);
    $(".flash-blip:not([class*='active'])").fadeTo(0, 0);    
    
    $(".destination > a", "#destinations").each(function()
    {
        var _boxTimer;
        var _this = $(this);
        var pointerID = $(this).attr("id").replace("link", "dest");
        var flashWrapperID = $(this).attr("id").replace("link", "flash-wrapper");
        var _pointer = $(".pointer-wrapper[id='" + pointerID +"']");
        var _flashWrapper = $(".flash-blip[id='" + flashWrapperID +"']");
        _this.attr("href", "#");        
        
        _this.click(function()
        {
            clearTimeout(_boxTimer);
            _boxTimer = setTimeout(
            function() {
            if (_pointer.css("opacity") > 0 && !(_pointer.hasClass("active"))) 
            {
                _pointer.fadeTo("slow", 0);
                _flashWrapper.fadeTo("slow", 0);                
            }
            else
            {
                _this.parent("div.destination").addClass("active").siblings("div.destination").removeClass("active");            
                _pointer.siblings("div.pointer-wrapper").removeClass("active").fadeTo("slow", 0, function(){_pointer.fadeTo("slow", 1).addClass("active");});
                _flashWrapper.siblings("div.flash-blip").removeClass("active").fadeTo("slow", 0, function(){_flashWrapper.fadeTo("slow", 1).addClass("active");});
                
                
                var flashvars = {};


                var params = {
                wmode: "transparent",
                bgcolor: "#ffffff",
                quality: "high"
                };


                var attributes = {

                };

                swfobject.embedSWF("/flash/blipper.swf",
                flashWrapperID + "-inner",
                "50", "50",
                "9.0.0",
                "/flash/expressInstall.swf",
                flashvars,
                params,
                attributes
                )
            }
            }, 600);
            return false;
        });
    });
});