if(document.images){
	preloadImage = new Image();
	preloadImage.src = "/images/loading.gif";
	preloadImage = new Image();
	preloadImage.src = "/images/news_loading.gif";
}

var postForm = function(formid, url){
	$(formid).addEvent('submit', function(e) {
		e.stop();
		var form = $(formid).addClass('loading');
		
		this.set('send', {
			onComplete: function(response) { 
				form.removeClass('loading');
				form.set('html', response);
			}
		});

		this.send('/inc/'+url);
	});
};

var portfolioSlide = function(page, id){
	var div;
	var url = '/inc/portfolio.php';
	
	div = $('portfolio');
		
	div.fade(0, 0);
	
	var myRequest = new Request({
		url: url,
		method: 'get',
		onComplete: function(response) {
			div.set({'html': response});
							
			external();
								
			div.fade(0, 1);
		}
	}).send('id='+id+'&page='+page);
	
	var portitemsrevert = $$("ul.portfolio a");
	portitemsrevert.each(function(portitemrevert, i) {
		portitemrevert.className='';
	});
	
	$('portfolio_'+id).className='active';
};

var portfolioSetup = function(page){
	var div;
	var url = '/inc/portfolio.php';
	
	var portitems = $$("ul.portfolio a");
	portitems.each(function(portitem, i) {
		portitem.addEvent("click", function(e) {
			new Event(e).stop();
			
			div = $('portfolio');
			
			div.fade(0, 0);
			
			var myRequest = new Request({
				url: url,
				method: 'get',
				onComplete: function(response) {
					div.set({'html': response});
									
					external();
										
					div.fade(0, 1);
				}
			}).send('id='+this.rel+'&page='+page);
			
			var portitemsrevert = $$("ul.portfolio a");
			portitemsrevert.each(function(portitemrevert, i) {
				portitemrevert.className='';
			});
			
			this.className='active';
	
		});
	});
};


var testimonials = function(file){
	var div;
	var url = '/inc/'+file;
	var current;
	
	var list=$('testimonials');
	var listTop=list.offsetTop;
	var listLeft=list.offsetLeft;
	var listHeight=(list.offsetHeight-58);
	
	var snippets = $$(".testimonials li a");
	snippets.each(function(snippet, i) {
		snippet.addEvent("click", function(e) {
			new Event(e).stop();
			
			current=this.id;
						
			var snippetsrevert = $$(".testimonials li");
			snippetsrevert.each(function(snippetrevert, i) {
				$(snippetrevert.id).fade(1, 0);
				
				if(snippetrevert.id==current+"_list"){
					currentItem=$(current+"_list");
					currentWidth=currentItem.getStyle('width');
					currentHeight=currentItem.getStyle('height');
					currentTop=currentItem.offsetTop;
					currentLeft=currentItem.offsetLeft;
					
					newItem= new Element('li', {'class' : 'dynamic', 'id':'dynamic'}).injectInside(list);	
					newItem.setStyle('height', currentHeight);
					
					var morph = new Fx.Morph(newItem, {duration: 700, onComplete: function(){
						var myRequest = new Request({
							url: url,
							method: 'get',
							onComplete: function(response) {
								div = new Element('div').injectInside($(newItem));	
								div.setStyle('visibility', 'hidden');
								div.set({'html': response});
								
								external();
													
								div.fade(0, 1);
							}
						}).send('ajax_id='+snippet.rel);
					
					}});
					
					morph.start({
						'height' : [currentHeight, listHeight],
						'width': [currentWidth, 854],
						'top': [currentTop, 0],
						'left': [currentLeft, 0]
					});
				}
			});
		});
	});
};

var resettestimonials = function(){
	var div=$('dynamic');
		
	var morph = new Fx.Morph(div, {duration: 700, onComplete: function(){
		div.destroy();
		
		var snippets = $$(".testimonials li");
		snippets.each(function(snippet, i) {
			$(snippet.id).fade(0, 1);
		});
	}});
	
	morph.start({'opacity' : 0});
};



function website(url){
	popupWindow = window.open(url, '_blank','');
	popupWindow.focus();
}

var external = function(){
	var anchors = $$("a");
	anchors.each(function(anchor, i) {
		var relAttribute = String(anchor.getAttribute('rel'));
		if (anchor.id=='print'){
			anchor.onclick = function() {
				print();
				return false;
			};
		}else if (anchor.getAttribute('href') && (relAttribute=='external')){
			anchor.onclick = function() {
				website(this);
				return false;
			};
		}
	});
};

window.addEvent('domready', function(){
	new external();
});
