var strOn = "/img/icon/icon-square-red.gif"
var strOff = "/img/icon/icon-square-black.gif"
var imgOn = new Image();
var imgOff = new Image();
imgOn.src = "/img/icon/icon-square-red.gif";
imgOff.src = "/img/icon/icon-square-black.gif";

function fnImageChange(intImage){
	idNavOffItem = 'news-image-nav-' + intActiveImage;
	document.images[idNavOffItem].src = imgOff.src;
	document.getElementById('news-image-' + intActiveImage).style.display = "none";
	document.getElementById('news-image-caption-' + intActiveImage).style.display = "none";
	
	idNavItem = 'news-image-nav-' + intImage;
	document.images[idNavItem].src = imgOn.src;
	document.getElementById('news-image-' + intImage).style.display = "block";
	document.getElementById('news-image-caption-' + intImage).style.display = "block";
	intActiveImage = intImage;
}

function fnImageNext(){
	(intActiveImage == (arrayImagePath.length - 1)) ? fnImageChange(1) : fnImageChange(intActiveImage + 1);
}

function fnImagePrevious(){
	(intActiveImage == 1) ? fnImageChange((arrayImagePath.length - 1)) : fnImageChange(intActiveImage - 1);
}

function createImageURL() {
	var simpleStr = arrayImageURL[intActiveImage];
	var tmpArr = (simpleStr.split('/'));
	tmpArr.splice(0,1);
	var newStr = tmpArr.join('/');
	var newStr2 = '/send/link/';
	var newStr3 = newStr2.concat(newStr);
	location.href = newStr3;

}

function fnBuildImageViewer() {
	var intTotalImages = (arrayImagePath.length - 1);
	
	document.write('<div class="news-image-corner-ur"></div>');
	
	for(i = 1; i <= intTotalImages; i++) {
		
		if (i == intActiveImage) { var strDisplay = "block" } else { var strDisplay = "none"; }
		document.write('<div class="news-image-display" id="news-image-' + i + '" style="display:' + strDisplay + ';"><a href="'+ arrayImageURL[i] + '"><img src="' + arrayImagePath[i] + '" width="256" height="243" alt="' + arrayImageCaption[i] + '" /></a></div>');
		document.write('<div class="bd-caption-2wide-bc" id="news-image-caption-' + i + '" style="display:' + strDisplay + ';">' + arrayImageCaption[i] + '</div>');
	}
	
	document.write('<div class="news-media-bottomLink"><a href="#" onclick="location.href= arrayImageURL[intActiveImage]; return false;">Enlarge</a>/<a href="#" onClick="createImageURL(); return false;">Send</a></div>');
	document.write('<ul class="news-media-nav">');
	document.write('<li><img src="/img/icon/icon-image.gif" width="14" height="12" alt="Image menu" title="Image menu" class="news-media-nav-icon" /></li>');
	if (intTotalImages > 1) {
		document.write('<li><a href="#" onclick="fnImagePrevious(); return false;" onmouseover="this.firstChild.src=\'/img/icon/icon-carratLeft-red.gif\';" onmouseout="this.firstChild.src=\'/img/icon/icon-carratLeft-black.gif\';"><img src="/img/icon/icon-carratLeft-black.gif" width="12" height="12" alt="Previous image" title="Previous image" /></a></li>');
	
		for(i = 1; i <= intTotalImages; i++) {
			if (i == intActiveImage) { var strColor = "red" } else { var strColor = "black"; }
			document.write('<li><a href="#" onclick="fnImageChange(' + i + '); return false;" onmouseover="this.firstChild.src =\'' + strOn + '\';" onmouseout="if (' + i + ' != intActiveImage) { this.firstChild.src =\'' + strOff + '\'; }"><img src="/img/icon/icon-square-' + strColor + '.gif" width="14" height="12" name="news-image-nav-' + i + '" title="' + arrayImageCaption[i] + '" /></a></li>');
		}
	
		document.write('<li><a href="#" onclick="fnImageNext(); return false;" onmouseover="this.firstChild.src=\'/img/icon/icon-carratRight-red.gif\';" onmouseout="this.firstChild.src=\'/img/icon/icon-carratRight-black.gif\';"><img src="/img/icon/icon-carratRight-black.gif" width="12" height="12" alt="Next image" title="Next image" /></a></li>');
	}
	document.write('</ul>');
	document.write('<div class="ballast"></div>');
	
}

function fnVideoChange(intVideo){
	idNavOffItem = 'news-video-nav-' + intActiveVideo;
	document.images[idNavOffItem].src = imgOff.src;
	document.getElementById('news-video-caption-' + intActiveVideo).style.display = "none";

	idNavItem = 'news-video-nav-' + intVideo;
	document.images[idNavItem].src = imgOn.src;
	document.getElementById('news-video-caption-' + intVideo).style.display = "block";

	strPath = String(arrayVideoPath[intVideo]);
	if (strPath.substring(0,4) == "http") {
		var pathSWF = strPath;	
	} else {
		var pathSWF = "/inc/swf/videoplayer.swf?flv=" + strPath;
	}
	var so = new SWFObject(pathSWF, 'website', '256', '192', '8', '#000000');
	so.write('videoplayer');
	
	intActiveVideo = intVideo;
}

