if(!rarebrick) var rarebrick = new Object();

function emailSignup() {
	rarebrick.popup(rarebrick.URL_CC,'emailsignup','menubar=yes,resizable=yes,width=375,height=420');
}

rarebrick.getPage = function() {
	var page;
	if(location.href.indexOf('/blog')==-1) {
		page = location.href.substring(location.href.lastIndexOf('/')+1, location.href.length);
	} else {
		page = location.href.substring(location.href.lastIndexOf('/blog')+1, location.href.length);
	}
	return page;
}

rarebrick.timeoutId = 1;

rarebrick.onresize = function() {
	clearTimeout(rarebrick.timeoutId);
	rarebrick.timeoutId = setTimeout('rarebrick.resizeNow()', 200);
}

rarebrick.resizeNow = function() {
	rarebrick.headerVals.W = rarebrick.getHeaderWidth();
	rarebrick.headerVals.H = Math.round(rarebrick.headerVals.W / rarebrick.headerVals.ASPECT);
	
	if(rarebrick.headerVals.H > rarebrick.getHeaderHeight()) {
		rarebrick.headerVals.H = rarebrick.getHeaderHeight();
		rarebrick.headerVals.W = Math.round(rarebrick.headerVals.H * rarebrick.headerVals.ASPECT);
	}
	
	rarebrick.resizeDivs();
	window.onresize = rarebrick.onresize;
}

rarebrick.getHeaderWidth = function() {
	var w;
	if(document.body.offsetWidth) w = document.body.offsetWidth - rarebrick.headerVals.PAD_X*2;
	if(document.body.style.pixelWidth) w = document.body.style.pixelWidth - rarebrick.headerVals.PAD_X*2;

	if(w < rarebrick.headerVals.W_MIN) w = rarebrick.headerVals.W_MIN;
	if(w > rarebrick.headerVals.W_MAX) w = rarebrick.headerVals.W_MAX;
	return Math.round(w); 
}

rarebrick.getHeaderHeight = function() {
	var h;
	if(document.body.offsetHeight) h = document.body.offsetHeight - rarebrick.headerVals.PAD_Y*2;
	if(document.body.style.pixelHeight) h = document.body.style.pixelHeight - rarebrick.headerVals.PAD_Y*2;

	if(h < rarebrick.headerVals.H_MIN) h = rarebrick.headerVals.H_MIN;
	return Math.round(h); 
}

rarebrick.calculateDimensions = function() {
	rarebrick.headerVals.Y1 = Math.round(rarebrick.headerVals.H * .10);
	rarebrick.headerVals.Y2 = Math.round(rarebrick.headerVals.H * .23);
	rarebrick.headerVals.Y3 = Math.round(rarebrick.headerVals.H * .80);
	rarebrick.headerVals.Y4 = Math.round(rarebrick.headerVals.H * .84);
	rarebrick.headerVals.Y5 = Math.round(rarebrick.headerVals.H * .90);
	rarebrick.headerVals.Y6 = Math.round(rarebrick.headerVals.H * .95);
	rarebrick.headerVals.Y7 = Math.round(rarebrick.headerVals.H * .16);
	rarebrick.headerVals.Y8 = Math.round(rarebrick.headerVals.H * .61);
	rarebrick.headerVals.Y9 = Math.round(rarebrick.headerVals.H * .11);

	rarebrick.headerVals.X1 = Math.round(rarebrick.headerVals.W * .12);
	rarebrick.headerVals.X2 = Math.round((rarebrick.headerVals.W - rarebrick.headerVals.X1) * rarebrick.headerVals.contentSplit);
	rarebrick.headerVals.X3 = Math.round((rarebrick.headerVals.W - rarebrick.headerVals.X1) * (1-rarebrick.headerVals.contentSplit));
}

