﻿var imageList=new Array();
var width = 1;
var height = 1;
// List the files and their respective index names here.
function storeImageList()
{
    // indexNumber, fileName, width, height

    imageList = [	
        [2209,  'TMG_LeinsterGold_700.jpg', 540, 700,'Therese McGrath - Master Howard'],
        [5509,  'Umpire Group_1000x560.jpg', 1000, 560,'National Umpire Course 2009'],
        [4509,  'Galway Grading 04-04-09_1000x626.jpg', 1000, 626,'Galway Grading 4th April 2009'],
        [3509,  'TeamPhoto_IrishOpen08_1000.jpg', 1000, 779,'Irish Open 2008 - Galway Team'],
        [6509,  'ITF_Int_Seminar_08.jpg',1000, 750,'Pictured at the recent historic ITF International Seminar in Dublin (the first ever to be conducted by an Irish Master): PJ Flaherty, Mr O&#39;Donnell, Ciaran Flatley, Seated: Master Robert Howard VII, Senior Master Barrett VIII, and Master George Vitali VII (USA).'],
        [7509,  'MunsterOpen2008.jpg', 1000, 688,'Munster Open 2008'],
        [8509,  'Athlone Grading 06-09-08.JPG', 1000, 738,'Galway and Athlone Schools Grading 6<sup>th</sup> September 2008'],
        [1509,  'juniorclassgradingjune08.JPG', 800, 600,'Junior Class Grading'],
        [2509,  'euro09_medals_480.jpg', 480, 384,'European Championships 2009  - Irish Medal Winners'],
        [1109,  'Euro09_MrMahony_Pattern_425.jpg', 425, 596,'European Championships 2009 - Mr Mahoney'],                
        [9509,  'euro09_IrishTeam_573.jpg', 573, 430,'Grand Master Rhee Ki Ha, 9th Dan with the Irish Team - European Championships 2009'],
        [9909,  '2009ITFCourseSMB_1000x414.jpg', 1000, 414,'ITF International Course 2009'],
        [5656,  'MrOD_MrM_1000x817.jpg', 1000, 817,'Mr. Krzysztof Misiewicz promoted to ITF 1st Degree Black here with Mr Mark O&#39;Donnell VI Degree'],
        [6666,  'ITFWorlds_1000x629.jpg', 1000, 629,'ITF Worlds Members'],
		[9109,  '4-Nations-Poster_408x555.jpg', 408, 558,'Four Nations and Charity Ball'],
		[1089,  'GMR MOD 05-09-09_571.jpg', 571, 700,'GrandMaster Rhee IX and Mr Mark O&#39;Donnell VI'],
		[1031,  'IMG_4388_1000.jpg', 1000, 546,'A former Irish team member and World Championship gold medalist, Master Howard has turned his attention to instructing and promoting Taekwon-Do over the past 16 years.  In 1993 he co-founded the Galway Taekwon-Do School with fellow instructor Mark O’Donnell, while in 1994, he set up the Stillorgan Taekwon-Do School in Dublin.  Four years later, in 1998, he founded the Athlone Taekwon-Do School, which was the setting for the recent weekend of seminars. Master Howard conducted a colour belt seminar on Saturday 12th September for the members of the Galway & Athlone Schools.  Mr O’Donnell prepared a slideshow documenting Master Howard’s 30 years in TKD and presented him with a commemorative photo album on behalf of the members of both schools.  After the seminar, Master Howard was brought to a local restaurant for a celebratory meal. The following day, the RITA National Black Belt Seminar was held in Athlone, and attended by Black Belts ranging from 1st to 6th Degree from RITA Schools all over the country. A great weekend was had by all. Congratulations to Master Howard on his first 30 years in Taekwon-Do from all of us in Galway! '],
		[1030,  'S5001581_1000.jpg', 1000, 534,'Commemorative Colour Belt Seminar '],
		[1032,  'IMG_4361_600.jpg', 600, 1089,'Master Howard&#39;s Commemorative Seminar '],
		[1181,  'bbgrading adjusted_725x494.jpg', 725, 494,'Ms. Therese McGrath promoted to ITF 1st Degree by Senior Master Phelan VIII Degree'],
		[6381,  'Irish Team_WC09_800.jpg', 800, 449,'Irish Team - ITF World Championships 2009']
		
    ];
}


function loadArray()
{
    for (i=0; i <imageList.length; i++)
    imageList[i]=new Array(2)
}

var randomGallery = 'images/';

var qsParm = new Array();

qsParm['ss'] = null;
qsParm['ap'] = null;

function getParams() 
{
    var query = window.location.search.substring(1);
    
    var parms = query.split('&');
    for (var i=0; i<parms.length; i++) 
    {
        var pos = parms[i].indexOf('=');
        if (pos > 0) 
        {
            var key = parms[i].substring(0,pos);
            var val = parms[i].substring(pos+1);
            qsParm[key] = val;
        }
    }
} 


function loadImage(bCentre)
{

    getParams();

    if (document.images)
        {
            
            if (document.location.search)
            {
            
                //var params = document.location.search.split('=');

                storeImageList();
                
                if (bCentre==true){setElementsSize();}
                
                var elImage = document.getElementById('imgPlaceholder');
                var elContainer = document.getElementById('ocontainer');
               
                //TODO: Test for null
                var index = qsParm['ss'];
                
                elImage.setAttribute("src",randomGallery+findImage(index));
                elImage.style.width = width+'px';
                elImage.style.height = height+'px';
                var marginLeft = setImageMargin(elImage, elContainer.style.width)+'px';
                elImage.style.marginLeft = marginLeft;
                elImage.style.marginRight = 'auto';
                elImage.style.marginTop = 'auto';
                elImage.style.marginBottom = 'auto';
                
                var elHref = document.getElementById('imageAnchor');
                elHref.setAttribute("href","index.htm#"+qsParm['ap']);
                
            }
            var elDesc = document.getElementById('pTitle');
            elDesc.innerHTML = findDesc(index);
            if (bCentre==true){elDesc.className='centertext';}else{elDesc.className='lefttext';}
            
        }
}

function setImageMargin(imageElement, containerWidth)
{
    var hMargin = ((parseInt(containerWidth)-parseInt(imageElement.style.width))) / 2;
    
    return hMargin;
}

function findImage(ix)
{
    for (var i=0;i<imageList.length;i++)
    {
        if (imageList[i][0]==ix){
        
            width = imageList[i][2];
            height = imageList[i][3];
        
            return(imageList[i][1]);
        
        }    
    }
}
function findDesc(ix)
{
    for (var i=0;i<imageList.length;i++)
    {
        if (imageList[i][0]==ix){
        
            return(imageList[i][4]);
        
        }    
    }
}


function setElementsSize()
{
    var screenWidth = screen.availWidth;
    var imageWidth = (screenWidth - 40);
    var hmargins = (screenWidth - imageWidth) / 2;
    imageWidth = (imageWidth - hmargins);

    var eDiv = document.getElementById('ocontainer');
    eDiv.style.marginLeft = hmargins+'px';
    eDiv.style.marginRight = hmargins+'px';
    eDiv.style.width = imageWidth+'px';
    
////    // set the img width and height
////    var eImg = document.getElementById('ige');
////    eImg.style.width = imageWidth+'px';
////    eImg.style.height = (parseInt(imageWidth*eHeightRatio))+'px';
////    //test for IE and set min width
//////    if (whichBrs() == 'Internet Explorer')
//////    {    
//////        setIE6Width(imageWidth);
//////    }
//    
//    return imageWidth;
//    
}


