BWS = function() {};
BWS.settings = {};
BWS.states = [];
BWS.Init = function() {
 	try {
		var m = new BWS.Menu(document.getElementById('nav'), 'mouseover', 0);
		NG.addEventListener(document.body, 'mouseover', function() { m.unselect(); });

	} catch(e) {}
	try {
		var menu = new BWS.Menu(document.getElementById('left-nav').firstChild.nextSibling, 'click', 0, false);
		menu.SetSelected('current');
	} catch(e) { }

	try { NG.addEventListener(NG.getElementsByClassName(document.body, 'rsa')[0], 'click', function() { document.location.href = BWS.settings['RSAURL']; }); } catch (e) {}
	try {
		NG.addEventListener(document.getElementById('postcode').getElementsByTagName('img')[0], 'click', function() {
			BWS.OpenStorefinder(document.getElementById('locator').value);
		});
	} catch(e) {}
	try {
		// trying to work out why home/close links don't work
		NG.addEventListener(
			NG.getElementsByClassName(
				document.getElementById('window'),
				'button-close'
			)[0],
			'click',
			function() {
				//console.log(document.location.href);
				document.location.href = BWS.settings['HomeURL'];
			}
		);
	} catch(e) {/*console.log("Bugger", e);*/}
	try {
		var s = new BWS.Search('search');
	} catch(e) {}
	BWS.AdjustMobileSubMenu();
	BWS.contentAreaHeight();
}
BWS.OpenStorefinder = function(str) {
	var frm = document.getElementById('store-locator-form');
	var qry = document.getElementById('store-locatory-query');
	var state = str.replace(/\./gi,"");
	if (!isNaN(str) && (str % 1 == 0)) {
	    qry.name = 'postcode';
	    qry.value = str;
	} else if (this.states.indexOf(state.toUpperCase()) > -1) {
	    qry.name = 'state';
	    qry.value = state;
	} else {
	    qry.name = 'suburb';
	    qry.value = str;
	}
	frm.submit();
}

BWS.Menu = function(node, eventType, depth) {
	this.depth = (arguments.length < 3 ? 0 : depth);
	this.appendchild = arguments.length > 3 ? arguments[3] : true;

	this.eventType = eventType;
	this.selectedItem = null;
	this.items = [];
	this.getNode = function () { return node; }

  	if (this.appendchild && this.depth > 0) document.body.appendChild(node);

	if (!node) return;
	var c = node.firstChild;
	while (c) {
		if (c.nodeName == 'LI') this.items[this.items.length] = new BWS.Menu.Item(c, this);
		c = c.nextSibling;
	}

	NG.addEventListener(node, eventType, NG.stopPropagation);
}

BWS.Menu.Item = function(node, menu) {
	this.getNode = function () { return node; }
	this.getMenu = function () { return menu; }
	this.submenu = null;

	var s = node.getElementsByTagName('ul');
	if (s.length > 0) this.submenu = new BWS.Menu(s[0], menu.eventType, menu.depth+1, menu.appendchild);
	var t = this;
	NG.addEventListener(node, menu.eventType, function (e) { menu.select(t); NG.stopPropagation(e); });
}


BWS.Menu.prototype.select = function(item) {
	if (this.selectedItem != item) {
		if (this.selectedItem) this.selectedItem.unselect();
		this.selectedItem = item;
		item.select();
	}
}

BWS.Menu.prototype.unselect = function() {
	this.selectedItem = null;
	for (var i = 0; i < this.items.length; i++) {
		this.items[i].unselect();
		NG.delClass(this.getNode(), 'nav-selected');
	}
}

