var lightwindow;

var Site = {
    init: function() {
        lightwindow = new Iwindow({ overlay: 'myOverlay', wrap: 'frameWrap', iframe: 'myFrame' });
        Site.mainScroller = new MooShow('carousel', 'navDots', { mode: 'fade', duration: 700 });

        Site.TextSize.init({ selector: '#textSize a', cookieName: 'textsize', targeted: 'siteContent' });
        Site.toggles();
        Site.exits();
        Site.recipes.init();

    },

    toggles: function() {
        var sendToggle = $('sendFriend') || false;
        if (sendToggle) {
            sendToggle = sendToggle.getElement('a')
		    .setProperties({ 'href': 'javascript:void(0);', 'id': 'friendToggle' })
		    .addEvent("click", function() { lightwindow.open((window.root || "") + "layer/sendToFriendFWC.aspx") });
        }
        var goHome = $('goHome') || false;
        if (goHome) {
            goHome = (goHome.getElement('a') || new Element("div"));
            Site.homeURL = goHome.get("href");
            goHome.setProperties({ 'href': 'javascript:void(0);' })
            goHome.addEvent("click", function() { lightwindow.open((window.root || "") + "layer/crosswordExit.aspx?redirect=home") });
        }

    },

    exits: function() {
        var exitLinks = $$('.exitlink');
        var exp = /dest=(\S*)/

        if (exitLinks.length > 0) {
            exitLinks.each(function(el, i) {
                var _href = el.get('href');
                var _tmpUrl = (_href.test("dest=")) ? _href.match(exp)[1] : "";

                el.set("href", "javascript:void(0);")
                if (!el.hasClass('elox')) el.addEvent("click", function() { lightwindow.open((window.root || "") + "layer/exitSiteFWC.aspx?dest=" + _tmpUrl) });
                else if (el.hasClass('elox')) el.addEvent("click", function() { lightwindow.open((window.root || "") + "interstitial.aspx?dest=" + _tmpUrl) });
            });
        }

    },

    backTo: function() {
        var scrollFx;

        var backTos = $$(".returnTop a");
        backTos.each(function(el, i) {
            el.addEvent("click", function(e) {
                e.stop();
                if (scrollFx) scrollFx.toTop();
                else scrollFx = new Fx.Scroll($(document.body)).toTop();
            })
        })
    },

    recipes: {
        curr: null,
        init: function() {
            this.parents = $$('.toggle');
            this.togs = $$('.expandBtn');
            this.contents = $$('.toggled');

            if (this.parents.length == 0) return;

            this.contents.each(function(el, i) {
                el.setStyle('display', 'none')
            });

            this.togs.each(function(tog, i) {
                tog.setStyle('display', 'block')
            }, this);

            this.parents.each(function(par, i) {
                par.removeClass('active')
                par.addEvent('click', function() {
                    this.toggleItem(i)
                } .bind(this));

            }, this)

            this.toggleItem(0)

        },
        toggleItem: function(i) {
            if ($chk(this.curr)) {
                this.togs[this.curr].set('html', 'click to expand')
                this.parents[this.curr].removeClass('active')
                this.contents[this.curr].setStyle('display', 'none')
            }

            if (this.curr != i) {
                this.togs[i].set('html', 'click to close')
                this.parents[i].addClass('active')
                this.contents[i].setStyle('display', '')
            }

            this.curr = (this.curr == i) ? null : i
        }
    },

    TextSize: {
        cName: null,
        opts: { duration: 60 },
        scale: ['1.0em', '1.2em', '1.3em', '1.4em'],
        myScale: null,
        els: null,
        curr: 0,
        init: function(obj) {
            this.els = $$(obj.selector)

            if (this.els.length == 0) return

            this.cName = obj.cookieName
            if (!$chk(Cookie.read(this.cName))) Cookie.write(this.cName, 0, this.opts) //if doesnt exist, set cookie to 0					
            this.myScale = parseInt(Cookie.read(this.cName)) || 0 //in case cookies are disabled use 0								

            this.els.each(function(el, i) {
                el.set('href', 'javascript:void(0);')
                el.addEvent('click', function() {
                    this.processScale(el, i)
                } .bind(this))
            }, this)
            this.targetEl = $(obj.targeted) || $(document.body)
            this.targetEl.setStyles({ 'font-size': this.scale[this.myScale] });
        },
        setCookie: function() {
            Cookie.write(this.cName, this.myScale, this.opts)
        },
        processScale: function(el, index) {
            switch (index) {
                case 0:
                    this.myScale = (this.myScale + 1 > this.scale.length - 1) ? this.scale.length - 1 : this.myScale + 1
                    break;
                case 1:
                    this.myScale = (this.myScale - 1 < 0) ? 0 : this.myScale - 1
                    break;
            }
            this.setCookie();
            this.targetEl.setStyle('font-size', this.scale[this.myScale]);
        }
    },

    Crossword: {
        mode: "normal",
        puzzle: null,
        wrap: null,
        firstCall: true,

        sendFriend: function() {
            lightwindow.open(window.root + "layer/sendToFriendFWC.aspx");
        },

        closeGamePrompt: function() {
            lightwindow.open(window.root + "layer/crosswordExit.aspx");
        },

        closeGame: function(str) {
            str = (str) ? str : null;
            if (str && str == "home") {
                try {
                    if (window.opener.location.href != window.location.href) {
                        var loc = window.opener.location;
                        var dest = loc.protocol + "//" + loc.host + "/default.aspx";
                        window.opener.location.href = dest;
                    }
                    setTimeout(window.close(), 500);
                }
                catch (e) { }
            }
            else {
                try {
                    window.close();
                }
                catch (e) { }
            }

        },

        solveGamePrompt: function() {
            lightwindow.open(window.root + "layer/crosswordSolve.aspx");
        },

        solveGame: function() {
            try {
                thisMovie("crosswordGame").gameCmd("solveGame");
            }
            catch (e) { }

        },

        replayGamePrompt: function() {
            lightwindow.open(window.root + "layer/crosswordReplay.aspx");
        },

        replayGame: function() {
            try {
                thisMovie("crosswordGame").gameCmd("restartGame");
            }
            catch (e) { }

        },

        toggleDisplay: function(state) {
            
            this.puzzle = this.puzzle || $("crossword");
            this.share = this.share || $("crossShare");

            this.crossFull = function(e) {
                var coords = $("crosswordWrap").getCoordinates($(document.body));
                var w = $(document.body).getSize().x;
                var h = window.getSize()//.y;
                this.puzzle.setStyles({
                    width: ((w <= 920) ? 920 : w) + "px",
                    height: h.y + "px", //((h <= 620) ? 620 : h) + "px"					
                    left: (w <= 920) ? 0 : "-" + coords.left + "px",
                    top: -(coords.top) + window.getScrollTop() + "px",
                    backgroundColor: "#FFFFFF"
                });
                var ww = (h.x <= 800) ? "750px" : "100%";
                $("flashGameWrap").setStyles({
                    height: h.y + "px",
                    width: ww
                });

            }
            this.boundFull = this.boundFull || this.crossFull.bind(this);

            if (state.toLowerCase() == "normal") {

                //window.document.crosswordGame.focus();
                this.puzzle.setStyles({
                    width: "892px",
                    height: "620px",
                    top: "0",
                    left: "0",
                    backgroundColor: ""
                });
                $("flashGameWrap").setStyles({
                    height: "100%",
                    width: "100%"
                });

                this.share.setStyle("zIndex", 1010);
                window.removeEvent("resize", this.boundFull).removeEvent("scroll", this.boundFull);
            }

            else if (state.toLowerCase() == "fullscreen") {
                window.innerWidth = screen.availWidth;
                window.innerHeight = screen.availHeight;
                window.screenX = 0;
                window.screenY = 0;

                this.share.setStyle("zIndex", 900);
                if (window.document.crosswordGame) window.document.crosswordGame.focus();
                this.boundFull();
                window.addEvent("resize", this.boundFull).addEvent("scroll", this.boundFull);
            }

            this.firstCall = false;

        }

    }
};