rarebrick.resizeDivHeader = function() {
	var header = document.getElementById('header');
	
	if(!rarebrick.divResizeFlag) {
		header.style.zIndex = '200';
		header.style.position = 'absolute';
	}
	header.style.width = rarebrick.headerVals.W + 'px';
	header.style.height = rarebrick.headerVals.Y2 + 'px';
	
	if(rarebrick.divResizeFlag) rarebrick.resizeFlashHeader();
}

rarebrick.resizeFlashHeader = function() {
	try {
		var flashPlayer = rarebrick.getFlashPlayer('headerInside');
		flashPlayer.onResize(rarebrick.headerVals.W,rarebrick.headerVals.Y2,rarebrick.headerVals.X1);
	} catch(e) {}
}

rarebrick.resizeDivNav = function() {
	var nav = document.getElementById('nav');
	var navBack = document.getElementById('navBack');
	
	if(!rarebrick.divResizeFlag) {
		nav.style.position = navBack.style.position = 'absolute';
		nav.style.zIndex = '300';
		navBack.style.zIndex = '20';
	}
	nav.style.width = navBack.style.width = rarebrick.headerVals.X1 + 'px';
	nav.style.height = navBack.style.height = rarebrick.headerVals.Y6 + 'px';
	nav.style.top = navBack.style.top = '0px';
	
	if(rarebrick.divResizeFlag) rarebrick.resizeFlashNav();
}

rarebrick.resizeFlashNav = function() {
	try {
		var flashPlayer = rarebrick.getFlashPlayer('navInside');
		//alert('flashPlayer: ' + flashPlayer);
		flashPlayer.onResize(rarebrick.headerVals.X1,rarebrick.headerVals.Y6);
	} catch(e) {}
}

rarebrick.resizeDivContent = function() {
	//resize font size
	
	var sizeRel = 1 - (rarebrick.headerVals.W_MAX - rarebrick.headerVals.W) / (rarebrick.headerVals.W_MAX - rarebrick.headerVals.W_MIN);
	var fontSize = rarebrick.headerVals.FONTSIZE_MIN + (sizeRel * (rarebrick.headerVals.FONTSIZE_MAX - rarebrick.headerVals.FONTSIZE_MIN));
	document.body.style.fontSize = fontSize + '%';

	var content = document.getElementById('content');
	var contentHTMLHolder = document.getElementById('contentHTMLHolder');
	var contentHTML = document.getElementById('contentHTML');
	var contentHTMLInside = document.getElementById('contentHTMLInside');
		
	if(!rarebrick.divResizeFlag) {
		content.style.position = 'absolute';
		content.style.zIndex = '20';
		contentHTMLHolder.style.position = 'absolute';
		contentHTMLHolder.style.zIndex = '30';
		contentHTML.style.position = 'absolute';
		contentHTML.style.zIndex = '40';
	}
	
	content.style.width = (rarebrick.headerVals.W - rarebrick.headerVals.X1) + 'px';
	content.style.height = rarebrick.headerVals.Y3 + 'px';
	content.style.top = rarebrick.headerVals.Y1 + 'px';
	content.style.left = rarebrick.headerVals.X1 + 'px';

	contentHTMLHolder.style.height = rarebrick.headerVals.Y3 + 'px';
	contentHTMLHolder.style.top = rarebrick.headerVals.Y1 + 'px';

	contentHTML.style.overflowY = 'hidden';
	contentHTML.style.height = rarebrick.headerVals.Y8 + 'px';
	contentHTML.style.top = (rarebrick.headerVals.Y9+20) + 'px';
	
	if(rarebrick.headerVals.contentFlashLeft == true) {
		contentHTMLHolder.style.width = rarebrick.headerVals.X3 + 'px';
		contentHTML.style.width = rarebrick.headerVals.X3 + 'px';
		contentHTMLHolder.style.left = (rarebrick.headerVals.X1 + rarebrick.headerVals.X2) + 'px';
	} else {
		contentHTMLHolder.style.width = rarebrick.headerVals.X2 + 'px';
		contentHTML.style.width = rarebrick.headerVals.X2 + 'px';
		contentHTMLHolder.style.left = rarebrick.headerVals.X1 + 'px';
	}
	
	
	var insideHeight;
	if(contentHTMLInside.offsetHeight) insideHeight = contentHTMLInside.offsetHeight;
	if(contentHTMLInside.style.pixelHeight) insideHeight = contentHTMLInside.style.pixelHeight;
	
	if(insideHeight > rarebrick.headerVals.Y8-20) contentHTML.style.overflowY = 'scroll';
	
	if(rarebrick.divResizeFlag) rarebrick.resizeFlashContent();
	
	if(rarebrick.gMap) {
		var mapholder = document.getElementById('gmap');
		var delta = rarebrick.headerVals.Y3 * .15;
		var w = rarebrick.headerVals.W - rarebrick.headerVals.X1;
		var h = rarebrick.headerVals.Y3-(delta*1.2);
		mapholder.style.top = delta+'px';
		mapholder.style.width = w+'px';
		mapholder.style.height = h+'px';
		
		if(!rarebrick.mapInited) {
			//startMap();
			rarebrick.mapInited = true;
		}
		/*
		if(map) {
			try {
				//var ysize = new YSize(w,h);
				//map.resizeTo(ysize);
			} catch(e) {}
		}
		*/
	}
}

