﻿var photoIndex_Parent = 0;
var photoIndex_Child = 0;
var theWindow = "Parent";

//Preload images

    //Conventional Oil & Gas
    var og_photo_ary = new Array();
    var og_names_ary = new Array();
    
    og_photo_ary[0]  = new Image(800,600);
    og_photo_ary[0].src = "Images/Gallery/oil-gas/Compressor Facility.JPG";
    og_names_ary[0] = "Kомпрессорные Сооружения";
    
    og_photo_ary[1] = new Image(814,527);
    og_photo_ary[1].src = "Images/Gallery/oil-gas/Compressor Stations .JPG";
    og_names_ary[1] = "Компрессорная станция";
    
    og_photo_ary[2] = new Image(1024,768);
    og_photo_ary[2].src = "Images/Gallery/oil-gas/Compressor Stations.JPG";
    og_names_ary[2] = "Компрессорная станция";
    
    og_photo_ary[3] = new Image(795,623);
    og_photo_ary[3].src = "Images/Gallery/oil-gas/Surface Facility.jpg";
    og_names_ary[3] = "Наземные Сооружения";
    
    og_photo_ary[4] = new Image(790,524);
    og_photo_ary[4].src = "Images/Gallery/oil-gas/Pipelines .JPG";
    og_names_ary[4] = "Трубопровод";
    
    og_photo_ary[5] = new Image(920,616);
    og_photo_ary[5].src = "Images/Gallery/oil-gas/Pipelines.jpg";
    og_names_ary[5] = "Трубопровод";
    
    og_photo_ary[6] = new Image(750,410);
    og_photo_ary[6].src = "Images/Gallery/oil-gas/Gas Processing and Dehydration.jpg";
    og_names_ary[6] = "Установка по Переработке Газа и Дегидрации";
    
    og_photo_ary[7] = new Image(806,605);
    og_photo_ary[7].src = "Images/Gallery/oil-gas/Power Generation.JPG";        
    og_names_ary[7] = "Электрогенераторы";        



    //Heavy Oil
    var ho_photo_ary = new Array();
    var ho_names_ary = new Array();
    
    ho_photo_ary[0] = new Image(750,563);
    ho_photo_ary[0].src = "images/Gallery/Heavy-oil/Gathering and Distribution Systems.jpg";
    ho_names_ary[0] = "Заборные и Распределительные Cистемы";
    
    ho_photo_ary[1] = new Image(750,563);
    ho_photo_ary[1].src = "images/Gallery/Heavy-oil/Hydrogen Manufacturing Unit.jpg";
    ho_names_ary[1] = "Установка Генерации Водорода";
    
    ho_photo_ary[2] = new Image(640,480);
    ho_photo_ary[2].src = "images/Gallery/Heavy-oil/Pad Facilities.JPG";
    ho_names_ary[2] = "Площадка для Скважины";


    //Modular
    var mod_photo_ary = new Array();
    var mod_names_ary = new Array();
    
    mod_photo_ary[0]  = new Image(735,486);
    mod_photo_ary[0].src  = "images/Gallery/modular/Alpine Production Facilities, Alaska.JPG";
    mod_names_ary[0] = "Оборудования и Устройство для Добычи, Элпайн, Аляска";
        
    mod_photo_ary[1]  = new Image(1472,1168);
    mod_photo_ary[1].src  = "images/Gallery/modular/Arctic Drillship Gulf Kulluk, Russia.jpg";
    mod_names_ary[1] = "Буровое Судно, Залив Каллук, Россия";
    
    mod_photo_ary[2]  = new Image(825,546);
    mod_photo_ary[2].src  = "images/Gallery/modular/Large Module Transportation Alpine, Alaska.JPG";
    mod_names_ary[2] = "Перевозка Больших Модулей, Элпайн, Аласка";
    
    mod_photo_ary[3]  = new Image(813,634);
    mod_photo_ary[3].src = "images/Gallery/modular/Sakhalin II - Lunskoye, Russia.jpg";
    mod_names_ary[3] = "Сахалин II, Ланское, Россия";

    mod_photo_ary[4]  = new Image(900,600);
    mod_photo_ary[4].src = "images/Gallery/modular/Sakhalin II - Lunskoye Sailout, Russia.jpg";
    mod_names_ary[4] = "Сахалин II, Ланское, Россия";
    
    mod_photo_ary[5]  = new Image(811,727);
    mod_photo_ary[5].src = "images/Gallery/modular/Sakhalin II - Molikpaq Drilling Rig, Russia.jpg";
    mod_names_ary[5] = "Сахалин II, Маликпак, Буровая Платформа Россия";

    mod_photo_ary[6]  = new Image(637,478);
    mod_photo_ary[6].src = "images/Gallery/modular/Sakhalin II - Molikpaq Under Tow, Russia.JPG";
    mod_names_ary[6] = "Сахалин II, Маликпак Буксировка, Россия";

    mod_photo_ary[7]  = new Image(800,600);
    mod_photo_ary[7].src = "images/Gallery/modular/Sakhalin II - Waterflood Module, Russia.jpg";
    mod_names_ary[7] = "Сахалин II, Модуль Заводнения, Россия";



    function nextPhoto(page)
    {
        detectCallingWindow();
        var curAry = new Array();
        if(page == 'heavyoil')
        {
            curAry = ho_photo_ary;
        }
        else if(page == 'oilgas')
        {
            curAry = og_photo_ary;
        }
        else if(page == 'modular')
        {
            curAry = mod_photo_ary;
        }        
        
        photoIndex_Parent += 1;
        if(photoIndex_Parent >= curAry.length)
        {
            photoIndex_Parent = 0;
        }
        top.document.getElementById("bigPicParent").setAttribute("src",curAry[photoIndex_Parent].src);
        top.frames[0].document.getElementById("bigPicChild").setAttribute("src",curAry[photoIndex_Parent].src);
        
        wideOrTall();
        writeRussianPhotoCaption(page);
    }

    function prevPhoto(page)
    {
        detectCallingWindow();
        var curAry = new Array();
        if(page == 'heavyoil')
        {
            curAry = ho_photo_ary;
        }
        else if(page == 'oilgas')
        {
            curAry = og_photo_ary;
        }
        else if(page == 'modular')
        {
            curAry =mod_photo_ary;
        }

        photoIndex_Parent -= 1;
        if(photoIndex_Parent < 0)
        {
            photoIndex_Parent = curAry.length-1;
        }
        top.document.getElementById("bigPicParent").setAttribute("src",curAry[photoIndex_Parent].src);
        top.frames[0].document.getElementById("bigPicChild").setAttribute("src",curAry[photoIndex_Parent].src);

        wideOrTall();
        writeRussianPhotoCaption(page);
    }
    
    function writeRussianPhotoCaption(page)
    {
         writeRussianPhotoCaptionParent(page);
         writeRussianPhotoCaptionChild(page);
    }
    
    function writeRussianPhotoCaptionParent(page)
    {
    detectCallingWindow();
        var curAry = new Array();
        if(page == 'heavyoil')
        {
            curAry = ho_names_ary;
        }
        else if(page == 'oilgas')
        {
            curAry = og_names_ary;
        }
        else if(page == 'modular')
        {
            curAry = mod_names_ary;
        }
    
         top.document.getElementById("photoNameColParent").innerHTML = curAry[photoIndex_Parent];
    }
   
   
    function writeRussianPhotoCaptionChild(page)
    {
        detectCallingWindow();
        var curAry = new Array();
        if(page == 'heavyoil')
        {
            curAry = ho_names_ary;
        }
        else if(page == 'oilgas')
        {
            curAry = og_names_ary;
        }
        else if(page == 'modular')
        {
            curAry = mod_names_ary;
        }
        
        top.frames[0].document.getElementById("photoNameColChild").innerHTML = curAry[photoIndex_Parent];
    }
   
   
   function detectCallingWindow()
   {
   /*
        if(top.document.getElementById("lgGallery").style.visibility  == 'visible')
        {
            theWindow = 'Child';
        }
        else
        {
            theWindow = 'Parent';
        }
    */
   } 
    
    
    

