plogtype_element = null;
flash_loaded = 0;

/* search field */
function search_on() {
	var el = document.getElementById("searchfield");
	if (el.value == "поиск"){el.value = ""; el.style.color = "black"};
}
function search_out() {
	var el = document.getElementById("searchfield");
	if (el.value == ""){el.value = "поиск"; el.style.color = "gray"};
}

/* quality service close */
function qsclose() {
	$('#qs').hide();
	$('#dark').hide();
};

/* region close */
function regclose() {
	$('#regions').hide();
	$('.footer').css('margin-top', '0px');
	$('#dark').hide();
};

/* jquery funk */
$(document).ready(function(){


	$(".gal_block a").fancybox({'hideOnContentClick': true}); 
	$("a.fancy").fancybox({'hideOnContentClick': true}); 

	$('.color_logo').animate({opacity: 0}, 1);
	$('.plashka_inner').animate({opacity: 0.4}, 1);

	
	/* quality service window */
	$('#qs_link2').click(function(){$('#qs_link').click();});
	$('#qs_link').click(function(){
		var all_height = $(document).height();
		$('#dark').css('height', all_height);
		$('#dark').show();
		$('#qs').slideDown();
    });
	
	/* region selector window */
	$('.region_selector').click(function(){
		var all_height = $(document).height();
		var pp_elem_height = $('#regions').height() + 120;
		if(pp_elem_height > all_height){
			var def = pp_elem_height - all_height;
			all_height = pp_elem_height;
			$('.footer').css('margin-top', def + 'px');
		}
		$('#dark').css('height', all_height);
		$('#dark').show();
		$('#regions').slideDown();
    });
	
	/* logos animation */	
	$('.color_logo').mouseover(function(){
		$(this).animate({opacity: 1}, 200);
	});
	$('.color_logo').mouseout(function(){
		$(this).animate({opacity: 0}, 80);
	});
	
	/* frame partner */	



	
	$('img.plogtype').click(function(){
		var dh = $(document).height();
		$('.framed:visible').not($(this).next('.framed')).fadeOut(200);

		if(!$.browser.msie && !$(this).hasClass('p_set')){
			$(this).addClass('p_set');
			$(this).next('.framed').find('div.plateblue_middle').css('height', $(this).next('.framed').height() + 'px');
			$(this).next('.framed').find('div.plateblue_middle_ex').css('height', $(this).next('.framed').height() + 'px');
		}


		var off = $(this).offset();
		var el_width = $(this).width();


		$(this).css('opacity', '1');
		$(this).next('.framed').css('top', off.top - 5);
		$(this).next('.framed').css('left', off.left + el_width + 25);
		
		plogtype_element = $(this);
		plogtype_off_h = -5;
		plogtype_off_w = el_width + 25;
		
		$(this).next('.framed').fadeIn(200);
		var all_h = $(this).next('.framed').find('div.plateblue_content').height();
		if($.browser.msie && !$(this).hasClass('p_set')){
			$(this).addClass('p_set');
			$(this).next('.framed').find('div.plateblue_middle').css('height', all_h + 'px');
			$(this).next('.framed').find('div.plateblue_middle_ex').css('height', all_h + 'px');
		}


		var b_t = off.top + $(this).next('.framed').height();
		if(b_t > dh){
			var def = $(this).next('.framed').height();
			$('.footer').css('margin-top', def + 'px');			
		}

	});



//------------------Клиенты------------------------
//------------------Старт------------------------
	$('img.plogtype_client').click(function(){
		var dh = $(document).height();
		$('.framed:visible').not($(this).next('.framed')).fadeOut(200);
		
		if(!$.browser.msie && !$(this).hasClass('p_set')){
			$(this).addClass('p_set');
			$(this).next('.framed').find('div.plateblue_middle').css('height', $(this).next('.framed').height() + 'px');
			$(this).next('.framed').find('div.plateblue_middle_ex').css('height', $(this).next('.framed').height() + 'px');
		}

		var off = $(this).offset();
		var el_width = $(this).width();
		var el_height = $(this).height();
		el_height_half = parseInt(el_height/2);
		
		$(this).next('.framed').css('top', off.top + el_height_half - 30);
		$(this).next('.framed').css('left', off.left + el_width + 40);
		
		plogtype_element = $(this);
		plogtype_off_h = el_height_half - 30;
		plogtype_off_w = el_width + 40;
		
		
		$(this).next('.framed').fadeIn(200);
		var all_h = $(this).next('.framed').find('div.plateblue_content').height();
		if($.browser.msie && !$(this).hasClass('p_set')){
			$(this).addClass('p_set');
			$(this).next('.framed').find('div.plateblue_middle').css('height', all_h + 'px');
			$(this).next('.framed').find('div.plateblue_middle_ex').css('height', all_h + 'px');
		}


		
		var b_t = off.top + $(this).next('.framed').height();
		if(b_t > dh){
			var def = $(this).next('.framed').height();
			$('.footer').css('margin-top', def + 'px');			
		}

		
	});


//------------------Клиенты------------------------
//------------------Конец------------------------


	$('a.plogtype').click(function(){
		var dh = $(document).height();
		$('.framed:visible').not($(this).next('.framed')).fadeOut(200);

		if(!$.browser.msie && !$(this).hasClass('p_set')){
			$(this).addClass('p_set');
			$(this).next('.framed').find('div.plateblue_middle').css('height', $(this).next('.framed').height() + 'px');
			$(this).next('.framed').find('div.plateblue_middle_ex').css('height', $(this).next('.framed').height() + 'px');
		}

		var off = $(this).offset();
		var el_width = $(this).width();

		$(this).next('.framed').css('top', off.top - 5 - 17);
		$(this).next('.framed').css('left', off.left + el_width + 35);
		plogtype_element = $(this);
		plogtype_off_h = -5 - 17;
		plogtype_off_w = el_width + 35;
		$(this).next('.framed').fadeIn(200);

		var all_h = $(this).next('.framed').find('div.plateblue_content').height();
		if($.browser.msie && !$(this).hasClass('p_set')){
			$(this).addClass('p_set');
			$(this).next('.framed').find('div.plateblue_middle').css('height', all_h + 'px');
			$(this).next('.framed').find('div.plateblue_middle_ex').css('height', all_h + 'px');
		}


		var b_t = off.top + $(this).next('.framed').height();
		//alert($(this).next('.framed').height());
		if(b_t > dh){
			var def = $(this).next('.framed').height();
			$('.footer').css('margin-top', def + 'px');			
		}
		
	});


	$(window).resize(function(){
			if(plogtype_element){
					var off = $(plogtype_element).offset();
					$(plogtype_element).next('.framed').css('top', off.top + parseInt(plogtype_off_h));
					$(plogtype_element).next('.framed').css('left', off.left + parseInt(plogtype_off_w));			
			}

	});


	$('.plateblue_close').click(function(){
		$('.footer').css('margin-top', '0px');
		plogtype_element = null;
		$(this).parent().parent().parent().parent().parent().fadeOut(200);
	});

	/*Услуги*/



	$('a.open_service_type').click(function(){
		$('#dark').fadeIn('fast');
		
		var st_id = $(this).attr('id');
		st_id = st_id.replace('open_service_type_', '');
		$('div.service:visible').hide();
		$('div.service_zero').show();
		$('#usluga_' + st_id).fadeIn('fast');
		
		if($('div#dark').height() < $(document).height()){
			$('div#dark').css('height', $(document).height() + 20 + 'px');
		}
		if($('div.footer').height() + $('div.footer').offset().top < $('div#dark').height()){
			$('div.footer').css('margin-top',  $('div#dark').height() - $('div.footer').height() - $('div.footer').offset().top  + 'px');
		}

	});

	$('img.service_type_close').click(function(){
		$('div.usluga:visible').hide();
		$('div#dark').fadeOut('fast');
	});


	$('a.open_service').click(function(){
		var id = $(this).attr('id');
		id = id.replace('open_service_', '');

		if(!$('div#service_' + id).is(':visible')){
			$('div.service:visible').slideUp('fast');
			$('div#service_' + id).slideDown('fast', function(){

				$('div.footer').css('margin-top', '0px');

				if($('div#dark').height() < $(document).height()){
					$('div#dark').css('height', $(document).height() + 20 + 'px');
				}
				if($('div.footer').height() + $('div.footer').offset().top < $('div#dark').height()){
					$('div.footer').css('margin-top',  $('div#dark').height() - $('div.footer').height() - $('div.footer').offset().top  + 'px');
				}

			});
		}


	});










});




	
	
