/* Swftype.js */
//<![CDATA[
var _debug;
function createSwftype(swftypeTag, swftypeSrc, cssSrc, swftypeWidth, swftypeHeight, txtSelect, resizeType, debug)
{
	_debug = debug;
	
	var elClassName = "";
	var hasDot = false;
	if(swftypeTag.indexOf(".") != -1)
	{	
		hasDot = true;
		elClassName = swftypeTag.substring(swftypeTag.indexOf(".")+1, swftypeTag.length);
		swftypeTag = swftypeTag.substring(0, swftypeTag.indexOf("."));
		if(swftypeTag.length==0)
		{
			swftypeTag=elClassName;
		}
	}		
	
	if((document.getElementsByTagName(swftypeTag) != "") || (document.getElementsByClassName(swftypeTag) != ""))
	{	
		if(document.getElementsByTagName(swftypeTag).length > 0)											
			var theSwftypeTag = document.getElementsByTagName(swftypeTag);												
		else if(document.getElementsByClassName(swftypeTag).length > 0 )
			var theSwftypeTag = document.getElementsByClassName(swftypeTag);			
	
		if(theSwftypeTag != null)
		{
			for(var i=0; i<theSwftypeTag.length; i++)
			{			
				var obj = theSwftypeTag[i];
				var tagName = obj.tagName;	
				var className= obj.className;	
				
				if(obj.className.indexOf(elClassName) != -1)
				{
					className = obj.className;
					obj.setAttribute('id', 'Swftype'+swftypeTag+i);			
					if(obj.innerHTML != null)
					{
						/* Swftype Content */
						var pageTxt = obj.innerHTML;			
						// search and add ' in classNames 
						if(pageTxt.indexOf('class=') != -1){			
							var firstQuote = (pageTxt.indexOf('class=') + 6);
							var spanCloseTag = pageTxt.indexOf('>');
							var className = pageTxt.substr(firstQuote, (spanCloseTag - firstQuote));				
							if(pageTxt.charAt(firstQuote) != '"'){
								pageTxt = pageTxt.replace(className,'"'+className+'"');
							}
						}									
						
						var printAlt = document.createElement("span");				
						// printAlt.setAttribute("class", "printSwfType");   
						printAlt.className = "printSwfType";				
						printAlt.innerHTML = pageTxt;   						
						obj.parentNode.insertBefore(printAlt, obj);
						
						
						// Escape all quotes with single quotes
						//pageTxt = pageTxt.replace(/"/g, "'");			
						
						// Convert apostrophes to ascii
						var ahrefStr = pageTxt.substring(pageTxt.indexOf("href=\"")+6, pageTxt.indexOf("\">"));
						pageTxt = pageTxt.replace(ahrefStr, ahrefStr.replace(/"/g, "'"));
						
						// Convert a href quotes to single quotes
						pageTxt = pageTxt.replace("<a href=\"", "<a href='");
						pageTxt = pageTxt.replace("<A href=\"", "<A href='"); // Because IE sucks!
						pageTxt = pageTxt.replace("\">", "'>");
						
						pageTxt = pageTxt.replace(/\+/g, "&#43;");		// Plus
						pageTxt = pageTxt.replace(/%/g, "&#37;");		// Percentage						
						pageTxt = pageTxt.replace(/&/g, "{and}");		// Ampersand
													
						if(_debug)
						{
							alert("Swftype Debug: " + pageTxt);
						}
					}
					else
					{
						var pageTxt = "DEFAULT";
					}
				}
				/* swfobject2 */
				var flashvars = {};
				flashvars.swftypeID		= "Swftype" + swftypeTag + i;
				flashvars.pageText		= pageTxt;
				flashvars.cssURL		= cssSrc;
				flashvars.tagName		= tagName;
				flashvars.hasDot		= hasDot;
				flashvars.className		= className;
				flashvars.txtWidth		= swftypeWidth;
				flashvars.txtHeight		= swftypeHeight;
				flashvars.txtSelect		= txtSelect;
				flashvars.resizeMethod	= resizeType;
				flashvars.debug 		= debug;
				flashvars.version		= 1.6;
				flashvars.swftypeURL	= "http://swftype.zeroseven.com.au/";
				var params = {};
				params.allowScriptAccess = "always";
				params.menu = "false";
				params.wmode = "transparent";
				var attributes = {};
				swfobject.embedSWF(swftypeSrc, "Swftype" + swftypeTag + i, swftypeWidth, swftypeHeight, "10", "false", flashvars, params, attributes);			
							
			}
		}
	}

}

/* Swftype Resize */
function resizeSwftype(SwftypeId, textWidth, textHeight)
{		
	//alert(textHeight);
	document.getElementById(SwftypeId).style.width = textWidth + "px";	
	document.getElementById(SwftypeId).style.height = textHeight + "px";
}

function resizeSwfTypeObject(SwftypeId,newWidth,newHeight)
{
	var flashvars = {};
	var params = {};
	params.allowScriptAccess = "always";
	params.menu = "false";
	params.wmode = "transparent";
	var attributes = {};	
	
	var objectID = document.getElementById(SwftypeId);
	if(navigator.appName.indexOf('Microsoft') != -1){
		var newUrl = objectID.movie;
	}else{
		var newUrl = objectID.data;
	}

	newUrl = newUrl.replace(/&txtWidth=.*&txtHeight/g,"&txtWidth="+newWidth+"&txtHeight");
	swfobject.embedSWF(newUrl, SwftypeId, newWidth, newHeight, "8", "false", flashvars, params, attributes);	
}

function showWarning(msg)
{
	if(_debug)
		alert("Swftype Warning: " + msg);
}

document.getElementsByClassName = function(elClassName)
{
    var arrayList = new Array();
    var elements = document.getElementsByTagName("*");
    for(var i = 0;i < elements.length;i++)
	 {
        if(elements[i].className.indexOf(" ") >= 0)
		  {
            var classes = elements[i].className.split(" ");
            for(var j = 0;j < classes.length;j++)
				{
               if(classes[j] == elClassName)
					{
                  arrayList.push(elements[i]);
					}
            }
        }
			else if(elements[i].className == elClassName)
			{
				arrayList.push(elements[i]);
			}		
    }
    return arrayList;
}
//]]>