﻿
//---------------------------------------|  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.
//
//------------------------------------------------------------------------------------------------------------

////hs.graphicsDir = '../highslide/graphics/';
hs.align = 'center';
hs.transitions = ['expand', 'crossfade'];
hs.outlineType = 'rounded-white';
hs.fadeInOut = true;
hs.dimmingOpacity = 0.75;

//// Add the controlbar
//hs.addSlideshow({
//	//slideshowGroup: 'group1',
//	interval: 5000,
//	repeat: false,
//	useControls: true,
//	fixedControls: 'fit',
//	overlayOptions: {
//		opacity: .75,
//		position: 'bottom center',
//		hideOnMouseOut: true
//	}
//});


SAOSS_Method = 'Empty';

var GotoTheCharityLine = false;
var arrCharities = new Array(); //Class Array
var HTML = '';

function Charity(ID,Name,SRC,URL,Number) //The Charity Object
{
    this.id = ID;
    this.Name = Name;
    this.SRC = '/Images/' + SRC;
    this.Website = URL;
    this.Title = Name + "\r\n(Charity No: " + Number + ")";
    arrCharities[arrCharities.length] = this;
}

var objCharity = new Charity("Barnardos","Barnardo's","Barnardos.png","http://www.barnardos.org.uk", 236598);
objCharity = new Charity("RedCross", "The British Red Cross", "TheRedCross.png", "http://www.redcross.org.uk", 236598);
objCharity = new Charity("BIBIC", "BIBIC", "BIBIC.png", "http://www.bibic.org.uk", 236598);
objCharity = new Charity("NBCS", "National Blind Children's Society", "NBCS.png", "http://www.nbcs.org.uk", 236598);
objCharity = new Charity("Missing", "Missing People", "Missing.png", "http://www.missingpeople.org.uk", 236598);
//objCharity = new Charity("Samaritans", "Samaritans", "Samaritans.png", "http://www.samaritans.org.uk", 236598);
//objCharity = new Charity("SharedSuccess", "The Shared Success Trust", "SharedSuccessTrust.png", "http://www.SAOSS.Org", 236598);

function loadCharities() {

    var divAds = getElement('Ads');
    var divCharities = getElement('Charities');

    var img;
    var A1;var A2;

    for (i = 0; i < arrCharities.length; i++) {

        A1 = document.createElement('a');
        A2 = document.createElement('a');

        A1.href = "/Images/PriceSplash.png";
        A1.rel = "modalbox"; 

        //alert(A1.href); 
        
        
        
        
        img = document.createElement('img');
        img2 = document.createElement('img');
        
        img.id = arrCharities[i].id;
        
        img.src = arrCharities[i].SRC;
        img2.src = arrCharities[i].SRC;

        img.title = arrCharities[i].Title;
        img2.title = arrCharities[i].Title;


        img.setAttribute('class', 'highslide');
        img2.setAttribute('class', 'highslide');
        //return hs.expand(this);

        img.ondblclick = new Function('alert("' + img.id + '")');
        img2.ondblclick = new Function('alert("' + img.id + '")');

        //img.onmouseover = new Function('showProfile("' + img.id + '")');
        //img2.onmouseover = new Function('showProfile("' + img.id + '")');

        //img.onmouseout = new Function('hideProfile("' + img.id + '")');
        //img2.onmouseout = new Function('hideProfile("' + img.id + '")');


        //img.setAttribute('click', "alert('done');");
        //img2.setAttribute('click', "alert('done');");

    
        img.width = 125;
        img2.width = 125;

        img.height = 125;
        img2.height = 125;

        (A1) ? A1.appendChild(img2) : '';
        
        //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
        //img2.onclick = new Function('SAOSS_OpenWindow1("' + arrCharities[i].Website + ((GotoTheCharityLine) ? '/TheCharityLine' : '') + '")');    //Others
        //alert('SAOSS_OpenWindow("' + arrCharities[i].Website + '")')

        //(divCharities) ? divCharities.appendChild(img) : '';
        //(divAds) ? divAds.appendChild(img2) : '';

        (divAds) ? divAds.appendChild(A1) : '';
    }

    PrepareOverlay();

    //((divCharities) && (divAds)) ? divCharities.innerHTML = divAds.innerHTML : '';    //Check the objects exist first, and then apply the HTML;

    //alert(divCharities.innerHTML);
    
    divCharities = null;
    divAds = null;

}

var T;
var ProfileOpen = false;
var ThePage = null;

function showProfile(Charity){
    ProfileOpen = true;
    //ThePage = document.getElementById('OuterPage');
    ThePage = document.getElementById('ThePage');
    (HTML == '') ? HTML = ThePage.innerHTML : '';

    //var R = new Math.random();
    var num = Math.floor(Math.random() * 999 + 1)

    $('#ThePage').load('/Remote/Profile.aspx?CharityName=' + Charity + '&T=' + num);
    
        

    //Page.innerHTML = value;
    
    // '<img src="/Images/PriceSplash.png" />';   //This could go and get some HTML from the server?
    //T = setTimeout(Restore,3000);
}
function hideProfile(Charity){
    ProfileOpen = false;
    ThePage.onmouseover = new Function('ProfileOpen = true;');
    ThePage.onmouseout = new Function('ProfileOpen = false;');
    ThePage.onclick = new Function('ProfileOpen = false;');
    
    T = setTimeout(Restore, 3000);  //Set the TimeOut once again to prevent switching when moving between charity icons.
}
function Restore() {
    if (ProfileOpen == false) {
        ThePage = document.getElementById('ThePage');
        ThePage.innerHTML = HTML;
        clearTimeout(T);
    }
}








//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

    var features = "toolbar=1,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1" //,width=530,height=400,left=" + Math.ceil((window.screen.width - 530) / 2) + ",top=" + Math.ceil((window.screen.height - 400) / 2);
    //var winName = "Contact";
    window.open(URL, winName, features);
}

(typeof $ == 'function') ? $(document).ready(function() { loadCharities(); }) : loadCharities();


(typeof SAOSS_Modules != 'undefined') ? SAOSS_AddModule('Charity Footer Module', '1.0', false) : '';   //Add this Module to the Modules Array (Tracking)
