﻿var actionDiv;

function OnLoad(inputDiv) { // On page load
      actionDiv = $("#inputDiv");
      // set the public varible to be that of the passed in element
}

function loadContent(msg) { // Just prior to flash animation ending
    setTimeout("loadContentNow()", 300);
   

}

function loadContentNow() {
    $("#homeFlash").css("display", "none");
    $('#homecontent').show();   // begin sequence of animation
    StartSifr(); // Call the sifr replacement script
    
}



function LoadFlash() {
    var params = {};
    var flashvars = {};
    var attributes = {};
    var i = Math.floor(Math.random() * 2);
    if (i == 1) {
        swfobject.embedSWF("Flash/RoomToGrow_Intro_v5.swf", "intro", "780", "440", "9.0.0", false, flashvars, params, attributes); 
    } else {
        swfobject.embedSWF("Flash/RoomToGrow_Intro_v5_2.swf", "intro", "780", "440", "9.0.0", false, flashvars, params, attributes);
    }
}

function HideLocations() {
    $("#locationsList").css("display", "none")
}

//Custom Accordion menu
//if the persistent option is set to true then the last visited tab is re-opened when the user goes back in their browser history
//if openByDefault is set then if a tab has not been previously selected then the first tab is opened

function accordion(speed, persistent, openByDefault) {
    $('.accordioncontent').hide();
    var y = $('ul#accordion li a');
    y.click(
        function() {
            var current = $(this).next();
            if ((current.is('div')) && (!current.is(':visible'))) {
                y.removeClass('selected');
                $(this).addClass('selected');
                $('.accordioncontent:visible').slideUp(speed);
                current.slideDown(speed);
            } else if ((current.is('div')) && (!current.is(':hidden'))) {
                $(this).removeClass('selected');
                current.slideUp(speed);
            }
        }
    );
    if (persistent) {
        if (location.href.indexOf('.aspx#') !== -1) {
            var str = location.href.split('.aspx#');
            var i = $('#content' + str[1]).slideDown('normal');
            i.siblings('a').addClass('selected');
        }
    }
    if (openByDefault) {
        if (location.href.indexOf('.aspx#') === -1) {
            var i = $('#content1').slideDown('normal');
            i.siblings('a').addClass('selected');
        }   
    }
}

//limit profiles on meet our people and profile pages
function limitProfiles(identifier,limit) {
    var ele = $(identifier);
    ele.each(function() {
        var arr = new Array(limit);
        var div = $(this).children().find('div');
        var len = div.length;
        if (len == limit || len > limit) {
            div.css('display', 'none');
            var count = 0;
            while (count < limit) {
                var rand = Math.floor(Math.random() * (len));
                if (!arr.inArray(rand)) {
                    $(div[rand]).css('display', 'block');
                    arr.push(rand);
                    count++;
                    
                }
            }
        }
    });
}


Array.prototype.inArray = function(value) {
    var i;
    for (i = 0; i < this.length; i++) {
        if (this[i] !== 'undefined') {
            if (this[i] === value) {
                return true;
            }
        }
    } return false;
};


//cycle text animation on the meet our people page in absence of flash
function cycleText() {
    $('div#quotes p').show();
    var para = $('div#quotes p');
    var right = $('#cycle');
    para.each(function() {
        $(this).hide();
        var m = $(this).html();
        
        right.append('<p style="position: absolute; top: 0;">' + m + '</p>');
    });
    var allParas = $('#cycle').children().css('display', 'none');
    var length = allParas.length;
    var i = 0;
    allParas.eq(0).fadeIn(1000);
    var inter = setInterval(function() {
        if (i != length && i !== (length -1)) {
            allParas.eq(i).fadeOut(1000, function() {
                allParas.eq(i).fadeIn(1000);
            });
        } else if (i == (length - 1)) {
            allParas.eq(length - 1).fadeOut(1000, function() {
                allParas.eq(0).fadeIn(1000);
            });
            i = -1;
        } ++i;
    }, 8000);
}



//function to cycle profiles on meet our people page in absence of flash
function meetOurPeopleXmlParser(doc) {
    var xmlDoc = loadXMLDoc(doc);
    var x = xmlDoc.getElementsByTagName("profile");
    var len = x.length;
    var rand = Math.floor(Math.random() * (len));
    var currentProfile = x[rand];
    var atts = currentProfile.attributes;
    var imageSrc = atts.getNamedItem('image').nodeValue;
    var nameValue = atts.getNamedItem('name').nodeValue;
    var container = document.getElementById('polaroidContainer');
    
    var name = document.createElement('h3');
    var im = document.createElement('img');
    var ptag = document.createElement('p');
    
    var nameText = document.createTextNode(nameValue);
    var tt = currentProfile.childNodes[0].firstChild.nodeValue;
    
    var texty = document.createTextNode(tt);
    
    name.appendChild(nameText); 
    im.src = imageSrc;
    ptag.appendChild(texty);
    
     container.appendChild(name);
     container.appendChild(im);
    container.appendChild(ptag);
   
   
}

function loadXMLDoc(dname) {
    var xmlDoc;
    if (window.XMLHttpRequest) {
        xmlDoc=new window.XMLHttpRequest();
        xmlDoc.open("GET",dname,false);
        xmlDoc.send("");
        return xmlDoc.responseXML;
    }
    // IE 5 and IE 6
    else if (ActiveXObject("Microsoft.XMLDOM")){
        xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async=false;
        xmlDoc.load(dname);
        return xmlDoc;
    }
    alert("Error loading document");
    return null;
}




