var availStories    = new Array;
var availBanners    = new Array;
var availFacts      = new Array;
var curBanner;
var curBannerId     = 0;
var numBanners      = 0;
var openQuote       = "&#8220;";
var closeQuote      = "&#8221;";

function init(page)
{	
	var curStoryID 	= "";
	var theStory 	= storiesJSON.stories[storyID];
	
	// getAvailableStories();
	// availStories.sort(sortByDate);
	// var theStory = availStories[(availStories.length)-1].storyID;
	// storyID = sid;
	
	preload_image = new Image(880,332); 
	preload_image.src = theStory.storyPhoto; 
    
    // var photoSmall = theStory.storyPhoto;
    // if ( typeof(theStory.storyPhotoSmall) !== 'undefined' && theStory.storyPhotoSmall !== null ) {
    //	photoSmall = theStory.storyPhotoSmall;
    // }
	$('mainPhoto').update('<img src="' + theStory.storyPhoto + '" width="880" height="331" alt="" onLoad="kickOff()">');
	// $('mainPhotoSmall').update('<img src="' + photoSmall + '" height="331" alt="">');
	var d = new SimpleDate(Date.parse(theStory.storyDate));
	$('teaserContentCopy').update(formatTeaserText(theStory));
	$('storyCopy').update(formatStoryText(theStory));
	$('story').style.height=theStory.storyHeight + "px";

	formatMediaArea(theStory);
}

function getMoreStories(){
	var curMonth="";
	var dateList="";
	getAvailableStories();
	availStories.reverse();
	storycnt = 0;
	for(var st in availStories){
		if (typeof availStories[st] != 'function') {
			storyRef = availStories[st];
			var dt = new SimpleDate(Date.parse(storyRef.storyDate));
			theMonth = dt.toFormattedString('~M');
			if (curMonth != theMonth) {
				if (curMonth != "") dateList = dateList + "</ul><div class='clear'></div><ul>";
				curMonth=theMonth;
				storycnt=0;
				dateList = dateList + "<li class='title'>"+ theMonth +"</li>";
			}
			dateList = dateList + "<li><a href='index.jsp?storyID="+storyRef.storyID+"'><img src='"+storyRef.storyThumbnail+"' alt='' width='131' height='89' /></a>"+storyRef.storyThumbnailCaption+"</li>";
			storycnt++;
			if (storycnt > 4) {
				dateList = dateList + "</ul><div class='clear'></div><ul>";
				storycnt=0;
			}

		}
	}
	document.write(dateList);
}

function getAvailableStories(){
	var today = new Date();

	for(var st=0; st<storiesJSON.stories.length; st++){
		var tmp = storiesJSON.stories[st].storyDate;
		var tdate = new Date(tmp);
		//alert(tdate+'..'+today+'...'+(tdate<=today));
		if (tdate <= today) {
			availStories[storiesJSON.stories[st].storyID]=storiesJSON.stories[st];
		}
	}
	
	availStories.sort(sortByDate);
}


function getAvailableFacts(){
	var today = new Date();

	for(var i=0; i<factsJSON.facts.length; i++){
		var tmp = factsJSON.facts[i].factDate;
		var tdate = new Date(tmp);
		//alert(tdate+'..'+today+'...'+(tdate<=today));
		if (tdate <= today) {
			availFacts[factsJSON.facts[i].factId]=factsJSON.facts[i];
		}
	}
	
	availFacts.sort(sortByDate);
}

function sortByDate(a, b) {
    var x = new Date(a.storyDate);
    var y = new Date(b.storyDate);
    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}

function showUpcomingEvents(){
	var x = new Effect.Morph('yellowBoxEvents',{style:'left: 720px;', duration:1.0});

}

function kickOff(){
	//fade the main photo in
	new Effect.Appear('mainPhoto', {duration: .80, from:0.1, to:1.0, afterFinish:showTeaser });
	//set to 530px with Share Your Story and 650 without
	var x = new Effect.Morph('yellowBoxWrapper',{style:'left: 530px;', duration:1.0, afterFinish:showLower});
}