BWS.Menu.Item.prototype.select = function() {
	var n = this.getNode();
	if (n) NG.addClass(n, 'selected');
	var p = NG.getPagePos(n);

	if (this.submenu) {
		var s = this.submenu.getNode();
		if (s) {
			if (this.getMenu().depth == 0) {
				s.style.top = (parseInt(document.documentElement.scrollTop)+parseInt(p.y)+parseInt(n.offsetHeight))+'px';
				s.style.left = (parseInt(document.documentElement.scrollLeft)+parseInt(p.x))+'px';
			} else {
				s.style.top = (parseInt(document.documentElement.scrollTop)+parseInt(p.y))-13+'px';
				s.style.left = (parseInt(document.documentElement.scrollLeft)+parseInt(p.x)+parseInt(n.offsetWidth)-25)+31+'px';
			}
			NG.addClass(s, 'nav-selected');
		}
	}
}


BWS.Menu.Item.prototype.unselect = function() {
	var n = this.getNode();
	if (n) NG.delClass(n, 'selected');
	if (this.submenu) this.submenu.unselect();
	if (this.tooltip) {
		NG.delClass(this.tooltip, 'tooltipvisible');
	}
}


BWS.ButtonGroup = function(form, id) {
	if (isStr(form)) form = document.getElementById(form);
	this.form = form;
	if (id) {
		var s = document.createElement('span');
		s.innerHTML = '<input type="hidden" name="' + id + '" id="' + id + '" />';
		this.form.appendChild(s);
		this.field = s.lastChild;
	} else {
		this.field = null;
	}
	this.buttons = [];
}
BWS.ButtonGroup.prototype.Add = function(button) {
	if (isStr(button)) button = document.getElementById(button);
	if (button) {
		var tmp = this;
		NG.addEventListener(button, 'click', function() { tmp.Select(button); });
		this.buttons.push(button);
	}
}
BWS.ButtonGroup.prototype.Select = function(button) {
	if (isStr(button)) button = document.getElementById(button);
	if (this.selected != null) NG.delClass(this.selected, 'button-select');
	this.selected = button;
	NG.addClass(button, 'button-select');
	if (this.field) this.field.value = (button.alt ? button.alt : button.title);
}

BWS.StateSelector = function(id) {
	var tmp = this;
	this.id = id;
	this.root = document.getElementById('state-selector-' + this.id);
	this.map = document.getElementById('state-selector-imagemap');
	this.hover = null
	this.selected = null;
	NG.addEventListener(this.root, 'mouseover', function(e) { NG.stopPropagation(e); });
	NG.addEventListener(this.map, 'mouseover', function(e) { NG.stopPropagation(e); });
	NG.addEventListener(document, 'mouseover', function(e) { tmp.Hover(tmp.selected); });
}
BWS.StateSelector.prototype.Add = function(name, submaps, submap) {
	var tmp = this;
	var r = document.getElementById('state-selector-' + (submap ? submap + '-' : '') + 'imagemap-' + name);
	var s = NG.getElementsByClassName(this.root, 'state-selector-' + name)[0];
	NG.addEventListener(r, 'mouseover', function(e) { tmp.Hover(s); } );
	NG.addEventListener(s, 'click', function() { tmp.Select(name, true); });
	if (submaps) {
		for (var i = 0; i < submaps.length; i++) {
			this.Add(name, null, submaps[i]);
		}
	}
}
BWS.StateSelector.prototype.Hover = function(node) {
	if (this.hover == node) return;
	if (this.hover != null) NG.delClass(this.hover, 'state-selector-state-hover');
	this.hover = node;
	if (this.hover != null) NG.addClass(this.hover, 'state-selector-state-hover');
}

