var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
/*****************************************************************************************************************/

//function SmartScrollerGetCoords() {
//	var scrollX, scrollY;
//	if (document.all) {
//	  if (!document.documentElement.scrollLeft)
//		  scrollX = document.body.scrollLeft;
//	  else
//		scrollX = document.documentElement.scrollLeft;

//		if (!document.documentElement.scrollTop)
//			scrollY = document.body.scrollTop;
//		else
//			scrollY = document.documentElement.scrollTop;
//	} else {
//		scrollX = window.pageXOffset;
//		scrollY = window.pageYOffset;
//	}
//	document.getElementById("IncFooter_scrollLeft").value = scrollX;
//	document.getElementById("IncFooter_scrollTop").value = scrollY;
//}

//function SmartScroll() {
//	if (document.getElementById("IncFooter_scrollLeft") != null) {
//		var x = document.getElementById("IncFooter_scrollLeft").value;
//		var y = document.getElementById("IncFooter_scrollTop").value;
//		window.scrollTo(x, y);
//	}
//}
/*****************************************************************************************************************/
/*
********************HELP http://jsfromhell.com/forms/masked-input
Default Rules
a = A-Z and 0-9 
A = A-Z, accents and 0-9 
9 = 0-9 
C = A-Z and accents 
c = A-Z 
* = Any character 
---------------------------------------------
Special rules
E = (Except) exception 
O = (Only) only 
---------------------------------------------
SIMPLE MASKS:
In this kind of mask the user can't type more characters than the amount of characters in the mask. 
Example: 
telephone = (99)9999-9999 
date = 99/99/9999 
---------------------------------------------
Special mask "rule^exceptions":
This kind of mask is composed ty two parts, separated by "^", the left side specified the rule and the right one, the exceptions for the selected rule. 
Example: 
9^abc = The rule is to accept only numbers "9" and the exception are the characters a, b and c 
c^123 = Accepts only a-z characters and the exception are the numbers 1, 2 and 3 
---------------------------------------------
Use of the special rules: it's similar to the special mask, but the left side has a different meaning, can be "E" (any character, except...) and "O" (only...) 
Example: 
E^abc: Accepts any character, except a, b and c 
O^123: Only allows the characters 1, 2 e 3 
*/

//MaskInput = function(f, m){
//    function mask(e){
//        var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[\xC0-\xFF]/i, "8": /./ },
//            rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
//        function acceptSerk(c, rule){
//            for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
//                if(r & i && patterns[i].test(c))
//                    break;
//                return i <= r || c == rule;
//        }
//        var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
//        (!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
//            r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : acceptSerk(c, r[1]) || r[0]
//            : (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
//            r.index : l)).length) < m.length && acceptSerk(c, m.charAt(l))) || e.preventDefault();
//    }
//    for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
//        addSerkEvent(f, i, mask);
//};

//addSerkEvent = function(o, e, f, s){
//    var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
//    r[r.length] = [f, s || o], o[e] = function(e){
//        try{
//            (e = e || (window.event ? (arguments = [].slice.call(arguments)).unshift(e = event) || 1 && e : {})).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
//            e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
//            e.target || (e.target = e.srcElement || null);
//            e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
//        }catch(f){}
//        for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.apply ? c = a.apply(o, arguments) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
//        return e = null, !!d;
//    }
//};

//removeSerkEvent = function(o, e, f, s){
//    for(var i = (e = o["_on" + e] || []).length; i;)
//        if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
//            return delete e[i];
//    return false;
//};
/*****************************************************************************************************************/
function FindPosition(object, direction) {
	var y = x = 0;
	if (object.offsetParent) {
		do {
			x += object.offsetLeft;
			y += object.offsetTop;
		} while (object = object.offsetParent);
	}
	if (direction == "x") {return x;} else {return y;};
}
/*****************************************************************************************************************/
function getElementsByAttribute(elm,att,val,arr){ //do not re-format this code!!
	if (arguments.length<4)	var arr=[];
	for(var k=0;k<elm.childNodes.length;k++){
		var child=elm.childNodes.item(k);
		if(child.nodeType==1){
			if(child.getAttribute(att)==val)
			arr[arr.length]=child;
			if(child.childNodes.length>0)
			getElementsByAttribute(child,att,val,arr);
		}
	}
	return arr;
}
/*****************************************************************************************************************/
function getAttributeValue(tag, attr) {
	for( var x = 0; x < tag.attributes.length; x++ ) {
		if (tag.attributes[x].nodeName.toLowerCase() == attr) {
			return tag.attributes[x].nodeValue;
		}
	}
}
/*****************************************************************************************************************/
function replaceAll(str, from, to) {
    var idx = str.indexOf( from );
    while ( idx > -1 ) {
        str = str.replace( from, to ); 
        idx = str.indexOf( from );
    }
    return str;
}
/*****************************************************************************************************************/
//var myWin;
//function OpenWindow(target, windowWidth, windowHeight){
//	if (myWin) myWin.close();
//	myWin = window.open(target, "AmeristarPopupWindow","toolbar=no, status=no, scrollbars=yes, resizable=yes, width="+windowWidth+", height="+windowHeight+"");
//	if (window.focus) {myWin.focus();};
//}

