window.onload=documentLoaded;
function documentLoaded(){
	
}
$(document).ready(function(){
			var str=navigator.userAgent;
   			var f_index=str.indexOf('Firefox/');
   			var new_s=str.substr(f_index+8)
   			var version=parseFloat(new_s);
   			if (version<3.5) {Cufon.replace('.main_block_left h1, .main_block_right h6, .obyav_top h6, .top_offers_top h6, .your_opinion_top h6, .mailing_top h6, .tags_col_left h6, .last_updates_top h3, .last_news_top h3, .upcoming_events_top h3, .last_publications_top h3, .enterprise_top h3, .photos_top h3, .hot_vacancies_top h3, .legal_advice_top h3, .col_1_top h3, .col_2_top h3, .col_3_top h3, .enterprise_main h3, .updates h3, .enterprise_main h3, .publications_main h3, .news h3, .photoalbum_main h3, .faq h3, .vist h3, .kar h3, .bizn h3, .ur h3, .bibl h3')}
			
			
			autoclearInput();
			tooltips();
			selects_my();
			table_decor();
			faq();
			vote_res();
			login();
			convert_drop();
			weather_block();
			weather_carusel();
			weather_carusel_2();
			weather_carusel_3();
			plashka_fix();
			obyav_list();
			height_align();
			
			main_block_carusel();
			rating();
			preload_banners();
			
			$('.banners_228x50 img:last').css('marginBottom',0)
			
			$("#tabs3 a.pirobox_gall").live('click',function(){
				var img_url=$(this).attr("href");
				var txt=$('div.active_hidden').html();
				txt_1=txt.replace(img_url+'|','');
				if (txt_1==txt) {txt_1=txt.replace('|'+img_url,'')}
				txt_1=img_url+'|'+txt_1;
				var urls=txt_1.split('|');
								
				showPupop(img_url,urls);
				return false;
			});					
			
			$("#shadow,#new_close").click(function(){
				 hidePupop();
			});
			
			keywords();

			
})

function keywords() {
				  var w=980-$('div.login').width()-($('div.lang a').size()+1)*25;
				  $('span.keywords').width(w);
	
}


function preload_banners() {
	if ($('div.static_otrasl_plashka').length!=0) {
	var load_is=0;
	var src_banners=[];
	$('div.static_otrasl_plashka div.banners_228x50 img').hide().each(function(j){
													 src_banners[j]=$(this).attr('src');
													 $(this).attr('src','');	
	});
	for (i=0;i<=3;i++) {
		$('div.static_otrasl_plashka div.banners_228x50 img').eq(i).load(function(){
													load_is++;
													})
	    .attr('src',src_banners[i])	
		}
		
	var interval=setInterval(function(){
						if(load_is==4) {$('div.static_otrasl_plashka div.banners_228x50 img').show();clearInterval(interval)}
						},100)
	}
	
	if ($('div.fragment').length!=0) {
	var load_is=0;
	var src_banners=[];
	$('div.fragment div.banners_228x50 img').hide().each(function(j){
													 src_banners[j]=$(this).attr('src');
													 $(this).attr('src','');	
	});
	for (i=0;i<=3;i++) {
		$('div.fragment div.banners_228x50 img').eq(i).load(function(){
													load_is++;
													})
	    .attr('src',src_banners[i])	
		}
	var interval=setInterval(function(){
						if(load_is==4) {$('div.fragment div.banners_228x50 img').show();clearInterval(interval)}
						},100)
	}
	
}


function showPupop(img_url_2,urls_2){
	
	var w=0,h=0;
	var PageSize=getPageSize();
	var pageheight=PageSize[1];
	$("#shadow").css('height',pageheight);
	$("#shadow").toggle();
	if (navigator.userAgent.indexOf('MSIE')!=-1) {
			img = new Image();
			img.src=img_url_2;
			w=img.width;
			h=img.height;
	}
	$("#my_pica").load(function(){
			if (navigator.userAgent.indexOf('MSIE')==-1)
			{
				w=$('#my_pica').attr('width');
				h=$('#my_pica').attr('height');
			}
			$('#ar_left').css('top',h/2-21);
			$('#ar_right').css('top',h/2-21);
			img_size(PageSize,w,h); 
			$("#big_pic").fadeIn();	
	}).attr('src',img_url_2);
	
	big_carusel(urls_2,PageSize);
}