BWS.StateSelector.prototype.Select = function(name, redirect) {
	var node = NG.getElementsByClassName(this.root, 'state-selector-' + name)[0];
	this.Hover(node);
	this.selected = node;
	if (redirect) {
		var url = NGUrl.thisRequest();
		url.addArgument('op','setstate', true);
		url.addArgument('bwsstate',name, true);
		url.redirect();
	}
}
BWS.Search = function(id) {
	BWS.ButtonGroup.apply(this, [id]);
	this.Add('search-tab-store');
	this.Add('search-tab-site');
	this.Select('search-tab-store');
	NG.addEventListener(NG.getElementsByClassName(this.form, 'button-stores')[0], 'click', function() {
		var url = new NGUrl(BWS.settings['LocatorURL']);
		url.addArgument('Query', document.getElementById('search-store').value, true);
		url.redirect();
	});
	NG.addEventListener(NG.getElementsByClassName(this.form, 'button-site')[0], 'click', function() {
		var url = new NGUrl(BWS.settings['SearchResultsURL']);
		url.addArgument('Query', document.getElementById('search-site').value, true);
		url.redirect();
	});


	NG.addEventListener(document.getElementById('search-store'), 'keyup', function(e) {
		// enter code
		if (e.keyCode == 13) {
			var url = new NGUrl(BWS.settings['LocatorURL']);
			url.addArgument('Query', document.getElementById('search-store').value, true);
			url.redirect();
		}
	});

	NG.addEventListener(document.getElementById('search-site'), 'keyup', function(e) {
		// enter code
		if (e.keyCode == 13) {
			var url = new NGUrl(BWS.settings['SearchResultsURL']);
			url.addArgument('Query', document.getElementById('search-site').value, true);
			url.redirect();
		}
	});

}
BWS.Search.prototype = new BWS.ButtonGroup();
BWS.Search.prototype.Add = function(name) {
	BWS.ButtonGroup.prototype.Add.apply(this, [name]);
	var ts = document.getElementById(name).getElementsByTagName('input');
	for (var i = 0; i < ts.length; i++) {
		ts[i].focusText = ts[i].value;
		NG.addEventListener(ts[i], 'focus', function() { if (this.value == this.focusText) this.value = ''; });
		NG.addEventListener(ts[i], 'blur', function() { if (this.value == '') this.value = this.focusText; });
	}
}
BWS.AddMeta = function() {
	var ads = !NG.hasClass(document.getElementById('page') ,'noads');
	if (typeof NGCMSLoader != 'undefined') {
		var f = NGCMSLoader._start;
		NGCMSLoader._start = function() {
			var g = NGCMS.load;
			NGCMS.load = function(req) {
				g(req);
				NG.addEventListener(NGCMS.getSideNode(), 'load', function() {
					var doc = NGCMS.getSideNode().contentWindow.document;
					var meta = doc.getElementById('meta-form');
					var div = doc.createElement('div');
					div.innerHTML = '<b>Tiles</b><br /><label><input type="checkbox" name="BWSShowAds" /> Show</label>';
					meta.appendChild(div);
					div.getElementsByTagName('input')[0].checked = ads;
				});
			}
			f();
		}
	}
}

