var o;
var flag;
o=1;



var req;
var reqTimeout;
var cur_div;
var last_id = 0;

function loadXMLDoc(url) {
    req = null;

    if (window.XMLHttpRequest) {
        try {
            req = new XMLHttpRequest();
        } catch (e){}
    } else if (window.ActiveXObject) {
        try {
            req = new ActiveXObject('Msxml2.XMLHTTP');
        } catch (e){
            try {
                req = new ActiveXObject('Microsoft.XMLHTTP');
            } catch (e){}
        }
    }

    if (req) {
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
        reqTimeout = setTimeout("req.abort(); ", 5000);
    } 
}

function processReqChange() {

    if (req.readyState == 4) {
        clearTimeout(reqTimeout);

        if (req.status == 200) {

            if (cur_div==1)
            {
                document.getElementById('aj_type').innerHTML = req.responseText;                
            }

        }
    }
}

function requestdata(params)
{
  if(cur_div==1)
	loadXMLDoc('/_ajax/filter.php'+params);
}  

function show_list()
{
    section_id = document.getElementById('mark').value;
    cur_div=1;
	requestdata("?action=list_show&section_id=" + section_id);
}
 



function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};
function mainmenu(){
$(" .main-menu ul ").css({display: "none"}); // Opera Fix
$(" .main-menu li").hover(function(){
$(this).css({"z-index": "6"});
		$(this).find('ul:first').css({display: "block"}).show(400);
		},function(){
$(this).css({"z-index": "5"});
		$(this).find('ul:first').css({display: "none"});
		});
$(" .main-menu li.last").hover(function(){ $(this).find('ul:first').css({display: "none"}); });
}

function maps () {

	$(".nansena").click(function(e) {
			e.preventDefault();
			$("#nansena").modal( { position: ["35%","35%"], maxWidth: 610, zIndex: 70 });	});
$(".central").click(function(e) {
			e.preventDefault();
			$("#central").modal({ position: ["35%","35%"], maxWidth: 610, zIndex: 70 });	});
$(".marshal").click(function(e) {
			e.preventDefault();
			$("#marshal").modal({ position: ["35%","35%"], maxWidth: 610, zIndex: 70 });	});

}

jQuery(document).ready(function() {
mainmenu();
maps();
fls = document.getElementsByTagName("object"); 
for (var a = 0; a < fls.length; a++){ 
fls[a].outerHTML = fls[a].outerHTML; 
}
    jQuery('#jcarousel').jcarousel({
        auto: 5,
		scroll: 1,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
	jQuery('#jcarousel2').jcarousel({
        auto: 4,
		scroll: 1,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
	jQuery('#jcarousel3').jcarousel({
        auto: 4,
		scroll: 1,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
	

	$("a.hide").click(function(){
		 $(".basket").animate ({ 
        width: "110px"
      });
		

	});
	$("a.open").click(function(){
		if ($(".basket").width() < 280) {
		$(".basket").animate ({ 
        width: "280px"
      });
		}
		else {
		$(".basket").animate ({ 
        width: "109px"
      });
		}



	});
	$("a.popup").click(function(){
		window.open( $(this).attr('href'),"mywindow"+o,'width=607,height=225' );
		o++;
        return false;
		

	});
	$("a.zoom").lightBox();
	$("a.light").lightBox();

	$(".user-info a.hide").click (function() {
		$(this).toggleClass("plus");
		$(".user-info table").toggle();
		if ($(this).hasClass("plus")) {
			$(this).text("развернуть");

		}
		else {
			$(this).text("свернуть");
		}
	});
	$(".user-basket a.hide").click (function() {
		$(this).toggleClass("plus");
		$(".user-basket table").toggle();
		if ($(this).hasClass("plus")) {
			$(this).text("развернуть");

		}
		else {
			$(this).text("свернуть");
		}
	});



});

function show(id)
{
 if ($('#'+id).is(":hidden")) {
        $('#'+id).slideDown("slow");
      } else {
        $('#'+id).slideUp("slow");
      }


}

function select(id)
{
j= document.getElementById('list');
j.options[id].selected=true; 
}