function img_size(PageSize,w,h) {
	var top=(PageSize[3]-h)/2;
	$('#big_pic').css({'width':w,'height':h,'top':top,'marginLeft':-w/2});
	$('#big_pic_in').css({'width':w,'height':h})
	$('#big_pic_in_carusel').css({'width':w,'height':h})
}

function hidePupop(){
	$("#shadow").hide();
	$("#big_pic").hide();
	$("#big_carusel_move").html('<img src="" title="" alt="" id="my_pica" class="my_pica" />')
}

function big_carusel(urls_2,PageSize) {
	 var left=$("#ar_left");
	 left.css('visibility','hidden');
 	 var right=$("#ar_right");
	 right.css('visibility','visible');
	 var amount=urls_2.length;
	 var amount_hidden=amount-1;
	 var amount_limit=amount_hidden;
	 var end_left=1;
	 var end_right=0;
	 var current_img=0
	 
	 right.unbind('click').click(function(){
		 	if (end_right==0) {
			 	if (amount_hidden!=0) {
					current_img++;
					if (navigator.userAgent.indexOf('MSIE')!=-1) {
							img = new Image();
							img.src=urls_2[current_img];
							w=img.width;
							h=img.height;
						}
					$("#my_pica").load(function(){
							if (navigator.userAgent.indexOf('MSIE')==-1)
							{
								w=$('#my_pica').attr('width');
								h=$('#my_pica').attr('height');
							}
							$('#ar_left').css('top',h/2-21);
							$('#ar_right').css('top',h/2-21);
							img_size(PageSize,w,h); 
					}).attr('src',urls_2[current_img]);
					amount_hidden--;
					
					if (amount_hidden!=amount_limit) {
							left.css('visibility','visible');
							end_left=0;		 
						}
					}
				if (amount_hidden==0) {
					end_right=1;
					end_left=0;		
					right.css('visibility','hidden');
					left.css('visibility','visible');
				}
			}	 
		 })
	 
	 left.unbind('click').click(function(){
		 	if(end_left==0) {
			   if (amount_hidden!=amount_limit) {
			   		current_img--;
					if (navigator.userAgent.indexOf('MSIE')!=-1) {
							img = new Image();
							img.src=urls_2[current_img];
							w=img.width;
							h=img.height;
						}
					$("#my_pica").load(function(){
							if (navigator.userAgent.indexOf('MSIE')==-1)
							{
								w=$('#my_pica').attr('width');
								h=$('#my_pica').attr('height');
							}
							$('#ar_left').css('top',h/2-15);
							$('#ar_right').css('top',h/2-15);
							img_size(PageSize,w,h); 
					}).attr('src',urls_2[current_img]);
					amount_hidden++;
					if (amount_hidden!=0) {
							right.css('visibility','visible');
							end_right=0;		 
						}	
			   }
			   if (amount_hidden==amount_limit) {
				   	end_right=0;
					end_left=1;
					right.css('visibility','visible');
				    left.css('visibility','hidden');
				   }
			}	 
		 })	 
	}

/**
 * @description очистка инпутов, при клике на них
 */
function autoclearInput(){
	$(".autoclear").each(function(){
		$(this).attr("defaultvalue",$(this).attr("value")); 
	});

	$(".autoclear").click(function(){ 
		if ($(this).attr("value")==$(this).attr("defaultvalue")) { 
			$(this).attr("value", "");
		}
	})
}
/**
 * @description подсказки - tooltips
 */
function tooltips() {
	$('.tooltips').mouseover(
	function () {
		$(this).addClass("tooltip_active");
		$('.info_close').click(function () {
			$(this).parent('div').parent('div').removeClass('tooltip_active');							 
		  }
		 )
	 })
	$('.tooltip-agro').mouseout(
	  function () {
	 		$(this).parent('div').removeClass('tooltip_active');
	 }
	)
}

/**
 * @description выпадающие селекты
 */
function selects_my () {
 $('div.select_my span').hover(
					function() {
							$(this).css('text-decoration','underline');
						},
					 function () {
        					$(this).css('text-decoration','none');
      					}
   					 );	
						  
 $('div.select_green,div.select_blue,div.select_blue_2,div.select_blue_3,div.select_black,div.select_grey,div.select_kar_3,div.select_bizn_3,div.select_bibl_3,div.select_vist_3').click( function () {
				$(this).find('div.select_my').show();
	})
 $('div.select_my').hover(
      function () {
		$(this).find('span').click( function () {
									  var choose=$(this).text();
									  $(this).parent('div').parent('div').find('span:first').text(choose);
									  }
						   )
      }, 
      function () {
        $(this).hide();
      }
    );
 
}
/**
 * @description подсказки - оформление таблицы 
 */
