/* 
 Chris McKee
 Virtual Tour Search Results Override
 $LastChangedRevision: 1113 $
*/
(function replaceElementsByClass(searchClass) {
	node = document;
	tag = '*';

	var els = node.getElementsByTagName(tag),
		elsLen = els.length,
		pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"),
		count = 1;
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
				var re1='.*?';	// Non-greedy match on filler
				var re2='(\\\'.*?\\\')';// Single Quote String 1
				var p = new RegExp(re1+re2,"i"),
					tmp = els[i].getAttributeNode('onclick') != null ? els[i].getAttributeNode('onclick').value : "";
				if(tmp != "")
				{
					var m = p.exec(tmp),
						popURL = "";
					if (m != null)
					{
					  var strng1=m[1];
					  popURL = strng1.replace(/'/g,'');
					}
					els[i].removeAttribute("onclick");
					
					var w = "830",
						h = "698";

					var standard = /VirtualTour.aspx/gi,
						gres = standard.test(popURL);
					if(gres){w="430"; h="440"; }

					//EHOUSE Override
					var ehouse =/ehouse/gi,
						eres = ehouse.test(popURL),
						ehouseprem = /.html/gi,
						eresb = ehouseprem.test(popURL);
						
					if(eres){ 
						w="430"; h="440"; 
						if(eresb){ w="850"; h="720"; }
					}
					
					//Flash Factory (SPAIN) Override
					var flashFactory = /360Factory/gi,
						fres = flashFactory.test(popURL);
					
					//Scotland 360 Override
					var flashScotland = /360Scotland/gi,
						fscot = flashScotland.test(popURL);
					if(fscot){ w="680"; h="480"; }
		
					popURL = popURL + "?keepthis=true&tb_iframe=true&height=" + h + "&width=" + w;
					
					if(eres || fscot)
					{
						els[i].href = "javascript:void(window.open('"+popURL+"','VirtualTours','resizable=no,scrollbars=no,status=no,innerWidth=830,innerHeight=698,centerscreen=true'));";
					}
					else
					{
						els[i].href = "javascript:void($.thickbox_open('Virtual Tours', '"+popURL+"',''));";
					}
					els[i].setAttribute("onclick", "_gaq.push(['_trackEvent', 'VirtualTour', 'SearchResultsPage']);");
					
				}
				j++;
				count++;
		}
	}

})("vtthickbox");
