function quiet(){
	return true;
}
window.onerror = quiet;
function printme(){
	window.print();
}
function closeme(){
	window.close();
}
function $(id){
  return (document.getElementById(id));
}
/*
function createEl(x){
	return(document.createElement(x));
}
function addCss(path,media){
	var c = createEl("link");
	if (c){
		if (media.length<=0){
			media = "all";
		}
		c.setAttribute("media", media);
		c.setAttribute("rel", "stylesheet");
		c.setAttribute("type", "text/css");
		c.setAttribute("href", path);
		var htmlHeader = document.getElementsByTagName("head");
		htmlHeader[0].appendChild(c);
	}
}
*/
function toggleDiv(id,mode){
	var e = $(id);
	if (e){
		mode = (mode==1) ? 1 : 0;
		var d = "none";
		var v = "hidden";
		if (mode==1){
			d = "block";
			v = "visible";
		}else if (mode==2){
			d = "inline";
			v = "visible";
		}
		e.style.display = d;
		e.style.visibility = v;
	}
}
function submenuExpand(){
	var arr = ['submenu1', 'submenu2'];
	for (var i=0; i<arr.length; i++){
		var e = $(arr[i]);
		if (e){
			var lis = e.getElementsByTagName("li");
			for (var j=0; j<lis.length; j++){
				lis[j].onclick = function(){
					var ahrefs = lis[j].getElementsByTagName("a");
					if (ahrefs[0]){
						window.location = ahrefs[0].getAttribute("href");
					}
				};
			}
		}
	}
}
function addMenu(){
  var e = $("swfMenu");
  if (e){
  	var menuArr = ["/the-cultural-precinct/", "/the-artisans/", "/eat-drink-be/", "/arts-and-events/", "/the-precincts-map/", "/the-precincts-gallery/", "/reach-for-the-stars/","/disclaimer/"];
  	var path = window.location.href;
  	var section = 100;
  	var o;
  	for (var i=0; i<menuArr.length; i++){
  		if (path.indexOf(menuArr[i])!=-1){
  			section = i;
  			break;
  		}
  	}
		o = (section==5) ? {in_id: section, menucolor: 1} : {in_id: section};
    attachSwf("swfMenu","/media/common/menu.swf", "soMenu", "158", "245", "8", "#ffffff", o);
	}
}
function attachSwf(divId, path, soId, w, h, v, bg, param){
  var e = $(divId);
  if (e){
    var so = new SWFObject(path, soId, w, h, v, bg);
    so.addParam('allowScriptAccess', 'sameDomain');
    so.addParam('scale', 'noborder');
    if (divId!='swfPrecinctMap'){
      so.addParam('wmode', 'transparent');
    }
    for (var prop in param){
      so.addVariable(prop, param[prop]);
    }
    so.write(divId);
	 			
    if (!$(soId)){
      if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
      	  	if ((window.location.pathname == "/") || (window.location.href.indexOf("the-precincts-map")!= -1) || (window.location.href.indexOf("the-precincts-gallery")!= -1) || (window.location.href.indexOf("reach-for-the-stars")!= -1))
				window.location.href="/site-map/";
			
			if (divId == "swfMenu") {
				var n=document.getElementById(divId);
				n.innerHTML='<img style="margin-top:175px" src="/images/common/logo.gif" alt="Starstreet"/>';
			}
	  } else {		
      	window.location.href="/noFlash.html";
      }
    } else if(navigator.userAgent.match(/iPhone/i)) {
  	  if ((window.location.pathname == "/") || (window.location.href.indexOf("the-precincts-map")!= -1) || (window.location.href.indexOf("the-precincts-gallery")!= -1) || (window.location.href.indexOf("reach-for-the-stars")!= -1))
		window.location.href="/site-map/";

		if (divId == "swfMenu") {
			var n=document.getElementById(divId);
			n.innerHTML='<img style="margin-top:175px" src="/images/common/logo.gif" alt="Starstreet"/>';
		}
   }
  }
}
function popwin(url, nam, w, h, resizable, scrollbars, toolbar, locationbar, directories, status, menubar){
	var prop = "";
	if (w != ""){
		prop = (prop=="") ? "" : prop+",";
		prop += "width="+w;
	}
	if (h == "" && window.screen.availHeight && window.screen.height){
		if (window.screen.availHeight != window.screen.height){
		  h = (window.screen.availHeight>window.screen.height) ? window.screen.height : ((window.screen.availHeight<window.screen.height) ? window.screen.availHeight : 680);
    }
  }
  if (document.documentElement && document.documentElement.clientWidth){
    h -= 60;
  }
	prop = (prop=="") ? "" : prop+",";
	prop += "height="+h;
	if (resizable != ""){
		prop = (prop=="") ? "" : prop+",";
		prop += "resizable="+resizable;
	}
	if (scrollbars != ""){
		prop = (prop=="") ? "" : prop+",";
		prop += "scrollbars="+scrollbars;
	}
	if (toolbar != ""){
		prop = (prop=="") ? "" : prop+",";
		prop += "toolbar="+toolbar;
	}
	if (locationbar != ""){
		prop = (prop=="") ? "" : prop+",";
		prop += "location="+locationbar;
	}
	if (directories != ""){
		prop = (prop=="") ? "" : prop+",";
		prop += "directories="+directories;
	}
	if (status != ""){
		prop = (prop=="") ? "" : prop+",";
		prop += "status="+status;
		prop = (prop=="") ? "" : prop+",";
		prop += "statusbar="+status;
	}
	if (menubar != ""){
		prop = (prop=="") ? "" : prop+",";
		prop += "menubar="+menubar;
	}
	if (window.screen && w!="" && h!="") {
		var left = (screen.width-w)/2;
		//var top = 0;
		var top = (screen.height-h)/2;
    prop += ",top="+top+",left="+left;
	}
	var winchild = window.open(url, nam, prop);
	if (winchild){
		winchild.opener = this;
		winchild.focus();
	}
}
function popwinHappenings(){
	var divMain = $("main");
	if (divMain){
		var a = divMain.getElementsByTagName("a");
		for (i=0; i<a.length; i++){
			if (a[i].className.indexOf("popHappenings")!=-1){
				a[i].onclick = function(){
					var url = this.getAttribute("href");
					//popwin(url, "stpop", "780", "680", "no", "yes", "no", "no", "no", "yes", "no");
					popwin(url, "stpop", "780", "", "no", "yes", "no", "no", "no", "yes", "no");
					return false;
				}
			}
			// for share-with-friends pop up under eat-drink-be
			else if (a[i].className.indexOf("popWho")!=-1){
				a[i].onclick = function(){
					var url = this.getAttribute("href");
					popwin(url, "sharepop", "780", "570", "no", "yes", "no", "no", "no", "yes", "no");
					return false;
				}
			}
		}
	}
}