function table_decor() {
  $('table thead td:first-child, table th:first-child').css('background', '#fff url(/images/th_l_b.gif) left bottom no-repeat')
  $('table thead td:last-child, table th:last-child').css('background', '#fff url(/images/th_r_t.gif) right top no-repeat')
  $('table thead td, table th,').not('table thead td:last-child, table th:last-child').css('border-right', '1px solid #c88282')
  $('tbody tr td').not('tbody tr td:last-child').css('border-right', '1px solid #c27e82')
}

function faq () {
	$('div.faq_row_1 a.a_answer, div.faq_row_2 a.a_answer').click( function()  {
							   $(this).toggleClass('answer_active');
							   $(this).parent('div').parent('div').find('div.answer').toggle();
							}
						  )
	}
	
/**
 * @description - установление ширины шкалы в модуле результаты голосования
 */
function vote_res () {
	var mas=new Array();
	$('div.vote_cent').each(function (i) {
										  mas[i-1]=$(this).text();
										 }
							);
	$('div.vote_graph').each(function (i) {
									       $(this).attr('style', "width:"+mas[i-1]);
									      }
							 );
}

/**
 * @description - форма логина
 */
function login() {
	$('a.enter').hover(
						 function (){
							$('div.enter_form').toggleClass('visible');	 
						 }
					 )
	$('div.enter_form').hover(
							    function(){},
							    function(){
								  $('div.enter_form').toggleClass('visible');	 
						 		}
							  )
	} 
	
/**
 * @description - работа с выпадающим списком валюты
 */
function convert_drop() 
{
    $('.select_converter_1').click(
	                         function() {
						 		 $('.scroll-pane-out_1').css('overflow','auto');
								 $('.scroll-pane-out_1').animate({height:150},'fast','linear');
								 								 
								 $('.scroll-pane-out_1 ul li a').click(function() {
																	      var cur=$(this).text();
																	     
																		  $('.select_converter_1').text(cur);
																	      $('.scroll-pane-out_1').animate({height:0},'fast','swing',function(){$(this).css('overflow','hidden')});
																		   CalcConvert();
																	   })
						     }					 		 
						   )
	
	$('.select_converter_2').click(
	                         function() {
						 		 $('.scroll-pane-out_2').css('overflow','auto');
								 $('.scroll-pane-out_2').animate({height:150},'fast','linear');
								 
								 $('.scroll-pane-out_2 ul li a').click(function() {
																	      var cur=$(this).text();
																	      $('.select_converter_2').text(cur);
																	      $('.scroll-pane-out_2').animate({height:0},'fast','swing',function(){$(this).css('overflow','hidden')});
																		   CalcConvert();
																	   })
						     }					 		 
						   )
	
}

function CalcConvert()
{
	var valuta1= $('.select_converter_1').text();
	var valuta2= $('.select_converter_2').text();
	//alert(valuta1+valuta2);
	$('#inputcurrency').attr('value',parseFloat($('#inputcurrency').attr('value')));
	$('#ouputcurrency').load();
	$.get('/convert.php?valuta1='+valuta1+'&valuta2='+valuta2+'&count='+ $('#inputcurrency').attr('value'), function(data) {
  			$('#ouputcurrency').attr('value',data);
  			
	});

}

/**
 * @description - работа с блоком погоды - аккордион
 */
function weather_block() {
   $('.arrow_blue, .select').click(function() {
								      $('.city_box').css('display','block')
								     }
						  )
   
   
   $('.city_box_top').click(function() {
							if ($(this).parent('div').parent('div').is('.city_act')) {
								   $(this).parent('div').parent('div').animate({height:33},200,'swing',function(){$(this).removeClass('city_act')});
							}
							else {
								  $('.city_act').animate({height:33},200,'swing',function(){$(this).removeClass('city_act')});
								  $(this).parent('div').parent('div').animate({height:190},300,'swing',function(){$(this).addClass('city_act')});
								 }
							 }
							)
   $('.city_box_one ul li a').live('click', function() {
  var value=$(this).text();
												//alert('/weather.php?lang_id='+lang_id+'&data='+$(this).attr('rel'));
												var rel = $(this).attr('rel');
												$('.city_act .city_box_top').text(value);
												if (rel.substr(0,7)=='country')	$('#zzz2 .city_move').load('/weather.php?lang_id='+lang_id+'&data='+$(this).attr('rel'));
												if (rel.substr(0,6)=='region')	$('#zzz3 .city_move').load('/weather.php?lang_id='+lang_id+'&data='+$(this).attr('rel'));
												if (rel.substr(0,4)=='city')
												{
													$.getJSON('/weather.php?lang_id='+lang_id+'&data='+$(this).attr('rel'),
        												function(data){
															
															//alert(data);
															$('.weather_text').text(' '+data.day+' °C / '+data.night+' °C');
															$('.planet').css('background','url("/images/weather/'+data.condition+'d.png") no-repeat scroll 0 0 transparent');
														});
												}
												
});
   
   
    
	$('.city_box').hover(function(){},function(){
											   		var value=$('.city_box_top:eq(2)').text();
													
													$('.select').text(value);
													
													 
													
													$(this).css('display','none');
												}
						)
}