//function OpenFullScreenWindow(url) {
//	if (myWin) myWin.close();
//	params  = "toolbar=yes, status=yes, scrollbars=yes, resizable=yes, location=yes";
//	params += ", width=" + (screen.width - 20);
//	params += ", height=" + (screen.height - 50);
//	params += ", top=0, left=0"
////	params += ", fullscreen=yes";

//	myWin = window.open(url,"AmeristarFullScreenWin", params);
//	if (window.focus) {myWin.focus();};
//}

/*****************************************************************************************************************/
function RoundCorners(){
	Rounded1Settings = {tl:{radius:8}, tr:{radius:8}, bl:{radius:8}, br:{radius:8}, antiAlias:true, autoPad:false, validTags:["div"]};
	Rounded2Settings = {tl:{radius:6}, tr:{radius:6}, bl:{radius:6}, br:{radius:6}, antiAlias:true, autoPad:false, validTags:["div"]};
	Rounded3Settings = {tl:{radius:4}, tr:{radius:4}, bl:{radius:4}, br:{radius:4}, antiAlias:true, autoPad:false, validTags:["div", "p"]};
	Rounded4Settings = {tl:{radius:2}, tr:{radius:2}, bl:{radius:2}, br:{radius:2}, antiAlias:true, autoPad:false, validTags:["div", "a"]};

	for (a=1; a<5; a++) {
		RoundedElementsList = getElementsByAttribute(document.body, "rounded", String(a));
		if (RoundedElementsList != "") {
			for (i=0; i<RoundedElementsList.length; i++) {
				RoundedElement = RoundedElementsList[i];
				var RoundedObject;
				if (RoundedElement.className == "Red") RoundedElement.innerHTML = "&nbsp; " + RoundedElement.innerHTML + " &nbsp;";
				switch (a) {
					case 1: RoundedObject = new curvyCorners(Rounded1Settings, RoundedElement); break;
					case 2: RoundedObject = new curvyCorners(Rounded2Settings, RoundedElement); break;
					case 3: RoundedObject = new curvyCorners(Rounded3Settings, RoundedElement); break;
					case 4: RoundedObject = new curvyCorners(Rounded4Settings, RoundedElement); break;
				}
				RoundedObject.applyCornersToAll();
			}
		}
	}
}
/*****************************************************************************************************************/
function HighlightClickedLink(){
//	pageName = String(document.location).split("/");
//	pageName = pageName[pageName.length-1];

	var links=document.getElementsByTagName("a");
	for (i=0; i<links.length; i++) {
		var link = links[i];
		var LastChar = link.href.substring(link.href.length - 1, link.href.length);
		if (LastChar != "#" && link.href == String(document.location)) {
			if (String(link.getAttribute("MarkSelected")).toLowerCase() != "false") {
				Indicate(link);
			} else {
				if (String(link.getAttribute("Color")).toLowerCase() != "null") link.style.color = link.getAttribute("Color");
			}
		}

		
		//////////////////////////////////// sub category highlight
		if (AmeristarPageSubCategory != "" || AmeristarPageCategory != ""){
			if (AmeristarPageSubCategory == "") AmeristarPageSubCategory = AmeristarPageCategory;
			
			if (AmeristarPageSubCategory.indexOf("~") > -1) {
				AmeristarPageSubCategory = AmeristarPageSubCategory.split("~")[1];
			}
			if (link.getAttribute("SubMenu")){
				LinkText = link.innerHTML.toLowerCase().replace("/", "");
				if (AmeristarPageSubCategory == "guestinfo") AmeristarPageSubCategory = "info";
				if (LinkText == "hotelspa") LinkText = "hotel";
			
				if (link.getAttribute("SubMenu").toLowerCase() == "true" && LinkText == AmeristarPageSubCategory)
				Indicate(link);
			}
		}
	}
}

