var animating = false;
var currentTT;
var lastDisplay = '';
var lastMedia = '';

Event.observe(window, 'load', function() {

    var mcBG = $('mcBG');
    //Event.observe($('mcBG'), 'load', function() {
    //    setTimeout('runStartUp()', 400);
    //})(mcBG);
    //$('mcBG').onload = function() { loadPicture(); }
    //mcBG.onload = function() {
    //    setTimeout('runStartUp()', 400);
    //}
    /*mcBG.onload = (function(elm) {
    return function() {
    return setTimeout('runStartUp()', 400);
    }
    })(mcBG);*/
    runStartUp();
    $$('#navMenu div.navLink').each(function(n) {
        n.observe('mouseover', moNav);
        n.observe('mouseout', moNav);
        n.observe('click', showItem);
    });

    $$('#ttWho div.ttNav').each(function(n) {
        n.observe('mouseover', moTTNav);
        n.observe('mouseout', moTTNav);
        n.observe('click', showWhoItem);
    });

    $$('#spList div.sponsorFrame').each(function(n) {
        n.observe('mouseover', moSponsorItem);
        n.observe('mouseout', moSponsorItem);
        n.observe('click', showSponsor);
    });

    $$('#ttRMNav div.ttRosterNavBtn').each(function(n) {
        n.observe('mouseover', moRosterNav);
        n.observe('mouseout', moRosterNav);
        n.observe('click', nextMenu);
    });

    $$('#ttRosterMenu area.rmMenuItem').each(function(n) {
        n.observe('click', showMenuItem);
    });

    $$('#mOpening div.mOpenMedia').each(function(n) {
        n.observe('mouseover', moMedia);
        n.observe('mouseout', moMedia);
        n.observe('click', showMedia);
    });

    $$('#mTVList div.mVideoBtn').each(function(n) {
        n.observe('mouseover', moVideoBtn);
        n.observe('mouseout', moVideoBtn);
        //n.observe('click', scrollVideos);
    });

    $$('#mPhotosListWrapper div.mPhotosBtn').each(function(n) {
        n.observe('mouseover', moPhotoBtn);
        n.observe('mouseout', moPhotoBtn);
        n.observe('click', scrollPhotos);
    });

    //Event.observe($('mPhotoLarge'), 'load', loadPicture, false);
    $('mPhotoLarge').onload = function() { loadPicture(); }

    getGotPhoBio();
    getPaddlerBios();

});

/*    $$('#ttRosterMenu div.rmMenuDivs').each(function(n) {
n.observe('click', showMenuPage);
});
*/

function runStartUp() {
    var indent = 730;
    var queuePos = 'end';
    var dTime = 4.3;
    animating = true;
    new Effect.Opacity($('gpTitleRed'), { from: 0.0, to: 1.0, duration: 1.3, queue: { scope: 'startScope', position: 'end' }, afterFinish: function() {
			$('gpTitleRed').style.opacity = '1.0';
			$('gpTitleRed').style.filter = 'alpha(opacity=100)'; 
	} 
	});
	new Effect.Event({ duration:1.0, queue: { position: 'end', scope: 'startScope' }, beforeUpdate: function() { animating = false; } });
    new Effect.Opacity($('gpTitleRed'), { from: 1.0, to: 0.0, duration: 0.8, queue: { scope: 'startScope', position: 'end'} });
    new Effect.Opacity($('middleContentWrapper'), { from: 0.0, to: 1.0, duration: 0.8, queue: { scope: 'startScope', position: 'end'}, afterFinish: function() {
        $('middleContentWrapper').style.opacity = '1.0';
        $('middleContentWrapper').style.filter = 'alpha(opacity=100)'; 
	} 
	}); 
    $('navMenu').morph({ left: '0px' }, { duration: 0.8, queue: { scope: 'startScope', position: 'end'} });
    $$('#navMenu div.navLink').reverse().each(function(n) {
        n.morph({ left: indent + 'px' }, { duration: dTime, transition: Effect.Transitions.spring, queue: { scope: 'startScope', position: queuePos} });
        indent -= 110;
        queuePos = 'with-last';
        dTime = dTime - 0.7;
    });
    new Effect.Event({ queue: { position: 'end', scope: 'startScope' }, beforeUpdate: function() { animating = false; } });
}

