﻿/******************************************************************************
* author: Alberta Health Services
*         Christopher Sheldon
*
* notes: Copyright (c) David Thompson Health Region. All Rights Reserved. 
*        The code contained within this file is not liscensed for public 
*        usage. Do not reproduce or alter this file complete or in part 
*        without the express written permission of the author. 
* 
******************************************************************************/

/******************************************************************************
* class: classCarousel
* notes: This class contains the DOM and Flash loading methods for the dynamic
*        carousel template element.        
*
********/

function classCarousel() {   
    this.version = '2.20090825';
    this.flashVersion = '';
    
//    this.flash = 'carousel.swf';
//    this.data = 'sample.xml';
    
    
    var urlQuery = document.location.href.toLowerCase();
        
    this.noScript = (urlQuery.toLowerCase().indexOf('noscript=1') != -1 || urlQuery.toLowerCase().indexOf('noscript=true') != -1) ? true : false;
    this.noFlash = (urlQuery.toLowerCase().indexOf('noflash=1') != -1 || urlQuery.toLowerCase().indexOf('noflash=true') != -1) ? true : false;
        
    if(!Array.indexOf){
        Array.prototype.indexOf = function(arrObject, intStart) {
            for(var intCount = (intStart || 0); intCount < this.length; intCount++) {
                if(this[intCount] == arrObject) {
                    return intCount;
                };
            };
            return -1;
        };
    };
        
    /**************************************************************************
    *    flash properties
    *
    ********/
    
    if(navigator.plugins && navigator.plugins.length) {                 
            for(var intCounter = 0; intCounter < navigator.plugins.length; intCounter++) {
            if(navigator.plugins[intCounter].name.indexOf('Shockwave Flash') != -1) {
                var strFlashPlugin = navigator.plugins[intCounter].description.split('Shockwave Flash ')[1];
                this.flashVersion = strFlashPlugin;
            }; 
        };
    } else if(window.ActiveXObject) { 
        for(var intCounter = 2; intCounter < 20; intCounter++) { 
            try { 
                objFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + intCounter + "');"); 
                if(objFlash) {
                    var arrFlashPlugin = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.' + intCounter).GetVariable("$version").split(',');
                    this.flashVersion = arrFlashPlugin[0].slice(arrFlashPlugin[0].indexOf(' ')) + '.' + arrFlashPlugin[1] + 'r' + arrFlashPlugin[2];
                };
            } catch(objError) {
            };
        };
    };

    /**************************************************************************
    *    flash properties
    *
    ********/
    
    this.convertUrl = function(strUrl) {
        strUrl = strUrl.replace(/&amp;/ig, '&');
        strUrl = strUrl.replace(/&/ig, '*');
        
        return strUrl;
    };
    
    /**************************************************************************
    *    flash properties
    *
    ********/
    
    this.create = function(strType, strData) {
        var arrVersion = this.flashVersion.split('r');

        if(!this.noScript) {        
            if((parseInt(arrVersion[0]) > 9 || (parseInt(arrVersion[0]) == 9 ) && parseInt(arrVersion[1])) && !this.noFlash) {
                this.loadFlash(strType, strData);
            };
        };
    };

    /**************************************************************************
    *    flash properties
    *
    ********/

    this.loadFlash = function(strType, strData) {
        var divCarousel = document.getElementById('features');
        var strFlash = '/images/carousel.swf';
        var intWidth = 450;
        var intHeight = 180;

        if(strType == 'home') {
            var strFlash = '/images/homeCarousel.swf';
            intHeight = 300;
        };
        
        var strHtml = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="' + intWidth + '" height="' + intHeight + '" id="carouselFlash" align="middle">';
        strHtml += '    <param name="allowScriptAccess" value="sameDomain" />';
        strHtml += '    <param name="allowFullScreen" value="false" />';
        strHtml += '    <param name="movie" value="' + strFlash + '?xml=' + this.convertUrl(strData) + '" />';
        strHtml += '    <param name="loop" value="false" />';
        strHtml += '    <param name="menu" value="false" />';
        strHtml += '    <param name="quality" value="best" />';
        strHtml += '    <param name="scale" value="noscale" />';
        strHtml += '    <param name="bgcolor" value="#000000" />';
        strHtml += '    <param name="wmode" value="transparent" />';        
        strHtml += '    <embed src="' + strFlash + '?xml=' + this.convertUrl(strData) + '" loop="false" menu="false" wmode="transparent" quality="best" scale="noscale" bgcolor="#000000" width="' + intWidth + '" height="' + intHeight + '" name="main" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
        strHtml += '</object>';
        
        divCarousel.innerHTML = strHtml;
        divCarousel.style.border = '0px';
    };    
};
var objCarousel = new classCarousel();