/**
 * @description - работа с блоком погоды - карусель
 */
function weather_carusel() {
	var move=$('#zzz1 .city_move');
	var count_slides=[];
	var iteration=1;
	var my_left=$('#zzz1 div.city_box_left');
	var my_right=$('#zzz1 div.city_box_right');
	
	my_right.click(function() {
														   $('div.city_act div.city_slide').each(function(i){
											 					count_slides[i]=$(this);
											 				})
															var count=count_slides.length;
														    if(iteration<count) {
														   		iteration++;
																move.animate({left:'-=230px'},'normal','swing') 
														      }
												          }
											   )
	my_left.click(function() {
														   $('div.city_act div.city_slide').each(function(i){
											 					count_slides[i]=$(this);
											 				})
														   var count=count_slides.length;
														   if(iteration>1) {
														   		iteration--;
																move.animate({left:'+=230px'},'normal','swing') 
														      }
												          }
											   )
	
}

function weather_carusel_2() {
	
	var move=$('#zzz2 .city_move');
	var count_slides=[];
	var iteration=1;
	var my_left=$('#zzz2 div.city_box_left');
	var my_right=$('#zzz2 div.city_box_right');
	
	my_right.click(function() {
														   $('div.city_act div.city_slide').each(function(i){
											 					count_slides[i]=$(this);
											 				})
															var count=count_slides.length;
														   
														   if(iteration<count) {
														   		iteration++;
																move.animate({left:'-=230px'},'normal','swing') 
														      }
												          }
											   )
	my_left.click(function() {
														   $('div.city_act div.city_slide').each(function(i){
											 					count_slides[i]=$(this);
											 				})
														   var count=count_slides.length;
														   
														   if(iteration>1) {
														   		iteration--;
																move.animate({left:'+=230px'},'normal','swing') 
														      }
												          }
											   )
	
}

function weather_carusel_3() {
	var move=$('#zzz3 .city_move');
	var count_slides=[];
	
	var iteration=1;
	var my_left=$('#zzz3 div.city_box_left');
	var my_right=$('#zzz3 div.city_box_right');
	
	my_right.click(function() {
														   $('div.city_act div.city_slide').each(function(i){
											 					count_slides[i]=$(this);
											 				})
															var count=count_slides.length;
														   if(iteration<count) {
														   		iteration++;
																move.animate({left:'-=230px'},'normal','swing') 
														      }
												          }
											   )
	my_left.click(function() {
														   $('div.city_act div.city_slide').each(function(i){
											 					count_slides[i]=$(this);
											 				})
														   var count=count_slides.length;
														   if(iteration>1) {
														   		iteration--;
																move.animate({left:'+=230px'},'normal','swing') 
														      }
												          }
											   )
}

function getPageSize(){
       var xScroll, yScroll;
       if (window.innerHeight && window.scrollMaxY) {
                xScroll = document.body.scrollWidth;
                yScroll = window.innerHeight + window.scrollMaxY;
          	 } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
                   xScroll = document.body.scrollWidth;
                   yScroll = document.body.scrollHeight;
             } else if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight){ // Explorer 6 strict mode
                   xScroll = document.documentElement.scrollWidth;
                   yScroll = document.documentElement.scrollHeight;
             } else { // Explorer Mac...would also work in Mozilla and Safari
                   xScroll = document.body.offsetWidth;
                   yScroll = document.body.offsetHeight;
             }
  
             var windowWidth, windowHeight;
             if (self.innerHeight) { // all except Explorer
                  windowWidth = self.innerWidth;
                  windowHeight = self.innerHeight;
             } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
                  windowWidth = document.documentElement.clientWidth;
                  windowHeight = document.documentElement.clientHeight;
             } else if (document.body) { // other Explorers
                     windowWidth = document.body.clientWidth;
                     windowHeight = document.body.clientHeight;
             }
  

             // for small pages with total height less then height of the viewport
             if(yScroll < windowHeight){
                    pageHeight = windowHeight;
             } else {
                    pageHeight = yScroll;
             }

           // for small pages with total width less then width of the viewport
           if(xScroll < windowWidth){
                pageWidth = windowWidth;
        } else {
                 pageWidth = xScroll;
         }
 

         return [pageWidth,pageHeight,windowWidth,windowHeight];
  }