/* ******* Nav ******* */

function moNav(e) {
    var item = (e.srcElement != null) ? e.srcElement : e.target;
    item.style.top = (e.type == 'mouseover') ? '-39px' : '0px';
}

function showItem(e) {
    var item = (e.srcElement != null) ? e.srcElement : e.target;
    if (animating) return;
    animating = true;
    var navMenu = $('navMenuWrapper');
    if (navMenu.style.top != '100px')
        navMenu.morph({ top: '100px' }, { duration: 1.0, queue: { scope: 'navScope', position: 'end'} });
    var gpTitle = $('gpTitle');
    if (gpTitle.style.top != '60px')
        gpTitle.morph({ top: '60px', left: '128px' }, { duration: 1.0, queue: { scope: 'navScope', position: 'with-last'} });

    if (item.id != lastDisplay)
        hideLastDisplay();
    switch (item.id) {
        case 'nav_team':
            {
                var ttWF = $('ttWrapperFrame');
                ttWF.morph({ left: '10px' }, { duration: 0.0, queue: { scope: 'navScope', position: 'end'} });
                new Effect.Opacity(ttWF, { from: 0.0, to: 0.9, duration: 1.0, queue: { scope: 'navScope', position: 'end'} });
                lastDisplay = 'nav_team';
                break;
            }
        case 'nav_sponsors':
            {
                var swF = $('sponsorsWrapperFrame');
                swF.morph({ left: '50px' }, { duration: 0.0, queue: { scope: 'navScope', position: 'end'} });
                new Effect.Opacity(swF, { from: 0.0, to: 0.9, duration: 1.0, queue: { scope: 'navScope', position: 'end'} });
                lastDisplay = 'nav_sponsors';
				getFirstSponsor();
                break;
            }
        case 'nav_festivals':
            {
                var fF = $('festivalsWrapperFrame');
                fF.morph({ left: '10px' }, { duration: 0.0, queue: { scope: 'navScope', position: 'end'} });
                new Effect.Opacity(fF, { from: 0.0, to: 0.9, duration: 1.0, queue: { scope: 'navScope', position: 'end'} });
                lastDisplay = 'nav_festivals';
				getFestivalsDetail();
                break;
            }
	   case 'nav_edbrc':
            {
                var eF = $('edbrcWrapperFrame');
                eF.morph({ left: '45px' }, { duration: 0.0, queue: { scope: 'navScope', position: 'end'} });
                new Effect.Opacity(eF, { from: 0.0, to: 0.8, duration: 1.0, queue: { scope: 'navScope', position: 'end'} });
                lastDisplay = 'nav_edbrc';
				getEDBRCContent();
                break;
            }			
        case 'nav_media':
            {
                var mF = $('mediaWrapperFrame');
                mF.morph({ left: '10px' }, { duration: 0.0, queue: { scope: 'navScope', position: 'end'} });
                new Effect.Opacity(mF, { from: 0.0, to: 0.9, duration: 1.0, queue: { scope: 'navScope', position: 'end'} });
                lastDisplay = 'nav_media';
                break;
            }
    }

    animating = false;
}

function hideLastDisplay() {
    var sframe;
    if (lastDisplay == 'nav_team')
        sframe = $('ttWrapperFrame');
    else if (lastDisplay == 'nav_sponsors')
        sframe = $('sponsorsWrapperFrame');
    else if (lastDisplay == 'nav_festivals')
        sframe = $('festivalsWrapperFrame');
    else if (lastDisplay == 'nav_edbrc')
        sframe = $('edbrcWrapperFrame');
    else if (lastDisplay == 'nav_media')
        sframe = $('mediaWrapperFrame');

    if (lastDisplay != '') {
        new Effect.Opacity(sframe, { from: 0.9, to: 0.0, duration: 0.8, queue: { scope: 'navScope', position: 'end'} });
        sframe.morph({ left: '1000px' }, { duration: 0.0, queue: { scope: 'navScope', position: 'end'} });
    }
}