function fnVideoNext(){
	(intActiveVideo == (arrayVideoPath.length - 1)) ? fnVideoChange(1) : fnVideoChange(intActiveVideo + 1);
}

function fnVideoPrevious(){
	(intActiveVideo == 1) ? fnVideoChange((arrayVideoPath.length - 1)) : fnVideoChange(intActiveVideo - 1);
}

function createVideoURL() {
	var simpleStr = arrayVideoURL[intActiveVideo];
	var tmpArr = (simpleStr.split('/'));
	tmpArr.splice(0,1);
	var newStr = tmpArr.join('/');
	var newStr2 = '/send/link/';
	var newStr3 = newStr2.concat(newStr);
	location.href=newStr3;
}

function fnBuildVideoViewer() {
	var intTotalVideos = (arrayVideoPath.length - 1);

	document.write('<div class="news-video-display" id="videoplayer"><strong>You need to upgrade your Flash Player!</strong></div>');
	for(i = 1; i <= intTotalVideos; i++) {
		if (i == intActiveVideo) { var strDisplay = "block" } else { var strDisplay = "none"; }
		document.write('<div class="bd-caption-2wide-lc" id="news-video-caption-' + i + '" style="display:' + strDisplay + ';">' + arrayVideoCaption[i] + '</div>');
	}
	document.write('<div class="news-media-bottomLink"><a href="#" onclick="location.href= arrayVideoURL[intActiveVideo]; return false;">Enlarge</a>/<a href="#" onClick="createVideoURL(); return false;">Send</a></div>');
	document.write('<ul class="news-media-nav">');
	document.write('<li><img src="/img/icon/icon-video.gif" width="14" height="12" alt="Video menu" title="Video menu" class="news-media-nav-icon" /></li>');

	if (intTotalVideos > 1) {
		document.write('<li><a href="#" onclick="fnVideoPrevious(); return false;" onmouseover="this.firstChild.src=\'/img/icon/icon-carratLeft-red.gif\';" onmouseout="this.firstChild.src=\'/img/icon/icon-carratLeft-black.gif\';"><img src="/img/icon/icon-carratLeft-black.gif" width="12" height="12" alt="Previous video" title="Previous video" /></a></li>');
	
		for(i = 1; i <= intTotalVideos; i++) {
			if (i == intActiveVideo) { var strColor = "red" } else { var strColor = "black"; }
			document.write('<li><a href="#" onclick="fnVideoChange(' + i + '); return false;" onmouseover="this.firstChild.src =\'' + strOn + '\';" onmouseout="if (' + i + ' != intActiveVideo) { this.firstChild.src =\'' + strOff + '\'; }"><img src="/img/icon/icon-square-' + strColor + '.gif" width="14" height="12" name="news-video-nav-' + i + '" title="' + arrayVideoCaption[i] + '" /></a></li>');
		}
	
		document.write('<li><a href="#" onclick="fnVideoNext(); return false;" onmouseover="this.firstChild.src=\'/img/icon/icon-carratRight-red.gif\';" onmouseout="this.firstChild.src=\'/img/icon/icon-carratRight-black.gif\';"><img src="/img/icon/icon-carratRight-black.gif" width="12" height="12" alt="Next video" title="Next video" /></a></li>');
	}
	document.write('</ul>');
	document.write('<div class="ballast"></div>');
	
	var pathSWF = "/inc/swf/videoplayer.swf?flv=" + String(arrayVideoPath[intActiveVideo] + "&url=" + arrayVideoURL[intActiveVideo]);
	var so = new SWFObject(pathSWF, 'website', '256', '192', '8', '#000000');
	so.write('videoplayer');
	
}


function fnLargeImageChange(intImage){
	location.href= arrayImageURL[intImage];
}

function fnLargeImageNext(){
	(intActiveImage == (arrayImagePath.length - 1)) ? fnLargeImageChange(1) : fnLargeImageChange(intActiveImage + 1);
}

function fnLargeImagePrevious(){
	(intActiveImage == 1) ? fnLargeImageChange((arrayImagePath.length - 1)) : fnLargeImageChange(intActiveImage - 1);
}