function main_block_carusel() {
	 var move=$("#move_new");
	 var left=$("#car_left_new");
 	 var right=$("#car_right_new");
	 var amount=$("#move_new li").size();
	 var amount_hidden=amount-3;
	 var amount_limit=amount_hidden;
	 var end_left=1;
	 var end_right=0;
	 	 
	 right.click(function(){
		 	if (end_right==0) {
			 	if (amount_hidden!=0) {
					move.animate({left:"-=126px"});
			 	    amount_hidden--;
					if (amount_hidden!=amount_limit) {
							left.css('visibility','visible');
							end_left=0;		 
						}
					}
				if (amount_hidden==0) {
					end_right=1;
					end_left=0;		
					right.css('visibility','hidden');
					left.css('visibility','visible');
				}
				
			}	 
		 })
	 left.click(function(){
		 	if(end_left==0) {
			   if (amount_hidden!=amount_limit) {
			   		move.animate({left:"+=126px"})
			   		amount_hidden++;
					if (amount_hidden!=0) {
							right.css('visibility','visible');
							end_right=0;		 
						}	
			   }
			   if (amount_hidden==amount_limit) {
				   	end_right=0;
					end_left=1;
					right.css('visibility','visible');
				    left.css('visibility','hidden');
				   }
			}	 
		 })	 
	 		
	}
	
function SendToOleg(rate,news_id,page_id){
	$.get('/voite.php',{rate:rate,news_id:news_id,page_id:page_id}, function(data) {});	
}

function rating() {
		var page_id=$('div.page_id').text();
		var on=1;
		var rate=1;
		var news_id;
		$('div.rating div.rate_one').click(function(){
														 	$(this).parent().attr('rel','1')
															rate=1;
															news_id=$(this).parent().parent().attr('rel');
															SendToOleg(rate,news_id,page_id);
												})
		$('.rating div').hover(function(){
										on=$(this).attr('rel');
										if(on!=1 && $(this).parent().attr('rel')=='0') {
										$(this).parent().find('div').each(function(e){
												if (on>e){
														$(this).find('img').attr('src','/images/rate_star.gif')
														$(this).removeClass().addClass('rate_star1');
													}
											})
										$(this).click(function(){
																	$(this).parent().attr('rel','1');
																	rate=on;
																	news_id=$(this).parent().parent().attr('rel');
																	SendToOleg(rate,news_id,page_id);
																})
										}
									},
								function(){
										if(on!=1 && $(this).parent().attr('rel')=='0') {
											$(this).parent().find('div.rate_star1:gt(0) img').attr('src','/images/rate_empty.gif');
								  			$(this).parent().find('div.rate_star1:gt(0)').removeClass().addClass('rate_empty1');
										}
								    }
								) 	
}


function plashka_fix() {
	$('.select_green span:eq(0), .select_blue span:eq(0), .select_blue_2 span:eq(0), .select_blue_3 span:eq(0), .select_black span:eq(0), .select_grey span:eq(0), .select_kar_3 span:eq(0), .select_bizn_3 span:eq(0), .select_bibl_3 span:eq(0), .select_vist_3 span:eq(0)')
	.addClass('plashka_fix');	
}

function obyav_list() {
	var ul=false;
	$('div.one_obyav').hover(
							  function(){
								  	if($(this).find('ul').length)
									{
									 $(this).find('ul').show();
									 ul=true
									}},
  							  function(){if (ul) $(this).find('ul').hide() }
							)
}


function height_align() {
		var h1=$('div.last_news').height();
		var h2=$('div.upcoming_events').height();
		var h3=$('div.last_publications').height();
		$('div.last_news, div.upcoming_events, div.last_publications').height(Math.max(h1,h2,h3));
		
		var h10=$('div.col_1_small').height();
		var h20=$('div.col_2_small').height();
		var h30=$('div.col_3_small').height();
		$('div.col_1_small, div.col_2_small, div.col_3_small').height(Math.max(h10,h20,h30));
}