/* ******* The TEAM ******* */
function moTTNav(e) {
    var item = (e.srcElement != null) ? e.srcElement : e.target;
    if (item.id == 'ttPRImg')
        $('ttPRImg').src = (e.type == 'mouseover') ? 'images/nav/phoroster_over.png' : 'images/nav/phoroster.png';
    if (item.id == 'ttPImg')
        $('ttPImg').src = (e.type == 'mouseover') ? 'images/nav/photos_over.png' : 'images/nav/photos.png';
    if (item.id == 'ttBImg')
        $('ttBImg').src = (e.type == 'mouseover') ? 'images/nav/whothepho_over.png' : 'images/nav/whothepho.png';
}

function showHideTTBio(show) {
    if (show) {
        $('ttBioContent').style.top = '0px';
        new Effect.Opacity($('ttBioContent'), { from: 0.0, to: 0.8, duration: 1.0, queue: { scope: 'ttScope', position: 'end'} });
    }
    else
        new Effect.Opacity($('ttBioContent'), { from: 0.8, to: 0.0, duration: 1.0, queue: { scope: 'ttScope', position: 'end' }, afterFinish: function() {
            $('ttBioContent').style.top = '-436px';
        }
        });
}

function showHideTTPhotos(show) {
    var imgViewerTop = show ? '330px' : '440px';
    var pictureTop = show ? '10px' : '-300px';
    if (show) {
        $('ttPhotosContent').style.top = '0px';
        new Effect.Opacity($('ttPhotosContent'), {from:0.0,to:0.8,duration: 1.0, queue: { scope: 'ttScope', position: 'end'}});
        $('ttPictureList').morph({ top: imgViewerTop }, { duration: 1.2, queue: { scope: 'ttScope', position: 'with-last'} });
        $('ttPictureFrame').morph({ top: pictureTop }, { duration: 1.2, queue: { scope: 'ttScope', position: 'with-last'} });
    }
    else {
        $('ttPictureList').morph({ top: imgViewerTop }, { duration: 0.6, queue: { scope: 'ttScope', position: 'end'} });
        $('ttPictureFrame').morph({ top: pictureTop }, { duration: 0.6, queue: { scope: 'ttScope', position: 'with-last'} });
        new Effect.Opacity($('ttPhotosContent'), { from: 0.8, to: 0.0, duration: 1.0, queue: { scope: 'ttScope', position: 'with-last' }, afterFinish: function() {
            $('ttPhotosContent').style.top = '-436px';
        } 
        });
    }
}

function showHideTTRoster(show) {
    var menuLeft = show ? '10px' : '-350px';
    var detailLeft = show ? '376px' : '776px';
    if (show) {
        $('ttRosterContent').style.top = '0px';
        new Effect.Opacity($('ttRosterContent'), { from: 0.0, to: 0.9, duration: 1.0, queue: { scope: 'ttScope', position: 'end'} });
        $('ttRosterMenu').morph({ left: menuLeft }, { duration: 1.2, queue: { scope: 'ttScope', position: 'end'} });
        $('ttRosterDetail').morph({ left: detailLeft }, { duration: 1.2, queue: { scope: 'ttScope', position: 'with-last'} });

        $('ttRMAppetizers').morph({ left: '0px' }, { duration: 0.8, queue: { scope: 'ttScope', position: 'end'} });
        $('ttRMMainCourse').morph({ left: '356px' }, { duration: 1.0, queue: { scope: 'ttScope', position: 'with-last'} });
        $('ttRMDeserts').morph({ left: '356px' }, { duration: 1.2, queue: { scope: 'ttScope', position: 'with-last'} });
    }
    else {
        $('ttRosterMenu').morph({ left: menuLeft }, { duration: 0.6, queue: { scope: 'ttScope', position: 'end'} });
        $('ttRosterDetail').morph({ left: detailLeft }, { duration: 0.6, queue: { scope: 'ttScope', position: 'with-last'} });
        new Effect.Opacity($('ttRosterContent'), { from: 0.9, to: 0.0, duration: 1.0, queue: { scope: 'ttScope', position: 'with-last'}, afterFinish:function() {
            $('ttRMMainCourse').style.left = '-356px';
            $('ttRMAppetizers').style.left = '-356px';
            $('ttRMDeserts').style.left = '-356px';
            $('ttRosterContent').style.top = '-436px';
        }
        });        
    }
}

