/*
$(document).observe('dom:loaded', function() {
    $$('a.showImage').each(function(el) { new FancyZoom(el); });
  });
*/

$(document).ready(function(){
	mapToggle();
})



window.onresize = homePortfolioHeight;

function pageLoad() {
	showCounter();
	getStats();
	homePortfolioHeight();
}


function showCounter()
{
	if(document.getElementById('footerCounter'))
		document.getElementById('footerCounter').innerHTML = '<a href="http://www.liveinternet.ru/click" '+'target=_blank><img src="http://counter.yadro.ru/hit?t18.10;r'+escape(document.referrer)+((typeof(screen)=='undefined')?'':';s'+screen.width+'*'+screen.height+'*'+(screen.colorDepth?screen.colorDepth:screen.pixelDepth))+';'+Math.random()+'" alt="liveinternet.ru: iieacaii ?enei oeoia ca 24 ?ana, iinaoeoaeae ca 24 ?ana e ca naaiai\y" '+'border=0 width=88 height=31></a>';
}


function toggleParagraph(obj_id){
	var header = $('h'+obj_id);
	if(header.className == 'minH')
	{
		Effect.BlindDown('p'+obj_id, { duration: 0.3 });
		header.className = 'minHCur';
	}
	else
	{
		Effect.BlindUp('p'+obj_id, { duration: 0.3 });
		header.className = 'minH';
	}
}
	
	
function closeParagraph(obj_id){
	Effect.BlindUp('p'+obj_id, { duration: 0.3 });
}

var h = 0;
function homePortfolioHeight() {
	var homePortfolio = document.getElementById('homePortfolio');
	var port = document.getElementById('homePortfolio').getElementsByTagName('div');
	
	for(var i=0; i<port.length; i++) {
		if(port[i].getAttribute('id') == 'homeProject2') {
			h = port[i].offsetHeight;
		}
	}
	
	for(var i=0; i<port.length; i++) {
		if(port[i].getAttribute('id') == 'homeProject') {
			port[i].style.height = h + 'px';
		}
	}
}

/*
function homePortfolioHeight() {
	var homePortfolio = document.getElementById('homePortfolio');
	var links = document.getElementById('homePortfolio').getElementsByTagName('a');
	var texts = document.getElementById('homePortfolio').getElementsByTagName('div');
	
	h = 0;
	for(i=0; i<links.length; i++) {
		if(links[i].offsetHeight > h)
			h = links[i].offsetHeight;
	}
	
	if(h!=prev) {
		for(i=0; i<texts.length; i++) {
			if(texts[i].hasAttribute('id'))
				texts[i].style.height = h;
		}
		prev = h;
		homePortfolio.style.height = 75 + h + 50 + 'px';
	}
}
*/

function requestTvToggle(obj_id)
{
	var bulit = $('bulit' + obj_id);
	if(document.getElementById('rtv'+obj_id).style.display == 'none')
	{
		Effect.BlindDown('rtv'+obj_id, { duration: 0.1 });
		bulit.className = 'on';
	}
	else
	{
		Effect.BlindUp('rtv'+obj_id, { duration: 0.1 });
		bulit.className = 'off';
	}
}

function contactsSwitch(s){
	var c_switch = document.getElementById('oncarSwitchLink');
	var f_switch = document.getElementById('onfootSwitchLink');
	var c_block = document.getElementById('onCar');
	var f_block = document.getElementById('onFoot');
	var c_points = document.getElementById('onCarPoints');
	var f_points = document.getElementById('onFootPoints');
	if(s)
	{
		c_switch.className = 'off';
		f_switch.className = 'on';
		c_block.style.display = 'none';
		f_block.style.display = 'block';
		c_points.style.display = 'none';
		f_points.style.display = 'block';
	}
	else
	{
		c_switch.className = 'on';
		f_switch.className = 'off';
		c_block.style.display = 'block';
		f_block.style.display = 'none';
		c_points.style.display = 'block';
		f_points.style.display = 'none';
	}
}



function mapToggle(){
	var animPer = 100,
		photo = {};
	
	
	$('.mapPoint').hover(
		function(){
			photo = new Photo($(this).parent().find('.mapPointImage'));
			photo.showIt();
		}, 
		function(){
			photo.hideIt();
			photo = {};
		}
	)
	

	
	function Photo(imgJQ){
		//public
		this.showIt = function(){
			setPos();  //задать верную позицию текущей картинке
			imgJQ.fadeIn(animPer);
		}
		
		this.hideIt = function(){
			imgJQ.fadeOut(animPer, function(){resetPos();});
		}
		
		
		//private
		var setPos = function(){
			var padding = 10,
				bodyScrollTop = imgJQ.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop),
				bottomOfEl = (imgJQ.parent().offset().top + imgJQ.height() + parseInt(imgJQ.css('padding-top'))+parseInt(imgJQ.css('padding-bottom')) + parseInt(imgJQ.css('top'))) - bodyScrollTop,
				windowHeight = (function(){
					var myHeight = 0;
					if(typeof( window.innerHeight ) == 'number' ) {
						myHeight = window.innerHeight;
					} 
					else if(document.documentElement && document.documentElement.clientHeight) {
						myHeight = document.documentElement.clientHeight;
					} 
					else if( document.body && document.body.clientHeight) {
						myHeight = document.body.clientHeight;
					}
					return myHeight;
				})();
			
			
			if(bottomOfEl > windowHeight - padding){
				imgJQ.css({'margin-top':-(bottomOfEl - windowHeight + padding)+'px'});
			}
		},
		
		resetPos = function(){
			imgJQ.css({'margin-top':'0px'});
		}  
		
	}
}


