var HERO_WIDTH = 616;
var HERO_HEIGHT = 519;
var BREADCRUMB_HEIGHT = 24;


// allows Flash to update the browser URL without reloading page
function flashPutHref(href) { location.href = href; }
function flashPutTitle(title) { document.title = title; }


// append a function to the window.onunload event
function AddUnloadEvent(func) { 
	var oldonunload = window.onunload; 
	if (typeof window.onunload != 'function'){ 
		window.onunload = func
	} else { 
		window.onunload = function() {
			oldonunload();
			func();
		}
	}
}

//get browser window width & height
function GetWindowSize() {
  var w = 0;
  var h = 0;

  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    w = window.innerWidth;
    h = window.innerHeight;
  } else if( document.documentElement && document.documentElement.clientWidth ) {
    //IE 6+ in 'standards compliant mode'
    w = document.documentElement.clientWidth;
    h = document.documentElement.clientHeight;
  } else if( document.body && document.body.clientWidth ) {
    //IE 4 compatible
    w = document.body.clientWidth;
    h = document.body.clientHeight;
  }
  return ([w, h]);
}

//get element's x & y position relative to the page document
function GetPosition(el) {
  var x = 0;
  var y = 0;
  if (el.offsetParent) {
		while(1) {
			x += el.offsetLeft;
			y += el.offsetTop;
			if (!el.offsetParent) break;
			el = el.offsetParent;
		}
  } else if (el.x) {
    x += el.x;
    y += el.y;
  }
  return ({x:x, y:y});
}



// resizes Flash photo gallery
function ToggleFlashResize() {

	if ($) {

		var hero = $("hero");
		var flash = $("fsPhotoGallery");
		var banner = $("bannerContent");
		var page_structure = $("pageStructure");
		var footer = $("footerContent");
		var page_title = $("page_title");
		var container1 = $("container1");
		var address = $("addressBar");
		
		
		var browser_dimensions = GetWindowSize();	    

		if (hero.offsetWidth == HERO_WIDTH) {
			
			
			page_structure.style.visibility = "hidden";
			banner.style.visibility = "hidden";
			address.style.visibility = "hidden";
			footer.style.visibility = "hidden";
			hero.style.visibility = "visible";
			
			flash.style.width = HERO_WIDTH;
			flash.style.height = HERO_HEIGHT;	
			
			

			if( typeof( window.innerWidth ) == 'number' ) {
				
				ResizeFlash(browser_dimensions[0] + "px",(browser_dimensions[1]-BREADCRUMB_HEIGHT) + "px");
				banner.style.position = "absolute";
				address.style.position = "absolute";
				page_title.style.position = "absolute";
				container1.style.position = "absolute";
				page_structure.style.position = "absolute";
				page_structure.style.top = 20;
				hero.style.position = "absolute";
				hero.style.left = 0;
				
				
				
			} else {
				
				hero.style.position = "absolute";
				hero.style.left = 0;
				hero.style.top = BREADCRUMB_HEIGHT;
				ResizeFlash(browser_dimensions[0] + "px",(browser_dimensions[1]-BREADCRUMB_HEIGHT) + "px");
			}


		} else {
			page_structure.style.visibility = "visible";
			page_structure.style.position = "";
			page_structure.style.top = "";
			banner.style.position = "";
			banner.style.visibility = "visible";
			address.style.position = "";
			address.style.visibility = "visible";
			page_title.style.position = "";
			container1.style.position = "";
			footer.style.visibility = "visible";
			hero.style.position = "";
			hero.style.top = "";
			hero.style.left = "";
			ResizeFlash(HERO_WIDTH + "px", HERO_HEIGHT + "px");
		}
		
		scrollTo(0,0);
	} 
}

function ResizeFlash(w, h) {
  if ($) {
  	
    var hero = $("hero");
    var flash = $("fsPhotoGallery");
	
	hero.style.width = w;
	hero.style.height = h;

	flash.style.width = w;
	flash.style.height = h ;
        
  }
}

// resize the flash movie to 100% of the browser viewport
function FullScreenFlash() {

  if ($) {
	var browser_dimensions = GetWindowSize();

	var page_structure = $("pageStructure")

	if (page_structure && page_structure.style.visibility == "hidden") {
		ResizeFlash(browser_dimensions[0],browser_dimensions[1]-BREADCRUMB_HEIGHT);
	}
  }
}

Event.observe( window, 'resize', FullScreenFlash);



