/* Слайдер
-----------------------------------------------------------------------------*/
slider = new Array();
big = new Array();
big["width"] = 157; //ширина img
big["height"] = 160;
big["widthli"] = 350; //ширина li.current
big["height2"] = 231;   //big["height"] + 28;
small = new Array();
small["width"] = 116;
small["height"] = 231/2;
timer = -1;
direct = '-';
constdelta = '130';
delta = constdelta;
function equilibrate() {
	$('#slider ul li').each(function(i) {
		d = Math.abs(actual*1 - i);
		var a = $(this);
		var img = a.children('a').children('img');
		var ttl = a.children('a').children('.imtitle');
		switch(d) {
			case 0:
				img.animate({width: big["width"], height: big["height"], top: "0px"});
                a.animate({width: big["widthli"]}, function () { ttl.css({'display':'block'}); });
				$('#slider ul.front').animate({'left':direct+'='+delta+'px'});
                $('#slider .rear').attr('class', 'rear color'+actual);
			break;
			case 1:
				if (slider[i] != 1) {
					slider[i] = 0;
				}
                    ttl.css({'display':'none'});
    				img.animate({width: small["width"], height: small["height"], top: "50px"});
    				a.animate({width: small["width"]}, function () { ttl.css({'display':'none'}); });

			break;
			default:
				if (slider[i] != 1) {
					slider[i] = 1;
				}
			break;
		}
	});
	//directlink();
	//rotate();
}
function actual_change(diff) {
	if (actual + diff > 0 && actual + diff < max) {
		actual = actual + diff;
		return true;
	}
	return false;
};
function directlink() {
	$('#directlink').attr('href', location.href.replace(location.search, '') + '?show=' + actual);
}
$(document).ready(function(){
    
	var requete = location.search.substring(1);
	var tab_paires = requete.split("&");
	var tab_elts = new Array();
	for (var i = 0; i < tab_paires.length; i++) {
		temp = tab_paires[i].split("=");
		tab_elts[temp[0]] = unescape(temp[1]);
	}

	max = $('#slider ul li').size();

	i = (tab_elts["show"]) ? parseInt(tab_elts["show"]) : 3;

	actual = (!isNaN(i) && i > 0 && i < max) ? i : 1;

	$('#slider ul li').each( function(i) {
		d = Math.abs(actual*1 - i);
				
		var a = $(this);
		var img = a.children('a').children('img');
		var ttl = a.children('.imtitle');
		switch(d) {
			case 0:
				img.css({width: big["width"]+'px', height: big["height"]+'px'});
				a.css({height: big["height2"]+'px'});
                $('#slider .rear').attr('class', 'rear color'+actual);
			break;
			case 1:
				img.css({width: small["width"]+'px', height: small["height"]+'px'});
			break;
			default:
				img.css({width: small["width"]+'px', height: small["height"]+'px'});
			break;
		}
	});
	$('#slider a.prev').click( function () {
		if (actual_change(-1)) {
		  direct = '+';
          equilibrate(); 
		}
		timer_stop();
		return false;
	});
	$('#slider a.next').click( function () {
		if (actual_change(+1)) {
		  direct = '-';
          equilibrate();
		}
		timer_stop();
		return false;
	});
    
    //движение банок в центр при клике на маленькую банку
    var step = 0;
    $('#slider .front li a').click(function(){
       var here = $(this).parent().index();
       if( here == actual ){return true;} // ссылка разрешена для увеличенной банки
       step = Math.abs(here - actual);
        setTimeout(function() {
            /* Тут изменение параметров */
            step--;
            if (step > -1) {
               if (here > actual) {
              		if (actual_change(+1)) {
                		  direct = '-';
                          equilibrate();
            		}
               } else {
            		if (actual_change(-1)) {
                		  direct = '+';
                          equilibrate(); 
            		}
               }
                setTimeout(arguments.callee, 400);
              }
        }, 0);
       return false;
    });
    
	$('#playpause').click( function () {
		var a = $('#playpause').children('img').attr('src');
		var a = a.split("/");
		if (a[a.length - 1] == 'pause.png') {
			timer_stop();
		}
		else {
			next();
			timer = window.setInterval("next()", 2200);
			$('#playpause').children('img').attr('src', 'images/pause.png');
		}

		return false;
	});
	$('#slider ul li a').click( function () {
		timer_stop();
	});
/*
	$('#slider').mousewheel(function(objEvent, intDelta){
		if (intDelta > 0) {
			if (actual_change(-1))
				equilibrate();
		}
		else if (intDelta < 0) {
			if (actual_change(+1))
				equilibrate();
		}
		return false;
	});
*/
	//timer = window.setInterval("next()", 3000);
});
function timer_stop() {
//	var a = $('#playpause').children('img').attr('src');
//	var a = a.split("/");
//	if (a[a.length - 1] == 'pause.png') {
//		$('#playpause').children('img').attr('src', 'images/playred.png'); /* ou play.png */
//		window.clearInterval(timer);
//	}
	var a = true;
	if (a) {
		window.clearInterval(timer);
	}
}
function next() {
	if (actual_change(+1))
		equilibrate();
}
function rotate() {
	//alert(max + ' ' + actual + ' ' + (max - actual));
/*
	if (actual < (max / 2)) {
		var a = $('#slider ul li').eq(max-1).remove();
		$('#slider ul').prepend(a);
		actual = actual + 1;
	}
*/
/*
		if (diff < 0) {
			var a = $('#slider ul li:last').remove();
			$('#slider ul').prepend(a);
		}
		else {
			var a = $('#slider ul li:first').remove();
			$('#slider ul').append(a);
		}
*/
}
//Показ текстовы блоков к картинкам
function showtext(id) {
	$('#texts .text').each( function (i) {
		if ($(this).css('display') != 'none')
			//$(this).fadeOut('fast');
			$(this).hide();
	});
	$('#texts #text'+id).slideDown('slow');
}