function fnBuildLargeImageViewer() {
	var intTotalImages = (arrayImagePath.length - 1);
	
		document.write('<div class="bd-content-6wide-white" style="text-align:center;"><img src="' + arrayImagePath[intActiveImage] + '" alt="' + arrayImageCaption[intActiveImage] + '"></div>');
		document.write('</div><div class="bd-box-6wide-white-rc">');
		document.write('<div class="bd-head-6wide-white-bc"></div>');
		document.write('<div class="bd-content-6wide-white">');

		
		if (intTotalImages > 1) {
		document.write('<ul class="gallery-nav">');
		document.write('<li><img src="/img/icon/icon-image.gif" width="14" height="12" alt="Image menu" title="Image menu" class="news-media-nav-icon" /></li>');
		document.write('<li><a href="#" onclick="fnLargeImagePrevious(); return false;" onmouseover="this.firstChild.src=\'/img/icon/icon-carratLeft-red.gif\';" onmouseout="this.firstChild.src=\'/img/icon/icon-carratLeft-black.gif\';"><img src="/img/icon/icon-carratLeft-black.gif" width="12" height="12" alt="Previous image" title="Previous image" /></a></li>');
	
		for(i = 1; i <= intTotalImages; i++) {
			if (i == intActiveImage) { var strColor = "red" } else { var strColor = "black"; }
			document.write('<li><a href="#" onclick="fnLargeImageChange(' + i + '); return false;" onmouseover="this.firstChild.src =\'' + strOn + '\';" onmouseout="if (' + i + ' != intActiveImage) { this.firstChild.src =\'' + strOff + '\'; }"><img src="/img/icon/icon-square-' + strColor + '.gif" width="14" height="12" name="team-image-nav-' + i + '" title="' + arrayImageCaption[i] + '" /></a></li>');
		}
	
		document.write('<li><a href="#" onclick="fnLargeImageNext(); return false;" onmouseover="this.firstChild.src=\'/img/icon/icon-carratRight-red.gif\';" onmouseout="this.firstChild.src=\'/img/icon/icon-carratRight-black.gif\';"><img src="/img/icon/icon-carratRight-black.gif" width="12" height="12" alt="Next image" title="Next image" /></a></li>');
		document.write('</ul>');
		if (arrayImageCaption[intActiveImage] != "") { document.write('<div style="float:left;">' + arrayImageCaption[intActiveImage] + "</div><br>") }
	}
}

function fnLargeVideoChange(intVideo){
	location.href= arrayVideoURL[intVideo];
}

function fnLargeVideoNext(){
	(intActiveVideo == (arrayVideoPath.length - 1)) ? fnLargeVideoChange(1) : fnLargeVideoChange(intActiveVideo + 1);
}

function fnLargeVideoPrevious(){
	(intActiveVideo == 1) ? fnLargeVideoChange((arrayVideoPath.length - 1)) : fnLargeVideoChange(intActiveVideo - 1);
}

function fnBuildLargeVideoViewer() {
	var intTotalVideos = (arrayVideoPath.length - 1);

	document.write('<div style="width:400px; margin:auto; text-align:center;"><br /><div class="bd-video-display-full" id="videoplayer"></div>');
	document.write('<div class="bd-caption-400-lc" style="margin-bottom:0;">' + arrayVideoCaption[intActiveVideo] + '</div><br/></div>');
	
	document.write('</div><div class="bd-box-6wide-white-rc">');
	document.write('<div class="bd-head-6wide-white-bc"></div>');
	document.write('<div class="bd-content-6wide-white">');
	
	document.write('<ul class="gallery-nav">');
	document.write('<li><img src="/img/icon/icon-video.gif" width="14" height="12" alt="Video menu" title="Video menu" class="news-media-nav-icon" /></li>');
	document.write('<li><a href="#" onclick="fnLargeVideoPrevious(); return false;" onmouseover="this.firstChild.src=\'/img/icon/icon-carratLeft-red.gif\';" onmouseout="this.firstChild.src=\'/img/icon/icon-carratLeft-black.gif\';"><img src="/img/icon/icon-carratLeft-black.gif" width="12" height="12" alt="Previous video" title="Previous video" /></a></li>');
	
	for(i = 1; i <= intTotalVideos; i++) {
		if (i == intActiveVideo) { var strColor = "red" } else { var strColor = "black"; }
		document.write('<li><a href="#" onclick="fnLargeVideoChange(' + i + '); return false;" onmouseover="this.firstChild.src =\'' + strOn + '\';" onmouseout="if (' + i + ' != intActiveVideo) { this.firstChild.src =\'' + strOff + '\'; }"><img src="/img/icon/icon-square-' + strColor + '.gif" width="14" height="12" title="' + arrayVideoCaption[i] + '" name="bike-video-nav-' + i + '" /></a></li>');
	}
	
	document.write('<li><a href="#" onclick="fnLargeVideoNext(); return false;" onmouseover="this.firstChild.src=\'/img/icon/icon-carratRight-red.gif\';" onmouseout="this.firstChild.src=\'/img/icon/icon-carratRight-black.gif\';"><img src="/img/icon/icon-carratRight-black.gif" width="12" height="12" alt="Next video" title="Next video" /></a></li>');
	document.write('</ul>');
	
	strPath = String(arrayVideoPath[intActiveVideo] + "&url=" + arrayVideoURL[intActiveVideo]);
	if (strPath.substring(0,4) == "http") {
		var pathSWF = strPath;	
	} else {
		var pathSWF = "/inc/swf/videoplayer400.swf?flv=" + strPath;
	}
	var so = new SWFObject(pathSWF, 'website', '400', '300', '8', '#000000');
	so.write('videoplayer');
	
}

function explodeArray(item,delimiter) {
  tempArray=new Array(1);
  var Count=0;
  var tempString=new String(item);

  while (tempString.indexOf(delimiter)>0) {
    tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter));
    tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1); 
    Count=Count+1
  }

  tempArray[Count]=tempString;
  return tempArray;
}
