var video;
var initialize = new domFunction(init);


function init()
{///////////////////////////////////////////////////////////////////////////////////////////////

//if (!document.getElementById||!document.appendChild) {return true;}
document.getElementById("header").getElementsByTagName("div")[0].onclick=function(){location.href="/"};

video=document.getElementById("rolik");if(video) {flashvideo();}

newDiv("header","photo");
newDiv("header","time");
newDiv("header","globe");

/*if(location.href.match(/ru\//)) {
    time1("Moscow",3,"alt_moscow.png"); time1("Kyiv",2,"alt_kiev.png");};
if(location.href.match(/ua\//)) {time1("Kyiv",2,"alt_kiev.png"); time1("Moscow",3,"alt_moscow.png");};*/
time1("Kyiv",2,"/media/design/images/alt_kiev.png");
time1("Moscow",3,"/media/design/images/alt_moscow.png");
time1("Nicosia",2,"/media/design/images/alt_nicosia.png"); // Eastern European Standard Time = GMT+2 Summer Time = GMT+3
time1("London",0,"/media/design/images/alt_london.png");
//time1("Tortola",-4,"/media/design/images/alt_tortola.png"); // Atlantic Standard Time, GMT-4, Local Time Zone: America/Tortola
time1("New%20York",-5,"/media/design/images/alt_newyork.png");

flash("globe","/media/design/images/globe.swf","/media/design/images/globe.png");

if(document.getElementById("map")) {setMap()};

validationlinks();
/*
jurLinks();
for (i=0; i< topNavIds.length; i++) {if(document.getElementById(topNavIds[i])) {topNavLnk[i] = document.getElementById(topNavIds[i]);}}
topNav();
*/

//if (window.opera) {document.documentElement.className = document.documentElement.className;}

//if((document.body.id=="index")&&(location.href.match(/amondsmith\.ru/))) {drawCurrency()}


if(document.body.id=="resources"&&document.getElementById("resources-links"))
{
var links = document.getElementById("resources-links").getElementsByTagName("a");
for(i=0;i< links.length;i++)
{
if(links[i].href==location.href) {links[i].className="selected";links[i].removeAttribute("href");}
}
// document.body.id = document.getElementsByTagname("body")[0].id;
// if (document.recalc) document.recalc(); // IE7
}

}///////////////////////////////////////////////////////////////////////////////////////////////



function liveinternet()
{
document.write("<a href='http://www.liveinternet.ru/click' "+
"target=_blank id=live-internet><img src='http://counter.yadro.ru/hit?t45.10;r"+
escape(document.referrer)+((typeof(screen)=="undefined")?"":
";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth?
screen.colorDepth:screen.pixelDepth))+";u"+escape(document.URL)+
";"+Math.random()+
"' alt='' title='LiveInternet' "+
"border=0 width=31 height=31><\/a>")
}

function flashvideo(target,flv,img)
//////////////////////////////////////// height and width must be set by CSS!
{
var requiredMajorVersion = 8;
var requiredMinorVersion = 0;
var requiredRevision = 22;
var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
if(!hasRightVersion) return null;
var el=document.createElement("span");
var flv=video.getElementsByTagName("a")[0].href.replace(".mp4",".flv");
flv="/media/flvplayer.swf?video="+flv+"&autoplay=true";
var alt=video.innerHTML;video.innerHTML="";
var
t = "<object type=application/x-shockwave-flash data="+ flv +" wmode=transparent quality=best>"
t+= "<param name=movie value="+ flv +">";
t+= "<param name=wmode value=transparent><param name=quality value=best>";
t+= alt;
t+= "</object>";
el.innerHTML=t;
video.appendChild(el);
}






////////////////////////  creating and appending new DIVs ///////////////

function newDiv(target,divId)
{
var div=document.createElement("div"); div.id=divId;
document.getElementById(target).appendChild(div);
}


function drawCurrency()
{

var meta = document.createElement("meta");
    meta.setAttribute("http-equiv","Pragma");
    meta.setAttribute("content","no-cache");
document.getElementsByTagName("head")[0].appendChild(meta);

var img = document.createElement("img");
    img.src = "http://pics.rbc.ru/img/grinf/usd/eur_cb_forex_000066_88x90.gif?" + Math.floor( 100000*Math.random() );
var lnk = document.createElement("a");
    lnk.href = "http://www.informer.ru/cgi-bin/redirect.cgi?id=177_1_1_33_40_1-0&url=http://www.rbc.ru&src_url=usd/eur_cb_forex_000066_88x90.gif";
var li = document.createElement("li");
    li.id = "currencies";
    li.className = "noprint";
    lnk.appendChild(img);
    li.appendChild(lnk);
document.getElementById("links-menu").appendChild(li);
}





////////////////////  flash watch time offset definitions ////////////////
var cities =
{
Kyiv:1,
Moscow:2,
Nicosia:1,
London:-1,
//Tortola:-5,
NewYork:-6   //too bad I can't use spaces in the name
}

