var SepWin;
  function OpenSepWin(url, width, height, alt) {
     if (SepWin) SepWin.close();
     if (alt) 
        WinHeight = height+20;
     else{
        alt='';
        WinHeight = height;
     }
        
     SepWin=window.open (url, 'SepWin', 'width='+width+',height='+WinHeight+',resizable=0');
     SepWin.document.open();
     SepWin.document.writeln("<HTML><BODY leftmargin=0 topmargin=0><img src="+url+" width="+width+" height="+height+" border=0><br><center>"+alt+"</center></BODY></HTML>");
     SepWin.document.title = alt;
     SepWin.document.close();
     SepWin.focus();
  }

  var pts_json_counter = 0;
  var pts_interval;
  var pts_counter = 0;
  
  function pts_timer() {
    if(pts_json_counter == 0) {
      clearInterval(pts_interval); 
      jqueryslidemenu.buildmenu("jMenu", arrowimages);
    }
  }
  
  $(document).ready(function() {
  
    var curpageId = "#"+jQuery("#curentpageId").val();
    jQuery("ul.nav li").removeClass("bold");
    jQuery("div.n_block").removeClass("actnav");

    var curli =  jQuery(curpageId);
    curli.addClass("bold");
    curli.closest(".n_block").addClass("actnav");

    jQuery("li.showchild").each(function(){
      var n = jQuery(this).attr("name");
      var subsource = jQuery("#"+n+" ul").clone();	
      jQuery(this).append(subsource.hide()); 
      jQuery(this).find("li").addClass("showchild");
    });

    jQuery("#2818").after("<div class='yel'/>");
	// косячок в админке
	jQuery("#2233").remove();
	
	
	
    jQuery(".showparent").each(function(){
      var n = jQuery(this).attr("name");
      var t = jQuery("#"+n);
      jQuery(this).text(jQuery(t).find("a").eq(0).text());
    });

    jQuery("li.showchild").hover(
      function () {
        jQuery(this).find("ul").show();
      }, 
      function () {
        jQuery(this).find("ul").hide(); 
      }
    );
  
  	//dmenu
  
  	var tourlist = $("#2238");
  //  tourlist.children("a").attr('href',"/tourtypes.php");
  	tourlist.children("ul").remove();

  	$.getJSON('http://gate.ptsonline.ru/?json_request={"psAction":"tourtypes","pnCountryId":0}&jsoncallback=?',
      function(data, textStatus) {
       	var res = "<ul class='nav'>";
       	$.each(data, function(key, val) { 
					res += "<li class='pnTourTypeId' id='"+val.id+"'><a href='/tourtypes.php?pnTourTypeId="+val.id+"' >"+val.name+"</a></li>";
				});
				res += "</ul>";
				tourlist.append(res);
				//страны
				var pnTourTypeId = $(".pnTourTypeId");
				var l = pnTourTypeId.length;
        pnTourTypeId.each(function(n) {		
        pts_json_counter++;
						
          var tis = this.id;
          var cur = this;												
          var request = 'http://gate.ptsonline.ru/?json_request={"psAction":"countries","pnTourTypeId":'+tis+',"pnShowOnlyPublic":1}&jsoncallback=?';						
          //****
          $.getJSON(request,
            function(data, textStatus) {
              var res = "<ul class='nav'>";
              $.each(data, function(key, val) { 											
                res += "<li class='showtour' id='"+tis+"' name='"+val.id+"'><a href='/tours.php?pnTourTypeId="+tis+"&pnCountryId="+val.id+"'>"+val.name+"</a></li>";										
              });
              res += "</ul>";
              $(cur).append(res);
              pts_json_counter--;		
              if(n==l-1) pts_interval = setInterval(function() { if(pts_json_counter == 0) {  clearInterval(pts_interval);       jqueryslidemenu.buildmenu("jMenu", arrowimages);} },100);
										
					});
				}); //.pnTourTypeId  
    });
	
		$("li.showtour").live("click", function() {
		
			var tid = this.id;
		
			var cid = $(this).attr("name")
			var cur = this;
			var request = 'http://gate.ptsonline.ru/?json_request={"psAction":"tours","pnTourTypeId":'+tid+',"pnCountryId":'+cid+',"pnSiteId":1}&jsoncallback=?';
								
			//*** chapterinfo.php?id=2302&pnGroupId=495
										
			$.getJSON(request,
                function(data, textStatus) {
                	var res = '';
                	$.each(data, function(key, val) { 
						res += "<a href='chapterinfo.php?id=2302&pnGroupId="+val.group_id+"&pnTourId="+val.tour_id+"'>"+ val.tour_title +"</a><br />"; 
					});			
					$("#dmenu").empty().append(res);
				});
				
    });
	
  //doc ready
  });
//jqueryslidemenu.buildmenu("jMenu", arrowimages);000000001