// ecard
var Ecard = new Class({
	movieRdy: false,
	stepGroup: null,
	shareGroup: null,
	navControl: null,
	
	completed: {
		0: false,
		1: false,
		2: false
	},
	
	curr: 0,
	total: 3,
	
	selectTemplate: "pattern={pattern}&msg={msg}&color={color}",
	selections: {
		pattern: "0",
		msg: "0",
		color: "50B4AC"
	},
	
	initialize: function() {
		this.selectionField = $("ctl00_ContentPlaceHolder_ecardSelections");
		
		this.stepGroup = new GroupManager("ecardPanel", ".stepPanel");		
		this.stepGroup.addEvent("select", function(index, slide) {				
			var val = this.selectTemplate + "";
			this.selectionField.value = val.substitute(this.selections);
		}.bind(this))
										
		this.navControl = new NavManager("ecardPrev", "ecardNext", window.root + "images/", {
			0: [
				{src: "", title: ""},
				{src: "ecard_btn_goto2.gif", title: "Go to step 2"}
			],
			1: [
				{src: "ecard_btn_backto1.gif", title: "Go back to step 1"},
				{src: "ecard_btn_goto3.gif", title: "Go to step 3"}
			],	
			2: [
				{src: "ecard_btn_backto2.gif", title: "Go back to step 1"},
				{src: "", title: ""}
			]					
		});
		// step 1
		this.patterns = new Selectables("#ecardThumbs img", "selected");
		this.patterns.addEvent("select", function(index, el) {						
			if (!this.completed[1]) {
				try {
					setMsg(-1);						
				}
				catch(e) {}			
			}
			try {
				setImg(index + 1);	
			}
			catch(e) {}
			this.completed[0] = true;
			this.selections.pattern = index + 1;		
		}.bind(this));		
		
		
		// step 2		
		this.msgGroup = new GroupManager("panel2Select", ".msgContent, .colorContent", {
			prefixed: "msgstate"
		});	
		this.messages = $$("#ecardPanel .msgItem");
		this.messages.each(function(msg, index) {
			msg.addEvent("click", function() {				
				try {
					setMsg(index + 1 + "");
				}
				catch(e) {}
				this.completed[1] = true;
				this.selections.msg = index + 1;			
			}.bind(this))
		}, this);
		
		var msgTabs = $$("#ecardPanel .msgColorTabs li");
		msgTabs.each(function(tab, i) {
			tab.addEvent("click", function() {
				this.msgGroup.selectItem(i);
			}.bind(this));
		}, this);
		
		// update the setTextColor function
		var self = this;
		window.setTextColor = function(textColor) {									
			try {
				thisMovie("eCardView").setTextColor(textColor);
			}
			catch (e) {}
			
			self.selections.color = textColor + "";
			var val = self.selectTemplate + "";			
			self.selectionField.value = val.substitute(self.selections);			
		}.bind(window);
		
		
		// nav
		this.prevBtn = $("ecardPrev");
		this.nextBtn = $("ecardNext");		
		this.prevBtn.addEvent("click", function(e) {
			e.stop();			
			this.goPrev();
		}.bind(this));
		
		this.nextBtn.addEvent("click", function(e) {
			e.stop();
			this.goNext();
		}.bind(this));		
		
		this.navControl.setNav(0);
		
	},
	
	goPrev: function() {
		var prev = (this.curr == 0) ? 0 : this.curr - 1;
		
		this.navControl.setNav(prev);
		this.stepGroup.selectItem(prev);
		this.curr = prev;
	},
	
	goNext: function() {
		if (!this.completed[this.curr]) return;
		
		var next = (this.curr == this.total - 1) ? this.total - 1 : this.curr + 1;
		if (this.completed[this.curr]) {
			this.navControl.setNav(next);
			this.stepGroup.selectItem(next);
		}
		this.curr = next;
	},
	
	gotoStep: function(step) {
		var isComplete = true;		
		for (var i = 0; i < step; i++) {			
			if (!!!this.completed[i]) isComplete = false;
		}		
		if (isComplete) {
			this.navControl.setNav(step);
			this.stepGroup.selectItem(step);			
			this.curr = step;
		}
		
		return this;
	},
	
	stepComplete: function(index) {
		if (this.navControl) this.navControl.markComplete(index);
	}
});

