window.onload = function(){
	if(document.getElementById('siteWrap')){
		toggleParagraph();
		counter();
		zoomImage();
	};
	
	if(document.getElementById('textContent'))
		if(document.getElementById('textContent').className.indexOf('contacts') !== -1)
			printAbility();		
};




function zoomImage(){
	hs.graphicsDir = 'highslide/graphics/';
	hs.showCredits = false;
	hs.outlineType = 'custom';
	hs.registerOverlay({
		html: '<div class="closebutton" onclick="return hs.close(this)" title="Close"></div>',
		position: 'top right',
		useOnHtml: true,
		fade: 2
	});
};



function toggleParagraph(){
	document.getElementById('siteWrap').onclick = function(e){
		e = e || window.event;
	    var t = e.target || e.srcElement;
	    if(t.className.indexOf('toggleParagraph') != -1){
			if(t.className.indexOf('active') == -1){
				t.className = t.className + ' active';
				t.nextSibling.style.display = 'block';
			}
			else{
				t.className = t.className.replace(' active', '');
				t.nextSibling.style.display = 'none';
			}
	    }

	};

};



function counter(){
	if(document.getElementById('counter')){
		var strHTML = 
			'<a href="http://www.liveinternet.ru/click" '+
			'target=_blank><img src="http://counter.yadro.ru/hit?t14.1;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>';
		document.getElementById('counter').innerHTML = strHTML;
	}
}




function printAbility(){
	document.getElementById('textContent').onclick = function(e){
		e = e || window.event;
		var t = e.target || e.srcElement;
		
		if(t.className.indexOf('print') !== -1){
			var paragraph = t.parentNode.cloneNode(true);
			
			paragraph.className = paragraph.className + ' printIt';
			document.body.appendChild(paragraph);
			document.body.originClassName = document.body.className; 
			document.body.className = document.body.originClassName + ' printVersion';
			
			var img = paragraph.getElementsByTagName('IMG')[0];
			img.src = img.src.replace('preview', 'image');
			
			setTimeout(function(){
				img.width = 800;
				img.height = 650;	
				window.print();
			}, 1000);
			
			
			//reset mutations
			setTimeout(function(){
				console.log('clear');
				paragraph.parentNode.removeChild(paragraph);
				document.body.className = document.body.originClassName;
			}, 2000);
		};
		
	};
};



