﻿///////////////////////
//
// Fleming's Namespace
//
///////////////////////

var Flemings = {
    set: function(obj, methodName, data) {
        return (function(e) {

            e = e || window.event;

            return obj[methodName](e, this, data);
        });
    },

    stopAll: function(displayText, emailPrefix) {
        return Flemings.Utils.Obfuscator.Init(displayText, "com", "flemingssteakhouse", emailPrefix);
        
    },
    
    clearSIFRTimer: function() {
        if (SIFRTimer != null) {
            clearInterval(SIFRTimer);
            SIFRTimer = null;
        }
    }

};

////////////////////////////////
//
// Fleming's Utilities Namespace
//
////////////////////////////////

Flemings.Utils = {
    scrollWindow: function() {
        if (window.innerWidth) //if browser supports window.innerWidth
        { var winWidth = window.innerWidth; }
        else {
            if (document.all) //else if browser supports document.all (IE 4+)
            { var winWidth = document.documentElement.clientWidth; }
        }

        if ((winWidth < 1100) && (winWidth > 960)) {
            var scrollAmount = (1100 - winWidth) / 2;
            window.scrollTo(scrollAmount, 0);
        } else {
            if (winWidth < 960) {
                window.scrollTo(60, 0);
            }
        }
    },

    goToLink: function(url) {
        Lightview.hide();
        var loc = document.location = url;
        setTimeout("loc;", 1000);
    },

    goToLoc: function(loc) {
        if ($('wine-menus')) {
            window.location = "/locations/" + loc;
        } else {
            window.location = "/locations/" + loc;
        }
    }
};

// Email Obfuscator
Flemings.Utils.Obfuscator = {
    p: "f='ma",
    t: String.fromCharCode(97),
    E: "/",
    A: String.fromCharCode(105, 108, 116),
    N: ">",
    o: " hre",
    s: "<",
    LL: "o:",
    D: "'",
    seperatorOne: String.fromCharCode(64),
    seperatorTwo: String.fromCharCode(46),

    Init: function(txt, ext, domain, prefix) {
        var encode;
        if (txt == "") {
            txt = prefix + this.seperatorOne + domain + this.seperatorTwo + ext;
        }
        encode = this.start() + prefix + this.seperatorOne + domain + this.seperatorTwo + ext + this.D + this.N + txt + this.end();

        document.write(encode);
    },

    start: function() {
        return (this.s + this.t + this.o + this.p + this.A + this.LL);
    },

    end: function() {
        return (this.s + this.E + this.t + this.N);
    }
};

//////////////////////////////////
//
// Fleming's Animations Namespace
//
//////////////////////////////////

Flemings.Animations = {};

Flemings.Animations.GiftCards = {
    i: 1,
    total: 3,
    interval: null,

    bannerRotate: function (n) {
        if (this.interval != null) {
            clearInterval(this.interval);
            this.interval = null;
        }

        Effect.Appear('banner-' + n);
        if (this.i != n) {
            Effect.Fade('banner-' + (this.i), { duration: 0.8 });
            this.i = n;
        }

        this.interval = setInterval(Flemings.set(this, 'changeBanner'), 6000);
    },

    changeBanner: function (e, scope) {
        if (this.i < this.total) {
            this.i++;
        }
        else {
            this.i = 1;
        }
        Effect.Appear('banner-' + (this.i), { duration: 0.8 });

        if (this.i != 1) {
            Effect.Fade('banner-' + (this.i - 1), { duration: 0.8 });
        }
        else {
            Effect.Fade('banner-3', { duration: 0.8 });
        }
    }
};

