function showImage(el, img)
{
	if (el != null)
	{
		el.style.background = "url(" + img + ")";
	}
}

function hideImage(el)
{
	if (el != null)
	{
		el.style.background = "";
	}
}

function initAdminPost(WEB_ROOT, SITE_ROOT)
{
	initAdminPostUpload(WEB_ROOT, SITE_ROOT, 'post');
}

function initAdminPostUpload(WEB_ROOT, SITE_ROOT, libDir)
{
	$('#fuBodyImage').uploadify({
		'uploader'  : WEB_ROOT + 'includes/plugins/uploadify/uploadify.swf',
		'script'    : WEB_ROOT + 'includes/plugins/uploadify/' + libDir + '_image_upload.php',
		'cancelImg' : WEB_ROOT + 'includes/plugins/uploadify/cancel.png',
		'buttonImg' : WEB_ROOT + 'images/imgBtnBrowse.jpg',
		'auto'      : true,
		'folder'    : SITE_ROOT + 'lib/' + libDir + '/images/original',
		'fileDesc'	: 'Image Files',
		'fileExt'	: '*.jpg;*.jpeg;*.gif;*.png;',
		'onError'	: function(e,q,f,o) 
		{
			alert("There was a problem uploading the file (" + f.name + ").  Please try again.");
		},
		'onComplete': function(e,q,f,r,d)
		{
			var arrImages = r.split('|');
			
			$('#hdBodyImage').val(arrImages[0]);
			$('#BodyImageView').html('<br /><img src="' + WEB_ROOT + 'lib/' + libDir + '/images/preview/md_' + arrImages[1] + '" /><br />');
		}
	});

	$('#fuThumbnail').uploadify({
		'uploader'  : WEB_ROOT + 'includes/plugins/uploadify/uploadify.swf',
		'script'    : WEB_ROOT + 'includes/plugins/uploadify/' + libDir + '_image_upload.php',
		'cancelImg' : WEB_ROOT + 'includes/plugins/uploadify/cancel.png',
		'buttonImg' : WEB_ROOT + 'images/imgBtnBrowse.jpg',
		'auto'      : true,
		'folder'    : SITE_ROOT + 'lib/' + libDir + '/images/original',
		'fileDesc'	: 'Image Files',
		'fileExt'	: '*.jpg;*.jpeg;*.gif;*.png;',
		'onError'	: function(e,q,f,o) 
		{
			alert("There was a problem uploading the file (" + f.name + ").  Please try again.");
		},
		'onComplete': function(e,q,f,r,d)
		{
			var arrImages = r.split('|');
			
			$('#hdPostThumbnail').val(arrImages[0]);
			$('#PostThumbnailView').html('<br /><img src="' + WEB_ROOT + 'lib/' + libDir + '/images/preview/tn_' + arrImages[1] + '" /><br />');
		}
	});

	$('#fuMP3').uploadify({
		'uploader'  : WEB_ROOT + 'includes/plugins/uploadify/uploadify.swf',
		'script'    : WEB_ROOT + 'includes/plugins/uploadify/' + libDir + '_audio_upload.php',
		'cancelImg' : WEB_ROOT + 'includes/plugins/uploadify/cancel.png',
		'buttonImg' : WEB_ROOT + 'images/imgBtnBrowse.jpg',
		'auto'      : true,
		'folder'    : SITE_ROOT + 'lib/' + libDir + '/audio',
		'fileDesc'	: 'Files',
		'fileExt'	: '*.mp3',
		'onError'	: function(e,q,f,o) 
		{
			alert("There was a problem uploading the file (" + f.name + ").  Please try again.");
		},
		'onComplete': function(e,q,f,r,d)
		{
			var arrFile = r;
			$('#hdPostAudio').val(arrFile);

			var flashObj = '<br />';
			flashObj += '<object type="application/x-shockwave-flash" data="' + WEB_ROOT + 'includes/plugins/audioPlayer/player.swf" id="audioplayer1" height="21" width="250">';
			flashObj += '<param name="movie" value="' + WEB_ROOT + 'includes/plugins/audioPlayer/player.swf">'; 
			flashObj += '<param name="bgcolor" value="#000000">';
			flashObj += '<param name="FlashVars" value="playerID=1&amp;soundFile=' + WEB_ROOT + 'lib/post/audio/' + arrFile + '">';
			flashObj += '<param name="quality" value="high">';
			flashObj += '<param name="menu" value="false">';
			flashObj += '<param name="wmode" value="transparent">';
			flashObj += '<embed src="' + WEB_ROOT + 'includes/plugins/audioPlayer/player.swf" id="audioplayer1" width="250" height="21" FlashVars="playerID=1&amp;soundFile=' + WEB_ROOT + 'lib/post/audio/' + arrFile + '" wmode="transparent" bgcolor="#000000">';
			flashObj += '</object>';
			
			$('#PostAudioView').html(flashObj);
		}
	});

	$('#fuFile').uploadify({
		'uploader'  : WEB_ROOT + 'includes/plugins/uploadify/uploadify.swf',
		'script'    : WEB_ROOT + 'includes/plugins/uploadify/' + libDir + '_file_upload.php',
		'cancelImg' : WEB_ROOT + 'includes/plugins/uploadify/cancel.png',
		'buttonImg' : WEB_ROOT + 'images/imgBtnBrowse.jpg',
		'auto'      : true,
		'folder'    : SITE_ROOT + 'lib/' + libDir + '/files',
		'fileDesc'	: 'Files',
		'fileExt'	: '*.doc;*.docx;*.xls;*.xlsx;*.ppt;*.pptx;*.pdf;',
		'onError'	: function(e,q,f,o) 
		{
			alert("There was a problem uploading the file (" + f.name + ").  Please try again.");
		},
		'onComplete': function(e,q,f,r,d)
		{
			var arrFile = r;
			$('#hdPostFile').val(arrFile);
			$('#PostFileView').html('<a href="' + WEB_ROOT + 'lib/' + libDir + '/files/' + arrFile + '" target="_blank" class="white">View File &#187;</a><br />');
		}
	});

	$('#fuImage').uploadify({
		'uploader'  : WEB_ROOT + 'includes/plugins/uploadify/uploadify.swf',
		'script'    : WEB_ROOT + 'includes/plugins/uploadify/' + libDir + '_image_upload.php',
		'cancelImg' : WEB_ROOT + 'includes/plugins/uploadify/cancel.png',
		'buttonImg' : WEB_ROOT + 'images/imgBtnBrowse.jpg',
		'auto'      : true,
		'folder'    : SITE_ROOT + 'lib/' + libDir + '/images/original',
		'fileDesc'	: 'Image Files',
		'fileExt'	: '*.jpg;*.jpeg;*.gif;*.png;',
		'onError'	: function(e,q,f,o) 
		{
			alert("There was a problem uploading the file (" + f.name + ").  Please try again.");
		},
		'onComplete': function(e,q,f,r,d)
		{
			var arrImages = r.split('|');
			
			$('#hdPostImage').val(arrImages[0]);
			$('#PostImageView').html('<br /><img src="' + WEB_ROOT + 'lib/' + libDir + '/images/preview/lg_' + arrImages[1] + '" /><br />');
		}
	});

	$('#fuSlideshow').uploadify({
		'uploader'  : WEB_ROOT + 'includes/plugins/uploadify/uploadify.swf',
		'script'    : WEB_ROOT + 'includes/plugins/uploadify/' + libDir + '_slideshow_upload.php',
		'cancelImg' : WEB_ROOT + 'includes/plugins/uploadify/cancel.png',
		'buttonImg' : WEB_ROOT + 'images/imgBtnBrowse.jpg',
		'auto'      : true,
		'multi'     : true,
		'folder'    : SITE_ROOT + 'lib/' + libDir + '/slideshows/original',
		'fileDesc'	: 'Image Files',
		'fileExt'	: '*.jpg;*.gif;',
		'onError'	: function(e,q,f,o) 
		{
			alert("There was a problem uploading the file (" + f.name + ").  Please try again.");
		},
		'onComplete': function(e,q,f,r,d)
		{ 
			var arrImages = r.split('|');
			var curImages = $('#hdPostSlideshow').val();
			
			if (curImages.length > 0)
			{
				$('#hdPostSlideshow').val(curImages + ',' + arrImages[0]);
			}
			else
			{
				$('#hdPostSlideshow').val(arrImages[0]);
			}

		},
		'onAllComplete': function(e,d)
		{
			var arrImages = $('#hdPostSlideshow').val().split(',');
			arrImages.sort();
			
			for (var i=0; i<arrImages.length; i++)
			{
				var filenameNoExt = arrImages[i].substr(0, arrImages[i].indexOf('.'));
				
				var curHtml = $('#PostSlideshowView').html(); 
				$('#PostSlideshowView').html(curHtml + '<div class="slideshowPreview" id="slideshowImageNew_' + filenameNoExt + '"><img src="' + WEB_ROOT 
					+ 'lib/' + libDir + '/slideshows/preview/tn_' + arrImages[i] + '" /><div><a href="javascript:void removeSlideshowImageNew(\'slideshowImageNew_' + filenameNoExt + '\',\'' + arrImages[i] + '\');" class="white">REMOVE</a></div></div>');
			}
		}
	});

	$('#fuVideo').uploadify({
		'uploader'  : WEB_ROOT + 'includes/plugins/uploadify/uploadify.swf',
		'script'    : WEB_ROOT + 'includes/plugins/uploadify/' + libDir + '_video_upload.php',
		'cancelImg' : WEB_ROOT + 'includes/plugins/uploadify/cancel.png',
		'buttonImg' : WEB_ROOT + 'images/imgBtnBrowse.jpg',
		'auto'      : true,
		'folder'    : SITE_ROOT + 'lib/' + libDir + '/videos',
		'fileDesc'		 : 'Video Files',
		'fileExt'		 : '*.flv;',
		'onError'		 : function(e,q,f,o) 
		{
			alert("There was a problem uploading the file (" + f.name + ").  Please try again.");
		},
		'onComplete'	 : function(e,q,f,r,d)
		{ 
			var arrFile = r;
			$('#hdPostVideo').val(arrFile);
			
			$('#PostVideoView').html('<br /><a href="' + WEB_ROOT + 'lib/' + libDir + '/videos/' + arrFile + '" style="display:block;width:425px;height:300px;" id="player"></a>');
			flowplayer("player", WEB_ROOT + "swf/flowplayer-3.1.5.swf", {clip: {autoPlay: false} });
		}
	});

	$('#fuFlash').uploadify({
		'uploader'  : WEB_ROOT + 'includes/plugins/uploadify/uploadify.swf',
		'script'    : WEB_ROOT + 'includes/plugins/uploadify/' + libDir + '_flash_upload.php',
		'cancelImg' : WEB_ROOT + 'includes/plugins/uploadify/cancel.png',
		'buttonImg' : WEB_ROOT + 'images/imgBtnBrowse.jpg',
		'auto'      : true,
		'folder'    : SITE_ROOT + 'lib/' + libDir + '/flash',
		'fileDesc'		 : 'Flash Files',
		'fileExt'		 : '*.swf;',
		'onError'		 : function(e,q,f,o) 
		{
			alert("There was a problem uploading the file (" + f.name + ").  Please try again.");
		},
		'onComplete'	 : function(e,q,f,r,d)
		{ 
			var arrFile = r;
			$('#hdPostFlash').val(arrFile);
			
			var flashvars = {};
			var params = {base:"swf", wmode:"transparent", bgcolor:"#ffffff", quality:"high", allowScriptAccess:"always", allowNetworking:"all", menu:"false", salign:"t"};
			var attributes = {};
			swfobject.embedSWF(WEB_ROOT + 'lib/' + libDir + '/flash/' + arrFile, 'PostFlashView', '1', '1', '9.0.124', WEB_ROOT + 'swf/expressInstall.swf', flashvars, params, attributes, swfCallback);
			
			function swfCallback(e)
			{
				setTimeout(function() {
					var widthHeight = getDimensions(e.id);
					var dimensions = widthHeight.split(',');
					swfobject.embedSWF(WEB_ROOT + 'lib/' + libDir + '/flash/' + arrFile, 'PostFlashView', dimensions[0], dimensions[1], '9.0.124', WEB_ROOT + 'swf/expressInstall.swf', flashvars, params, attributes);
				}, 1000);
			}
		}
	});

	$('#fuFlashThumbnail').uploadify({
		'uploader'  : WEB_ROOT + 'includes/plugins/uploadify/uploadify.swf',
		'script'    : WEB_ROOT + 'includes/plugins/uploadify/' + libDir + '_flash_thumbnail_upload.php',
		'cancelImg' : WEB_ROOT + 'includes/plugins/uploadify/cancel.png',
		'buttonImg' : WEB_ROOT + 'images/imgBtnBrowse.jpg',
		'auto'      : true,
		'folder'    : SITE_ROOT + 'lib/' + libDir + '/flash/thumbs/',
		'fileDesc'		 : 'Image Files',
		'fileExt'	: '*.jpg;*.jpeg;*.gif;*.png;',
		'onError'		 : function(e,q,f,o) 
		{
			alert("There was a problem uploading the file (" + f.name + ").  Please try again.");
		},
		'onComplete'	 : function(e,q,f,r,d)
		{ 
			var arrImages = r.split('|');
			$('#hdPostFlashThumbnail').val(arrImages[0]);
			$('#PostFlashThumbnailView').html('<br /><img src="' + WEB_ROOT + 'lib/' + libDir + '/flash/thumbs/tn_' + arrImages[1] + '" /><br />');
		}
	});

	togglePostType();
}