rarebrick.resizeFlashContent = function() {
	try {
		var flashPlayer = rarebrick.getFlashPlayer('contentInside');
			if(rarebrick.headerVals.contentFlashLeft == true) {
				flashPlayer.onResize(0, rarebrick.headerVals.X2, rarebrick.headerVals.Y3);
			} else {
				flashPlayer.onResize(rarebrick.headerVals.X2, rarebrick.headerVals.X3, rarebrick.headerVals.Y3);
			}
	} catch(e) {}
}

rarebrick.resizeDivFooter = function() {
	var footer = document.getElementById('footer');
	
	if(!rarebrick.divResizeFlag) {
		footer.style.position = 'absolute';
		footer.style.zIndex = '25';
	}
	footer.style.width = rarebrick.headerVals.W + 'px';
	footer.style.height = rarebrick.headerVals.Y7 + 'px';
	footer.style.top = rarebrick.headerVals.Y4 + 'px';
	
	if(rarebrick.divResizeFlag) rarebrick.resizeFlashFooter();
}

rarebrick.resizeFlashFooter = function() {
	try {
		var flashPlayer = rarebrick.getFlashPlayer('footerInside');
		flashPlayer.onResize(rarebrick.headerVals.W,rarebrick.headerVals.Y7,rarebrick.headerVals.X1,rarebrick.headerVals.Y9);
	} catch(e) {}
}

rarebrick.resizeDivFlashReveal = function() {
	var flashReveal = document.getElementById('flashReveal');
	
	if(!rarebrick.divResizeFlag) {
		flashReveal.style.position = 'absolute';
		flashReveal.style.zIndex = '150';
	}
	flashReveal.style.width = (rarebrick.headerVals.W - rarebrick.headerVals.X1) + 'px';
	flashReveal.style.height = rarebrick.headerVals.Y3 + 'px';
	flashReveal.style.top = rarebrick.headerVals.Y1 + 'px';
	flashReveal.style.left = rarebrick.headerVals.X1 + 'px';
	flashReveal.style.display = 'block';
	
	if(rarebrick.divResizeFlag) rarebrick.resizeFlashReveal();
	rarebrick.resizeDivFlashReveal = null;
}

rarebrick.resizeFlashReveal = function() {
	try {
		var flashPlayer = rarebrick.getFlashPlayer('flashRevealInside');
		flashPlayer.onResize(rarebrick.headerVals.W,rarebrick.headerVals.Y1,rarebrick.headerVals.X1,rarebrick.headerVals.Y3);
	} catch(e) {}
}

rarebrick.removeReveal = function() {
	var flashReveal = document.getElementById('flashReveal');
	flashReveal.style.display = 'none';
}