function showWhoItem(e) {
    var item = (e.srcElement != null) ? e.srcElement : e.target;
    if (item.id == 'ttBImg') {
        if (currentTT != item.id) {
            if (currentTT == 'ttPRImg')
                showHideTTRoster(false);
            else if (currentTT == 'ttPImg')
                showHideTTPhotos(false);

            showHideTTBio(true);
            currentTT = item.id;
        } 
    }
    else if (item.id == 'ttPRImg') {
        if (currentTT != item.id) {
            if (currentTT == 'ttBImg')
                showHideTTBio(false);
            else if (currentTT == 'ttPImg')
                showHideTTPhotos(false);

            showHideTTRoster(true);
            currentTT = item.id;
        } 
    }
    else if (item.id == 'ttPImg') {
        if (currentTT != item.id) {
            if (currentTT == 'ttBImg')
                showHideTTBio(false);
            else if (currentTT == 'ttPRImg')
                showHideTTRoster(false);

            showHideTTPhotos(true);
            currentTT = item.id;
        } 
    }
}

function showMenuPage(e) {
    var item = (e.srcElement != null) ? e.srcElement : e.target;
    var ttA = $('ttRMAppetizers');
    var ttMC = $('ttRMMainCourse');
    var ttD = $('ttRMDeserts');
    var ttALeft = '356px';
    var ttMCLeft = '356px';
    var ttDLeft = '356px';
    
    if (item.id == 'ttRMAppetizers') {
        if (ttMC.style.left != ttMCLeft) 
            ttMCLeft.morph({ left: ttMCLeft }, { duration: 0.6, queue: { scope: 'menuScope', position: 'with-last'} });
        if (ttD.style.left != 'ttDLeft')
            ttD.morph({ left: ttDLeft }, { duration: 0.6, queue: { scope: 'menuScope', position: 'with-last'} });
        ttA.morph({ left: '0px' }, { duration: 0.6, queue: { scope: 'menuScope', position: 'with-last'} });
    }
    else if (item.id == 'ttRMMainCourse') {
        if (ttA.style.left != ttALeft)
            ttALeft.morph({ left: ttALeft }, { duration: 0.6, queue: { scope: 'menuScope', position: 'with-last'} });
        if (ttD.style.left != 'ttDLeft')
            ttD.morph({ left: ttDLeft }, { duration: 0.6, queue: { scope: 'menuScope', position: 'with-last'} });
        ttMC.morph({ left: '0px' }, { duration: 0.6, queue: { scope: 'menuScope', position: 'with-last'} });
    }
    else if (item.id == 'ttRMDeserts') {
        if (ttMC.style.left != ttMCLeft)
            ttMCLeft.morph({ left: ttMCLeft }, { duration: 0.6, queue: { scope: 'menuScope', position: 'with-last'} });
        if (ttA.style.left != 'ttALeft')
            ttA.morph({ left: ttALeft }, { duration: 0.6, queue: { scope: 'menuScope', position: 'with-last'} });
        ttD.morph({ left: '0px' }, { duration: 0.6, queue: { scope: 'menuScope', position: 'with-last'} });
    }
}

function showMenuItem(e) {
    var item = (e.srcElement != null) ? e.srcElement : e.target;
    var menuItem = paddlers.find(function(n) { return n.id == item.id });
    if (menuItem) {
        $('ttRDImage').src = 'images/people/team_cards/'+ menuItem.image;
        $('ttRDRealName').innerHTML = menuItem.realName;
        $('ttRDMenuItem').innerHTML = menuItem.menuItem;
        //$('ttRDAlias').innerHTML = "aka: " + menuItem.nickName;
    }
}

function moRosterNav(e) {
    var item = (e.srcElement != null) ? e.srcElement : e.target;
    item.style.top = (e.type == 'mouseover') ? '-30px' : '0px';
}

