function replaceTitlesInit() {
  /* Check for DOM support */
  if (!(document && document.implementation && document.implementation.hasFeature))
    return;
    
  /* Check for image support */
  if (!document.images)
    return;
    
  /* Tags to be replaced */
  replaceTitles(document.getElementsByTagName('h1'));
  replaceTitles(document.getElementsByTagName('h2'));
  replaceTitles(document.getElementsByTagName('a'));
}

function replaceTitles(tags) {
	for (var i = 0; i < tags.length; i++) {
		if (tags[i].id) {
			var image = document.createElement('img');
		 	image.className = 'png';
			image.src = '/images/' + tags[i].id + '.png';
			image.alt = tags[i].firstChild.nodeValue;
			image.title = tags[i].firstChild.nodeValue;
			tags[i].replaceChild(image,tags[i].firstChild);
		}
	}
}


/*
window.addEvent('domready', function() { //we can use this instead of css expressions
	if(window.ie6) {
		$$('.png').forEach(addPngImgIeFix);
		$$('.pngbg').forEach(addPngBgIeFix);
	}
})*/;

function addPngImgIeFix(element) {
	var tmpSrc = element.src;
	element.setAttribute("src","/images/blank.gif");
	element.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+ tmpSrc +'", sizingMethod="none")';	
}

function addPngBgIeFix(element) {	
	var tmpBgImgSrc = element.getStyle('background-image').match(/^url[("']+(.*\.png)[)"']+$/i)[1]; //we don't know if always index 1 is proper
	element.style.background = 'none';
	element.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale src="'+tmpBgImgSrc+'");'
}

function setCssClassForBodySection(class_name) {
	$('body').className = class_name;	
}

function showProjectsWithKeyword(section_id, project_id, keyword) {
	projectsSlider = new Fx.Slide('projects');

	projectsSlider.slideOut().chain(function() {
		new Ajax("/projects/get_updated_projects_list/"+project_id+"?keyword="+keyword, {
			method: 'get',	
			onComplete: function() {
					$('projects').innerHTML = this.response.text;
					projectsSlider.slideIn();		
				}
			}).request();
	});			
}

function zoomImages(zoomElements) {
	window.addEvent("domready",function(){
		var effects = [];
		
		$$(zoomElements).each(function(element,index){		
			effects[index] = new Fx.Styles($E('img',element),{duration:150, wait:false});
	 
			element.addEvent('mouseenter', function(){
				effects[index].start({'width': 46,'height': 82});							
			});
	 
			element.addEvent('mouseleave', function(){
				effects[index].start({'width': 36,'height': 72});
				
			});
		});
	});
}

function fadeOutFlashNotice(flashId) {
	flashFadeOut = new Fx.Style(flashId, 'opacity', {
		duration: 800, 
		onComplete: function() { 
			$(flashId).innerHTML = '';
		}
	});
	setTimeout('flashFadeOut.start(1,0)',2000);
}