﻿/* ---------------------------------
Made by: Nikolai Khilkovsky
E-mail: khilkovn@gmail[dot]com
URL: http://www.himself.pp.ua
--------------------------------- */


$j(document).ready(function(){
     	//When you click on a link with class of poplight and the href starts with a #
	$j('a.poplight').click(function() {
		var popID = $j(this).attr('rel'); //Get Popup Name

		var popWidth = 360;

		//Fade in the Popup and add close button
		$j('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="/img/close-modal.png" class="btn_close" title="Закрыть окно" alt="Закрыть" /></a>');

		//Apply Margin to Popup
		$j('#' + popID).css({
			'margin-top' : -153.5,
			'margin-left' : -220
		});

		//Fade in Background
		$j('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
		$j('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer

		return false;
	});


	//Close Popups and Fade Layer
	$j('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
	  	$j('#fade , .popup_block').fadeOut(function() {
			$j('#fade, a.close').remove();
	}); //fade them both out

		return false;
	});
});


//Общие переменные
var elSize=new  Array(),
		k=0;			
//Функции разметки и функционала страницы
function LabelsClean(){
	$j('.LC_Active input.text-input').each(function(i){
		var	inputLabel=$j(this).val();
		$j(this).focus(function(){if ($j(this).val() == inputLabel) {$j(this).val('')}});
		$j(this).blur(function(){if ($j(this).val() == '') {$j(this).val(inputLabel)}})
	});
	$j('.LC_Active textarea.textarea-input').each(function(i){
		var	textareaLabel=$j(this).val();
		$j(this).focus(function(){if ($j(this).val() == textareaLabel) {$j(this).val('')}});
		$j(this).blur(function(){if ($j(this).val() == '') {$j(this).val(textareaLabel)}})
	})
};
function menuHover(el){
	el.each(function(i){
		$j(this).hover(function(){$j(this).addClass('jqhover')},function(){$j(this).removeClass('jqhover')});
		if ($j(this).find('ul').length>0) {
			$j(this).hover(function(){
				$j(this).css({'z-index':'100'});
				$j(this).find('ul:first').css({'z-index':'10000'});
				if ($j.browser.msie && $j.browser.version > 8) {
					$j(this).find('ul:first').show(0)
				}
				else {$j(this).find('ul:first').show(100)};
				$j(this).find('ul:first > li:last > a:first').css('border-bottom','0px none');
			},
			function(){
				$j(this).css({'z-index':'10'});
				$j(this).find('ul:first').css({'z-index':'9000'});
				if ($j.browser.msie && $j.browser.version < 8) {
					$j(this).find('ul:first').hide(0)
				}
				else {$j(this).find('ul:first').hide(100)};
			})
		}
	})
};
function LineUpRelAn(){
	$j('.relative_announcement_block').each(function(i){
		$j(this).find('.item:first > .contents').css({'float':'left','margin':'0px'});
		$j(this).find('.item:last > .contents').css({'float':'right','margin':'0px'});
		elSize[0]=0;
		elSize[1]=0;
		elSize[2]=0;
		elSize[3]=0;
		$j(this).find('.item').each(function(j){
			if (elSize[0]<$j(this).find('.item_name').height()) {elSize[0]=$j(this).find('.item_name').height()};
			if (elSize[1]<$j(this).find('.sys_links').height()) {elSize[1]=$j(this).find('.sys_links').height()};
			if (elSize[2]<$j(this).find('.text').height()) {elSize[2]=$j(this).find('.text').height()}
			if (elSize[3]<$j(this).find('.info').height()) {elSize[3]=$j(this).find('.info').height()}
		});
		$j(this).find('.item_name').height(elSize[0]);
		$j(this).find('.sys_links').height(elSize[1]);
		$j(this).find('.text').height(elSize[2]);
		$j(this).find('.info').height(elSize[3])
	})
};
function BuildPage(){
	LabelsClean();
	if (document.getElementById('main-menu')) {menuHover($j('#main-menu li'))};
	$j('img[align="left"]').css('margin-left','0px');
	$j('img[align="right"]').css('margin-right','0px');
	$j('.content').each(function(i){
		var	colHe=new Array;
		colHe[0]=$j(this).find('.float-left > .list').height();
		colHe[1]=$j(this).find('.float-right > .list').height();
		if (colHe[0] && colHe[1]) {
			if (colHe[0]<colHe[1]) {colHe[3]=colHe[1]}
			else {colHe[3]=colHe[0]};
			$j(this).find('.float-left > .list').height(colHe[3]);
			$j(this).find('.float-right > .list').height(colHe[3]);
		}
	});
	RemadeFooter();
	$j('.announcement_block p.send_message > span').click(function(){
		if ($j("#contact_form_block").is(":hidden"))
		{
			$j('#contact_form_block').slideDown(100,function(){RemadeFooter()});
		}
		else
		{
			$j('#contact_form_block').hide();
		}	
	})
    $j('.add-infos > a').click(function(){
		if ($j("#add-obb").is(":hidden"))
		{
			$j('#add-obb').slideDown(100,function(){RemadeFooter()});
			$j('#add_ob_arrow').html('&laquo;');
		}
		else
		{
			$j('#add-obb').hide();
			$j('#add_ob_arrow').html('&raquo;');
		}
	})
};
function RemadeFooter(){
	if ($j.browser.msie && $j.browser.version < 8) {
		$j('#footer').hide(0);
		$j('#footer').show(0)
	}
};
$j(document).ready(function(){
	BuildPage()
});
if (window.addEventListener) window.addEventListener('load', function () {
}, false)
else window.attachEvent('onload', function () {
});