function nextMenu(e) {
    var item = (e.srcElement != null) ? e.srcElement : e.target;
    var ttA = $('ttRMAppetizers');
    var ttMC = $('ttRMMainCourse');
    var ttD = $('ttRMDeserts');
    var ttRMCP = $('ttRMCurrentPage');
    
    var curNavA = (ttA.style.left == '0px');
    var curNavMC = (ttMC.style.left == '0px');
    var curNavD = (ttD.style.left == '0px');

    if (item.id == 'ttRMRightNav') {
        if (curNavA) {
            ttA.morph({ left: '356px' }, { duration: 0.8, queue: { scope: 'menuScope', position: 'end'} });
            ttMC.morph({ left: '0px' }, { duration: 0.8, queue: { scope: 'menuScope', position: 'end' }, afterFinish: function() {
                ttRMCP.innerHTML = 'Main Course';
            }});
        }
        else if (curNavMC) {
            ttMC.morph({ left: '356px' }, { duration: 0.8, queue: { scope: 'menuScope', position: 'end'} });
            ttD.morph({ left: '0px' }, { duration: 0.8, queue: { scope: 'menuScope', position: 'end' }, afterFinish: function() {
                ttRMCP.innerHTML = 'Desserts';
            }});
        }
        else if (curNavD) {
            ttD.morph({ left: '356px' }, { duration: 0.8, queue: { scope: 'menuScope', position: 'end'} });
            ttA.morph({ left: '0px' }, { duration: 0.8, queue: { scope: 'menuScope', position: 'end' }, afterFinish: function() {
                ttRMCP.innerHTML = 'Appetizers';
            }});
        }
    }
    else if (item.id == 'ttRMLeftNav') {
        if (curNavA) {
            ttA.morph({ left: '356px' }, { duration: 0.8, queue: { scope: 'menuScope', position: 'end'} });
            ttD.morph({ left: '0px' }, { duration: 0.8, queue: { scope: 'menuScope', position: 'end' }, afterFinish: function() {
                ttRMCP.innerHTML = 'Desserts';
            }});
        }
        else if (curNavMC) {
            ttMC.morph({ left: '356px' }, { duration: 0.8, queue: { scope: 'menuScope', position: 'end'} });
            ttA.morph({ left: '0px' }, { duration: 0.8, queue: { scope: 'menuScope', position: 'end' }, afterFinish: function() {
                ttRMCP.innerHTML = 'Appetizers';
            }});
        }
        else if (curNavD) {
            ttD.morph({ left: '356px' }, { duration: 0.8, queue: { scope: 'menuScope', position: 'end'} });
            ttMC.morph({ left: '0px' }, { duration: 0.8, queue: { scope: 'menuScope', position: 'end' }, afterFinish: function() {
                ttRMCP.innerHTML = 'Main Course';
            }});
        }
    }
}

/* ******* Sponsor ******* */
function moSponsorItem(e) {
    var item = (e.srcElement != null) ? e.srcElement : e.target;
    if (e.type == 'mouseover') {
        item.style.backgroundColor = '#826262';
        //Effect.Queues.get('sponsorScope').each(function(e) { e.cancel() });
        //new $(item.id).morph({ opacity:1.0,backgroundColor: '#826262' }, { duration: 0.5, queue: { scope: 'sponsorScope', position: 'end'} });
    }
    else
        item.style.backgroundColor = '#888888';
        //new $(item.id).morph({ opacity: 0.7, backgroundColor: '#888888' }, { duration: 0.5, queue: { scope: 'sponsorScope', position: 'end'} });
}


/* ******* Nav ******* */
function moMedia(e) {
    var item = (e.srcElement != null) ? e.srcElement : e.target;
    if (item.id == 'mOpenPhotos')
        $('mOpenPhotos').style.top = (e.type == 'mouseover') ? '-28px' : '0px';
    else if (item.id == 'mOpenVideos')
        $('mOpenVideos').style.top = (e.type == 'mouseover') ? '-28px' : '0px';
    else if (item.id == 'mOpenTweets')
        $('mOpenTweets').style.top = (e.type == 'mouseover') ? '-28px' : '0px';
}