function Indicate(link){
	link.innerHTML = "&nbsp;" + link.innerHTML + "&nbsp;";
	link.style.color = "#000000";
	link.style.backgroundColor = "#E6D4BA";
	link.style.fontWeight = "normal";
	link.setAttribute("rounded", "4");
	//its IE, lets do more stuff
	//if (navigator.appName.indexOf("Internet Explorer") > -1) link.style.width = getPixelWidth(link);
}

/*****************************************************************************************************************/
function SetInputMasks(){
	var inputs=document.getElementsByTagName("input");
	for (i=0; i<inputs.length; i++) {
		var inputType = inputs[i].type.toLowerCase();
		var myInput = inputs[i];
		if (inputType == "text" && myInput.attributes.mask) MaskInput(myInput, getAttributeValue(myInput, "mask"));
	}
}
/*****************************************************************************************************************/
function RandomNumberMaker(max){
	return Math.floor(Math.random()*max);
}

//function SetBackgroundImage(){
//	var loc = String(document.location).toLowerCase();
//	//alert(AmeristarPageCategory);
//	if (loc.indexOf("/rate_a_slot.aspx") > -1) {
//		//BgImage =  "Images/BackgroundRateASlot.jpg";
//		BgImage = "Images/BackgroundDefault.jpg";
//	} else if (AmeristarPageCategory == "gaming") {
//		BgImage =  "Images/BackgroundGaming"+(RandomNumberMaker(5)+1)+".jpg"; 
//	} else if (AmeristarPageCategory == "shopping") {
//		BgImage =  "Images/BackgroundShopping"+(RandomNumberMaker(5)+1)+".jpg";
//	} else if (AmeristarPageCategory == "hotel") {
//		BgImage =  "Images/BackgroundHotel.jpg";
//	} else if (AmeristarPageCategory == "dining") {
//		BgImage =  "Images/BackgroundDining"+(RandomNumberMaker(5)+1)+".jpg";
//	} else if (loc.indexOf("/events.aspx") > -1) {
//		BgImage =  "Images/BackgroundEvents"+(RandomNumberMaker(6)+1)+".jpg";
//	} else if (AmeristarPageCategory == "entertainment" && loc.indexOf("entertainment.aspx") == -1) {
//		BgImage =  "Images/BackgroundEntertainment"+(RandomNumberMaker(7)+1)+".jpg";
//	} else if (AmeristarPageCategory == "guestinfo") {
//		BgImage =  "Images/BackgroundGuestServices"+(RandomNumberMaker(5)+1)+".jpg";
//	} else if (loc.indexOf("star_awards.aspx") > -1) {
//		BgImage =  "Images/BackgroundStarAwards"+(RandomNumberMaker(4)+1)+".jpg";
//	} else {
//		BgImage = "Images/BackgroundDefault.jpg";
//	}

//	if (loc.indexOf("meetings") > -1 ) {
//		BgImage =  "Images/BackgroundMeetings.jpg";
//	} else if (loc.indexOf("hivi") > 1 || loc.indexOf("hi-vi") > -1 || loc.indexOf("hi_vi") > -1) {
//		BgImage =  "Images/BackgroundHiVi.jpg";
//	} else if (loc.indexOf("kids_quest") > -1) {
//		BgImage =  "Images/BackgroundKidsQuest.jpg";
//	} else if (loc.indexOf("weddings") > -1 ) {
//		BgImage =  "Images/BackgroundWeddings.jpg";
//	} else if (loc.indexOf("_spa") > -1 ) {
//		BgImage =  "Images/BackgroundSpa.jpg";
//	} else if (loc.indexOf("_home_nightclub") > -1 ) {
//		BgImage =  "Images/BackgroundHomeNightclub.jpg";
//	} else if (loc.indexOf("entertainment_bar_8042") > -1 ) {
//		BgImage =  "Images/BackgroundBH8042.jpg";
//	} else if (loc.indexOf("council_bluffs_entertainment_amerisports_bar.aspx") > -1 ) {
//		BgImage =  "Images/BackgroundCBAmerisports.jpg";
//	} else if (loc.indexOf("entertainment_depot") > -1 ) {
//		BgImage =  "Images/BackgroundKCDepot9.jpg";
//	} else if (loc.indexOf("st_charles_entertainment_bottleneck_blues_bar.aspx") > -1 ) {
//		BgImage =  "Images/BackgroundSCBBB.jpg";
//	} else if (loc.indexOf("vicksburg_entertainment_bottleneck_blues_bar.aspx") > -1 ) {
//		BgImage =  "Images/BackgroundVBBBB.jpg";
//	}