///////////////   directly inputting city and offset ////////////////
function time1(city,offset,img)
{
var swf= "/media/design/images/time.swf?city="+city+"&offset="+offset;
flash("time",swf,img);
}

//////////////   using a cities hash above //////////////////////////
function time2(city)
{
var swf= "/media/design/images/time.swf?city="+city+"&offset="+cities[city];
flash("time",swf);
}



function flash(target,swf,img)
//////////////////////////////////////// height and width must be set by CSS!
{
var el=document.createElement("span");
var
t = "<object type=application/x-shockwave-flash data="+ swf +" wmode=transparent quality=best>"
t+= "<param name=movie value="+ swf +">";
t+= "<param name=wmode value=transparent><param name=quality value=best>";
t+= "</object>";
el.innerHTML=t;
//if(img){i=document.createElement("img"); i.src=img; el.firstChild.appendChild(i);};
document.getElementById(target).appendChild(el);
}

// DOM-based js works fime in Mozilla - fails in IE


////////////// jurisdiction maps  /////////////////
var jurisdictions =
{
bahamas:       {left:9, top:72},
belize:        {left:3, top:80},
bvi:           {left:14, top:78},
cyprus:        {left:80, top:60},
dominica:      {left:20, top:81},
gibraltar:     {left:63, top:58},
hongkong:      {left:148, top:75},
liechtenstein: {left:76, top:47},
luxembourg:    {left:70, top:45},
mauritius:     {left:108, top:90},
panama:        {left:5, top:86},
stkitts_nevis: {left:20, top:80},
seychelles:    {left:107, top:98},
suisse:        {left:75, top:50},
turks_caicos:  {left:15, top: 73},
uk:            {left:63, top: 40},
uruguay:       {left:20, top:123},
usa:           {left:0, top:60}
}

function setMap()
{
var m=document.getElementById("map");
var p=m.getElementsByTagName("img")[0];
var j=p.src.split("/");
    j=j[j.length-1].slice(4,-4);
t = document.createTextNode("Посмотреть карту");
s = document.createElement("span");
s.id="loco";
s.style.left = jurisdictions[j]["left"]+"px";
s.style.top  = jurisdictions[j]["top"]+"px";
s.appendChild(t);
m.appendChild(s);
m.onclick=function()
  {
  p.style.visibility=p.style.visibility=="visible" ? "hidden"  : "visible";
  s.style.visibility=s.style.visibility=="hidden"  ? "visible" : "hidden";
document.documentElement.className = document.documentElement.className;
  }

}

//////////////  re-locating links for jurisdictions  ////////////////

function jurLinks()
{
    alert('!');
if(document.getElementById("links-offshore"))
{
var lo = document.getElementById("links-offshore");
if(document.getElementById("jurisdiction"))
{
var ul = document.createElement("ul"); ul.id="links-offshore-new";
var li = lo.getElementsByTagName("li");
var lk = [];
for (i=0;i < li.length;i++) {lk[i]=li[i]}
for (i=0;i < lk.length;i++) {ul.appendChild(lk[i])}
document.getElementById("content").insertBefore(ul,document.getElementById("map").nextSibling);
}
document.body.removeChild(lo);
}
}


var topNavLi=[];
var topNavIds=["lnk-links","lnk-searc","lnk-adres","lnk-press"]
var topNavLnk=[];

function topNav()
{

ul = document.createElement("ul");
ul.id="toplinks";
var begin = document.createElement("i"); begin.id="begin"; ul.appendChild(begin);
var end   = document.createElement("i"); end.id  ="end";   ul.appendChild(end);

for (i=0;i< topNavLnk.length; i++)
{
topNavLi[i]=topNavLnk[i];
topNavLi[i].id="";
ul.appendChild(topNavLi[i]);
}

document.body.appendChild(ul);

}






////////////// new window open    /////////////////

function newWin(fileToOpen,nameOfWindow,windowWidth,windowHeight) {
    x='width='+windowWidth;
    y='height='+windowHeight;
	features = x+","+y+",location=0,menubar=0,resizable=1,scrollbars=0,status=0,toolbar=0";
	window.open(fileToOpen,nameOfWindow,features);
}


//////////////  validation links  /////////////////

function validationlinks()
{
var    ul=document.createElement("ul");   ul.id="validators";
var   li1=document.createElement("li");  li1.id="validxhtml";
var   li2=document.createElement("li");  li2.id="validcss";
var link1=document.createElement("a") ;
var link2=document.createElement("a") ;
var text1=document.createTextNode("xhtml 1.0");
var text2=document.createTextNode("css 2");
link1.href="http://validator.w3.org/check/referer";
link2.href="http://jigsaw.w3.org/css-validator/validator?uri="+location.href;
link1.title="Valid XHTML 1.0 Strict";
link2.title="Valid CSS";
link1.appendChild(text1);
link2.appendChild(text2);
li1.appendChild(link1);
li2.appendChild(link2);
ul.appendChild(li1);
ul.appendChild(li2);
document.body.appendChild(ul);
}


