/* 

ui.js  

*/
function roundedCorners(tagName, cssClass) {

	// Check for DOM complience
	if(!Array.prototype.push || !document.getElementById) {
		return;
	}
	
	// Which tags are generated in the footer and header
	// Generated content gets their CSS classnames according to the container
	var elements, i, j, elContent, elChildNodes, elWidth;
	
	// Which tag to look for. If no tagname is provided the script will look for all tags.
	if(tagName != '') {
		elContainerTag = tagName;
	}
	
	// Which CSS class to look for. If no CSS class is provided the script will look for the default CSS class 'highlight';
	if(cssClass != '') {
		elClass = cssClass;
	}
	
	/* flash properties */
	var flashvars = {};
	var params = { };
	var attributes = {};	
	params.scale = "noscale";
	params.wmode = "transparent";
	
	elements = document.getElementsByTagName(elContainerTag);
	for (i = 0; i < elements.length; i++) {
		if (hasClass(elements[i], elClass)) {			
			// Create rounded corners
			elContent = elements[i].innerHTML;
			elements[i].innerHTML = '<span class="tl png"></span><span class="tr png"></span>' + elContent + '<span class="bl png"></span><span class="br png"></span>';
			
			if (hasClass(elements[i], 'section')) {
				elChildNodes = elements[i].childNodes;
				/* get flash width */
				elWidth = elements[i].offsetWidth;
				/* loop through box content */
				for (j=0; j < elChildNodes.length; j++) {
					/*  add flash waves */
					if (hasClass(elChildNodes[j], 'flash_wave')) {
						/* add unique id for flash container */
						elChildNodes[j].setAttribute('id', 'flash' + i + j);
						/* if flash is positioned on top of the box */
						if (hasClass(elChildNodes[j], 'top')) {
							setClass(elements[i], 'flash_top');
							params.salign = 't';
							params.align = 't';
							attributes.styleclass = 'top';
							swfobject.embedSWF('/flash/pilvi_yla_685x15.swf', 'flash' + i + j, elWidth, '15', '9.0.0', false, flashvars, params, attributes);
						/* if flash is positioned on bottom of the box */
						} else if (hasClass(elChildNodes[j], 'bottom')) {
							setClass(elements[i], 'flash_bottom');
							attributes.styleclass = 'bottom';
							swfobject.embedSWF('/flash/pilvi_ala_437x15.swf', 'flash' + i + j, elWidth, '15', '9.0.0', false, flashvars, params, attributes);
						}
					}
				}
			}
			
		}

	}

}

Initializers.add(function(){roundedCorners('div','highlight')});