BWS.Ratings = function(node) {
	if (isStr(node)) var node = document.getElementById(node);
	this.root = node;
	this.root.BWSRatings = this;
	this.ratings = {};
	this.current = 0;
	this.init = false;
	var tmp = this;
	var slots = NG.getElementsByClassName(this.root, 'slot');
	for (var i = 0; i < slots.length; i++) {
		NG.addEventListener(slots[i], 'click', function() { tmp.Select(this); });
	}
}
BWS.Ratings.Init = function(delay) {
	if (typeof delay == 'undefined') {
		setTimeout('BWS.Ratings.Init(true);',1000);
		return;
	} else {
		var ratings = NG.getElementsByClassName(document, 'bwsratings');
		for (var i = 0; i < ratings.length; i++) {
			if (!ratings[i].BWSRatings.init) ratings[i].BWSRatings.Init();
		}
	}
}
BWS.Ratings.prototype.Init = function() {
	var clicked = NG.getElementsByClassName(this.root, 'slot-0')[0];
	this.init = true;
	if (clicked.BWSRating) {
		this.Select(clicked);
	} else {
		setTimeout('BWS.Ratings.Init();',1000);
	}
}
BWS.Ratings.prototype.Add = function(obj) {
	this.ratings[obj.id] = obj;
	if (this.current < 5) {
		this.Set(this.current, obj.id);
	}
	this.current++;
}
BWS.Ratings.prototype.Select = function(clicked) {
	if (isInt(clicked)) clicked = BWS.ratings[clicked].slot;
	if (clicked.BWSRating) {
		this.Set(0, clicked.BWSRating, true);
	} else {
		var slot = clicked.className.match(/slot-([0-9]+)/)[1];
		this.Set(slot, NG.getElementsByClassName(this.root, 'slot-0')[0].BWSRating);
		this.Clear(0);
	}
}
BWS.Ratings.prototype.Set = function(slot, id, swap) {
	var tmp = this;
	var node = NG.getElementsByClassName(this.root, 'slot-' + slot)[0];
	var rating = this.ratings[id];
	if (!this.init) {
		setTimeout(function() { tmp.Set(slot,id,swap); }, 1000);
		return;
	}
	if (!rating) return;
	switch (node.tagName) {
		case 'OBJECT':
			if (isFunc(node.Change)) {
				node.Change(rating.ProductMedia, rating.LargeMedia, rating.Staff, rating.Product, rating.Header, rating.Body);
			}
			break;
		default:
			node.style.backgroundImage = 'url(' + rating.FramedMedia + ')';
			var img = node.getElementsByTagName('img')[0];
			if (img) {
				img.src = rating.SmallProductMedia;
				img.style.display = 'inline';
			}
			break;
	}
	if (swap && node.BWSRating) this.Set(rating.slot, node.BWSRating);
	else if (rating.slot) this.Clear(rating.slot);
	node.BWSRating = id;
	this.ratings[id].slot = slot;
}
BWS.Ratings.prototype.Clear = function(slot) {
	var node = NG.getElementsByClassName(this.root, 'slot-' + slot)[0];
	switch (node.tagName) {
		case 'OBJECT':
			node.Change('', '', '', '', '', '');
			break;
		default:
			node.style.backgroundImage = 'none';
			var img = node.getElementsByTagName('img')[0];
			if (img) img.style.display='none';
			break;
	}
	node.BWSRating = null;
}

BWS.Specials = function() {};
BWS.Specials.Init = function(node, url) {
	var spans = node.getElementsByTagName('span');
	for (var i = 0; i < spans.length; i++) {
		if (NG.hasClass(spans[i], 'button-download')) NG.addEventListener(spans[i],'click', function() { window.location = url; });
		if (NG.hasClass(spans[i], 'button-friend')) NG.addEventListener(spans[i],'click', function() { new NG.SendToFriends('', 1); BWS.SendToFriends(); });
		if (NG.hasClass(spans[i], 'button-contents')) NG.addEventListener(spans[i],'click', function() { tmp.TOC(); });
	}
}
BWS.SendToFriends = function() {
	var region = document.getElementById('ngcms-region-main');
	var visible = region.style.visibility;
	var display = region.style.display;

	var submits = document.getElementsByTagName('input');
	for (var i = 0; i < submits.length; i++) {
		var submit = submits[i];
		if (submit.value == 'Send' && submit.type == 'submit') {
			NG.addEventListener(submit, 'click', function() {
				region.style.visibility = visible;
				region.style.display    = display;
			});
		}
	}
	var divs = document.getElementsByTagName('div');
	for (var i = 0; i < divs.length; i++) {
		var div = divs[i];
		if (NG.hasClass(div, 'close') && div.innerHTML == 'X') {
			NG.addEventListener(div, 'click', function() {
				region.style.visibility = visible;
				region.style.display    = display;
			});
		}
		try{ this.node.appendChild(this.toc); }
		catch (e) {}
	}

	region.style.visibility = 'hidden';
	region.style.display    = 'none';
}

BWS.contentAreaHeight = function () {
	var e = [];
	var m = document.getElementById('main');
	var maxHeight = 0;

	e.push(m)
	e.push(document.getElementById('ngcms-region-main'));
	e.push(document.getElementById('side-bar'));
	for (var i = 0; i < e.length; i++) {
		if (e[i]) {
			if (e[i].id == 'side-bar') {
				maxHeight = Math.max(e[i].offsetHeight + 15, maxHeight);

			} else {
				maxHeight = Math.max(e[i].offsetHeight, maxHeight);
			}
		}
	}

	var i = document.getElementById('inner');
	if (m && m.offsetHeight < maxHeight) m.style.height = maxHeight+'px';
	if (i && i.offsetHeight < maxHeight) i.style.height = maxHeight+'px';

	var p = document.getElementById('page');
	var pr = document.getElementById('right-shadow');
	var pl = document.getElementById('left-shadow');
	if (p && pl && p.offsetHeight > pl.offsetHeight) pl.style.height = p.offsetHeight+'px';
	if (p && pr && p.offsetHeight > pr.offsetHeight) pr.style.height = p.offsetHeight+'px';
}