/*
function kickOff(){
    //fade the main photo in
    new Effect.Parallel([
                        new Effect.Appear('mainPhotoSmall',{sync: true }),
                        new Effect.Appear('mainFlavorBattle',{sync: true })
                        ], { 
                          duration: 0.1,
                          queue: { position: 'front', scope: 'storyscope' }
                        });
    
    new Effect.Parallel([
                        new Effect.Move('mainPhotoSmall', { x: -440, mode: 'relative', sync: true }),
                        new Effect.Move('mainFlavorBattle', { x: 440, mode: 'relative', sync: true })
                        ], { 
                          duration: 1.0,
                          queue: { position: 'front', scope: 'storyscope' },
                          afterFinish: function () {
                          	new Effect.Parallel([
				                        new Effect.Appear('teaserContent', {from:0.0, to: 0.7, sync: true }),
				                        new Effect.Appear('teaserContentCopy', {from: 0.0, to: 0.9, sync: true }),
				                        new Effect.Appear('teaserBack', {from: 0.0, to: 0.3, sync: true }),
				                        new Effect.Appear('flavorBattleLink', {sync: true })
				                        ], { 
				                          duration: 2.0,
				                          queue: { position: 'end', scope: 'storyscope' }
				                        });
                          }
                        });
   
    //set to 530px with Share Your Story and 650 without
    new Effect.Morph('yellowBoxWrapper',{style:'left: 530px;', duration:1.0, queue: { position: 'end', scope: 'yellowboxscope' }, afterFinish:showLower });
}
*/
function showTeaser(){
    new Effect.Parallel([
        new Effect.Appear('teaserContent', {from:0.0, to: 0.7, sync: true }),
        new Effect.Appear('teaserContentCopy', {from: 0.0, to: 0.9, sync: true }),
        new Effect.Appear('teaserBack', {from: 0.0, to: 0.3, sync: true })
        ], { 
          duration: 2.0,
          queue: { position: 'end', scope: 'storyscope' }
        });
}

function showFlavorBattle(){
    new Effect.Appear('flavorBattleLink', {duration: 2.0, queue: { position: 'end', scope: 'storyscope' } } );
}

function showStory(){
	element = $('story');
	if(element.style.display == 'none') {
		new Effect.BlindDown(element, {duration: 0.5,  scaleX: false, afterFinish: showMedia });
		new Effect.Fade('teaserBack', {duration: 0.75, from:0.9, to:0.0} );
		new Effect.Fade('teaserContent', {duration: 1.0, from:0.9, to:0.0} );
		new Effect.Fade('teaserContentCopy', {duration: 1.0, from:0.9, to:0.0} );
	}
}
/*
function showStory(){
    var element = $('story');
    if(element.style.display == 'none') {
    	var elArray = ['flavorBattleLink','teaserBack','teaserContent','teaserContentCopy'];
        Effect.multiple(elArray, Effect.Fade, { duration: 0.1, queue: { position: 'front', scope: 'storyscope' }});
        
    	new Effect.Parallel([
	                new Effect.Move('mainPhotoSmall', { x: 440, mode: 'relative', sync: true }),
	                new Effect.Move('mainFlavorBattle', { x: -440, mode: 'relative', sync: true }),
	                new Effect.Fade('mainPhotoSmall',{sync: true }),
                    new Effect.Fade('mainFlavorBattle',{sync: true })
	                ], { 
	                  duration: 0.4,
	                  afterFinish: function () {
                            new Effect.Parallel([
                                       new Effect.Appear('mainPhoto', { sync: true }),
                                       new Effect.BlindDown('story', { scaleX: false, sync: true })
                                        ], { 
                                          duration: 0.5,
                                          afterFinish: showMedia
                                        });
	                  }
	                });
    }
}
*/
function getAvailableBanners() {
	var today = new Date();
	var j = 0;

	for( var i=0; i<bannersJSON.banners.length; i++ ) {

		var onDate = new Date( bannersJSON.banners[i].bannerOnDate );
		var offDate = new Date( bannersJSON.banners[i].bannerOffDate );

		if ( onDate <= today && offDate >= today ) {
			availBanners[j] = bannersJSON.banners[i];
			j++;
		}
	}
	
	availBanners.sort(sortByBannerId);
	
	numBanners = ( availBanners.length );
}

