$(document).ready(function(){
	initIndexAnimations();
	func_for_ulregion();
	func_for_orange();
	$(".open_link").click(function(){
		$(this).siblings(".more").slideToggle("slow");
		$(this).toggleClass("open");
		if ($(this).hasClass('open'))
				$(this).find("a").html('Скрыть...');
			else
				$(this).find("a").html('Подробнее...');
	});
	
	$('#news_menu .one_news_ul').hide();
	$('#news_menu .date_month_ul').hide();
	$('#news_menu .date_year div.year').click(function(){
		$('.date_month_ul').hide();
		$('#news_menu .date_year div.year').removeClass('active_y');
		$(this).next('.date_month_ul').toggle();
		$(this).addClass('active_y');
	});
	$('#news_menu .date_month div.month').click(function(){
		$('.one_news_ul').hide();
		$('#news_menu .date_month div.month').removeClass('active_m');
		$(this).next('.one_news_ul').toggle();
		$(this).addClass('active_m');
	});
	
	var gety = window.location.search.substring(1).split("&");
	if(gety.length == 3){
		var yr_id = gety[1].split('=');
		yr_id = yr_id[1];
		var m_id = gety[2].split('=');
		m_id = m_id[1];
		var n_id = gety[0].split('=');
		n_id = n_id[1];
		
		$('#news_menu #'+yr_id+' div').eq(0).addClass('active_y');
		$('#news_menu #'+yr_id+' .date_month_ul .'+m_id+' div').addClass('active_m');
		$('#news_menu #'+yr_id+' .date_month_ul .'+m_id+' #'+n_id).addClass('active_n');
		
		$('#news_menu #'+yr_id+' .date_month_ul').show();
		$('#news_menu #'+yr_id+' .date_month_ul .'+m_id+' .one_news_ul').show();
	};
	
	$(".fancybox").fancybox();
	
	var start_resize_img = $('.resize_img').width();
	
	$(window).resize(function(){
		func_for_ulregion(start_resize_img, '90%', '50px', '80px', '20px center');
		func_for_orange();
	})
	
	var wid = $(window).width();
	if(wid < 1100){
		func_for_ulregion(start_resize_img, '90%', '50px', '80px', '20px center');
	}
	
	$('#featured').height(1241);
	
	$('#fragment_a_1').click(function(){
		$('#featured').animate({height: '1241px'});
	});
	$('#fragment_a_2').click(function(){
		$('#featured').animate({height: '603px'});
	});
	$('#fragment_a_3').click(function(){
		$('#featured').animate({height: '582px'});
	});
	
	$('#sliderer').anythingSlider({
		width: 805,
		height: 576,
		startPanel: 1,
		autoPlay: false,
		resizeContents: false
	});
	
	$('#sliderer2').anythingSlider({
		width: 852,
		height: 695,
		startPanel: 1,
		autoPlay: false,
		resizeContents: false,
		buildNavigation: false
	});
	
	$("#featured > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 0, true);
	
});

func_for_orange = function(){
	var width_window = 'CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
	var width_block_orange = $('#block_orange').width();
	$('#block_orange').css('margin-left', -(width_block_orange-width_window)/2);
};	

func_for_ulregion = function(start_resize_img, start_block_ulreg_in, start_anythingSlider, start_featured, start_featured_selected){

	var wid = $(window).width();
	if(wid < 1100){
		$('.resize_img').width('800');
		$('.block_ulreg_in').width('95%');
		$('div.anythingSlider').css({'padding-left':'20px', 'padding-right':'20px'});
		$('#featured ul.ui-tabs-nav li').css({'padding-left':'50px'});
		$('#featured ul.ui-tabs-nav li.ui-tabs-selected').css({'background-position':'7px center'});
	} else {
		$('.resize_img').width(start_resize_img);
		$('.block_ulreg_in').width(start_block_ulreg_in);
		$('div.anythingSlider').css({'padding-left' : start_anythingSlider, 'padding-right' : start_anythingSlider});
		$('#featured ul.ui-tabs-nav li').css({'padding-left':start_featured});
		$('#featured ul.ui-tabs-nav li.ui-tabs-selected').css({'background-position' : start_featured_selected});
	}
	
	$pb_w = $('#plahi_blue').width();
	$pb_w_pl = $('.plahi_blue_one_thirst').width() + $('.plahi_blue_one_second').width();
	
	if(wid < 1200){
		$('.plahi_blue_one_thirst').css({'background' : 'url(/include/images/ulregion_fon_ramli_1.gif) 0 -512px no-repeat', 'width' : '406px', 'height' : '209px' });
		$('.plahi_blue_one_second').css({'background' : 'url(/include/images/ulregion_fon_ramli_2.gif) 0 -686px no-repeat', 'width' : '406px', 'height' : '364px' });
		$('.block_ulreg0 #plahi_blue .plahi_blue_one ul li').css({'padding-bottom' : '7px' });
		$('.plahi_blue_one_thirst').css({'margin-left' : ($pb_w - $pb_w_pl)/3 });
	} else if(wid >= 1200 && wid < 1600){
		$('.plahi_blue_one_thirst').css({'background' : 'url(/include/images/ulregion_fon_ramli_1.gif) 0 -228px no-repeat', 'width' : '466px', 'height' : '223px' });
		$('.plahi_blue_one_second').css({'background' : 'url(/include/images/ulregion_fon_ramli_2.gif) 0 -315px no-repeat', 'width' : '465px', 'height' : '313px' });
		$('.block_ulreg0 #plahi_blue .plahi_blue_one ul li').css({'padding-bottom' : '10px' });
		$('.plahi_blue_one_thirst').css({'margin-left' : ($pb_w - $pb_w_pl)/3 });
	} else {
		$('.plahi_blue_one_thirst').css({'background' : 'url(/include/images/ulregion_fon_ramli_1.gif) 0 0px no-repeat', 'width' : '599px', 'height' : '168px' });
		$('.plahi_blue_one_second').css({'background' : 'url(/include/images/ulregion_fon_ramli_2.gif) 0 0px no-repeat', 'width' : '599px', 'height' : '257px' });
		//$('.block_ulreg0 #plahi_blue .plahi_blue_one ul li').css({'line-height' : '17px' });
		$('.plahi_blue_one_thirst').css({'margin-left' : '0' });
	}
}

initIndexAnimations = function(){

	var timer;
	var pos = 0;
	$(".sprite_design_outer").mouseenter(function(){
		clearInterval(timer);
		timer = setInterval(function(){
			if (pos<=-1800) {clearInterval(timer); return;};
			pos -= 180; 
			$(".sprite_design").animate({top: pos+"px"}, {duration: 0, queue: false});
		}, 30);
		
	}).mouseleave(function(){
		clearInterval(timer);
		timer = setInterval(function(){
			if (pos>=0) {clearInterval(timer); return;};
			pos += 180; 
			$(".sprite_design").animate({top: pos+"px"}, {duration: 0, queue: false});
		}, 30);
	});
	
	var timer1;
	var pos1 = 0;
	$(".sprite_quality_outer").mouseenter(function(){
		clearInterval(timer1);
		timer1 = setInterval(function(){
			if (pos1<=-3600) {clearInterval(timer1); return;};
			pos1 -= 180; 
			$(".sprite_quality").animate({top: pos1+"px"}, {duration: 0, queue: false});
		}, 30);
		
	}).mouseleave(function(){
		clearInterval(timer1);
		timer1 = setInterval(function(){
			if (pos1<=-3960) {
				clearInterval(timer1);
				pos1=0;
				$(".sprite_quality").animate({top: pos1+"px"}, {duration: 0, queue: false});
				return;
			};
			pos1 -= 180; 
			$(".sprite_quality").animate({top: pos1+"px"}, {duration: 0, queue: false});
		}, 30);
	});
	
	var timer2;
	var pos2 = 0;
	$(".sprite_process_outer").mouseenter(function(){
		clearInterval(timer2);
		timer2 = setInterval(function(){
			if (pos2<=-2340) {clearInterval(timer2); return;};
			pos2 -= 180; 
			$(".sprite_process").animate({top: pos2+"px"}, {duration: 0, queue: false});
		}, 30);
		
	}).mouseleave(function(){
		clearInterval(timer2);
		timer2 = setInterval(function(){
			if (pos2>=0) {clearInterval(timer2); return;};
			pos2 += 180; 
			$(".sprite_process").animate({top: pos2+"px"}, {duration: 0, queue: false});
		}, 30);
	});
	
	var timer3;
	var pos3 = 0;
	$(".sprite_attention_outer").mouseenter(function(){
		clearInterval(timer3);
		timer3 = setInterval(function(){
			if (pos3<=-900) {clearInterval(timer3); return;};
			pos3 -= 180; 
			$(".sprite_attention").animate({top: pos3+"px"}, {duration: 0, queue: false});
		}, 30);
	}).mouseleave(function(){
		clearInterval(timer3);
		timer3 = setInterval(function(){
			if (pos3>=0) {clearInterval(timer3); return;};
			pos3 += 180; 
			$(".sprite_attention").animate({top: pos3+"px"}, {duration: 0, queue: false});
		}, 30);
	});
	
	var timer4;
	var pos4 = 0;
	$(".sprite_dealers_outer").mouseenter(function(){
		clearInterval(timer4);
		timer4 = setInterval(function(){
			if (pos4<=-1260) {clearInterval(timer4); return;};
			pos4 -= 180; 
			$(".sprite_dealers").animate({top: pos4+"px"}, {duration: 0, queue: false});
		}, 30);
	}).mouseleave(function(){
		clearInterval(timer4);
		timer4 = setInterval(function(){
			if (pos4>=0) {clearInterval(timer4); return;};
			pos4 += 180; 
			$(".sprite_dealers").animate({top: pos4+"px"}, {duration: 0, queue: false});
		}, 30);
	});
	
};