var Selectables = new Class({
	Implements: [Events, Options],
	
	options: {
		start: 0
	},
	
	curr: null,
	
	initialize: function(toggles, activeClass, opts) {
		this.setOptions(opts);
		
		this.toggles = $$(toggles);
		this.activeClass = activeClass;
		
		this.toggles.each(function(el, i) {
			el.addEvent("click", function() {
				this.selectItem(i);
			}.bind(this))
		}, this)
	},
	
	selectItem: function(index) {
		if (index == this.curr) return;
		
		if ($chk(this.curr)) {
			this.toggles[this.curr].removeClass(this.activeClass)
		}
		
		this.toggles[index].addClass(this.activeClass)
		
		this.fireEvent("onSelect", [index, this.toggles[index]])
		this.curr = index;
		
	}
});


var GroupManager = new Class({
	Implements: [Options, Events],
	
	options: {
		start: 0,
		prefixed: "state",
		activeClass: "selected"
	},
	
	initialize: function(parent, children, opts) {
		this.p = $(parent);
		
		if (!this.p) return this.fireEvent("error");		
		
		if (opts) this.setOptions(opts);
		
		this.c = this.p.getElements(children);
		
		this.curr = this.options.start ? this.options.start : 0;
			
		this.p.addClass(this.options.prefixed + this.curr);
		if ($type(this.options.parentStyles) == "object") this.p.setStyles(this.options.parentStyles)
			
		this.c.each(function(c, i) {
			var isCurr = (this.curr == i);			
			if (isCurr) c.addClass(this.options.activeClass)
			else c.setStyle("display", "none")
		}, this)
	},
	
	selectItem: function(index) {
		if (index == this.curr) return;
		
		this.p.removeClass(this.options.prefixed + this.curr).addClass(this.options.prefixed + index);
		
		this.c[this.curr].setStyle("display", "none");
		this.c[this.curr].removeClass(this.options.activeClass);
		
		this.c[index].setStyles({
			display: "block",
			"class": this.options.activeClass
		});
		
		this.fireEvent("onSelect", [index, this.c[index]]);
		this.curr = index;
	}
	
});

