// default rule set
var defaultRules = 
{
	start: function()
	{
		// thumb image swap
		// $$('img.thumb').each(function(el){
		// 	el.addEvent('mouseover', function() {
		// 		// reset borders
		// 		$$('img.thumb').each(function(el){
		// 				el.style.border='1px solid #fff';
		// 		});
		// 		var source = this.src;
		// 		this.style.border='1px solid red';
		// 		source = source.replace('/cache','');
		// 		source = source.split('_');
		// 		source.pop();
		// 		source = source.join('_');
		// 		source += '.jpg';
		// 		var txtid = this.id + 'text';
		// 		// alert(txtid);
		// 		$('main_image').src = source;
		// 		$('main_image_caption').innerHTML = $(txtid).innerHTML;
		// 	});
		// });
		
		var targets = $$('#project_img div.project_image');
		
		$$('#related_images a.thumb').each(function(el){
			var target = $(el.id.replace('thumb','image'));
			el.addEvent('mouseover', function() {
				targets.addClass('hidden');
				target.removeClass('hidden');
			});
		});
		
		// image preloading
		// var cache = new Array();
		// $$('img.thumb').each(function(el){
		// 	var id = cache.length;
		// 	cache[id] = new Image();
		// 	cache[id].src = el.src.replace('/cache','');
		// 	cache[id].src = cache[id].src.replace('_70x53','');
		// });
		
		// XHTML 1.1 'valid' targets
		$$('a.external').each(function(el){
			el.target = '_blank';
		});
		
		$$('.external a').each(function(el){
			el.target = '_blank';
		});
		
		
		
		
	}
};

var resizeHome = 
{
	start: function()
	{
		if ($('home'))
		{
			var homeCoords = $('home').getCoordinates();
			var homeHeight = homeCoords.height;
			
			var windowHeight = window.getHeight();
			$('home').style.height = windowHeight - 32 + 'px';
		}
	}
};

var resizeOne = 
{
	start: function()
	{
		if ($('blok4') && !$('news_items'))
		{
			var contentCoords = $('content').getCoordinates();
			var contentHeight = contentCoords.height;
			
			var blok4Height = 0;
			
			var blok4Coords = $('blok4').getCoordinates();
			blok4Height = blok4Coords.height;
			
			var windowHeight = window.getHeight();
			
			var availHeight = windowHeight - blok4Height - 205;
			
			$('blok4').style.height = blok4Height + availHeight + 'px';
			
			if ($('company_info_text')) $('company_info_text').style.height = windowHeight - 180 + 'px';
			if ($('project_txt')) $('project_txt').style.height = windowHeight - 280 + 'px';
			if ($('project_left')) $('project_left').style.height = windowHeight - 217 + 'px';
			if ($('project_right')) $('project_right').style.height = windowHeight - 217 + 'px';
			
			$('footer').style.backgroundColor = '#ec1c24';
			$('footer').style.color = '#fff';
		}
	}
};

var resizeTwo = 
{
	start: function()
	{
		if ($('news_block_1'))
		{
			var contentCoords = $('content').getCoordinates();
			var contentHeight = contentCoords.height;
			
			var news_block_1Heigth = 0;
			
			var news_block_1Coords = $('news_block_1').getCoordinates();
			news_block_1Heigth = news_block_1Coords.height;
			
			var news_block_2Coords = $('news_block_2').getCoordinates();
			news_block_2Heigth = news_block_2Coords.height;
			
			var windowHeight = window.getHeight();
			
			var availHeight = windowHeight - news_block_1Heigth - news_block_2Heigth - 244;
			
			availHeight = Math.round(availHeight/2);
			
			$('news_block_1').style.height = news_block_1Heigth + availHeight + 'px'; // evt + 1px
			$('news_block_2').style.height = news_block_2Heigth + availHeight + 'px';
			
			if ($('news_left')) $('news_left').style.height = windowHeight - 178 + 'px';
			if ($('news_right')) $('news_right').style.height = windowHeight - 178 + 'px';
			
			if ($('right_img')) $('right_img').setOpacity(0.2);
			
			$('footer').style.backgroundColor = '#ec1c24';
			$('footer').style.color = '#fff';
		}
	}
};

var resizeThree = 
{
	start: function()
	{
		if ($('blok1') && $('blok2') && $('blok3'))
		{
			var contentCoords = $('content').getCoordinates();
			var contentHeight = contentCoords.height;
			
			var blok1Height = 0;
			var blok2Height = 0;
			var blok3Height = 0;
			
			var blok1Coords = $('blok1').getCoordinates();
			blok1Height = blok1Coords.height;
			
			var blok2Coords = $('blok2').getCoordinates();
			blok2Height = blok2Coords.height;
			
			var blok3Coords = $('blok3').getCoordinates();
			blok3Height = blok3Coords.height;
			
			var windowHeight = window.getHeight();
			
			var space = 40+(3*15);
			var availHeight = windowHeight - blok1Height - blok2Height - blok3Height - 282;
			
			availHeight = Math.round(availHeight/3);
			
			$('blok1').style.height = blok1Height + availHeight + 'px';
			$('blok2').style.height = blok2Height + availHeight + 'px';
			$('blok3').style.height = blok3Height + availHeight + 'px';
			
			if ($('project_txt')) $('project_txt').style.height = windowHeight - 280 + 'px';
			if ($('project_left')) $('project_left').style.height = windowHeight - 217 + 'px';
			
			$('footer').style.backgroundColor = '#ec1c24';
			$('footer').style.color = '#fff';
		}
	}
};

var resizeNews = 
{
	start: function()
	{
		if ($('news_items'))
		{
			var contentCoords = $('content').getCoordinates();
			var contentHeight = contentCoords.height;
			
			var news_itemsHeight = 0;
			
			var news_itemsCoords = $('news_items').getCoordinates();
			news_itemsHeight = news_itemsCoords.height;
			
			var windowHeight = window.getHeight();
			
			var availHeight = windowHeight - news_itemsHeight - 205;
			var itemsHeight = windowHeight - news_itemsHeight - 182;
			
			$$('.item').each(function(el){
				
				el.addEvent('mouseover', function() {
					el.removeClass('hover');
				});
				el.addEvent('mouseout', function() {
					if (!el.hasClass('active')) el.addClass('hover');
				});
				
			});
			
			// $('blok4').style.height = blok4Height + availHeight + 'px';
			
			$('news_items').style.height = news_itemsHeight + itemsHeight + 'px';
			$('project_right').style.height = news_itemsHeight + itemsHeight + 'px';
			$('project_left').style.height = news_itemsHeight + itemsHeight + 'px';
			
			$('footer').style.backgroundColor = '#ec1c24';
			$('footer').style.color = '#fff';
		}
	}
};

// initialize rules
window.addEvent('domready', function() {
	// resizeHome.start();
	// resizeNews.start();
	// resizeOne.start();
	// resizeTwo.start();
	// resizeThree.start();
	
	defaultRules.start();
});

/*
window.addEvent('resize', function() {
	resizeHome.start();
	resizeNews.start();
	resizeOne.start();
	resizeTwo.start();
	resizeThree.start();
});
*/