/* конец - Слайдер
-----------------------------------------------------------------------------*/



$(function(){
	
	$(".main_block.articles div").mouseenter(function(){
		$(".main_block.articles div").addClass("hidden");
		$(this).removeClass("hidden");
	});

	var lock = 0;
	$('div.big_sot span').css({
		"opacity": "0",
		"display": "none",
	})
	$('div.big_sot div.close').css({
		"display": "none",

	})
	
	
	$('div.big_sot div.close').hover(function(){
	
		$(this).css({
			"background-position" : "right top" 
		
		})
	
	},function(){
	
			$(this).css({
				"background-position" : "left top" 
			})
	
	})
	

///////////////////////////////////////////////////////////////////////////////////
//Подсветка сот при наведении	
	$('area.sot_hook_map_area').hover(function(){
			if(lock == 0){
				$(this).parent('map').parent('div.sot').addClass('sot_hover')
			}
		}, function(){
			if(lock == 0){
				$(this).parent('map').parent('div.sot').removeClass('sot_hover')	
			}
	})
	$('div.sot img.bucket').hover(function(){
			$(this).parent('div.sot').addClass('sot_hover')
		}, function(){
			$(this).parent('div.sot').removeClass('sot_hover')	
	})
	$('div.sot a').hover(function(){
			$(this).parent('div.sot').addClass('sot_hover')
		}, function(){
			$(this).parent('div.sot').removeClass('sot_hover')	
	})	
//Анимация по клику		

	$('div.sot').click(function(){/*
		if(lock == 0){
			$(this).animate({opacity: 0});
			$('div.sot').not(this).animate({opacity: 0.20}); 
			var left_cord = $(this).css("left")
			var top_cord = 	$(this).css("top")	
			left_cord = left_cord.substring(0,left_cord.indexOf('px'))*1  + 176/2
			top_cord = top_cord.substring(0,top_cord.indexOf('px'))*1    + 116/2
			$(this).next('div.big_sot').css({
				"left" : left_cord, 
				"top" : top_cord,
				"display": "block",

			})
			$(this).next('div.big_sot').animate({
				"height" : "290px", 
				"width" : "391px", 
				"left" : "298px", 
				"top" : "225px",
			})
			$(this).next('div.big_sot').children('img').css({
				"left": "0px",
				"top":"0px",
			})
			$(this).next('div.big_sot').children('img').animate({
				"height" : "178px", 
				"width" : "129px", 
				"left": "60px",
				"top":"27px",
			})
			$(this).next('div.big_sot').children('span.name').css({
				"left": "213px",
				"top": "74px",
				"display": "block",

			})
			$(this).next('div.big_sot').children('span.descr').css({
				"left": "211px",
				"top": "134px",
				"display": "block",
			})
			$(this).next('div.big_sot').children('div.close').css({
				"display": "block",
				"opacity": "0"
			})

			$(this).next('div.big_sot').children('span.name').delay(300).animate({

				"opacity": "1"
			})
			$(this).next('div.big_sot').children('span.descr').delay(300).animate({

				"opacity": "1",
			})
			$(this).next('div.big_sot').children('div.close').delay(300).animate({
				"opacity": "1"
			})

			lock=1;
		}*/
	})
	$('div.big_sot div.close').click(function(){
		if(lock=1){
			var left_cord = $(this).parent('div.big_sot').prev('div.sot').css("left")
			var top_cord = 	$(this).parent('div.big_sot').prev('div.sot').css("top")	
			left_cord = left_cord.substring(0,left_cord.indexOf('px'))*1  + 176/2
			top_cord = top_cord.substring(0,top_cord.indexOf('px'))*1    + 116/2
			$(this).parent('div.big_sot').animate({
				"height" : "0px", 
				"width" : "0px", 
				"left" : left_cord, 
				"top" : top_cord
			})
			$(this).parent('div.big_sot').children('img').animate({
				"height" : "0px", 
				"width" : "0px", 
			})
			$('div.sot').animate({opacity: 1});
			$(this).parent('div.big_sot').children('span').animate({
				"opacity": "0",
			})
			$(this).parent('div.big_sot').children('div').css({
				"opacity": "0",
				"display":"none",
			})
			
			
			lock=0;
		}
	})	
///////////////////////////////////////////////////////////////////////////////////
})