var NavManager = new Class({
	Implements: [Options, Events],
	
	options: {
		start: 0	
	},
	
	firstTime: true,
	
	initialize: function(prev, next, base, map) {
		this.prevBtn = $(prev);
		this.nextBtn = $(next);		
		if (!this.prevBtn || !this.nextBtn) return this.fireEvent("error");
		
		this.base = base;		
		this.map = new Hash(map);
		
		this.total = this.map.getLength();
		
		this.curr = null;
		//this.setNav(this.options.start);
		
		return this;				
	},
	
	markComplete: function(index) {
		this.completed[index] = true;
	},
	
	goPrev: function() {
		var prev = (this.curr == 0) ? 0 : this.curr - 1;
		this.setNav(prev);
	},
	
	goNext: function() {
		var next = (this.curr == this.total) ? this.total : this.curr + 1;
		this.setNav(next);		
	},
	
	setNav: function(index) {
		if (index == this.curr) return; 
		
		[this.prevBtn, this.nextBtn].each(function(btn, i) {			
			btn.set("src", this.base + this.map[index][i].src);
			btn.set("title", this.map[index][i].title);
			btn.setStyle("display", (this.map[index][i].src == "") ? "none" : "")
		}, this);
		
		//this.prevBtn.setProperties(this.map[index]);
		//this.nextBtn.setProperties(this.map[index]);
		
		this.fireEvent("onNavigate", [index]);
		this.firstTime = false;
		this.curr = index;
	}	
	
});

