window.addEvent('domready', function(){

/****************************
/*  Target bar animation
/***************************/
	var toWidth = $('progress_bar').getStyle('width').toInt();
	var duration = toWidth * 10 + 300;
	//console.log(toWidth);
	var fx = new Fx.Styles('progress_bar', {duration: duration, wait: false, transition: Fx.Transitions.Sine.easeOut});
	fx.start({
		'width': [1, toWidth]
	});

/***************************************
/  PNG transparency fix for IE 6
/**************************************/
	if ((window.ie6) && (document.body.filters)) 
	{
		$$('img').each(function(img){
			var imgName = img.src.toUpperCase()
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
			{
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText 
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
				img.outerHTML = strNewHTML
			}
		});
	}

/***************************************
/  Gallery image description injection
/**************************************/
	$$('#gallery li p.description').each(function(el){
		var description = el.getText();
		var anchor = el.getParent().getFirst();
		//console.log('Before: ' + anchor.getAttribute('title'));
		anchor.setAttribute('title', anchor.getAttribute('title') + '<br/><span style="font-weight: normal !important; padding-bottom: 1em !important;">' + description + '</span>');
		//console.log('After: ' + anchor.getAttribute('title'));
	});
});

window.addEvent('load', function(){
								 
/***************************************
/  Gallery image positioning
/**************************************/
	$$('#gallery li a img').each(function(img){

			img.setStyles({
				'margin-top': (155/2) - (img.getStyle('height').toInt()/2) + img.getStyle('margin-top').toInt(),
				'margin-left': (155/2) - (img.getStyle('width').toInt()/2) + img.getStyle('margin-left').toInt() - 1
			});

	});
	

	
/***************************************
/  Gallery image hover effects
/**************************************/
/*
	var imgfade = new Element('div', {
		'styles': {
			'position': 'relative',
			'z-index': 5,
			'background': 'white',
			'opacity': 0.3,
			'cursor': 'pointer',
			'margin-left': '8px'
		}
	});

	$$('#gallery li a img').each(function(el){

		var imgfade_clone = imgfade.clone().setStyles({
			'width': el.getStyle('width'),
			'height': el.getStyle('height'),
			'margin-top': el.getStyle('height').toInt() * -1,
			'margin-left': el.getStyle('margin-left')
		});
		
		imgfade_clone.injectInside(el.getParent());
	
		var fx = new Fx.Styles(imgfade_clone, {duration: 400, wait: false, transition: Fx.Transitions.Quad.easeOut});
		
		imgfade_clone.getParent().addEvent('mouseenter', function(){
			fx.start({ 'opacity': 0 });
		});
		
		imgfade_clone.getParent().addEvent('mouseleave', function(){
			fx.start({ 'opacity': 0.3 });
		});
	});
*/
});