function initBlogUpload(WEB_ROOT, SITE_ROOT)
{
	$('#fuBodyImage').uploadify({
		'uploader'  : WEB_ROOT + 'includes/plugins/uploadify/uploadify.swf',
		'script'    : WEB_ROOT + 'includes/plugins/uploadify/blog_image_upload.php',
		'cancelImg' : WEB_ROOT + 'includes/plugins/uploadify/cancel.png',
		'buttonImg' : WEB_ROOT + 'images/imgBtnBrowse.jpg',
		'auto'      : true,
		'folder'    : SITE_ROOT + 'lib/blog/original',
		'fileDesc'	: 'Image Files',
		'fileExt'	: '*.jpg;*.jpeg;*.gif;*.png;',
		'onError'	: function(e,q,f,o) 
		{
			alert("There was a problem uploading the file (" + f.name + ").  Please try again.");
		},
		'onComplete': function(e,q,f,r,d)
		{
			var arrImages = r.split('|');
			
			$('#hdBodyImage').val(arrImages[0]);
			$('#BodyImageView').html('<br /><img src="' + WEB_ROOT + 'lib/blog/preview/md_' + arrImages[1] + '" /><br />');
		}
	});
}

function togglePostType()
{
	var arrTypes = new Array('Audio','File','Flash','Image','Podcast','RSS','Slideshow','Text','Video');
	for (var type in arrTypes)
	{
		$('#div' + arrTypes[type]).removeClass('show').addClass('hide');
	}
	
	var type = $('#ddType').val();
	switch (type)
	{
		case 'audio':
			$('#divAudio').removeClass('hide').addClass('show');
			break;
		case 'file':
			$('#divFile').removeClass('hide').addClass('show');
			break;
		case 'image':
			$('#divImage').removeClass('hide').addClass('show');
			break;
		case 'podcast':
			$('#divPodcast').removeClass('hide').addClass('show');
			break;
		case 'slideshow':
			$('#divSlideshow').removeClass('hide').addClass('show');
			break;
		case 'video':
			$('#divVideo').removeClass('hide').addClass('show');
			break;
		case 'flash':
			$('#divFlash').removeClass('hide').addClass('show');
			break;
	}
}