var Toggable = new Class({
	Implements: Options,
	
	options: {
		freedom: true,
		autoShow: false,
		start: 0,
		activeClass: "selected"
	},
	
	curr: null,
	
	initialize: function(togs, togd, opts) {
		if (opts) this.setOptions(opts);
		
		this.togs = $$(togs)
		this.togd = $$(togd)
		
		if (this.togs.length == 0) return;
		
		this.togd.each(function(el, i) {
			el.setStyle('display', 'none')
		});		
		this.togs.each(function(el, i) {			
			el.addEvent('click', function() {
				this.toggleItem(i)
			}.bind(this));			
		}, this)	
		
		if (this.options.autoShow) this.toggleItem(this.options.start);
	},

	toggleItem: function(i) {										
		if ($chk(this.curr)) {
			this.togs[this.curr].removeClass(this.options.activeClass)
			this.togd[this.curr].setStyle('display', 'none')				
		}
		
		if (this.curr != i) {
		    this.togs[i].addClass(this.options.activeClass)
		    this.togd[i].setStyle('display', '')				
		}
		
		this.curr = (this.curr == i) ? null : i												
	}	
});

// landing carousel 
var MooShow = new Class({
	Implements: [Options, Events],
	
	options: {
		wrapSelector: '.wrapper',
		slideSelector: '.slide',
		
		navSelector: 'a',
		
		mode: 'fade', // options: fade OR scroll
		
		duration: 500,
		
		startRandom: true,
		autoRotate: true,
		rotateDuration: 7500,
		welcomeFrame: false		
	},
	
	startIndex: 0,
	slideScale: null,
	curr: null,
	slideInterval: null,
	
	firstTime: true,
	
	initialize: function(scrollId,  navId, opts) {
		if (opts) this.setOptions(opts);
		
		this.scroller 	= $(scrollId)
		this.controller = $(navId)
		// IDs dont exist, try again
		if (!this.scroller || !this.controller) return	

		this.scrollWrap = this.scroller.getElement(this.options.wrapSelector)
		this.scrollWrap.setStyles({height: "auto", width: "auto"})
		
		this.scrollSlides 	= this.scroller.getElements(this.options.slideSelector)				
							
		// change mode to default if they pass invalid mode
		if (!$A(['fade', 'scroll']).contains(this.options.mode.toLowerCase())) this.options.mode = 'fade'

		this.slideScale = {x: this.scrollSlides[0].getStyle('height').toInt(), y: this.scrollSlides[0].getStyle('width').toInt()}				
		
		// if scroll..
		if (this.options.mode == 'scroll') {
			this.scrollWrap.setStyle('width', (this.slideScale.y * this.scrollSlides.length).toInt() + 'px')			
			this.scrollFx = new Fx.Tween(this.scrollWrap, {property: 'left', duration: this.options.duration}).set((this.startIndex == 0) ? 0 : -(this.slideScale.y * this.startIndex))
		}
		
		// if fade..
		if (this.options.mode == 'fade') {
			this.scroller.setStyle("overflow", "visible");
			this.scrollSlides.each(function(slide, i) {
				slide.setStyles({
					position: 'absolute',
					top: 0,
					left: 0,
					zIndex: this.scrollSlides.length - i
				})
				slide.set('tween', {property: 'opacity', duration: this.options.duration, link: 'cancel'}).set('opacity', (this.startIndex == i) ? 1 : 0)
			}, this)
									
		}
		
		// inital frame isn't related to show, so exclude it
		if (this.options.welcomeFrame) {
			this.startingSlide = this.scrollSlides[0];
			this.scrollSlides.splice(0,1)				
		}	
		
		this.navs = this.controller.getElements(this.options.navSelector)			
		if ($chk(this.startIndex)) {
			this.navs[this.startIndex].addClass('active')
			this.curr = this.startIndex
		}
		
		this.setNavBinds(true)
		
		// if its automated
		if (this.options.autoRotate) {
			$clear(this.slideInterval)
			
			var enterFunc = function() {
				$clear(this.slideInterval)			
			}.bind(this)
			
			var leaveFunc = function() {
				$clear(this.slideInterval)
				this.slideInterval = this.runShow.periodical(this.options.rotateDuration, this)				
			}.bind(this)
			
			this.slideInterval = this.runShow.periodical(this.options.rotateDuration, this)
			
			this.scroller.addEvent('mouseenter', enterFunc)
			this.scroller.addEvent('mouseleave', leaveFunc)
			this.controller.addEvent('mouseenter', enterFunc)
			this.controller.addEvent('mouseleave', leaveFunc)			
			
		}
		
	},
	
	runShow: function() {
		this.nextSlide();
	},
	
	nextSlide: function() {
		var next = (!$chk(this.curr)) ? 0 : (this.curr + 1 > this.scrollSlides.length - 1) ? 0 : this.curr + 1
		this.gotoSlide(next)
	},
	
	prevSlide: function() {
		var prev = (this.curr - 1 < 0) ? this.scrollSlides.length - 1 : this.curr - 1
		this.gotoSlide(prev)
	},
	
	gotoSlide: function(index) {
		var mode = this.options.mode
				
		if (this.options.welcomeFrame && this.firstTime) {
			this.startingSlide.tween(0)	
		}				

		if (mode == 'scroll') {
			this.scrollFx.start((index == 0) ? 0 : -(this.slideScale.y * index))				
		}
		
		else if (mode == 'fade') {
			if ($chk(this.curr)) this.scrollSlides[this.curr].tween(0)
			this.scrollSlides[index].tween(1)
		}				
		
		if (this.navs.length > 2) {
			if ($chk(this.curr)) this.navs[this.curr].removeClass('active')
			this.navs[index].addClass('active')
		}					
		
		this.curr = index
		this.firstTime = false
		
	},
	
	setNavBinds: function(state) {
		var fn = (state) ? 'addEvent' : 'removeEvent'
		
		// if nav items more than 2, assume clickable nav
		if (this.navs.length > 2) {
			this.navs.each(function(el, i) {
				el[fn]('mouseenter', function() {
					this.gotoSlide(i);
				}.bind(this))
			}, this)
		}
		else {
			this.navs[0][fn]('click', this.prevSlide.bind(this))
			this.navs[1][fn]('click', this.nextSlide.bind(this))
		}
		
	}	

});