BWS.AdjustMobileSubMenu = function() {
	try {
		var m = document.getElementById('mobile-sub-menu');
		var h1 = document.getElementById('ngcms-region-main').getElementsByTagName('h1')[0];
		if(h1 != null) {
			var h1Parent = h1.parentNode;
			h1Parent.insertBefore(m, h1);
		}
	}
	catch(e){}
}

/** Dynamically set width so that it does not overflow on 100% */
BWS.setPollWidth = function(i, p) {
	var r = document.getElementById('poll_result_'+i);
	var s = document.getElementById('poll_resultbar_'+i);

	if (r && p) s.style.width = ((r.offsetWidth - 40) * p / 100)+'px';
}

/*** Deprecated Interface ***/
CharacterFinished = function() { return BWS.Character.FinishAll(); }
IsMute = function() { return BWS.Character.IsMute(); }
Mute = function(val) { return BWS.Character.Mute(val); }


BWS.Splash = function(xhtml) {
	this.shade = new NG.Shade();
	this.shade.setOpacity(100);
	document.body.appendChild(document.createElement('div'));
 	document.body.lastChild.innerHTML = xhtml;

	var s = NG.getElementsByClassName(document.body,'shade')[0];
	var p = document.getElementById('page');
	if (s && p && s.offsetHeight < p.offsetHeight) s.style.height = p.offsetHeight+'px';
}


BWS.ChangeMap = function(url) {
	var map = document.getElementById('map');

	if (map) {
		pc = BWS.GetPostcode();
		if (pc) map.src = url + '?postcode=' + pc;
	}
}

BWS.GetPostcode = function(){
	var pc = null;
	var map_pc  = document.getElementById('map_pc');

	if (map_pc && map_pc.value){
		var cdate = new Date();
		cdate.setYear(cdate.getFullYear() + 1);
		document.cookie = "bws.map_pc=" + map_pc.value  + '; expires=' + cdate.toGMTString() + "; path=/";
		pc = map_pc.value;
	} else {
		var cookies = document.cookie.split(';');
		for (var i = 0; i < cookies.length; i++) {
		    var cookie = cookies[i].split('=');
		    if (cookie[0].replace(' ','') == 'bws.map_pc') {
			pc = cookie[1];
		    }
		}
	}
	return pc;
}


BWS.UpdateMainStoreLocator = function(str) {
	if (!str){
	    var req = NGUrl.thisRequest();
	    str = req.arguments.Query;
	}
	if (str) BWS.OpenStorefinder(str);
}

BWS.gotoMainStoreLocator = function(){
    var url = new NGUrl(BWS.settings['LocatorURL']);
    var pc  = document.getElementById('map_pc');
    if (pc.value) url.addArgument('Query', pc.value, true);
    url.redirect();
}

