/**
 * popup.js
 * JavaScript used on all popup ianritchiearchitects.co.uk pages
 */

/* map the popup function in the main window */
var popup = top.window.popup;
/* map the addToHistory function in the main window */
var addToHistory = top.window.addToHistory;
/* global reference to the div with overflow set to "auto" */
var scrollingDiv = false;
/* initialization */
window.onload = function()
{
    /* if this is a data page, add it to history */
		if (window.location.href.indexOf('menus/') == -1) {
		    //addToHistory(window.location.href);
		}
		getScrollingDiv();
		makeAnchorsScrollWhenClicked();
		if (window.location.search.indexOf('?scrollto=') == 0) {
		    scrollDivToAnchor(window.location.search.substring(10));
		}
		/*if (window.location.href.indexOf("#") != -1) {
		    scrollDivToAnchor(window.location.href.split("#")[1]);
		}*/
}
function showLocation() { alert(window.location.href); }
function getScrollingDiv()
{
    if (document.getElementById) {
		    if (document.getElementById("th-content")) {
				    scrollingDiv = document.getElementById("th-content");
				} else if (document.getElementById("ih-content")) {
				    scrollingDiv = document.getElementById("ih-content");
				}
		}
}
/**
 * makeAnchorsScrollWhenClicked
 * fix bug in Safari which prevents scrolling divs with overflow set to auto to named anchors
 * from:
 * http://blog.deconcept.com/2005/03/25/safari-and-links-to-elements-in-overflow-auto-content
 */
function makeAnchorsScrollWhenClicked()
{
	  /* make sure we aren't in a menu window */
		if (window.location.href.indexOf("menus/") == -1) {
    		if (document.getElementById && document.getElementsByTagName) {
		        var atags = document.getElementsByTagName("A");
		        for (var i = 0; i < atags.length; i++) {
			          var ca = atags[i];
			          if (ca.href.indexOf("#") > -1) {
				            ca.onclick = function() {
					              scrollDivToAnchor(this.href.split("#")[1]);
				            }
			          }
		        }
	      }
		}
}
function scrollDivToAnchor(anchorId)
{
    if (scrollingDiv && document.getElementById(anchorId)) {
        scrollingDiv.scrollTop = document.getElementById(anchorId).offsetTop - 5;
		}
}
/**
 * movie loading script
 * @requires SWFObject
 */
function loadMovie(movie, width, height)
{
    var fo = new SWFObject("/players/flvplayer.swf", "single", width,height,"7");
    fo.addVariable("usefullscreen","false");
    fo.addVariable("image","/players/bg.gif");
    fo.addVariable("width", width);
    fo.addVariable("height", height);
    fo.addVariable("overstretch", "none");
    fo.addVariable("autostart", "true");
    fo.addVariable("shownavigation", "true");
    fo.addVariable("showicons", "false");
    fo.addVariable("backcolor", "0x0055E5");
    fo.addVariable("screencolor", "0x0055E5");
    fo.addVariable("frontcolor", "0xCCCCCC");
    fo.addVariable("lightcolor", "0xFFFFFF");
    fo.addVariable("file", movie);
    fo.write("movieplayer");
}