var Iwindow = new Class({
	overlay: null,
	frameWrap: null,
	myFrame: null,
	myFx: null,
	myUrl: null,
	_tWin: null,
	widths: null,
	
	initialize: function(obj) {
		// set static dimensions for HTTPS pages
		// keys are in lowercase and correspond to page file names
		this.fixed = {
			sendtofriend_popup: 385
		};
				
		this.build(obj);	
	},
	build: function(obj) {
		[
			this.overlay = new Element('div',{id: obj.overlay}), 
			this.frameWrap = new Element('div',{id: obj.wrap}),
			this.loader = new Element('div', {id: 'frameLoader', html: '<p>Loading</p>'})
		].each(function(el) {
			el.hide().inject(document.body, 'bottom')			
		});
		
		this.overlay.addEvent('click',function() { this.closeWin()}.bind(this));
	
		this.myFrame = new Element("iframe", {
			"id": "myFrame",
			"class": "myFrameClass",
			scrolling: "no",
			frameborder: 0,
			src: window.root + "blank.htm"
		}).hide().inject(this.frameWrap).addEvent('load', function() {this.frameLoaded()}.bind(this));
		
		this.closeBtn = new Element("div", {"class":"frameCloseWrap"});
		this.closeBtn.adopt(new Element("iframe", {
			"class": "closeFrame",
			scrolling: "no",
			frameborder: 0,
			src: window.root + "blank.htm"
		}).set("opacity", 0)).adopt(new Element("div", {"class":"frameBtn"}));		
		this.closeBtn.addEvent("click", function() {this.closeWin();}.bind(this)).inject(this.frameWrap, "bottom");

		this._tWin 	= $(document.body);
		
		this.myFx = {
			overlay: new Fx.Tween(this.overlay, {property:"opacity",duration:300, onComplete: function() {this._setDisplay}.bind(this)}).set(0),
			frameWrap: new Fx.Tween(this.frameWrap, {property:"opacity",duration:500})/*.set(0)*/,
			frame: new Fx.Tween(this.myFrame, {property:"height",duration:500}),
			win: new Fx.Scroll(this._tWin, {duration: 500})
		};	
	
		this.targeted = (obj.targeted) ? ($(obj.targeted) || new Element("div")) : false; //($('siteWrap') || new Element("div")).getSize().x
								
	},
	open: function(url, mode) {
		this.frameUrl = url;
		this.mode = (mode) ? mode : null;			
		
		this._resizeOverlay()
		this.overlay.show()
		this.myFx.overlay.start(0.5).chain(function() {
			this.loader.show()
			this.setFrame(url)
		}.bind(this))
						
		try {pauseVideo()} catch(e) {}
		//hideDDown();																		
		
		this.boundResize = this.boundResize || this._resizeOverlay.bind(this);
		
		window.addEvent("scroll",this.boundResize).addEvent("resize", this.boundResize);						
	},
	closeWin: function() {
		this.loader.hide()
		this.myFx.frame.start(1).chain(function() {
			this.myFrame.hide()
			this.frameWrap.hide()
			this.myFrame.set('src','javascript:void(0)')
		}.bind(this))
		this.myFx.overlay.start(0);
		try { resumeVideo() } catch(e) {}
		//showDDown();
		window.removeEvent("scroll", this.boundResize).removeEvent("resize", this.boundResize);		
	},
	setHeight: function(y) {			
		if (y && this.myFrame.getStyle('visibility') != 'hidden') {
			this.myFrame.setStyle('height', y);
		}
		else {
		    try { this.myFrame.contentWindow.scaleWindow() } catch(e) {}
		}
	},
	scale: function(y) {
		if (this.myFrame.isDisplayed() && this.mode) this.myFx.win.toTop();
		this.myFx.frame.start(y);
	},
	setFrame: function(a) {			
		this.myFrame.set('src', a);
	},
	frameLoaded: function() {
		if (this.myFrame.get('src').test("blank.htm")) return 
		this.loader.hide();
		this.frameWrap.show()
		this.myFrame.show();
		try {this.myFrame.contentWindow.scaleWindow()} 
		catch(e) {
			var page = this.frameUrl.split("/").getLast().split(".")[0].toLowerCase();			
			if (this.fixed[page]) this.scale(this.fixed[page]);
		}	
	},
	_resizeOverlay: function() {
		if (!this.widths) {
			this.widths = {
				wrap: this.frameWrap.getStyle("width").toInt(),
				loader: this.loader.getStyle('width').toInt()	
			}
			if (this.targeted) this.widths.targeted = this.targeted.getSize().x		
		}		
		
		wrapStyles = {left: (this.targeted) ? ((this.targeted - this.widths.wrap) / 2) : ((window.getSize().x - this.widths.wrap) / 2)}
		loaderStyles = {left: (this.targeted) ? ((this.targeted - this.widths.loader) / 2) : ((window.getSize().x - this.widths.loader) / 2)}		
		
		wrapStyles.top = loaderStyles.top = (this.mode) ? 25 : window.getScrollTop() + 25
		
		try{
			this.overlay.setStyles({top:window.getTop(), height:window.getScrollHeight()});
			this.loader.setStyles(loaderStyles)
		    this.frameWrap.setStyles(wrapStyles);		
		} catch (e) {}
	},	
	_setDisplay: function() {
		if (this.overlay.getStyle('visibility') == 'hidden') {
			$$([this.overlay, this.frameWrap]).setStyle('display','none')
		}
	}	
});