function sortByBannerId(a, b) {
	var x = a.bannerId;
	var y = b.bannerId;
	return((x < y) ? -1 : ((x > y) ? 1 : 0));
}

function getRandomBanner() {
	var rnd = 0;
	while( rnd == 0 || rnd == curBannerId )
	{
		rnd = Math.floor(Math.random() * numBanners);
	}
	return rnd;
}

function getNextBanner() {
	curBannerId++;
	
	if ( curBannerId >= numBanners ) {
		curBannerId = 0;
	}
	
	return curBannerId;
}

function showLower(){
	var bannerRef;
	getAvailableBanners();
	
	var id = 0; // getNextBanner();
	
	if (typeof availBanners[id] != 'function') {
		bannerRef = availBanners[id];
		
		curBanner = bannerRef.bannerDiv;
		curBannerId = id;
	}

	if (numBanners > 0 ) {
		new Effect.Morph(curBanner,{ style:'left: 0px;', duration:1.0, queue: { position: 'end', scope: 'bannerscope' } });
		if (typeof bannerRef.extraJSStart == 'function') {
			bannerRef.extraJSStart();
		}
	}
}


function hideLower(prevId){
	var bannerRef;
	
	if (typeof availBanners[prevId] != 'function') {
		bannerRef = availBanners[prevId];
	}
	
	if (typeof bannerRef.extraJSEnd == 'function') {
		bannerRef.extraJSEnd();
		/* setTimeout("new Effect.Morph(curBanner,{ style:'left: -1000px;', duration:1.0, queue: { position: 'end', scope: 'bannerscope' } });", 1000); */
	}
	else {
		
	}
	
	new Effect.Morph(curBanner,{ style:'left: -1000px;', duration:1.0, queue: { position: 'end', scope: 'bannerscope' } });
}

function updateBanners(){
	var bannerRef;
	var nextBanner = "";
	var nextBannerId = "";
	
	var prevId = curBannerId;
	var id = getNextBanner();
	

	if (typeof availBanners[id] != 'function') {
		bannerRef = availBanners[id];
	
		nextBanner = bannerRef.bannerDiv;
		nextBannerId = id;
	}
	
	
	if ( nextBanner != "" ) {
		hideLower(prevId);
		curBanner = nextBanner;
		curBannerId = nextBannerId;
		new Effect.Morph(curBanner,{ style:'left: 0px;', duration:1.0, queue: { position: 'end', scope: 'bannerscope' } });
		if (typeof bannerRef.extraJSStart == 'function') {
			bannerRef.extraJSStart();
		}
	}

}

bannerPE = new PeriodicalExecuter(updateBanners, bannerTimeout);