Flemings.Animations.PrivateDining = {
    i: 0,
    total: 0,
    interval: null,
    listChanging: false,

    promoRotate: function(n) {
        if (typeof n == 'number' && n > 0) {
            this.total = n;
            this.i = Math.floor(Math.random() * this.total);
            Effect.Appear('promo-' + (this.i + 1), { duration: 0.2 });
            this.total--;
            this.interval = setInterval(Flemings.set(this, 'changePromo'), 6000);
        }
        else {
            Effect.Appear('promo-1', { duration: 0.2 });
        }
    },

    changePromo: function(e, scope) {
        Effect.Fade('promo-' + (this.i + 1), { duration: 0.8 });
        if (this.i < this.total) {
            this.i++;
        }
        else {
            this.i = 0;
        }
        Effect.Appear('promo-' + (this.i + 1), { duration: 1 });
    },
    
    changeMenus: function(id) {        
        var menus = new Array(5);
        menus[0] = "chardonnay";
        menus[1] = "merlot";
        menus[2] = "zinfandel";
        menus[3] = "hors-d-oeuvres";
        menus[4] = "syrah";
        menus[5] = "gamay";
        menus[6] = "riesling";
        var menuNav = id + "-nav";

        if (!this.listChanging) {
            this.listChanging = true;

            setTimeout(Flemings.set(this, 'viewChangeDone'), 1500);
            Effect.Fade('intro', { duration: 0.5 });

            for (var j = 0; j < menus.length; j++) {
                if (menus[j] != id) {
                    Effect.Fade(menus[j], { duration: 0.5 });
                    $(menus[j] + "-nav").style.textDecoration = "";
                    $(menus[j] + "-nav").style.color = "";
                }

            }
            Effect.Appear(id, { duration: 0.8 });
            $(menuNav).style.textDecoration = "none";
            $(menuNav).style.color = "#333333";
            $(menuNav).blur();
        
        }
    },

    viewChangeDone: function(e, scope) {
        this.listChanging = false;
    }
};

Flemings.Animations.LocationTours = {
    timedMsg: function() {
        // Adds a radom querystring to the animated GIF to prevent caching
        var imageReloader = Math.ceil(100*Math.random());
        var wineGlass = "<img src=\'../../Images/360/Flemings_Wine-Glass_animated.gif?" + imageReloader +"\' border=\'0\' />";
        $('wine-glass').innerHTML = wineGlass;
            
        var t=setTimeout(Flemings.set(this, 'roomViewWait'), 500);
    },

    roomViewWait: function() {
        $('tours').style.display = "block";
        var t=setTimeout(Flemings.set(this, 'roomViewShow'), 3500);
    },

    roomViewShow: function() {
        new Effect.BlindUp('animated', {duration:3});
        new Effect.Fade('message', {duration:2});
    }
};

Flemings.Animations.OurCompany = {
    listChanging: false,
    tabId: null,
    tabNavId: null,

    Video_Disable: function() {
        try {
            var player = $('ply');
            //player.sendEvent("STOP", "true");
        }
        catch (err) { }
    },

    //Change tabs funtionality
    changeTabs: function(id) {
        this.tabId = id;

        var tabs = new Array(5);
        tabs[0] = "company";
        tabs[1] = "culture";
        tabs[2] = "careers";
        tabs[3] = "contact";
        tabs[4] = "restaurants";

        this.tabNavId = id + "-nav";

        if (!this.listChanging) {
            this.listChanging = true;
            //Disable Video
            if (id != "culture") {
                this.Video_Disable();
            }

            for (var j = 0; j < 5; j++) {
                if (tabs[j] != id) {
                    $(tabs[j]).style.backgroundColor = "#ffffff";
                    Effect.Fade(tabs[j], { duration: 0.5 });
                    $(tabs[j] + "-nav").style.backgroundPosition = "1px -46px";
                }
            }
            $(id).style.backgroundColor = "#ffffff";
            Effect.Appear(id, { duration: 0.8 });
            $(this.tabNavId).blur();
            setTimeout(Flemings.set(this, 'setBackgroundPosition'), 50);
            setTimeout(Flemings.set(this, 'setBackgroundColor'), 850);
            setTimeout(Flemings.set(this, 'viewChangeDone'), 1500);
        }
    },

    setBackgroundPosition: function(e, scope) {        
        $(this.tabNavId).style.backgroundPosition = "1px 0px";
    },

    setBackgroundColor: function(e, scope) {
        $(this.tabId).style.backgroundColor = "";
    },

    viewChangeDone: function(e, scope) {
        this.listChanging = false;
    }

};



////////////////////////////
//
// Page Specific Namespaces
//
////////////////////////////

// Location Page Namespace
var LocationPage = {
    emailAddress: "Default",

    Init: function(email) {
        this.emailAddress = email;
        return Flemings.Utils.scrollWindow();
    },

    stopAll: function() {
        return Flemings.Utils.Obfuscator.Init("Private Dining Email", "com", "flemingssteakhouse", this.emailAddress);
    },

    privateDiningTour: function() {
        return Flemings.Animations.LocationTours.timedMsg();
    }
};