function thisMovie(movieName) {
	 if (navigator.appName.indexOf("Microsoft") != -1) {
		 //return window[movieName];
		 return document.getElementById(movieName);
	 } else {
		 return document[movieName];
	 }
}
function setMsg(msgId)
{
	thisMovie("eCardView").setMsg(msgId);
}
function setImg(imgId)
{
	thisMovie("eCardView").setImg(imgId);
}
function setTextColor(textColor)
{
	thisMovie("eCardView").setTextColor(textColor);
}
function setTextGlowColor(glowColor)
{
	thisMovie("eCardView").setTextGlowColor(glowColor);
}
function setTextGlowSize(glowSize)
{
	thisMovie("eCardView").setTextGlowSize(glowSize);
}
function setTextGlowAlpha(glowAlpha)
{
	thisMovie("eCardView").setTextGlowAlpha(glowAlpha);
}
function eCardViewIsReady()
{
	//called when ecard is ready
	Ecard.movieRdy = true;
	thisMovie("eCardView").setMsg('0');
	
}
/*-- crossword functions --*/
function solveGame()
{
	Site.Crossword.solveGamePrompt();	
}
function sendToFriend()
{
	Site.Crossword.sendFriend();
}
function closeGame()
{
	Site.Crossword.closeGamePrompt();
}
function setDisplayState(state)
{
	Site.Crossword.toggleDisplay(state);
}
function restartGame()
{
	Site.Crossword.replayGamePrompt();
}
function doRestartGame()
{
	thisMovie("crosswordGame").gameCmd("restartGame");
}