/*
function flavorBattleOpen() {
	new Effect.Morph('ads_flavor-battle',{ style:'width: 880px;', duration:1.0, queue: { position: 'front', scope: 'bannerscope' } });
	
	var elArray = ['flavor-battle_choose','flavor-battle_logo','flavor-battle_rules','flavor-battle_close'];
	Effect.multiple(elArray, Effect.Appear, {delay: 1.0, queue: { scope: 'bannerscope' }});
	
	new Effect.Parallel([
						new Effect.Appear('flavor-battle_bigmac-motion',{sync: true }),
						new Effect.Morph('flavor-battle_bigmac-motion',{ style: 'right: 126px;', sync: true })
						], { 
						  duration: 0.8,
						  queue: { position: 'end', scope: 'bannerscope' }
						});
						
	new Effect.Parallel([
						new Effect.Fade('flavor-battle_bigmac-motion',{ sync: true }),
						new Effect.Appear('flavor-battle_bigmac',{ sync: true }),
						new Effect.Appear('flavor-battle_bigmac-text',{ sync: true })
						], { 
						  duration: 0.2,
						  queue: { position: 'end', scope: 'bannerscope' }
						});

	new Effect.Parallel([
						new Effect.Appear('flavor-battle_dqpwc-motion',{sync: true }),
						new Effect.Morph('flavor-battle_dqpwc-motion',{ style: 'right: 247px;', sync: true })
						], { 
						  duration: 0.8,
						  queue: { position: 'end', scope: 'bannerscope' }
						});
						
	new Effect.Parallel([
						new Effect.Fade('flavor-battle_dqpwc-motion',{ sync: true }),
						new Effect.Appear('flavor-battle_dqpwc',{ sync: true }),
						new Effect.Appear('flavor-battle_dqpwc-text',{ sync: true })
						], { 
						  duration: 0.2,
						  queue: { position: 'end', scope: 'bannerscope' }
						});

	new Effect.Parallel([
						new Effect.Appear('flavor-battle_angus-motion',{sync: true }),
						new Effect.Morph('flavor-battle_angus-motion',{ style: 'right: 381px;', sync: true })
						], { 
						  duration: 0.8,
						  queue: { position: 'end', scope: 'bannerscope' }
						});
						
	new Effect.Parallel([
						new Effect.Fade('flavor-battle_angus-motion',{ sync: true }),
						new Effect.Appear('flavor-battle_angus',{ sync: true }),
						new Effect.Appear('flavor-battle_angus-text',{ sync: true })
						], { 
						  duration: 0.2,
						  queue: { position: 'end', scope: 'bannerscope' }
						});
							
}

function flavorBattleClose(){
	
	var elArray = [	'flavor-battle_angus','flavor-battle_angus-text','flavor-battle_dqpwc','flavor-battle_dqpwc-text','flavor-battle_bigmac','flavor-battle_bigmac-text','flavor-battle_choose','flavor-battle_logo','flavor-battle_rules','flavor-battle_close'];
	Effect.multiple(elArray, Effect.Fade, {queue: { scope: 'bannerscope' }});
	
	new Effect.Morph('ads_flavor-battle',{ style:'width: 447px;', duration:0.5, queue: { position: 'end', scope: 'bannerscope' } });
	$('flavor-battle_angus-motion').setStyle({right: '781px'});
	$('flavor-battle_dqpwc-motion').setStyle({right: '647px'});
	$('flavor-battle_bigmac-motion').setStyle({right: '526px'});
}
*/

function hideStory(){
	$('media').hide();
	element = $('story');
	new Effect.BlindUp(element, {duration: 1.0,  scaleX: false, afterFinish:showMedia });
	new Effect.ScrollTo('wrapper');
	showTeaser();	
}

/*
function hideStory(){
    $('media').hide();
    element = $('story');
    new Effect.Parallel([
            new Effect.BlindUp('story', {duration: 1.0,  scaleX: false, sync: true }),
            new Effect.ScrollTo('wrapper',{sync: true }),
            new Effect.Fade('mainPhoto',{sync: true })
            ], { 
              duration: 0.5,
              afterFinish: function () {
          		    new Effect.Parallel([
	                        new Effect.Appear('mainPhotoSmall',{sync: true }),
	                        new Effect.Appear('mainFlavorBattle',{sync: true })
	                        ], { 
	                          duration: 0.1
	                        });

                    new Effect.Parallel([
	                        new Effect.Move('mainPhotoSmall', { x: -440, mode: 'relative', sync: true }),
	                        new Effect.Move('mainFlavorBattle', { x: 440, mode: 'relative', sync: true })
	                        ], { 
	                          duration: 1.0,
	                          afterFinish: function () {
	                            new Effect.Parallel([
	                                        new Effect.Appear('teaserContent', {from:0.0, to: 0.7, sync: true }),
	                                        new Effect.Appear('teaserContentCopy', {from: 0.0, to: 0.9, sync: true }),
	                                        new Effect.Appear('teaserBack', {from: 0.0, to: 0.3, sync: true }),
	                                        new Effect.Appear('flavorBattleLink', {sync: true })
	                                        ], { 
	                                          duration: 2.0
	                                        });
	                          }
	                        });
              }
        });
}
*/