BWS.DisplayFairGoRoadBlock = function(closedelay) {
    this.closeDisplay = function() {
        document.body.removeChild(this.shade.node.shade);
        document.body.removeChild(this.rbContainer);

        var fairgoroadblock_container = document.getElementById('fairgoroadblock-container');
        if (fairgoroadblock_container != null) {
            document.body.removeChild(fairgoroadblock_container);
        }
    }

    this.getFlashDimension = function() {
        var embededObj = document.getElementById('roadblockembedobj');
        try {
            var rawWidth = embededObj.offsetWidth;
            var rawHeight = embededObj.offsetHeight;
        }
        catch(e){}

        if (rawHeight > 0 && rawWidth > 0) {
            //width is exactly twice the height
            if ((rawHeight * 2) == rawWidth) {
                //flash is displayed fullscreen perfectly
                this.flashObjWidth = rawWidth;
                this.flashObjHeight = rawHeight;
            } else if ((rawHeight * 2) < rawWidth) {
                //screen is wider so there will be white space on the left and right of flash object
                this.flashObjHeight = rawHeight;
                this.flashObjWidth = rawHeight*2;
            } else if ((rawHeight * 2) > rawWidth) {
                //screen is taller so there is letter-boxing effect, which displays white space above and below the flash object
                this.flashObjHeight = (rawWidth/2);
                this.flashObjWidth = rawWidth;
            }
        }
    }

    this.handleCloseButton = function() {
        if (this.closeButtonOverlay != null) {
            this.rbContainer.removeChild(this.closeButtonOverlay);
        }

        this.getFlashDimension();

        var closeButtonWidth = Math.round(this.flashObjWidth / 9);
        var closeButtonHeight = Math.round(this.flashObjHeight / 10);

        var cb = document.createElement('div');
        NG.addClass(cb, 'fairgoroadblockclosebutton');
        cb.id = 'fairgoroadblockclosebutton';
        cb.style.height = closeButtonHeight + 'px';
        cb.style.width = closeButtonWidth + 'px';
        cb.style.right = ((document.body.offsetWidth - this.flashObjWidth) / 2) + 'px';
        cb.style.top = ((this.rbContainer.offsetHeight - this.flashObjHeight) / 2) + 'px';

        this.closeButtonOverlay = cb;

        var t = this;
        NG.addEventListener(this.closeButtonOverlay, 'click', function() { t.closeDisplay(); });

        this.rbContainer.appendChild(this.closeButtonOverlay);
    }

    this.ControlVersion = function () {
        var version, axo, e;
        // NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry
        try {
            // version will be set for 7.X or greater players
            axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
            version = axo.GetVariable("$version");
        } catch (e) {}
        if (!version) {
            try {
                // version will be set for 6.X players only
                axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");

                // installed player is some revision of 6.0
                // GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
                // so we have to be careful.

                // default to the first public version
                version = "WIN 6,0,21,0";
                // throws if AllowScripAccess does not exist (introduced in 6.0r47)
                axo.AllowScriptAccess = "always";
                // safe to call for 6.0r47 or greater
                version = axo.GetVariable("$version");
            } catch (e) {}
        }
        if (!version) {
            try {
                // version will be set for 4.X or 5.X player
                axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
                version = axo.GetVariable("$version");
            } catch (e) {}
        }
        if (!version) {
            try {
                // version will be set for 3.X player
                axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
                version = "WIN 3,0,18,0";
            } catch (e) {}
        }
        if (!version) {
            try {
                // version will be set for 2.X player
                axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
                version = "WIN 2,0,0,11";
            } catch (e) {
                version = -1;
            }
        }
        return version;
    }

    // JavaScript helper required to detect Flash Player PlugIn version information
    this.GetSwfVer = function (){
        // NS/Opera version >= 3 check for Flash plugin in plugin array
        var flashVer = -1;

        if (navigator.plugins != null && navigator.plugins.length > 0) {
            if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
                var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
                var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
                var descArray = flashDescription.split(" ");
                var tempArrayMajor = descArray[2].split(".");
                var versionMajor = tempArrayMajor[0];
                var versionMinor = tempArrayMajor[1];
                var versionRevision = descArray[3];
                if (versionRevision == "") {
                    versionRevision = descArray[4];
                }
                if (versionRevision[0] == "d") {
                    versionRevision = versionRevision.substring(1);
                } else if (versionRevision[0] == "r") {
                    versionRevision = versionRevision.substring(1);
                    if (versionRevision.indexOf("d") > 0) {
                        versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
                    }
                }
                var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
            }
        }
        // MSN/WebTV 2.6 supports Flash 4
        else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
        // WebTV 2.5 supports Flash 3
        else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
        // older WebTV supports Flash 2
        else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
        else if ( this.isIE && this.isWin && !this.isOpera ) {
            flashVer = this.ControlVersion();
        }
        return flashVer;
    }

    this.isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
    this.isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
    this.isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

    if( /iPad|iPhone/i.test(navigator.userAgent) ){
        return;
    } else if (this.GetSwfVer() == -1) {
        return;
    }

    this.timeBeforeClosingDisplay = (closedelay*1000);
    this.flashObjWidth = null;
    this.flashObjHeight = null;

    this.shade = new NG.Shade();
    this.shade.setOpacity(50);
    this.shade.node.shade.id = 'fairgoshade';

    this.rbContainer = document.createElement('div');
    NG.addClass(this.rbContainer, 'fairgoroadblock-container');
    this.rbContainer.id = 'fairgoroadblock-container';

    var rbWrapper = document.createElement('div');
    rbWrapper.id = 'fairgoroadblock-wrapper';
    this.rbContainer.appendChild(rbWrapper);

    var ob = document.createElement('object');
    var rb = '<embed id="roadblockembedobj" src="/designs/bws/BWS0737P_roadblock_v1.swf" quality="high" bgcolor="#ffffff" width="100%" height="100%" wmode="transparent" name="BWS0737P_roadblock_v1" align="middle" allowScriptAccess="sameDomain" fullscreen="yes" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />';
    rbWrapper.innerHTML = rb;
    document.body.appendChild(this.rbContainer);

    var t = this;
    setTimeout(function(){ t.closeDisplay();}, this.timeBeforeClosingDisplay);

    this.handleCloseButton();

    NG.addEventListener(this.rbContainer, 'resize', function(){t.handleCloseButton();});
}

