/*
PROJECT: THE RIVERSIDE MANOR
AUTHOR: RULIAN ESTIVALLETTI
DATE: 3/31/2009
NOTE: COMMON CUSTOM SCRIPTS FOR THERIVERSIDEMANOR.COM
ALL RIGHTS RESERVED
*/


function watermark(obj)
	{
		if (obj.value == obj.defaultValue) obj.value=""; 
		obj.onblur = function()
			{
				if (obj.value == "") obj.value=obj.defaultValue;	
			}
	}
function o(obj)
	{
		return (typeof obj !== "string") ? obj : document.getElementById(obj); 	
	}
function directions(obj)
	{
		var d = o(obj); 
		var x = d.getElementsByTagName("DIV"); 
		var t = d.getElementsByTagName("SPAN"); 
		$("#directions").fadeOut(500, function()
				{
					$("#directions").html("<div>" + t[0].innerHTML + "</div>" + x[0].innerHTML);  
					$("#directions").fadeIn(1000); 
				});
		
	}

function getCenter()
	{
		if (window.innerWidth)

						{
							X = window.innerWidth + window.pageXOffset;
							Y = window.innerHeight +  window.pageYOffset;
						}
					else
						{
							X = document.documentElement.clientWidth + document.documentElement.scrollLeft;
							Y = document.documentElement.clientHeight + document.documentElement.scrollTop;
						} 
		return new Array(Math.round( X / 2 ), Math.round( Y /  2 )); 					
	}