function showMedia(){
	new Effect.Appear('media', {duration: 1.0, from:0.0, to: 1.0 } );
}

function mediaPlayer(contentType,mfile,mimg,mwidth,mheight) {
	switch (contentType){
		case "flash":
			var so = new SWFObject("./assets/swf/mediaplayer.swf","single",mwidth,mheight,"7");
			so.addVariable("file",mfile);
			so.addParam("width",mwidth);
			so.addParam("height",mheight);
			so.addVariable("image",mimg);
			so.addVariable('autostart','true');
			so.addParam('allowfullscreen','true');
			so.addParam('allowscriptaccess','always');
			so.useExpressInstall('./assets/swf/expressinstall.swf');
			so.write("flvplayer");				
			break;
		default:
	}
}

function formatTeaserText(storyRef)
{
	var teaserHTML = "";
	var dt = new SimpleDate(Date.parse(storyRef.storyDate));
	
	var spacer = "";
	if (storyRef.storyTeaserQuote.length < 50 || storyRef.storyTeaserLeadin == "")
	{ 
		spacer="<br/>";
	}
	
	var leadInTrailer = "..";
	if (storyRef.storyTeaserLeadin == "" )
	{ 
		leadInTrailer = "";
	}
	
	if (storyRef.storyTeaserQuoteMarks == "false" ) 
	{
		openQuote = "";
		closeQuote = "";	
	}


	teaserHTML = "<table style='height: 230px;'>" +
				"	<tr valign='middle'>" +
				"		<td>" +
				"			<span class='teaser_date'>" + dt.toFormattedString('~M ~d, ~Y') + "</span>" +
				"			<span class='teaser_quote'>"+openQuote+  storyRef.storyTeaserQuote+closeQuote+"</span>"+spacer+"" +
				"			<span class='teaser_byline'>"+ storyRef.storyTeaserByLine+"</span>" +
				"			<p class='teaser_leadin'>"+ storyRef.storyTeaserLeadin+leadInTrailer+"</p>"+spacer+"" +
				"			<a href='javascript:showStory()'>Read More</a>" +
				"		</td>" +
				"	</tr>" +
				"</table>";
	
	return teaserHTML;
}

/*
function formatTeaserText(storyRef)
{
    var teaserHTML = "";
    var dt = new SimpleDate(Date.parse(storyRef.storyDate));
    
    var spacer = "";
    if (storyRef.storyTeaserQuote.length < 50 || storyRef.storyTeaserLeadin == "")
    { 
        // spacer="<br/>";
    }
    
    var leadInTrailer = "..";
    if (storyRef.storyTeaserLeadin == "" )
    { 
        leadInTrailer = "";
    }
    
    if (storyRef.storyTeaserQuoteMarks == "false" ) 
    {
        openQuote = "";
        closeQuote = "";    
    }


    teaserHTML = "<table style='height: 66px;'>" +
                "   <tr valign='middle'>" +
                "       <td>" +
                "           <span class='teaser_byline'>"+ storyRef.storyTeaserByLine+"</span>" +spacer+"" +
                "           <a href='javascript:showStory()'>Read More</a>" +
                "       </td>" +
                "   </tr>" +
                "</table>";
    
    return teaserHTML;
}
*/

function formatStoryText(storyRef){
	var storyHTML = "";
	var dt = new SimpleDate(Date.parse(storyRef.storyDate));
	if (storyRef.storyTeaserQuoteMarks == "false" ) {
		openQuote="";
		closeQuote="";	
	}

	storyHTML = "<span class='teaser_date'>" + dt.toFormattedString('~M ~d, ~Y') + "</span><span class='teaser_quote_story'>"+openQuote+storyRef.storyTeaserQuote+closeQuote+ "</span><span class='teaser_byline'>" + storyRef.storyTeaserByLine+ "</span><p class='teaser_leadin'>" + storyRef.storyTeaserLeadin+"</p><p>" + storyRef.storyText +  "</p><!--<span class='haveStory'>Have you received an opportunity from McDonald's? <a href='http://tmsroom.com/365black/index.html' class='lightwindow page-options' params='lightwindow_width=750,lightwindow_height=500' title='Share your story' >Share your story.</a></span> --> <a href='javascript:hideStory();' class='closeButton'>X Close</a>";

	return storyHTML;
}