BWS.DisplayStateSelector = function(prompt) {

    if (prompt == null) prompt = 'Please select your state:';

    var shadeHeight = null;
    if (document.body.offsetHeight < 600) {
        shadeHeight = 600;
    }

    this.shade = new NG.Shade(null, shadeHeight);
    this.shade.setOpacity(70);
    this.shade.node.shade.id = 'stateselectorshade';

    this.node = document.createElement('div');
    this.node.id = 'stateselectorshade-container';
    this.node.appendChild(document.createElement('div'));
    NG.addClass(this.node.lastChild, 'inner');
    this.node.appendChild(document.createElement('form'));
    var url = NGUrl.thisRequest();
    this.node.lastChild.method = 'post';
    this.node.lastChild.action = url.toString();
    this.node.lastChild.innerHTML = prompt + ' <input type="hidden" name="siteop" value="changestate" />';
    var chooser = document.createElement('select');
    chooser.name = 'State';
    NG.addEventListener(chooser, 'change', function() { this.form.submit(); });
    this.node.lastChild.appendChild(chooser);
    var o = document.createElement('option');
    o.innerHTML = '(Select)';
    o.value = 0;
    this.node.lastChild.lastChild.appendChild(o);
    document.body.appendChild(this.node);

    this.node.style.right = Math.max(0, Math.floor((document.body.clientWidth - this.node.clientWidth)  / 2)) + 'px';
    this.node.style.top = Math.max(50, Math.floor((document.body.clientHeight - this.node.clientHeight - 400)  / 2)) + 'px';

    var tmp = this;
    var url = NGUrl.thisRequest();
    url.addArgument('action','statexml',true);
    var req = new NG.AJAX(url, function (data) { tmp.Populate(data); });
    req.send();

    this.Populate = function(request) {
        var stores = request.responseXML.documentElement.getElementsByTagName('state');
        for (var i = 0; i < stores.length; i++) {
            var o = document.createElement('option');
            o.innerHTML = stores[i].getAttribute('name');
            o.value = stores[i].getAttribute('id');
            this.node.lastChild.lastChild.appendChild(o);
        }
        document.body.appendChild(this.node);
        this.node.style.right = Math.max(0, Math.floor((document.body.clientWidth - this.node.clientWidth)  / 2)) + 'px';
    }


}