function birthday_offer()
	{
		var D = document.createElement("DIV");
		D.style.width=$("#content").width()+ "px"; 
		D.style.height=$("#content").height()+ "px"; 
		D.style.position="absolute";
		D.style.top=$("#content").offset().top + "px"; 
		D.style.left=$("#content").offset().left + "px"; 
		window.theD = D; 
		jQuery.ajax({complete: function(data, status)
				{
					D.innerHTML = data.responseText;
					document.body.appendChild(D); 
				}, url: "pages/shared/birthday.php" }); 
		
		window.bday = function(f)
			{
				var ereg = new RegExp(/^(([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+([;.](([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+)*$/);	
				var num = new RegExp(/^[0-9]+$/); 
				var E = new Array(); 
				var ER = o("err"); 
				if (f.fname.value =="") E.push("First Name"); 
				if (f.lname.value =="") E.push("Last Name"); 
				if (!f.dobm.value.match(num) || !f.dobd.value.match(num) || !f.doby.value.match(num)) E.push("Date of Birth"); 
				if (!f.phone1.value.match(num) || !f.phone2.value.match(num) || !f.phone3.value.match(num)) E.push("Phone Number"); 
				if (!f.bem.value.match(ereg)) E.push("E-Mail"); 				
				if (E.length > 0) 
					{
						if (window.setT) clearTimeout(window.setT);
						ER.innerHTML = ""; 
						var D = document.createElement("DIV"); 
						D.innerHTML = "<strong>MISSING:</strong> " + E.join(", "); 
						ER.appendChild(D); 
						window.setT= setTimeout(function()
							{
								$(D).fadeOut(1000,function()
										{
											ER.removeChild(D); 
										}); 
								
							}, 4000); 
					return false;
					}
				jQuery.ajax({complete: function(data, status)
				{
							
						if ( data.responseText !== "true") alert(data.responseText);
						setTimeout(function()
							{
							$(window.theD).fadeOut(800, function()				  
							{
								document.body.removeChild(window.theD);	
							});
							}, 500); 
						
				}, url: "pages/shared/birthday_send.php",
				method: "post", 
				data: "fname=" + f.fname.value + "&lname="+ f.lname.value + "&bday="+ (f.doby.value + "-" + f.dobm.value + "-" + f.dobd.value) + "&phone="+ (f.phone1.value + "-" + f.phone2.value + "-" + f.phone3.value) + "&email=" + f.bem.value}); 	
			
				return false;
			}
	
		
		/* ORIGINAL 
		if (o("special_offer") !== null) return false; 
		var c = getCenter(); 
		var D = document.createElement("DIV");
		D.id="special_offer"; 
		D.style.left=(c[0] - 246) + "px"; 
		D.style.top=(c[1] - 171) + "px"; 
		jQuery.ajax({complete: function(data, status)
				{
					D.innerHTML = data.responseText;
					document.body.appendChild(D); 	
				}, url: "pages/shared/offer.php" }); 
		*/
		
	}
function special_offer()
	{
		 
		if (o("special_offer") !== null) return false; 
		var c = getCenter(); 
		var D = document.createElement("DIV");
		D.id="special_offer"; 
		D.style.left=(c[0] - 246) + "px"; 
		D.style.top=(c[1] - 171) + "px"; 
		jQuery.ajax({complete: function(data, status)
				{
					D.innerHTML = data.responseText;
					document.body.appendChild(D); 	
				}, url: "pages/shared/offer.php" }); 
			
	}
function special_offer_send(f)
	{
		var ereg = new RegExp(/^(([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+([;.](([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+)*$/);	
		var num = new RegExp(/^[0-9]+$/); 
		var E = new Array(); 
		if (f.first.value.length < 1) E.push("First Name"); 
		if (f.last.value.length < 1) E.push("Last Name"); 
		if (!f.email.value.match(ereg)) E.push("Email Address");
		if (!f.dobm.value.match(num) || !f.dobd.value.match(num) || !f.doby.value.match(num)) E.push("Date of Birth"); 
		if (E.length > 0) 
			{
				if (window.setT) clearTimeout(window.setT);
				var T = f.getElementsByTagName("DIV"); 
				if (T.length > 0) f.removeChild(T[0]) 
				var D = document.createElement("DIV"); 
				D.style.color="#d89696"; 
				D.innerHTML = "Please provide the following: " + E.join(","); 
				f.appendChild(D); 
				window.setT = setTimeout(function()
					{
						$(D).fadeOut(1000,function()
								{
									f.removeChild(D); 
								}); 
						
					}, 4000); 
			return false;
			}
		
		$.post("pages/shared/offer_send.php", { fname: f.first.value, lname: f.last.value, email: f.email.value,phone:'false', bday: (f.doby.value + "-" + f.dobm.value + "-" + f.dobd.value)} , function(data) { 
																												 var D = document.createElement("DIV"); 
																												D.style.color="#d89696"; 
																												var s = true;
																												eval('var obj = ' + data); 
																												if (obj.type == 'true')
																													 {
																														$.post("pages/shared/birthday_send.php", { name: obj.data.name, file: obj.data.url, email: obj.data.email });
																														D.innerHTML = "Your information has been recieved. Please check your email for the voucher. Thank You.";
																													 }
																													 else 
																													 	{
																															if (obj.type == "false") D.innerHTML = "Your information was not sent, please try again"; 
																															else D.innerHTML = obj.data; 
																															s = false; 
																														}
																													f.appendChild(D);  
																													setTimeout(function()
																													{
																														$(D).fadeOut(1000,function()
																																{
																																	f.removeChild(D); 
																																	if (s == true) 
																																		{
																																			var C = f.parentNode; 
																																			$(C).fadeOut(500, function()
																																				{
																																					C.parentNode.removeChild(C); 
																																				}); 
																																		}
																																}); 
																														
																													}, 4000); 
																												 } );
	}
function preload(_G)
	{
		/// preload images
		_hold = document.createElement("DIV"); 
		_hold.style.position="absolute"; 
		_hold.style.overflow="hidden"; 
		_hold.style.height="5px"; 
		_hold.style.width="5px"; 
		_hold.style.left="-20px"; 
		_hold.style.top="-20px"; 
		setTimeout(function() /// because of IE
					{
						document.body.appendChild(_hold); 
						var _arr = new Array(); 
						for (_pre = 0; _pre < _G.length; _pre++)
							{
								_arr[_pre] = new Image(); 
								_arr[_pre].src=_G[_pre][0]; 
								if (_pre + 1 == _G.length)
									{
										_arr[_pre].onload = function()
											{
											 document.body.removeChild(_hold); 
											}
									}
								_hold.appendChild(_arr[_pre]); 	
							}
						}, 20);	
				
	}

/*** MENU GALLERIES ***/
function menu_gallery(target, Gallery, catagory)
	{
		var area = 600; 
		var _height = 100; 
		var _time = 5000; 
		var _gap = 450;
		var _type = "horizontal"; 
		var _G = Gallery[catagory]; 
		var _M = _G.length -1; 
		var current = 0; 
		var using = new Object(); 
		var _t = o(target); 
		_t.innerHTML = "";
		var fade = 0; 
		if (window._timeouts) 
			{
				for (key in window._timeouts) 
					{
						clearTimeout(window._timeouts[key]); 	
					}
			}
		window._timeouts = new Array(); 	
		preload(_G); 
		/// END PRELOAD	
		function click_image(img, r)
			{
				var c = getCenter(); 
				var imgval = _G[r]; 
				var D = document.createElement("DIV"); 
				D.className="menu_popup"; 
				D.style.left= (c[0] - 225) + "px"; 
				D.style.top = (c[1] - 150 ) + "px"; 
				D.id="popup_menu";
				window._popup=false; 
				img.onclick = function()
					{
						if (document.getElementById("popup_menu")) document.body.removeChild(document.getElementById("popup_menu"));
						D.innerHTML = ""; 
							var _D = document.createElement("DIV"); 
							_D.innerHTML = "<a href='javascript:;'><img src='images/close.png' /></a>"; 
							_D.style.textAlign="right"; 
							_D.style.color= D.style.color ="#FFFFFF"; 
							_I = document.createElement("IMG"); 
							_I.src=_G[r][0]; 
							_I.width=350;
							_I.height=230;
							_D2=document.createElement("DIV"); 
							_D.style.color= _D2.style.color= D.style.color ="#FFFFFF"; 
							_D2.style.textAlign=D.style.textAlign="center"; 
							D.appendChild(_D); 
							D.appendChild(_I); 
							D.appendChild(_D2); 
							document.body.appendChild(D);		
					}
				D.onclick= function()
					{
						document.body.removeChild(D); 
						window._popup=false; 
					}
			}
		/// load first images & start rotation
		function switch_image(img,r)
			{
				var newimg = Math.floor(Math.random() * _M); 
				if (newimg <  _M && newimg > 0) 
					{
						if (!using[newimg] || using[newimg] == false)
							{
								using[r] = false; 
								using[newimg] = true;
								var olda = _G[r]; 
								var newa = _G[newimg];
								/// JUST TO KEEP TRACK OF SPACE
								var oldW = Math.round(olda[1] *(olda[2] / _height));
								var newW = Math.round(newa[1] * (newa[2] / _height)); 
								current = current - oldW;
								current=current + newW; 
								var img = img;
								/// END TRACK
								$("#image_" + r).fadeOut(1000, function()
										{
											click_image(img, newimg)
											img.src=newa[0]; 
											img.id = "image_" + newimg; 
											$("#image_" + newimg).fadeIn(1000); 
											window._timeouts[newimg]=setTimeout(function()
											{
												switch_image(img, newimg); 
											}, _time); 
										}); 
								
							}
							else switch_image(img,r); 
					}
					else switch_image(img,r); 
				
			}
		while(current < area)
			{
				var r = Math.floor(Math.random() * _M); 
				if (r <  _M && r > 0) 
					{	
						if (!using[r] || using[r] == false)
							{
								using[r] = new Array(); 
								using[r][0] = new Image();
								using[r][0].id="image_" + r; 
								var src = _G[r]; 
								var ratio = src[2] / _height; 
								var w = Math.round(src[1] / ratio); 
								using[r][0].src=src[0]; 
								current += w;
								_t.appendChild(using[r][0]); 
								using[r][1] = function()
									{
										
										var x = r; 
										var p = using[r][0]; 
										click_image(using[r][0], x)
										window._timeouts[r]=setTimeout(function()
											{
												switch_image(p, x); 
											}, _time + fade); 
									}
								fade += _gap;
								using[r][1](); 
					
							}
					}
			}
	}
	 		
function create_menu(obj,on) /// CREATES COLLAPSEABLE MENU
	{
		window.menus = new Object();
		var list = o(obj); 
		var ids = 0; 
		menus.register = new Array(); 
		menus.liset = false;
		for(i = 0; i<list.childNodes.length;i++)
			{
				if (list.childNodes[i].tagName == "LI") 
					{
						ids++;
						var li = list.childNodes[i]; 
						var gul = li.getElementsByTagName("UL"); 
						if (gul[0]) 
						{
							menus.register[ids] = new Array(gul[0], li);  
							gul[0].style.display="none";
							// DO UL LI ONCLICK//
							var slis = gul[0].getElementsByTagName("LI"); 
							for (si=0; si<slis.length; si++)
								{
									var sli=slis[si]; 
									sli.onclick=function()
										{
											if (menus.liset !== null || menus.liset !== false)
												{
													menus.liset.className=""; 	
												}
											this.className="on"; 
											menus.liset = this; 
										}
								}
							li.className="off"; 
							li.id=ids; 
							li.onclick= function()
								{
									for(var a in menus.register)
										{
											if (a == this.id) 
												{
													menus.register[a][0].style.display="";	
													menus.register[a][1].className="on"; 
												} 
											else 
												{
													menus.register[a][0].style.display="none"; 
													menus.register[a][1].className="off"; 
												}
										}
									
								}
						}
					}
			}
		if (on)
			{
			 	menus.register[on][0].style.display="";	
				menus.register[on][1].className="on";
			}
	}
	function mouse(ev)
			{
				e = ev || window.event; 		
						if (e.pageX || e.pageY)
								{
									var X=e.pageX; 
									var Y=e.pageY; 
								}
							else if (e.clientX || e.clientY) 
								{
									var X=(e.clientX + document.body.scrollLeft - document.body.clientLeft); 
									var Y=(e.clientY + document.body.scrollTop  - document.body.clientTop); 
								}
				return [X,Y]; 				
			}
	function absolute(obj)
		{
			var x = y = 0; 
				if (!obj.tagName) while(!obj.tagName) obj=obj.offsetParent; 
				if (obj == null) return false;
					while (obj.tagName && (obj.tagName !== "BODY"))
						{
							x += obj.offsetLeft; 
							y += obj.offsetTop; 
							if (obj.offsetParent !== null) obj=obj.offsetParent; 
							else  obj = obj.parentNode;
						}
				return [x, y];
		}
function fade_gallery(_G)
	{
		var IMG = o("image_gallery");
		var SMALL = o("gallery_buttons"); 
		var TITLE = o("title"); 
		IMG.innerHTML ="";
		var maxX = 500
		var maxY = 440; 
		var thumb = 60; 
		var gal = 420; 
		SMALL.style.width = ((thumb + 5 + 2) * _G.length )+ "px";
		SMALL.style.left = "0px";
		/// SET SCROLL FEATURE
		var C = SMALL.parentNode; 
		var move = 0;
		var direction = 0; 
		var int = false; 
		on=true; 
		function pansmall()
			{
				int = setInterval(function()
					{
						if (move !== 0)
							{

								var SET =  parseInt(SMALL.style.left) + (Math.round(move/100) * direction); 
								if (SET <  600 - parseInt((thumb + 5 + 2) * _G.length )) SET =  600 -parseInt(SMALL.style.width);
								if (SET > 0) SET = 0; 
								SMALL.style.left = SET + "px"; 
							}
					}, 60); 
			}
		C.onmouseover=function(ev)
			{
				on = true; 
				pansmall(); 
				var Start = mouse(ev);
				var CC = absolute(C); 
				C.onmousemove = function(ev)
					{
					var Now = mouse(ev); 	
					if (Now[0] > CC[0] + 300) 
						{
							move = Now[0] - (CC[0] + 300);
							direction = -1; 
						}
						else 
						{
							move = (CC[0] + 300) - Now[0];
							direction = 1; 
						}
					}
				C.onmouseout = function()
					{
						on = false; 
						setTimeout(function()
							{
							 	if (on == false)
									{
										C.onmousemove = null;	
										move=0; 
										clearInterval(int); 
									}
							}, 50); 
					}
									
			}
		preload(_G);
		/// add buttons to gallery buttons
		for (key in _G)
			{
					var i = new Image(); 
					i.src = _G[key][0]; 
					i.id=key; 
					i.onclick= function()
						{
							add_img(_G[this.id]); 
						}
					if (_G[key][1] > _G[key][2]) 
						{
							i.height = thumb; 
							var ratio = _G[key][1] / _G[key][2]; 
							i.width= Math.round(thumb * ratio);
						}
					else 
						{
							i.width = thumb; 
							var ratio = _G[key][2] / _G[key][1]; 
							i.height= Math.round(thumb * ratio);
						}
				var D = document.createElement("DIV"); 
				D.appendChild(i); 
				SMALL.appendChild(D); 
			}
			
		/// add default image
			add_img(_G[0]);
		/// function to add images	
			function add_img(imgs)
				{
					if (IMG.childNodes.length > 0)
						{
							$("#gallery_image_view").fadeOut(500,function()
										{
											var x = o("gallery_image_view"); 
											x.parentNode.removeChild(x); 
											add_i(imgs); 
										}); 
						}
						else add_i(imgs); 					
					
					function add_i(img)
						{
							var A = new Image(); 
							A.src=img[0]; 
							A.id="gallery_image_view"; 
							if (img[1] > img[2]) 
									{
										A.width = 600;  
										var ratio = img[2] / img[1]; 
										A.height= Math.round(600 * ratio);
									}
								else 
									{
										A.height = 440; 
										var ratio = img[1] / img[2]; 
										A.width= Math.round(440 * ratio);
									}
							A.style.opacity = 0.0;
							A.style.MozOpacity=0.0;
							A.style.filter = 'alpha(opacity=0)';
							A.style.KhtmlOpacity = 0.0; 
							IMG.appendChild(A); 
							i=0; 
							TITLE.innerHTML = img[3]; 
							var T = setInterval(function()
									{
										i = i + 5; 
										A.style.opacity = i / 100; 
										A.style.MozOpacity= i / 100; 
										A.style.filter = 'alpha(opacity=' + i + ')';	
										A.style.KhtmlOpacity = i / 100; 
										if (i == 100) clearInterval(T); 
									}, 10); 
							
						}
				}
	}
	
function change_video(url)
	{
		var X = o("video"); 
		var A = document.createElement("A"); 
		A.href="../pages/restaurant/commercials/" + url;  
		A.style.display="block"; 
		A.style.width="500px";
		A.style.heigh="375px";  
		A.id="player"
		X.innerHTML=""; 
		X.appendChild(A); 
		flowplayer("player", "pages/restaurant/flowplayer-3.0.7.swf");
	}
	
var lp_709c=0;
function lp_709()
	{
			var ARR = new Array(); 
			ARR[0] = "pages/restaurant/landing/Page1.jpg";
 			ARR[1] = "pages/restaurant/landing/Page2.jpg";
            ARR[2] = "pages/restaurant/landing/Page3.jpg";
            ARR[3] = "pages/restaurant/landing/Page4.jpg";
            ARR[4] = "pages/restaurant/landing/Page5.jpg";
			ARR[5] = "pages/restaurant/landing/Page6.jpg";
			ARR[6] = "pages/restaurant/landing/Page7.jpg";
            ARR[7] = "pages/restaurant/landing/Page8.jpg";

            var x = document.getElementById("limg"); 
			if (lp_709c >= ARR.length - 1) lp_709c = 0; 
			else lp_709c++; 
			x.src=ARR[lp_709c]; 
			
	}	

var lp_710c=0;
function lp_710()
	{
			var ARR = new Array(); 
			ARR[0] = "pages/restaurant/landing/mothersday.jpg";
 		

            var x = document.getElementById("limg"); 
			if (lp_710c >= ARR.length - 1) lp_710c = 0; 
			else lp_710c++; 
			x.src=ARR[lp_710c]; 
			
	}	