//////////////  style switcher //////////////////
function fixed()
{
document.getElementById("designby").getElementsByTagName("a")[0].onclick=function()
{
document.body.className = document.body.className=="fixed"?"fluid max-limited":"fixed";
alert(document.body.className);
return false;
}
}









//////////////////////////////////////////////////////////////////////////////////
// DF1.1 :: domFunction
// *****************************************************
// DOM scripting by brothercake -- http://www.brothercake.com/
// GNU Lesser General Public License -- http://www.gnu.org/licenses/lgpl.html
//******************************************************
//DOM-ready watcher
function domFunction(f, a)
{
//initialise the counter
var n = 0;

//start the timer
var t = setInterval(function()
{
                  //continue flag indicates whether to continue to the next iteration
var c = true;     //assume that we are going unless specified otherwise
n++;              //increase the counter

//if DOM methods are supported, and the body element exists
//(using a double-check including document.body, for the benefit of older moz builds [eg ns7.1]
//in which getElementsByTagName('body')[0] is undefined, unless this script is in the body section)

if(typeof document.getElementsByTagName != 'undefined' && (document.getElementsByTagName('body')[0] != null || document.body != null))
{
c = false;                //set the continue flag to false because other things being equal, we're not going to continue
if(typeof a=='object')    //but ... if the arguments object is there
{
for(var i in a) //iterate through the object
{
/* if its value is "id" and the element with the given ID doesn't exist
   or its value is "tag" and the specified collection has no members */
if((a[i]=='id' && document.getElementById(i)==null)||(a[i]=='tag' && document.getElementsByTagName(i).length < 1))
{
c = true;  /*set the continue flag back to true because a specific element or collection doesn't exist*/
break;     /*no need to finish this loop as long a single element is found*/
}
}
}
if(!c) {f();clearInterval(t);} /*if we're not continuing we can call the argument function and clear the timer*/
}
/*if the timer has reached 60 (so timeout after 15 seconds)
in practise, I've never seen this take longer than 7 iterations in kde3
in second place was IE6, which takes 2 or 3 iterations roughly 5% of the time */
if(n >= 60){clearInterval(t);}  //clear the timer
},500);
};
////////////////////////////////////////////////////////////////////////////////////





//v1.7
// Flash Player Version Detection
// Detect Client Browser type
// Copyright 2005-2007 Adobe Systems Incorporated.  All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function ControlVersion()
{
var version;
var axo;
var e;
try {axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");version = axo.GetVariable("$version");} catch (e) {}
if (!version) {try {axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");version = "WIN 6,0,21,0"; axo.AllowScriptAccess = "always"; version = axo.GetVariable("$version");} catch (e) {}}
if (!version) {try {axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3"); version = axo.GetVariable("$version");} catch (e) {}}
if (!version) {try {axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3"); version = "WIN 3,0,18,0";} catch (e) {}}
if (!version) {try {axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); version = "WIN 2,0,0,11";} catch (e) {version = -1;}}
return version;
}


function GetSwfVer(){
var flashVer = -1;
if (navigator.plugins != null && navigator.plugins.length > 0)
{
if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"])
{
var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
var descArray = flashDescription.split(" ");
var tempArrayMajor = descArray[2].split(".");
var versionMajor = tempArrayMajor[0];
var versionMinor = tempArrayMajor[1];
var versionRevision = descArray[3];
if (versionRevision == "") {versionRevision = descArray[4];}
if (versionRevision[0] == "d")
{
versionRevision = versionRevision.substring(1);
} else if (versionRevision[0] == "r")
{
versionRevision = versionRevision.substring(1);
if (versionRevision.indexOf("d") > 0) {versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));}}
var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
}
}
else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
else if ( isIE && isWin && !isOpera ) {flashVer = ControlVersion();}
return flashVer;
}


function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
versionStr = GetSwfVer();
if (versionStr == -1 ) {return false;}
else if (versionStr != 0)
{
if(isIE && isWin && !isOpera) {
tempArray    = versionStr.split(" ");
tempString   = tempArray[1];
versionArray = tempString.split(",");
} else {versionArray = versionStr.split(".");}
var versionMajor      = versionArray[0];
var versionMinor      = versionArray[1];
var versionRevision   = versionArray[2];
if (versionMajor > parseFloat(reqMajorVer)) {return true;}
else if (versionMajor == parseFloat(reqMajorVer))
{
if (versionMinor > parseFloat(reqMinorVer))	return true;
else if (versionMinor == parseFloat(reqMinorVer))
{
if (versionRevision >= parseFloat(reqRevision))	return true;}
}
return false;
}
}