rarebrick.resizeDivSeo = function() {
	return;
	var seo = document.getElementById('seo');
	
	seo.style.width = rarebrick.headerVals.W + 'px';
}

rarebrick.resizeDivs = function() {
	rarebrick.calculateDimensions();
	
	var flashHolder = document.getElementById('flashHolder');
	flashHolder.style.width = rarebrick.headerVals.W + 'px';
	flashHolder.style.height = rarebrick.headerVals.H + 'px';
	
	rarebrick.resizeDivHeader();
	rarebrick.resizeDivNav();
	rarebrick.resizeDivContent();
	rarebrick.resizeDivFooter();
	rarebrick.resizeDivSeo();
	//rarebrick.resizeDivFlashReveal();
	
	rarebrick.divResizeFlag = true;
}

function popup(location, y) {
	var dx=640;
	var dy=360;
	if(y != undefined) dy = y;
	var w = window.open(location, 'popup', 'width=' + dx + ',height=' + dy + ',status=no,resizable=yes,menubar=yes,location=no,scrollbars=yes,toolbar=no');
	w.focus();
}

function popuplg(location, y) {
	var dx=800;
	var dy=500;
	if(y != undefined) dy = y;
	var w = window.open(location, 'popuplg', 'width=' + dx + ',height=' + dy + ',status=no,resizable=yes,menubar=yes,location=no,scrollbars=yes,toolbar=no');
	w.focus();
}

function popDown(location) {
	if(!window.opener.closed) {
		window.opener.location = location;
		window.opener.focus();
	} else {
		var ww = window.open(location);
		ww.focus();
	}
}

function anchorLink(which) {
	document.location = '#' + which + '_a';
}

function bookOnline() {
	var flashid = 'reservePopup';
	var reservePopup = document.getElementById(flashid);
	if(rarebrick.useFlash() == true) {
		//flash
		if(!rarebrick.reservePopupFlag) {
			//init popup
		var flashvars = {};
		flashvars.id = flashid;
		var params = {};
		params.allowScriptAccess = "always";
		params.wmode = "transparent";
		var attributes = {};
		attributes.id = flashid+'_swf';
		
		swfobject.embedSWF(rarebrick.baseURL+'reservePopup.swf', 'reserveFlash', '532', '264', '9.0.0', 'swf/expressInstall.swf', flashvars, params, attributes);
		}
		reservePopup.style.display = 'block';
		reservePopup.style.zIndex = '1000';
	} else {
		//non-flash version
		//pageTracker._getLinkerUrl('http://requests.bookingcenter.com/enquiry.phtml?site=CASLAG');
		pageTracker._link('http://requests.bookingcenter.com/enquiry.phtml?site=CASLAG');
		return false;
	}
}

rarebrick.bookSubmit = function(vars) {
	//flash version submit function
	var arr = vars.split(',');
	//alert('arr: ' + arr);
	var theForm = document.getElementById('bookForm');
	theForm['arrival_month'].value = arr[0];
	theForm['arrival_year'].value = arr[1];
	theForm['arrival_day'].value = arr[2];
	theForm['stay'].value = arr[3];
	theForm['adult'].value = arr[4];
	theForm.submit();
}

rarebrick.hideReserve = function() {
	var flashid = 'reservePopup';
	var reservePopup = document.getElementById(flashid);
	reservePopup.style.display = 'none';
	reservePopup.style.zIndex = '0';
}

rarebrick.playVideo = function() {
	if(rarebrick.useFlash()==true) {
		var vidPopup = document.getElementById('vidPopup');
		vidPopup.style.display = 'block';
		vidPopup.style.zIndex = '999';
		
		var flashvars = {};
		var params = {};
		params.allowScriptAccess = "always";
		//params.wmode = "transparent";
		var attributes = {};
		
		flashvars.MM_ComponentVersion = 1;
		flashvars.skinName = 'video/ClearOverAll';
		flashvars.autoPlay = true;
		flashvars.autoRewind = false;
		
		flashvars.streamName = 'video/CASA_low';
		swfobject.embedSWF('FLVPlayer_Progressive.swf', 'vidFlashInside', '640', '360', '9.0.0', 'swf/expressInstall.swf', flashvars, params, attributes);
	}
}