function wideOrTall()
{
	wideOrTallParent();
	wideOrTallChild();
}



function wideOrTallParent()
{
top.document.getElementById("bigPicParent").style.width  = 'auto';
top.document.getElementById("bigPicParent").style.height = 'auto';

var theParentWidth  = top.document.getElementById("bigPicParent").offsetWidth;	
var theParentHeight = top.document.getElementById("bigPicParent").offsetHeight;	

var wthRatio  = theParentWidth/theParentHeight; //non-zero height... width too
//The ratio will be the same for the photo in the parent window and in the child window

var MAX_PARENT_WIDTH  = 480;
var MAX_PARENT_HEIGHT = 480;

	if(theParentWidth > theParentHeight) //The same for both windows
	{
		//alert("WIDE");	
	}
	else
	{
		//alert("TALL");
	}

	if(theParentWidth > MAX_PARENT_WIDTH)
	{
		theParentWidth = MAX_PARENT_WIDTH;
		theParentHeight = theParentWidth/wthRatio;
	}
	
	if(theParentHeight > MAX_PARENT_HEIGHT)
	{
		theParentHeight = MAX_PARENT_HEIGHT;
		theParentWidth  = theParentHeight*wthRatio;
	}

	top.document.getElementById("bigPicParent").style.width  = theParentWidth;
	top.document.getElementById("bigPicParent").style.height = theParentHeight;
}



function wideOrTallChild()
{
top.frames[0].document.getElementById("bigPicChild").style.width  = 'auto';
top.frames[0].document.getElementById("bigPicChild").style.height = 'auto';

var theChildWidth  = top.frames[0].document.getElementById("bigPicChild").offsetWidth;	
var theChildHeight = top.frames[0].document.getElementById("bigPicChild").offsetHeight;	

var wthRatio  = theChildWidth/theChildHeight; //non-zero height... width too
//The ratio will be the same for the photo in the parent window and in the child window

var MAX_CHILD_WIDTH  = 700;
var MAX_CHILD_HEIGHT = 700;

	if(theChildWidth > theChildHeight) //The same for both windows
	{
		//alert("WIDE");	
	}
	else
	{
		//alert("TALL");
	}

	if(theChildWidth > MAX_CHILD_WIDTH)
	{
		theChildWidth = MAX_CHILD_WIDTH;
		theChildHeight = theChildWidth/wthRatio;
	}
	
	if(theChildHeight > MAX_CHILD_HEIGHT)
	{
		theChildHeight = MAX_CHILD_HEIGHT;
		theChildWidth  = theChildHeight*wthRatio;
	}
	
	top.frames[0].document.getElementById("bigPicChild").style.width  = theChildWidth;
	top.frames[0].document.getElementById("bigPicChild").style.height = theChildHeight;
}