// Private Dining Page Namespace
var PrivateDining = {
    Init: function(n) {
        return Flemings.Animations.PrivateDining.promoRotate(n);
    },

    changeMenus: function(id) {
        return Flemings.Animations.PrivateDining.changeMenus(id);
    }
};

// Our Company Page Namespace
var OurCompany = {
    Init: function(view) {
        var s1 = new SWFObject('../scripts/player.swf', 'ply', '326', '260', '9', '#ffffff');
        s1.addParam('allowfullscreen', 'false');
        s1.addParam('allowscriptaccess', 'always');
        s1.addParam('wmode', 'transparent');
        s1.addParam('flashvars', 'file=../Assets/our-company/Cultures_video.flv&controlbar=over&backcolor=460300&frontcolor=f9ebd1');
        s1.write('preview');
        window.ply = document.getElementById('ply');

        if (view != '') {
            return this.changeTabs(view);
        }
        else {
            return this.changeTabs('company');
        }
    },

    changeTabs: function(tab) {
        return Flemings.Animations.OurCompany.changeTabs(tab);
    },

    stopAll: function(emailPrefix) {
        return Flemings.Utils.Obfuscator.Init("", "com", "flemingssteakhouse", emailPrefix);
    }
};

// Wine Page Namespace
var WinePage = {
    outerAccords: new Array(),
    innerAccordion: new Array(),
    listChanging: false,
    activated: false,
    
    Init: function() {        
        return this.LoadAccordions();   
    },
    
    LoadAccordions: function() {        
        //Define outer Accordions
        this.outerAccords[0] = new accordion('vertical_container_wines');
        this.outerAccords[1] = new accordion('vertical_container');
        
        //Define Inner Accordions			
	    this.innerAccordion[0] = new accordion('sparkling', {
	      classNames : {
			    toggle : 'vertical_accordion_toggle',
			    toggleActive : 'vertical_accordion_toggle_active',
			    content : 'vertical_accordion_content'
		    }
	    });
    	
	    this.innerAccordion[1] = new accordion('white_wines', {
	      classNames : {
			    toggle : 'vertical_accordion_toggle',
			    toggleActive : 'vertical_accordion_toggle_active',
			    content : 'vertical_accordion_content'
		    }
	    });
    	
	    this.innerAccordion[2] = new accordion('sauvignon', {
	      classNames : {
			    toggle : 'vertical_accordion_toggle',
			    toggleActive : 'vertical_accordion_toggle_active',
			    content : 'vertical_accordion_content'
		    }
	    });
    	
	    this.innerAccordion[3] = new accordion('chardonnay', {
	      classNames : {
			    toggle : 'vertical_accordion_toggle',
			    toggleActive : 'vertical_accordion_toggle_active',
			    content : 'vertical_accordion_content'
		    }
	    });
    	
	    this.innerAccordion[4] = new accordion('pinot', {
	      classNames : {
			    toggle : 'vertical_accordion_toggle',
			    toggleActive : 'vertical_accordion_toggle_active',
			    content : 'vertical_accordion_content'
		    }
	    });
    	
	    this.innerAccordion[5] = new accordion('red_wines', {
	      classNames : {
			    toggle : 'vertical_accordion_toggle',
			    toggleActive : 'vertical_accordion_toggle_active',
			    content : 'vertical_accordion_content'
		    }
	    });
    	
	    this.innerAccordion[6] = new accordion('syrah', {
	      classNames : {
			    toggle : 'vertical_accordion_toggle',
			    toggleActive : 'vertical_accordion_toggle_active',
			    content : 'vertical_accordion_content'
		    }
	    });
    	
	    this.innerAccordion[7] = new accordion('zinfandel', {
	      classNames : {
			    toggle : 'vertical_accordion_toggle',
			    toggleActive : 'vertical_accordion_toggle_active',
			    content : 'vertical_accordion_content'
		    }
	    });
    	
	    this.innerAccordion[8] = new accordion('merlot', {
	      classNames : {
			    toggle : 'vertical_accordion_toggle',
			    toggleActive : 'vertical_accordion_toggle_active',
			    content : 'vertical_accordion_content'
		    }

        });

        this.innerAccordion[9] = new accordion('cab_blend', {
            classNames: {
                toggle: 'vertical_accordion_toggle',
                toggleActive: 'vertical_accordion_toggle_active',
                content: 'vertical_accordion_content'
            }
        });
    	
	    this.innerAccordion[10] = new accordion('cabernet_sauvignon', {
	      classNames : {
			    toggle : 'vertical_accordion_toggle',
			    toggleActive : 'vertical_accordion_toggle_active',
			    content : 'vertical_accordion_content'
			}

});




    	
	    this.innerAccordion[11] = new accordion('dessert', {
	      classNames : {
			    toggle : 'vertical_accordion_toggle',
			    toggleActive : 'vertical_accordion_toggle_active',
			    content : 'vertical_accordion_content'
		    }
	    });
    	
	    this.innerAccordion[12] = new accordion('wines_under_ten', {
	      classNames : {
			    toggle : 'vertical_accordion_toggle',
			    toggleActive : 'vertical_accordion_toggle_active',
			    content : 'vertical_accordion_content'
		    }
	    });
	    
	    // Start with Accordions all closed
        var verticalNestedAccordions = $$('.vertical_accordion_toggle');
        verticalNestedAccordions.each(function(accordion) {
	        $(accordion.next(0)).setStyle({
	          height: '0px'
	        });
        });
        
        var verticalAccordions = $$('.accordion_toggle');
        verticalAccordions.each(function(accordion) {
	        $(accordion.next(0)).setStyle({
	          height: '0px'
	        });
        });	    
	        
    },
    
    reserveList: function() {
        if (!this.listChanging) {				
			this.listChanging = true;								
			new Effect.Parallel([
				new Effect.Appear('ReserveList', {sync: true}),
				new Effect.Fade('FlemList', {sync: true})
				], {
				duration: 2
			});				
			this.outerAccords.each(function(accordion) {
				accordion.deactivate();
				});				
			this.innerAccordion.each(function(accordion) {
				accordion.deactivate();
				});				
			setTimeout(Flemings.set(this, 'viewChangeDone'), 3000);				
		}
    },
    
    FlemingsList: function() {
		if (!this.listChanging) {
			
			this.listChanging = true;
			
			new Effect.Parallel([			
				new Effect.Fade('ReserveList', {sync: true}),
				new Effect.Appear('FlemList', {sync: true})
				], {
				duration: 3
			});
			
			this.outerAccords.each(function(accordion) {
				accordion.deactivate();
				});
			
			this.innerAccordion.each(function(accordion) {
				accordion.deactivate();
				});
			
			setTimeout(Flemings.set(this, 'viewChangeDone'), 4000);				
		}							
	},
	
	viewChangeDone: function() {
		this.listChanging = false;
	},
	
	readMore: function() {
         if(!this.activated) {
             new Effect.BlindDown('wine-read-more', {duration: 1});
             new Effect.Fade('readMore_toggle', {duration: 0.8});
             new Effect.Fade('footer', {duration: 0.8});
             this.activated = true;
         }
    }    
};

// Menu Page Namespace
var MenuPage = {
    activated: false,
    
    Init: function() {
        return this.LoadAccordion();
    },
    
    LoadAccordion: function() {
        var flemings_menu = new accordion('vertical_container');

        var verticalAccordions = $$('.accordion_toggle');
        verticalAccordions.each(function(accordion) {
            $(accordion.next(1)).setStyle({
                height: '0px'
            });
        });    
    },
    
    readMore: function() {
	    if(!this.activated) {
	        new Effect.SlideDown('menu-read-more', {duration: 0.5});
	        new Effect.Fade('readMore_toggle', {duration: 1});
	        this.activated = true;
	    }
    }

};

// Bar Menu Page Namespace
var BarMenuPage = {
    Init: function () {
        return this.LoadAccordion();
    },

    LoadAccordion: function () {
        var flemings_bar_menu = new accordion('vertical_container');

        var verticalAccordions = $$('.accordion_toggle');
        verticalAccordions.each(function (accordion) {
            $(accordion.next(1)).setStyle({
                height: '0px'
            });
        });
    }
};

// Remove sIFR interval when no page title exists
SIFRTimer = setTimeout(Flemings.set(Flemings, 'clearSIFRTimer'), 1000);