function formatMediaArea(storyRef){
	var mediaHTML = "";
	var mediaType = storyRef.storyMediaType;
	var mediaWidth = storyRef.storyMediaWidth;
	var mediaHeight = storyRef.storyMediaHeight;
	
	switch( mediaType ){
		case "imageGalleryPlusVideo":
			mediaHTML = "";
			mediaHTML = mediaHTML + "<div style='margin-left: 10px; text-align: center;'><div id='flvplayer'><p><a href='http://www.macromedia.com/go/getflashplayer'><img src='http://www.macromedia.com/images/shared/download_buttons/get_flash_player.gif' alt='Get macromedia Flash Player' style='border: none;' /></a></p></div></div>";
			
			mediaHTML = mediaHTML + '<br /><br />' + storyRef.storyMediaCaption + '<br /><div id="gallery"><table border="0" cellpadding="20" cellspacing="20" width="100%">';
			var tmpArray = storyRef.storyMediaList.split(",");
			for (lcv=0; lcv< tmpArray.length; lcv=lcv+2)
			{
				lwopts="hidden";
				if (lcv == 0)
				{ 
					lwopts="page-options";
				}
				lwopts="";
				
				/* check for odd content*/
				if ( (tmpArray.length % 2) == 1 && (lcv + 1) == tmpArray.length )
				{
					mediaHTML = mediaHTML + '<tr><td colspan="2" align="center"><a href="' + tmpArray[lcv] + '.jpg" class="lightview" rel="gallery[myset]"><img src="' + tmpArray[lcv] + '_thumb.jpg" width='+ mediaWidth + '  height='+ mediaHeight + '></a></td></tr>';
				}
				else
				{
					mediaHTML = mediaHTML + '<tr><td><a href="' + tmpArray[lcv] + '.jpg" class="lightview" rel="gallery[myset]"><img src="' + tmpArray[lcv] + '_thumb.jpg" width='+ mediaWidth + '  height='+ mediaHeight + '></a></td><td><a href="' + tmpArray[lcv+1] + '.jpg" class="lightview" rel="gallery[myset]"><img src="' + tmpArray[lcv+1] + '_thumb.jpg" width='+ mediaWidth + '  height='+ mediaHeight + '></a></td></tr>';
				}
			}
			mediaHTML = mediaHTML + "</table>";
			mediaHTML = mediaHTML + '<div style="text-align: center;">' + storyRef.storyMediaCaptionBottom + '</div></div>';
			mediaHTML = mediaHTML + "<script type='text/javascript'>Lightview.updateViews()</script>";
			
			break;
		
		case "video":
			mediaHTML = storyRef.storyMediaCaption +"<div id='flvplayer'><p><a href='http://www.macromedia.com/go/getflashplayer'><img src='http://www.macromedia.com/images/shared/download_buttons/get_flash_player.gif' alt='Get macromedia Flash Player' style='border: none;' /></a></p></div>";
            mediaHTML = mediaHTML + '<div style="text-align: center;">' + storyRef.storyMediaCaptionBottom + '</div>';
			break;
			
		case "radio":
			var tmpArray = storyRef.storyMediaList.split(",");
			mediaHTML = mediaHTML + "<span class='media_caption'>" + storyRef.storyMediaCaption + '</span><br/><br/>';
			galCntr = 0;
			for (lcv=0; lcv< tmpArray.length; lcv++){
				curItem = tmpArray[lcv];
				dot = curItem.lastIndexOf(".");
				extension = ""; 
				
 				if( dot != -1 ) extension = curItem.substr(dot,curItem.length);
				switch(extension){
					case ".jpg":
						thumbItem = curItem.replace(".jpg","_thumb.jpg");
						mediaHTML = mediaHTML + '<a href="' + curItem + '" class="lightview" rel="gallery[myset]"><img src="' + thumbItem+ '"  height="126"></a>&nbsp;';
					
					break;
					case ".mp3":
						playervars = 'height=20&width=180&allowfullscreen=true&autostart=true&file=' + escape(curItem);

						mediaHTML = mediaHTML + '<a href="assets/swf/mediaplayer.swf?' + playervars + '" class="lightview" title=" :: :: width: 180, height: 20, topclose: true"><img src="' + storyRef.storyMediaPoster + '" alt="image" height="126" border="0" /></a>&nbsp;';
					break;
				}
				galCntr++;
				if (galCntr > 1) {
					galCntr=0;
					mediaHTML = mediaHTML + "<br/><br/>";
				}
			}
			mediaHTML = mediaHTML + '<div style="text-align: center;">' + storyRef.storyMediaCaptionBottom + '</div>';
			mediaHTML = mediaHTML + "<p class='media_legal'>" + storyRef.storyMediaLegal + "</p><script type='text/javascript'>Lightview.updateViews()</script>";
			break;
			
		case "imageGallery":
			mediaHTML = storyRef.storyMediaCaption + '<br /><br /><div id="gallery"><table border="0" cellpadding="20" cellspacing="20">';
			var tmpArray = storyRef.storyMediaList.split(",");
			for (lcv=0; lcv< tmpArray.length; lcv=lcv+2)
			{
				lwopts="hidden";
				if (lcv == 0)
				{ 
					lwopts="page-options";
				}
				lwopts="";
				
				/* check for odd content*/
				if ( (tmpArray.length % 2) == 1 && (lcv + 1) == tmpArray.length )
				{
					mediaHTML = mediaHTML + '<tr><td colspan="2" align="center"><a href="' + tmpArray[lcv] + '.jpg" class="lightview" rel="gallery[myset]"><img src="' + tmpArray[lcv] + '_thumb.jpg" width='+ mediaWidth + '  height='+ mediaHeight + '></a></td></tr>';
				}
				else
				{
					mediaHTML = mediaHTML + '<tr><td><a href="' + tmpArray[lcv] + '.jpg" class="lightview" rel="gallery[myset]"><img src="' + tmpArray[lcv] + '_thumb.jpg" width='+ mediaWidth + '  height='+ mediaHeight + '></a></td><td><a href="' + tmpArray[lcv+1] + '.jpg" class="lightview" rel="gallery[myset]"><img src="' + tmpArray[lcv+1] + '_thumb.jpg" width='+ mediaWidth + '  height='+ mediaHeight + '></a></td></tr>';
				}
			}
			mediaHTML = mediaHTML + '</table>';
			mediaHTML = mediaHTML + '<div style="text-align: center;">' + storyRef.storyMediaCaptionBottom + '</div></div>';
			mediaHTML = mediaHTML + '<script type="text/javascript">Lightview.updateViews()</script>';
			break;
	}
	
	$('media').update(mediaHTML);
	
	if ( mediaType == "video" ) 
	{
		mediaPlayer("flash",storyRef.storyMediaList,storyRef.storyMediaPoster,storyRef.storyMediaWidth,storyRef.storyMediaHeight);
		$('flvplayer').style.height=mediaHeight + "px";
	}
	else if ( mediaType == "imageGalleryPlusVideo" )
	{
		mediaPlayer("flash",storyRef.videoMediaList,storyRef.videoMediaPoster,storyRef.videoMediaWidth,storyRef.videoMediaHeight);
		$('flvplayer').style.height=storyRef.videoMediaHeight + "px";
	}
}


function padLeft(n, total_length ) 
{ 
    n = n.toString(); 
    var pd = ''; 
    if (total_length > n.length) 
    { 
        for (i=0; i < (total_length - n.length); i++) 
        { 
            pd += '0'; 
        } 
    } 
    return pd + n.toString(); 
} 