function MM_openBrWindow_(theURL, winName, features) { //v2.0
    window.open(theURL, winName, features);
}


window.addEvent("domready", function() {
	Site.init();
})


// Prints Individual Recipes 

var _h1 = "<html><head>";
var _h2 = "</head>";
var _b1 = "<body>";
var _b2 = "</body></html>";

function printRecipe(id, recipeTitle, imageID) {
  var x=document.getElementById(id);
  var img ="";
  if(document.getElementById(imageID) != null)
    img = document.getElementById(imageID).innerHTML;
  var rTitle = "<h3>" + recipeTitle + "</h3>";
    
  win = window.open();
  self.focus();
  win.document.open();
  win.document.write(_h1+_h2+_b1+rTitle+img+"<br />"+x.innerHTML+_b2);

  win.document.close();
  win.print();
  win.close();
}


//Burak Gokoglu 09/22
var num; // this is # of divs you have

var urlpath = "/share";
if (location.host.indexOf("localhost") != -1)
    urlpath = "/womens" + urlpath;


if (location.pathname == urlpath + "/recipes.aspx")
    num = 31;
else if (location.pathname == urlpath + "/mocktails.aspx")
    num = 4;
else
    num = 0; //unknown situation


function swap(what) {
    for (var i = 0; i < num; i++) {
        document.getElementById('swap' + i).style.display = 'none';
    }
    document.getElementById('swap' + what).style.display = 'block';
}
var createStyle = document.createElement('style');
var createStyleProp = document.createTextNode('.hidden { display:none; }');

document.getElementsByTagName('head')[0].appendChild(createStyle);


function cellImg(idCell, imgName) {
    document.getElementById(idCell).style.background = "url(" + imgName + ")";
}

function hoverpurple() {
    this.style.color = '#8b357d';
}

function linkIn(what)
{
 for (var i = 0; i < num; i++) {
        document.getElementById('recipe' + i).style.color = '#142b4c';
    }
    document.getElementById('recipe' + what).style.color = '#8b357d';
}

function validateZipSearch(source, args) {
    args.IsValid = false;
    if (document.getElementById('ctl00_sidebarfwc1_txtZipCode').value.length > 0) {
           args.IsValid = true;
     } 
}