//	document.body.background = BgImage;
//}
/*****************************************************************************************************************/
//function getToolTipElements(elm,att,arr){
//	if(arguments.length<3) var arr=[]
//	for(var k=0;k<elm.childNodes.length;k++) {
//		var child = elm.childNodes.item(k)
//		if(child.nodeType == 1) {
//			if (child.attributes && child.attributes[att]) arr[arr.length] = child
//			//if(val == "*" || child.getAttribute(att) == val) arr[arr.length] = child
//			if (child.childNodes.length > 0) getToolTipElements(child,att,arr)
//		}
//	}
//	return arr
//}

//function setAllTooltips(){
//	var docLength = document.body.innerHTML.length;
//	if (docLength < 2000000) {
//		var arrNode = getToolTipElements(document.body, "help");
//		for(var i=0;i<arrNode.length;i++){
//			arrNode[i].onmouseover = function(){
//				Tip(this.attributes["help"].value, FADEIN, 200, FADEOUT, 200, BGCOLOR, "#E6D4BA", BORDERCOLOR, "#1B0100", SHADOW, true, SHADOWCOLOR, "#1B0100", SHADOWWIDTH, 2, CENTERMOUSE, true, ABOVE, true,  FONTFACE, "'Lucida Sans Unicode','Lucida Grande'", WIDTH, -300);
//			}
//			arrNode[i].onmouseout = function(){
//				UnTip();
//			}
//		}
//	}
//}
/************************************************************************************************************/
function GetStringWidth(text) { //for IE only
	var spanElement = document.createElement("span");
	spanElement.style.whiteSpace = "nowrap";
	spanElement.innerHTML = text;
	document.body.appendChild(spanElement);
	var width = spanElement.offsetWidth;
	document.body.removeChild(spanElement);
	return width;
}

function getPixelWidth(obj) {
	return (document.all)?obj.offsetWidth:obj.document.width;
}
function getPixelHeight(obj) {
	return (document.all)?obj.offsetHeight:obj.document.height;
}
/************************************** DROP DOWN MENUS ***************************************************************/
//	new Effect.SlideUp(MenuItem, {duration:0.5});
//	new Effect.SlideDown(MenuItem, {duration:0.3,afterFinish: OnFinish, beforeStart: OnStart});

var CloseTimer=0;
var MenuItem;
var LastMenuItem;

function OpenMenuS(ItemID, MenuButton) {
	CancelCloseTimeS();
	if (LastMenuItem) LastMenuItem.style.visibility = "hidden";

	MenuItem = document.getElementById(ItemID);
	LastMenuItem = MenuItem;

	MenuItem.style.top = (FindPosition(MenuButton, "y") + 22) + "px";
	
	if (!MenuItem.style.height) MenuItem.style.height = (MenuItem.clientHeight - 15) + "px";

	var MNewX;

	if ((document.all) && (BrowserDetect.browser == "Explorer" && BrowserDetect.version < 8)) {
		MyMenuWidth = GetStringWidth(MenuItem.innerHTML) + 12;
		MenuItem.style.width = MyMenuWidth + "px";
		MNewX = FindPosition(MenuButton, "x") - ((MyMenuWidth - getPixelWidth(MenuButton)) / 2)
	} else {
		MenuItem.style.width = "auto";
		MNewX = FindPosition(MenuButton, "x") - ((MenuItem.offsetWidth - MenuButton.offsetWidth) / 2)
	}
	//CENTERED
	MenuItem.style.left = MNewX + "px";
	//TO THE LEFT
	//MenuItem.style.left = (FindPosition(MenuButton, "x") - 14) + "px";

 	MenuItem.style.visibility = "visible";
}

function CancelCloseTimeS(){if(CloseTimer){window.clearTimeout(CloseTimer);CloseTimer=null;}}
function SetCloseTimeS(){CloseTimer = window.setTimeout(CloseMenuS, 50);}
function CloseMenuS(){if (MenuItem){MenuItem.style.visibility = "hidden"; MenuItem=null;};}
document.onclick = CloseMenuS;

/*****************************************************************************************************************/
window.onload = function(){
	HighlightClickedLink();
	//SetBackgroundImage();
	RoundCorners();
	//SmartScroll();
	//SetInputMasks();
	//setAllTooltips();
	//if (typeof DoUponLoad == "function") DoUponLoad();
}

//window.onscroll = SmartScrollerGetCoords;
//window.onclick = SmartScrollerGetCoords;
//window.onkeypress = SmartScrollerGetCoords;