function showMedia(e) {
    var item = (e.srcElement != null) ? e.srcElement : e.target;
	var mOpen = $('mOpening');
	if (mOpen.style.top != '440px')
		mOpen.morph({ top: '440px' }, { duration: 0.8, queue: { scope: 'mediaScope', position: 'end'} });
	
	HideLastMedia();
	
	var curPanel = (item.id == 'mOpenVideos') ? $('mTV') : (item.id == 'mOpenPhotos') ? $('mPhotos') : $('mTweets');
	lastMedia = (item.id == 'mOpenVideos') ? 'Video' : (item.id == 'mOpenPhotos') ? 'Photos' : 'Tweets';
	
	curPanel.morph({ left: '20px' }, { duration: 0.0, queue: { scope: 'mediaScope', position: 'end'} });
	new Effect.Opacity(curPanel, {from:0.0,to:1.0,duration: 1.0, queue: { scope: 'mediaScope', position: 'end'}, afterFinish: function(e) {
		curPanel.style.opacity = '1';
		curPanel.style.filter = 'alpha(opacity=100)';
	}
    });

    if (item.id == 'mOpenVideos') {
        if (videos.length == 0)
            getVideos();
        else
            getFirstVideo();
    }
    else if (item.id == 'mOpenPhotos') {
        if (photos.length == 0)
            getPhotos();
        else
            getFirstPhoto();
    }
	else if (item.id =='mOpenTweets') {
		getTweets();
	}
}

function getFirstVideo() {
    var curVid = videos[0];
    $('mCurVideo').innerHTML = curVid.videoObject();
}

function getFirstPhoto() {
    var curPhoto = photos[0];
    $('mPhotoLarge').src = curPhoto.largeImage;
}

function HideLastMedia() {
	var lastPanel = (lastMedia == 'Video') ? $('mTV') : (lastMedia == 'Photos') ? $('mPhotos') : (lastMedia == '') ? '' : $('mTweets');
	if (lastMedia == 'mTweets') 
		$('mTweetsContent').innerHTML = '';
		
	if(lastPanel != '') {
		new Effect.Opacity(lastPanel, {from:1.0,to:0,duration: 1.0, queue: { scope: 'mediaScope', position: 'end'}, afterFinish: function(e) {
			lastPanel.style.left = '-1000px';
		}});
	}
}

function moVideoBtn(e) {
    var item = (e.srcElement != null) ? e.srcElement : e.target;
    //item.style.left = (e.type == 'mouseover') ? '-248px' : '0px';
}

function scrollVideos(e) {
    var item = (e.srcElement != null) ? e.srcElement : e.target;
    var mVideos = $('mVideos');
    var moveTop = '0px';
    if (animating) return;
    animating = true;
    if (item.id == 'mVideoUp') {
        if (videos.length < 4) {
            animating = false;
            return;
         }
        else {
            var moveTopAmount = mVideos.style.top.substring(0, mVideos.style.top.length-2);
            moveTop = moveTopAmount + 200 + 'px';
        }
    }
    else if (item.id == 'mVideoDown') {
        if (mVideos.style.top == '0px') {
            animating = false;
            return;
        }
        else {
            var moveTopAmount = mVideos.style.top.substring(0, mVideos.style.top.length - 2);
            moveTop = moveTopAmount - 200 + 'px';
        }
    }
    mVideos.morph({ top: moveTop }, { duration: 0.8, queue: { scope: 'mediaScope', position: 'end' }, afterFinish: function() { animating = false; } });
}

function moVideo(e) {
    var item = (e.srcElement != null) ? e.srcElement : e.target;
    item.style.backgroundColor = (e.type == 'mouseover') ? '#640000' : '#333';
}

function viewVideo(e) {
    var item = (e.srcElement != null) ? e.srcElement : e.target;
    var vid = videos.find(function(n) { return n.id == item.id });
    if (vid != null) {
        $('mCurVideo').innerHTML = vid.videoObject();
	}
}

function moPhotoBtn(e) {
    var item = (e.srcElement != null) ? e.srcElement : e.target;
    var mpl = $('mPhotosList');
    var cLeft = mpl.style.left.substring(0,mpl.style.left.length-2);
    if ( (item.id == 'mPhotoLeft') && ( (cLeft == photoLefts[0]) || (cLeft == "") ) )
        item.style.top = '-60px';
    else if ((item.id == 'mPhotoRight') && (cLeft == photoLefts[photoLefts.length - 1]))
        item.style.top = '-60px';
    else
        item.style.top = (e.type == 'mouseover') ? '-60px' : '0px';
}

