$(document).ready(function(){
    
    
    $(".carousel").css("height","100px");
    $(".main_slider li").css("margin-left","5px");
    $(".carousel").jCarouselLite({
		btnNext: ".r",
		btnPrev: ".l",
		visible: 4,
		circular: true
	});
	
    $(".header_course a").live("click",function(){
        var el = $(this);
        if(el.parent().parent().hasClass("opened")){
            //  change
            el.parent().parent().removeClass("opened");
            $(".header_course ul li").hide();
            el.parent().addClass("a").show();
			$.ajax({
			  method: 'get',
			  url: '/include/course_change.php',
			  success: function(data) {
				$('#courses_val').html(data);
			  },
			  error: function(xhr, textStatus, errorThrown) {
				alert(textStatus);
			  },
			  data: {html: el.html()}
			});
        } else {
            //  open
            $(".header_course .a").removeClass("a");
            el.parent().parent().addClass("opened");
            $(".header_course ul li").show();
        }
        return false;
    });

    $(".courses ul li a").live("click",function(){
        //  tabs
        var el = $(this);
		if (el.html() == "<span>Ценных бумаг</span>")
		{
			$.get("/include/course_change_paper.php",{'id': el.html()},function(data){
				$(".courses_wrap .mid").html(data);
			});
		}
		if (el.html() == "<span>Драгоценных металлов</span>")
		{
			$.get("/include/course_change_metal.php",{'id': el.html()},function(data){
				$(".courses_wrap .mid").html(data);
			});
		}
		if (el.html() == "<span>Валют</span>")
		{
			$.get("/include/course_change_course.php",{'id': el.html()},function(data){
				$(".courses_wrap .mid").html(data);
			});
		}
		$(".courses ul .a").html("<a href=\"#\"><span>"+$(".courses .a span span").html()+"</span></a>");
		$(".courses ul .a").removeClass("a");
        el.parent().addClass("a");
		el.parent().html("<span>"+el.html()+"</span>");

		/*
        $(".prev_news .title .a").html("<a href=\"#\">"+$(".prev_news .title .a span").html()+"</a>");
        $(".prev_news .title .a").removeClass("a");
        el.parent().addClass("a");
        el.parent().html("<span>"+el.html()+"</span>");
        //  load
        $(".newsBlock").html("loading..");

        $.get("/news.php",{'id': el.html()},function(data){
           $(".newsBlock").html(data); 
        });*/
		return false;
    });
    
    $(".prev_news .title ul li a").live("click",function(){
        //  tabs
        var el = $(this);
        
        $(".prev_news .title .a").html("<a href=\"#\">"+$(".prev_news .title .a span").html()+"</a>");
        $(".prev_news .title .a").removeClass("a");
        el.parent().addClass("a");
        el.parent().html("<span>"+el.html()+"</span>");
        //  load
        $(".newsBlock").html("loading..");

        $.get("/news.php",{'id': el.html()},function(data){
           $(".newsBlock").html(data); 
        });
		return false;
    });
    
    $(".service li").hover(function(){
        $(this).find(".service_popup").show();
        if($.browser.msie==true && $.browser.version==6){
        $(".main .service_popup").css("width",($(".main .service ul").width()-27)); 
        $(".li_1 .service_title").css("margin-left",($(".main .service ul").width()-$(".li_0").width()*2-34)); 
        $(".li_2 .service_title").css("margin-left",($(".main .service ul").width()-$(".li_0").width()-21)); 
        }
    },function(){
        $(this).find(".service_popup").hide();
    });

	$(".filials .item a.more").live("click",function(){
        $(this).parent().parent().find(".item_block").show();
		$(this).parent().html('<a href="#" class="hide">Скрыть</a>');		
		return false;
    });
	$(".filials .item a.hide").live("click",function(){
        $(this).parent().parent().find(".item_block").hide();
		$(this).parent().html('<a href="#" class="more">Показать</a>');
		return false;
    });

	$(".filials .item div.name a").live("click",function(){
        $(this).parent().parent().find(".item_block").toggle();
		return false;
    });
	
	$(".current .title a").live("click",function(){
        //  tabs
        var el = $(this);
        
        $(".current .title .a").removeClass("a");
        el.addClass("a");
		if (el.html() == "на карте")
		{
			el.parent().parent().find(".list").hide();
			el.parent().parent().find(".map").html("загрузка...");
			el.parent().parent().find(".map").show();
			el_sect_id = document.getElementById('geo_section_id');
			el_serv_id = document.getElementById('geo_service_id');
			var el_is_atm = document.getElementById('el_is_atm');
				/*$.get("/atm.php",{'id': el_sect_id.value, 'b': 'Y'},function(data){
					el.parent().parent().find(".map").html(data);
				});*/
			/*if ()
			{
				is_atm_val = el_is_atm.value;
			}
			alert(is_atm_val);*/
			if (el_is_atm.value == "Y")
			{
				var el_is_b = document.getElementById('el_is_b');
				$.get("/atm.php",{'id': el_sect_id.value, 'b': el_is_b.value},function(data){
					el.parent().parent().find(".map").html(data);
				});
			}
			else
			{
				$.get("/map.php",{'id': el_sect_id.value, 'serv': el_serv_id.value},function(data){
					el.parent().parent().find(".map").html(data);
				});
			}
		}
		if (el.html() == "списком")
		{
			el.parent().parent().find(".map").hide();
			el.parent().parent().find(".list").show();
		}
		return false;
    });

	$(".prev_img_wrap a").live("click",function(){
        // coins photo
		var id = $(this).attr('id').replace(/ph/, "");
        $(".prev_img_wrap .a").removeClass("a");
        $(this).parent().parent().parent().parent().parent().addClass("a");
		$('.prev_img img').fadeOut(200);
		
		setTimeout( function(){
			$('.prev_img img#pr'+id).fadeIn(200);
		}, 300);
		return false;
    });
});

function showList()
{
	$(".current").find(".map").hide();
	$(".current").find(".list").show();
	$("#list_a_id").addClass("a");
	$("#map_a_id").removeClass("a");
	return true;
}

function showService()
{
	$(".filter #outer_in2").hide();
	$(".filter #outer_in").show();
	return true;
}
function hideService()
{
	$(".filter #outer_in").hide();
	$(".filter #outer_in2").show();
	return true;
}

function more_inf_calc(id)
{
	$("div.questionnaire #"+id).toggle();
	//$(".filter #outer_in2").show();
	return true;
}