function DeleteCookie (name,path,domain) {

		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}

	
	
function SetCookie (name,value,expires,path,domain,secure) {

	document.cookie = name + "=" + escape (value) +

	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
	}



function GetCookie(check_name){
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false;

	for( i = 0; i < a_all_cookies.length; i++ ){
		a_temp_cookie = a_all_cookies[i].split( '=' );
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		if(cookie_name == check_name){
			b_cookie_found = true;
			if(a_temp_cookie.length > 1){
				cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
			}
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if(!b_cookie_found){
		return null;
	}
}

function switchFlash(){
	if(GetCookie('flash') != 'disable'){
		actFlash();
	}else{
		disFlash();
	}
}

	


function disFlash(){
	var today = new Date();
	var expiry = new Date(today.getTime() + 3 * 365 * 24 * 60 * 60 * 1000);
	
	var flashdiv = document.getElementById('plashka_main');
	var noflashdiv = document.getElementById('plashka_main_noflash');
	
	flashdiv.style.display = 'none';
	noflashdiv.style.display = 'block';
	
	DeleteCookie('flash','/');
	SetCookie('flash', 'disable', expiry,'/');
}

function actFlash(){
	var today = new Date();
	var expiry = new Date(today.getTime() + 3 * 365 * 24 * 60 * 60 * 1000);
	
	var flashdiv = document.getElementById('plashka_main');
	var noflashdiv = document.getElementById('plashka_main_noflash');
	
	flashdiv.style.display = 'block';
	noflashdiv.style.display = 'none';
	
	DeleteCookie('flash','/');
	SetCookie('flash', 'enable', expiry,'/');
}