function happeningsSubNav(){
  var e = $("popupSubmenu");
  if (e){
    var lis = e.getElementsByTagName("li");
    for (i=0; i<lis.length; i++){
      var li = lis[i];
      if (li.className!="current"){
        var divs = li.getElementsByTagName("span");
        for (j=0; j<divs.length; j++){
          var div = divs[j];
          if (div.className == "on" || div.className == "off"){
          div.onmouseover = happeningsSubNavToggleOn;
          div.onmouseout = happeningsSubNavToggleOff;
          }
        }
      }
    }
  }
}
function happeningsSubNavToggleOn(){
  var myId = this.id.substring(0, this.id.indexOf('O'));
  toggleDiv(myId+'On',1);
  toggleDiv(myId+'Off',0);
}
function happeningsSubNavToggleOff(){
  var myId = this.id.substring(0, this.id.indexOf('O'));
  toggleDiv(myId+'On',0);
  toggleDiv(myId+'Off',1);
}
function menuOn(){
  toggleDiv(this.id+"On", 1);
  toggleDiv(this.id+"Off", 0);
}
function menuOff(){
  toggleDiv(this.id+"On", 0);
  toggleDiv(this.id+"Off", 1);
}
function attachRollover(e){
  var ahrefs = e.getElementsByTagName("a");
  for (var i=0; i<ahrefs.length; i++){
    ahrefs[i].onmouseover = menuOn;
    ahrefs[i].onmouseout = menuOff;
  }
}
function menuRoll(){
  var menuArr = ["header","footer","homefooter","whoBtn","vibeScenes","vibeGallery","artisansBtn"];
  for (k=0; k<menuArr.length; k++){
    var e = $(menuArr[k]);
    if (e){
      if (menuArr[k]=="artisansBtn"){
        var divs = e.getElementsByTagName("div");
        for (var j=0; j<divs.length; j++){
          if (divs[j].className=="linkBtn"){
            attachRollover(divs[j]);
          }
        }
      }else{
        attachRollover(e);
      }
    }
  }
}
function morph(h){
  var e = $('swfArtisans');
  var s = $('soArtisans');
  if (e && h>450){
    e.style.height = h + "px";
    s.style.height = h + "px";
  }
}
function setContent(id,htm){
  var e = $(id);
  if (e){
    e.innerHTML = htm;
  }
}
function setLogStatus(){
  setContent('logmsg','You are logged in');
}
function callSubmit(){
  callExternalInterface("soStreetVibeGallery");
}
function callExternalInterface(id) {
/* Call a function registered as callPlayBall in the SWF named myMovie. */
getMovieName(id).callLogin(); 
}
/* This utility function resolves the string movieName to a Flash object reference based on browser type. */
function getMovieName(movieName) {
  if (navigator.appName.indexOf("Microsoft") != -1) {
    return window[movieName];
  } else {
    return document[movieName];
  }
}
var followupEIM;
function ExternalInterfaceManager(){
  this.registerMovie = function(movieName) {
    if(!window.fakeMovies) window.fakeMovies = new Array();
    window.fakeMovies[window.fakeMovies.length] = movieName;
  }
  this.initialize = function() {
    if(document.all){
      if(window.fakeMovies){
        for(i=0;i<window.fakeMovies.length;i++){
          window[window.fakeMovies[i]] = new Object();
        }
        if (typeof(window.onload)=="function") followupEIM = window.onload;
        window.onload = initializeExternalInterface;
      }
    }
  }
}
function initializeExternalInterface(){
  for(i=0;i<window.fakeMovies.length;i++){
    var movieName = window.fakeMovies[i];
    var fakeMovie = window[movieName];
    var realMovie = $(movieName);
    for(var method in fakeMovie){
      realMovie[method] = function() {flashFunction = "<invoke name=\"" + method.toString() + "\" returntype=\"javascript\">" + __flash__argumentsToXML(arguments, 0) + "</invoke>";this.CallFunction(flashFunction);}
    }
    window[movieName] = realMovie;
  }
  if (typeof(followupEIM)=="function") followupEIM();
}
function pophome(){
  var e = $("pophome");
  if (e){
    e.onclick = function(){
      if (window.opener){
        window.opener.location = "/";
        window.opener.focus();
        window.close();
      }
      return false;
    }
  }
}
function init(){
/* START remove when move to production server */
/*
	if (window.location.href.indexOf(".aspx")!=-1 || window.location.href.indexOf("http://192.168.1.")!=-1){
  	var divs = ["outermost","popup"];
  	var cssArr = ["the-cultural-precinct", "the-artisans", "eat-drink-be", "arts-and-events", "the-precincts-map", "the-precincts-gallery", "reach-for-the-stars"];
    var siteArr = ["cultural", "artisans", "who", "happenings", "what", "vibe", "reach"];
  	for (var j=0; j<divs.length; j++){
  		var e = $(divs[j]);
  		if (e){
  			for (var i=0; i<siteArr.length; i++){
  				if (e.className == siteArr[i]){
  					addCss("/css/"+cssArr[i]+".css","all");
  					break;
  				}
  			}
  		}
  	}
	}
*/
/* END remove when move to production server */
	// global rollover menu items
	menuRoll();
	addMenu();
  // detail page submenu - the artisans, who's here
  if (window.location.href.indexOf("/detail/?id=")!=-1){
	submenuExpand();
	}
	// happenings popup links and popup pages menu
	popwinHappenings();
	happeningsSubNav();
	pophome();
  // page specific swf
  if ($("swfHome")){
    attachSwf("swfHome","/media/home/home.swf", "soHome", "960", "600", "8", "#ffffff", {s:getQueryParamValue("s")});  
  }
  if ($("swfArtisans")){
    attachSwf("swfArtisans","/media/artisans/landing.swf", "soArtisans", "695", "100%", "8", "#ffffff", {});
  }
  if ($("swfPrecinctMap")){
    attachSwf("swfPrecinctMap","/media/what/map.swf", "soPrecinctMap", "695", "560", "8", "#ffffff", {id:getQueryParamValue("id")});
  }
  if ($("swfReachForTheStars")){
    var rftsId = (getQueryParamValue("id")=="") ? -1 : getQueryParamValue("id");
    attachSwf("swfReachForTheStars","/media/reach/stars.swf", "soReachForTheStars", "960", "560", "8", "#474546", {id:rftsId});
  }
	if (typeof(followup)=="function"){
		followup();
	}
}
var followup = null;
if (typeof(window.onload)=="function"){
	followup = window.onload;
}
window.onload = init;