rarebrick.hideVideo = function() {
	var vidPopup = document.getElementById('vidPopup');
	vidPopup.style.display = 'none';
}






var xmlhttp;


rarebrick.getSpecialsDelayed = function() {
	var timeout = setTimeout(rarebrick.getSpecials, rarebrick.specialsDelay);
}


rarebrick.getSpecials = function() {
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null) {
	  //alert ("Your browser does not support AJAX!");
	  return;
	}
	
	var pagename = document.location.pathname;
	if(pagename.lastIndexOf('/')==pagename.length-1) pagename = pagename.substring(0,pagename.length-1);
	var pos;
	if((pos = pagename.lastIndexOf('/')) != -1) pagename = pagename.substring(pos+1,pagename.length);
	if(pagename=='') pagename = 'index.htm';
	pagename = encodeURIComponent(pagename);
	//alert('page: ' + pagename);
	
		var url="http://www.casalaguna.com/blog/!/specials/popup-special/?mypage=" + pagename;
		xmlhttp.onreadystatechange=stateChanged;
	try {
		xmlhttp.open("GET",url,true);
	} catch(e) { 
		//alert('rb'); 
	}
		xmlhttp.send(null);
}

function stateChanged() {
	if (xmlhttp.readyState==4) {		
		if(xmlhttp.responseText.indexOf('nospecialsfound') != -1) return;
		var elem = document.getElementById("specialDiv");
		elem.innerHTML = elem.innerHTML + xmlhttp.responseText;
		rarebrick.specialShow(elem);
	}
}

function GetXmlHttpObject() {
	if (window.XMLHttpRequest) {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  return new XMLHttpRequest();
	}
	if (window.ActiveXObject) {
	  // code for IE6, IE5
	  return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}

rarebrick.specialShow = function(elem) {
	rarebrick.specialOp = 0;
	rarebrick.setSpecialOp();
	elem.style.display = 'block';
	elem.style.zIndex = '999';
	rarebrick.fadeSpecial(1);
}

rarebrick.setSpecialOp = function() {
	var elem = document.getElementById("specialDiv");
	if(elem.filters) {
		elem.style.filter='alpha(opacity=' + (rarebrick.specialOp*100) + ')';
	}
	else {
		elem.style.opacity = rarebrick.specialOp;
	}
	if(rarebrick.specialOp == 0) {
		elem.style.display = 'none';
		elem.style.zIndex = '1';
	}
}

rarebrick.specialHide = function() {
	rarebrick.fadeSpecial(0);
}

rarebrick.fadeSpecial = function(op) {
	//alert('fade: ' + op + '|' + rarebrick.specialOp);
	var doAgain = true;
	if(op == 1) {
		rarebrick.specialOp = rarebrick.specialOp + .2;
		//alert('rarebrick.specialOp: ' + rarebrick.specialOp);
		if(rarebrick.specialOp > .9) {
			rarebrick.specialOp = .9;
			doAgain = false;
		}
	} else {
		rarebrick.specialOp = rarebrick.specialOp - .3;
		if(rarebrick.specialOp < 0) {
			rarebrick.specialOp = 0;
			doAgain = false;
		}
	}
	rarebrick.setSpecialOp();
	//alert('doAgain: ' + doAgain);
	if(doAgain == true) setTimeout('rarebrick.fadeSpecial('+op+')', 20);
}



if(rarebrick.useFlash() == true) {
	swfobject.addDomLoadEvent(rarebrick.getSpecialsDelayed);
}


function popup(location, y) {
	var dx=640;
	var dy=360;
	if(y != undefined) dy = y;
	var w = window.open(location, 'popup', 'width=' + dx + ',height=' + dy + ',status=no,resizable=yes,menubar=yes,location=no,scrollbars=yes,toolbar=no');
	w.focus();
}