function removeSlideshowImage(id, image)
{
	$('#' + id).remove();
	
	var curRemoveVal = $('#hdPostSlideshowRemove').val();
	if (curRemoveVal)
	{
		curRemoveVal += (curRemoveVal.length > 0) ? ',' + id : id;
		$('#hdPostSlideshowRemove').val(curRemoveVal);
	}
	else
	{
		$('#hdPostSlideshowRemove').val(id);
	}
		
	var curVal = $('#hdPostSlideshow').val();
	curVal = curVal.replace(image, '');
	curVal = curVal.replace(',,', ',');
	curVal = (curVal.charAt(0) == ',') ? curVal.substr(1,curVal.length - 1) : curVal;
	curVal = (curVal.charAt((curVal.length - 1) == ',')) ? curVal.substr(0,curVal.length - 1) : curVal;
	$('#hdPostSlideshow').val(curVal);
}

function removeSlideshowImageNew(id, image)
{
	$('#' + id).remove();
	
	var curVal = $('#hdPostSlideshow').val();
	curVal = curVal.replace(image, '');
	curVal = curVal.replace(',,', ',');
	curVal = (curVal.charAt(0) == ',') ? curVal.substr(1,curVal.length - 1) : curVal;
	curVal = (curVal.charAt((curVal.length - 1)) == ',') ? curVal.substr(0,curVal.length - 1) : curVal;
	$('#hdPostSlideshow').val(curVal);
}

function getFlashObj(movie)
{
   if (window.document[movie]) {
      return window.document[movie];
   }
   if (navigator.appName.indexOf("Microsoft Internet")==-1) {
      if (document.embeds && document.embeds[movie]) {
         return document.embeds[movie]; 
      }
   } else {
      return document.getElementById(movie);
   }
}

function getDimensions(movie) 
{
   var movieObj = getFlashObj(movie);
   var width = movieObj.TGetProperty("/", 8);
   var height= movieObj.TGetProperty("/", 9);
   return width + ',' + height;
   //alert("The current dimensions for the Flash Object ("+movie+") are "+width+" in width and "+height+" in height.");
}

function toggleNumAnswers(ddAnswers, id)
{
	document.location.href = 'poll-edit.php?id=' + id + '&n=' + ddAnswers.value;	
}

function submitVote()
{
	var radioList = document.forms['fmVote'];
	if (radioList) 
	{
		radioList.submit();
	}
}
