﻿
//---------------------------------------|  Charity Footer Module    |----------------------------------------
//
//  This module will contact the media server and return a collection of charity objects using JSON and AJAX.
//  The objects are then itterated through to display FIVE at a time to the user.
//
//------------------------------------------------------------------------------------------------------------

SAOSS_Method = 'Empty';

var GotoTheCharityLine = false;
var arrCharities = new Array(); //Class Array


function Charity(ID,Name,SRC,URL) //The Charity Object
{
    this.ID = ID;
    this.Name = Name;
    this.SRC = '/Images/' + SRC;
    this.Website = URL;
    arrCharities[arrCharities.length] = this;
}

var objCharity = new Charity("Barnardos",'Barnardo\'s','Barnardos.png','http://www.barnardos.org.uk');
objCharity = new Charity("RedCross", 'RedCross', 'TheRedCross.png', 'http://www.redcross.org.uk');
objCharity = new Charity("BIBIC", 'BIBIC', 'BIBIC.png', 'http://www.bibic.org.uk');
objCharity = new Charity("NBCS", 'NBCS', 'NBCS.png', 'http://www.nbcs.org.uk');
objCharity = new Charity("Missing", 'Missing People', 'Missing.png', 'http://www.missingpeople.org.uk');
objCharity = new Charity("Samaritans", 'Samaritans', 'Samaritans.png', 'http://www.samaritans.org.uk');


function loadCharities() {

    var divAds = getElement('Ads');
    var divCharities = getElement('Charities');
    var img;
    for (i = 0; i < arrCharities.length; i++) {

        img = document.createElement('img');
        img.id = arrCharities[i].ID;
        img.src = arrCharities[i].SRC;
        img.title = arrCharities[i].ID;
        img.width = 125;
        img.height = 125;
        
        
        //xb.addEvent(img,'click',"\'doClick(this);\'")
        //img.setAttribute('onClick', 'SAOSS_OpenWindow1("' + arrCharities[i].Website + ((GotoTheCharityLine) ? '/TheCharityLine' : '') + '))');  //IE
        img.onclick = new Function('SAOSS_OpenWindow1("' + arrCharities[i].Website + ((GotoTheCharityLine) ? '/TheCharityLine' : '') + '")');    //Others
        //alert('SAOSS_OpenWindow("' + arrCharities[i].Website + '")')
        
        (divCharities) ? divCharities.appendChild(img) : '';
        (divAds) ? divAds.appendChild(img) : '';

    }

    ((divCharities) && (divAds)) ? divCharities.innerHTML = divAds.innerHTML : '';    //Check the objects exist first, and then apply the HTML;
    
    divCharities = null;
    divAds = null;   
}

//function doClick(Which) {
//    switch (Which.id) {

//        case 'Barnardos': { SAOSS_OpenWindow(objCharity.Website); break; }
//        case 'RedCross': { SAOSS_OpenWindow(''); break; }
//        case 'BIBIC': { SAOSS_OpenWindow(''); break; }
//        case 'NBCS': { SAOSS_OpenWindow(''); break; }
//        case 'Missing': { SAOSS_OpenWindow('http://www.missingpeople.org.uk'); break; }
//        case 'Samaritans': { SAOSS_OpenWindow(''); break; }
//    }
//}

function SAOSS_OpenWindow1(URL, winName, features) { //v2.0
    window.open(URL, winName, features);
}

(typeof addLoadEvent == 'function') ? addLoadEvent(loadCharities) : loadCharities();

(typeof SAOSS_Modules != 'undefined') ? SAOSS_AddModule('Charity Footer Module', '1.0', false) : '';   //Add this Module to the Modules Array (Tracking)