function scrollPhotos(e) {
    var item = (e.srcElement != null) ? e.srcElement : e.target;
    var mPhotos = $('mPhotosList');
    var moveLeft = '0px';
    var curLeft = mPhotos.style.left.substring(0, mPhotos.style.left.length - 2);
    if (animating) return;
    animating = true;
    if (item.id == 'mPhotoLeft') {
        if (mPhotos.style.left == '32px') {
            animating = false;
            return;
        } 
        else {
            for (var i = 0; i < photoLefts.length; i++) {
                if (curLeft == photoLefts[i]) {
                    moveLeft = photoLefts[i - 1];
                    $('mPhotoRight').style.top = '0px';
                    if ((i - 1) == 0) {
                        $('mPhotoLeft').style.top = '-60px';
                    }
                }
            }
            
        }
    }
    else if (item.id == 'mPhotoRight') {
        if (photos.length < 12) {
            animating = false;
            return;
        }
        else {
            if ((curLeft == '') || (curLeft == photoLefts[0])) {
                moveLeft = photoLefts[1];
                $('mPhotoLeft').style.top = '0px';
            }
            else {
                for (var i = 0; i < photoLefts.length; i++) {
                    if (curLeft == photoLefts[i]) {
                        moveLeft = photoLefts[i + 1];
                        if (moveLeft == photoLefts[photoLefts.length - 1]) {
                            $('mPhotoRight').style.top = '-60px';
                        }
                    }
                }
            }
        }
    }
    mPhotos.morph({ left: moveLeft+'px' }, { duration: 1.2, queue: { scope: 'mediaScope', position: 'end' }, afterFinish: function() { animating = false; } });
}

function moThumb(e) {
    var item = (e.srcElement != null) ? e.srcElement : e.target;
    item.style.borderColor = (e.type == 'mouseover') ? '#da5200' : '#ccc';
}

function viewPhoto(e) {
    var item = (e.srcElement != null) ? e.srcElement : e.target;
    var photo = photos.find(function(n) { return n.id == item.id });
    var fullImage = $('mPhotoLarge');
    var mpl = $('mPhotoLoader');
    new Effect.Opacity(mpl, { from: 0, to: 1.0, duration: 0.2, queue: { scope: 'mediaScope', position: 'end' }, afterFinish: function(e) {
        mpl.style.opacity = '1.0';
        mpl.style.filter = 'alpha(opacity=100)';
    } 
    });
	fullImage.morph({top:'-300px'}, {duration:0.6,queue:{scope:'mediaScope',position:'end'}, afterFinish: function(e) {
		fullImage.src = photo.largeImage;
	}});
//	new Effect.Opacity(fullImage, {from:1.0,to:0.0,duration: 0.4, queue: { scope: 'mediaScope', position: 'end'}, afterFinish: function(e) {
//	    fullImage.src = photo.largeImage;
//	}});
}

function loadPicture() {

	$('mPhotoLarge').morph({top:'35px'}, {duration:0.6,queue:{scope:'mediaScope',position:'end'}});

	//new Effect.Opacity($('mPhotoLarge'), {from:0,to:1.0,duration: 0.6, queue: { scope: 'mediaScope', position: 'end'}, afterFinish: function(e) {
	//    fullImage.src = photo.largeImage;
	//}});
	
    new Effect.Opacity($('mPhotoLoader'), {from:1.0,to:0.0,duration:1.0,queue: {scope:'mediaScope', position:'end'}});
	
}

/* ******* SPONSORS ********** */
function getFirstSponsor() {
	if (sponsors.length == 0)
		getSponsors();
	
	var curSponsor = sponsors.find(function(n) { return n.id == 'doans' });

	$('spDetailTitle').innerHTML = curSponsor.title;
	$('spDetailSummary').innerHTML = curSponsor.summary;	
}

function showSponsor(e) {
    var item = (e.srcElement != null) ? e.srcElement : e.target;
	
	if (sponsors.length == 0)
		getSponsors();
	
 	var curSponsor = sponsors.find(function(n) { return n.id == item.id });

	$('spDetailTitle').innerHTML = curSponsor.title;
	$('spDetailSummary').innerHTML = curSponsor.summary;
	
}
