// Add DOM event to the page
function addEvent(obj,evt,func)
{ 
	if(window.addEventListener)
	{ 
		evt = evt.replace(/^on/i,""); 
		obj.addEventListener(evt,func,false); 
	}	
	else 
		obj.attachEvent(evt,func);
}
// Quick and easy function to grab an element...
function $() 
{
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}
// Function to grab an element via the CSS classname...
function getElementsByClass(searchClass,node,tag) 
{
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

// Toggle 'display' property...
function showDIV(objDiv)
{
   var myElement = document.getElementById(objDiv); 
   if (myElement.style.display == "none")
   {
       myElement.style.display = "";
   }
   else
   {
       myElement.style.display = "none";
   }
}
// Toggle commentPreview div
function toggleCommentPreview()
{
	var cPreview = document.getElementById('commentPreview');
	if (cPreview.style.display == "none")
	{
		addEvent(cPreview, "onfocus", initLivePreview);
		cPreview.style.display = "";
		cPreview.focus();
	}
	else
		cPreview.style.display = "none";
}

// Add flash video clip to page...
function foovid(fvid,width,height) 
{
	if(document.getElementById)
	{
		document.write('<div class="fvid">');
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+width+'" height="'+height+'" id="FLVPlayer">');
		document.write('<param name="movie" value="/vids/FLVPlayer_Progressive.swf" />');
		document.write('<param name="salign" value="lt" />');
		document.write('<param name="quality" value="high" />');
		document.write('<param name="scale" value="noscale" />');
		document.write('<param name="wmode" value="transparent" />');
		document.write('<param name="FlashVars" value="&skinName=clearSkin_2&streamName=' + fvid + '&autoPlay=false&autoRewind=false" />');
		document.write('<embed src="/vids/FLVPlayer_Progressive.swf" flashvars="&skinName=clearSkin_2&streamName=' + fvid + '&autoPlay=false&autoRewind=false" quality="high" scale="noscale" width="'+width+'" height="'+height+'" name="FLVPlayer" salign="LT" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
		document.write('</object>');
		document.write('</div>');
	}	
}

// Add the FooPlayer to the page...
function fooPlayer(name,song)
{
	if(document.getElementById)
	{
		document.write('<div align="center" style="margin:10px 0"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="300" height="50" id="FooSounds" align="middle" VIEWASTEXT>');
		document.write('<param name="allowScriptAccess" value="sameDomain" />');
		document.write('<param name="movie" value="/FooSounds.swf?initColor=0x333333&&autoPlaySong=&autoLoopSong=&initName=' + name + '&initFile=/tunes/' + song + '.mp3" />');
		document.write('<param name="quality" value="high" />');
		document.write('<param name="bgcolor" value="#ffffff" />');
		document.write('<embed src="/FooSounds.swf?initColor=0x333333&autoPlaySong=&autoLoopSong=&autoinitName=' + name + '&initFile=/tunes/' + song + '.mp3" quality="high" bgcolor="#ffffff" width="300" height="50" name="FooSounds" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
		document.write('</object></div>');
	}	
}	
// Add the DarkXP FooVid Player...
function darkFooVid(src)
{
	if(document.getElementById)
	{
		if (window.ActiveXObject)
			var flgAuto = "0";
		else
			var flgAuto = "1";
				
		document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="320" height="240" id="fooDarkVids" align="middle" VIEWASTEXT>');
		document.write('<param name="allowScriptAccess" value="sameDomain" />');
		document.write('<param name="movie" value="/vids/fooVids.swf?autoLoopVideo='+flgAuto+'&autoPlayVideo='+flgAuto+'&initFile=/vids/' + src + '.flv" />');
		document.write('<param name="quality" value="high" />');
		document.write('<param name="bgcolor" value="#333333" />');
		document.write('<embed src="/vids/fooVids.swf?autoLoopVideo='+flgAuto+'&autoPlayVideo='+flgAuto+'&initFile=/vids/' + src + '.flv" quality="high" bgcolor="#000000" width="320" height="240" name="fooVids" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
		document.write('</object>');
	}	
}

// IE browser check
function isIE4() {
	return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') );
}

// Another version of toggle'n an element's Display property:
function getEl(id) { return document.getElementById(id); }
function showhide(id) { getEl(id).style.display =  getEl(id).style.display == 'none' ? '' : 'none'; }

function switchDiv(el) {  
	var id = el;  
	var num = 1;  
	var obj = document.getElementById("oDiv" + num); 
	
	while (obj) 
	{	
	  if (obj.id == el) obj.style.display = "";	
	  else obj.style.display = "none";
	
	obj = document.getElementById("oDiv" + num++); 
	} 
}

sID = "";
function commentWin(sID) 
{
	if (window.ActiveXObject)
		var winH = "466";
	else
		var winH = "482";

	window.open('/comments/2k3/?blogid='+sID+'','FooComment2K3','toolbar=0,location=0,status=1,menubar=0,scrollbars=0,resizable=0,width=660,height='+winH);
}

function fcWin(sID,sh) {
	window.open('/comments/2k3/?blogid='+sID+'&show='+sh+'','FooComment2K3','toolbar=0,location=0,status=1,menubar=0,scrollbars=0,resizable=1,width=600,height=475');
}

function openVid() {
    window.open('/foovid.cfm','FooVids','toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=1,width=500,height=260');
}
function rssLinkWin(cid) {
    window.open('http://www.forgetfoo.com/rsslinx.cfm?catid='+cid+'','RSSLinks','toolbar=0,location=1,status=0,menubar=0,scrollbars=1,resizable10,width=760,height=500');
}
function contactWin() {
    window.open('/contact/','ContactFoO','toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=500,height=420');
}
function fooDesktop(){
	if (document.all) 
		window.open('http://desktop.forgetfoo.com/','FooDESKTOP','fullscreen');		
}
function openFooChat() {
	if (document.all)
		//window.open("/fooChat/fc-real.cfm","FooChat","width=622,height=400,scrollbars=no,resizable=no,location=no,toolbar=no");
		window.open("http://chat.forgetfoo.com/","FooChat","width=640,height=480,scrollbars=no,resizable=no,location=no,toolbar=no");
}
function sideChat() {
	void(_search=open('/sidechat/','_search'))
}
function swfWin(swf,w,h) {
	window.open(swf,'FooFlash','toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+w+',height='+h+'')
}
function openWin(theURL,winName,features) {
  	window.open(theURL,winName,features);
}

// simple DOM rollovers...
function mOver(el,img) {
	$(el).setAttribute("src","/images/"+img+".gif");
}
function mOut(el,img) {
	$(el).setAttribute("src","/images/"+img+".gif");
}

// Zoomify EZ (Flash Image Viewer)
function zoomify(img,w,h) 
{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="'+w+'" height="'+h+'" id="zoomEZ">');
	document.write('<param name="FlashVars" value="zoomifyImagePath=http://www.forgetfoo.com/images/blog/' + img + '/&zoomifyNavWindow=0">');
	document.write('<param name="MENU" value="FALSE">');
	document.write('<param name="SRC" value="http://www.forgetfoo.com/swf/zoomifyViewer.swf">');
	document.write('<embed FlashVars="zoomifyImagePath=http://www.forgetfoo.com/images/blog/' + img + '/&zoomifyNavWindow=0" src="zoomifyViewer.swf" menu="false" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width="'+w+'" height="'+h+'" name="zoomez"></embed>');
	document.write('</object>');
}

function togglePlus(objDiv,objImage)
{
   var myElement = document.getElementById(objDiv,objImage);    
   if (myElement.style.display == "none")
   {
       myElement.style.display = "";
       objImage.src = "/images/bx-minus.gif";
   }
   else
   {
       myElement.style.display = "none";
       objImage.src = "/images/bx-plus.gif";
   }
}

//Text field counter
function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else 
		countfield.value = maxlimit - field.value.length;
	}

// Function to add the code for bold italic and underline, to the message
function AddMessageCode(code,promptText, InsertText) {

	if (code != "") {
		insertCode = prompt(promptText + "\n[" + code + "]xxx[/" + code + "]", InsertText);
			if ((insertCode != null) && (insertCode != "")){
				document.frmImgComment.cComments.value += "[" + code + "]" + insertCode + "[/"+ code + "] ";
			}
	}		
	document.frmImgComment.cComments.focus();
}
	
//Function to add the code to the message for the smileys
function AddSmileyIcon(iconCode) {	
		document.frmImgComment.cComments.value += iconCode + " ";
		document.frmImgComment.cComments.focus();
		document.frmImgComment.cComments.className = 'frm-on';
}

//Function to toggle 'Loading images' in Gallery
function ImgChk()
{
  if (loadingImgallery.style.display == "none")
    return "block";
       
  imgs = galleryContainer.getElementsByTagName('IMG');
  for (var i=0; i<imgs.length; i++)
    if (!imgs[i].complete)
      return "none";
  
  loadingImgallery.style.display = "none";
  return "block";
}
		

