function replace_txtarea()
{
   $("li.repl").each(function () {
      var code = $(this).children("textarea").val();
      //alert(code);
      $(this).replaceWith(code);
   });
}

$(replace_txtarea);

////////////////////////////////////////////
var toPreload = [];

function go_preload()
{
   if (!toPreload.length)
      return;
      
   var im = toPreload.shift();
   var src = im.attr("alt");
   
   if ( im.hasClass("pbg") )
   {
      src = $(".for_" + im.attr("id")).attr("href");
      //alert(src);
      //console.log(src);
   }
   else
   {
      im.attr("alt", "");
   }
   
   var tmp_im = $("<img />");
   tmp_im.css({
      left: "-9999px",
      top: "-9999px",
      position: "absolute"
   });
   tmp_im.bind('load', function () {
      im
         .attr("src", src)
         .css({
            opacity: 0
         })
         .animate({
            opacity: 1
         }, {
            queue: false,
            duration: 200
         })
         .removeClass("img_loading")
      ;
      $(this).remove();
      if (0)
      {
         setTimeout(go_preload, 500);
      }
      else
      {
         go_preload();  
      }
      //alert("loaded");
   });
   tmp_im.appendTo("body");
   tmp_im.attr("src", src);
}

$(document).ready(function () {
   $("img").each(function () {
      var alt = $(this).attr("alt");
      //console.log( $(this).hasClass("pbg") );
      if (alt.match(/^http\:\/\/./) || $(this).hasClass("pbg"))
      {
         toPreload.push( $(this) );
         $(this).addClass("img_loading");
      }
   });
   //alert( toPreload.length );
   setTimeout(function () {
      //go_preload();
   }, 2000);
});
////////////////////////////////////////////

var menu_is_clickable=true;

$(function () {
   $(".gal_wrapper").each(function () {
      if ( !$(this).children().length )
         $(this).remove();
   });
});

var prev_location_hash = window.location.hash;
//prev_location_hash = '#comment-4';
var hide2level = false;

$(function () {
   if (hide2level)
   {
      $(".nav_div > ul ul").remove();
   }
   var bn = 0;
   $(".uniform").each(function () {
      bn++;
      $("[name]", this).each(function () {
         $(this).attr("id", $(this).attr("name")+"_"+bn );
      });
      $(this).attr("id", $(this).attr("name")+"_"+bn );
   });
});

var dt_settings = {
   // how long will it take the dots to disappear
   dots_duration: 7500,
   // how many dots to display on sliders
   dots_count:    15,
   // which elements should have highslide attached
   highslide: 'a.pf, .post-i a.alignleft_left, .prettyPhoto',
   // options for hs.expand(...)
   highslide_gall: '.gallery_item:not(.single) a.shadow_light:not(.no_hs), a.single_hs, ul li a.hs_me'
   // options for hs gallery
};

// prettyPhoto options, deprecated!
var pf_options = {
   theme: 'light_rounded',
   gallery_markup: ''
};

if (Cufon) {

Cufon('#about', {
	color: '-linear-gradient(#b0b5b8, #f5f5f5)', textShadow: '1px 1px #000'
});

Cufon('h1, h2, h3, h4, h5, h6, .quote_author', {
	color: '-linear-gradient(#686b6c, #181818)', textShadow: '1px 1px #fff',
	hover: {
		color: '-linear-gradient(#a8abad, #434343)'
	}
});

Cufon('.pxs_thumbnails > li > a', {
    color: '-linear-gradient(#aeb3b3, #f6f6f6)',textShadow: '1px 1px #000'
  });
  
Cufon('.desc h2', {
 color: '-linear-gradient(#aeb3b3, #f6f6f6)', textShadow: '1px 1px #000'
  });
    Cufon('.gallery-cont h2', {
 color: '-linear-gradient(#aeb3b3, #f6f6f6)', textShadow: '1px 1px #000'
  });

Cufon('.post_type div, .post_type span, .header', {
	color: '-linear-gradient(#b0b5b8, #f5f5f5)', textShadow: '1px 1px #000'
});
Cufon('#footer .header', {
	color: '-linear-gradient(#b0b5b8, #f5f5f5)', textShadow: '-1px -1px #000'
});
Cufon('.article_c h2', {
	color: '-linear-gradient(#b0b5b8, #f5f5f5)', textShadow: '-1px -1px #000'
});

Cufon('.ico_link.comments');
Cufon('.gallery-content h2', {
	color: '-linear-gradient(#aeb3b3, #f6f6f6)', textShadow: '1px 1px #000'
});

Cufon('.pxs_thumbnails > li > a', {
    color: '-linear-gradient(#aeb3b3, #f6f6f6)',
    textShadow: '1px 1px #000'
});


}


$(function () {
   
   $(".pxs_slider").css('overflow', 'visible');
   
   // fix menu
   $(".pxs_thumbnails > li > ul").wrap('<div />');
   $(".pxs_thumbnails > li > div").append('<i />');
   $(".pxs_thumbnails > li > div > ul").show();
   $(".pxs_thumbnails > li > div > ul > li:first").addClass('first');
   
   $(".menu-item").each(function () {
      var cl = $(this).attr("class");
      var matches = /menu-item-(\d+)/.exec(cl);
      $(this).children("a").attr("id", "page_"+matches[1]);
   });
   
   $(".pxs_thumbnails li ul li.current_page_item").each(function () {
      var a = $(this).parent().parent().parent().children("a");
      a.addClass("selected").addClass("act");
   });

   $(".page_item, .page-item, .current_page_item").each(function () {
      var cl = $(this).attr("class");
      var matches = /page-item-(\d+)/.exec(cl);
      if (!matches)
      {  
         return;
      }
      var e = $(this).children("a");
      if (!e.attr("id"))
         e.attr("id", "page_"+matches[1]);
   });
   
   $(".pxs_thumbnails > li:first > a").each(function () {
      $(this).attr("id", "page_0");
   });
   
   // fix cursor
   $("a.nofollow").css('cursor', 'default');
   
   upd_ev();
});




/*
   Move comments form
*/

var slider_auto = 0;

function move_form_to(ee, p_form)
{
   p_form = p_form.parents(".containers");
   var e = $(".form_holder", p_form).html();
   var tt = $(".form_holder h1", p_form).attr("title");
   $(".form_holder", p_form).slideUp(500, function () {
      $(".form_holder", p_form).remove();
      
      ee.append('<div class="form_holder">'+e+'</div>');
      $(".form_holder h1", p_form).html(tt);
      $(".form_holder [valed]", p_form).removeAttr('valed');
      $(".form_holder .do-clear", p_form).attr('remove', 1);
      
      if (Cufon) Cufon.replace('.form_holder h1', {
	      color: '-linear-gradient(#686b6c, #181818)', textShadow: '1px 1px #fff',
	      hover: {
		      color: '-linear-gradient(#a8abad, #434343)'
	      }
      });
      
      $(".formError").remove();
      
      $(".form_holder", p_form).hide().slideDown(500, function () {
         upd_ev();
      });
      
      if (!ee.hasClass("form_prev_holder"))
      {
         var the_id = ee.parent().attr("class");
         var matches = /comment-(\d+)/.exec(the_id);
         //alert(matches);
         if (matches)
         {
            the_id = matches[1];
            $("input[name=comment_parent]", p_form).val( the_id );
         }
      }
      else
      {
         $("input[name=comment_parent]", p_form).val("0");
      }
      
      //upd_ev();
   });
}

function upd_ev()
{
   /* 
      Валидация форм
   */
   
   $(".gallery").each(function () {
      var ch = $(this).children().length;
      var cols = ch;
      var pad = 16;
      var one_w = 304 + pad;
      var all_w = one_w * cols - pad;
      //all_w += 18;
      //all_w -= 1;
      $(this).css({
         'width': all_w+'px'
      });
      $(this).children(":eq("+(cols-1)+")").css('margin-right', 0);
      $(this).children(":last").css('margin-right', 0);
   });
   
   if ( $.jScrollHorizontalPane )
   {
     $('.scroll-box, #scroll-box').each(function () {
         if ( $(this).attr("sc") )
            return;
         $(this).attr("sc", "done");
         $(this).jScrollHorizontalPane({
            showArrows:       true,
            arrowSize:        23,
            scrollbarHeight:  14,
            scrollbarMargin:  0,
            skip: 26
         });
         
         var the_e = $(this);
         
         var tracker = $(this).parent().find(".jScrollPaneDrag").unbind();
         
         var sc       = $('.gallery', this);
         var scroller = $(this).parent().find(".jScrollPaneDrag");
         var ch       = Math.ceil(sc.children().length / 2);
         var sc_one   = 304 + 16;
         var pad      = 16;
         var sc_w     = sc.width();
         var one_ch   = 3;
         var sc_min_w = one_ch*sc_one-pad;
         var maxw     = 878 - scroller.width(); 
         var anim_dur = 500;
         var is_animating_slider = false;
         
         $(".jScrollPaneTrack, .jScrollArrowLeft, .jScrollArrowRight, .jScrollPaneDrag, .jScrollPaneDragLeft, .jScrollPaneDragRight", $(this).parent()).unbind();
         
         if (ch<=one_ch)
         {
            //$('#scroll_bar, .do_scroll').remove();
         }
         
         $(".jScrollArrowLeft, .jScrollArrowRight", $(this).parent()).unbind().click(function () {
            //alert("click");
            var p = ($(this).hasClass('jScrollArrowLeft') ? -1 : 1);
            var e = jQuery.Event("drag");
            e.custom = 1;
            var k = (maxw) / (sc_w-sc_min_w);
            var x_now = parseInt(scroller.css('left'));
            var x = x_now+((sc_one) * k)*p;
            
            // автодоводка
            var i;
            var _x = x;
            for (i=1; i<ch; i++)
            {
               var _x1 = (i-1)*sc_one*k;
               var _x2 = i*sc_one*k;
               if (Math.round(_x1) == Math.round(x)) continue;
               if (Math.round(_x2) == Math.round(_x)) continue;
               if ((_x < _x2) && (_x > _x1) && ( Math.abs(x_now - _x1) > 5 ) )
               {
                  x = _x1;
                  //alert(x);
                  break;
               }
            }
            
            if ( Math.abs(x - maxw) < 5 ) x = maxw;
            
            e.offsetX = x;
            scroller.trigger(e);
            return false;
         });
         
         scroller.parent().click(function (e) {
            if (!$(e.target).hasClass('jScrollPaneTrack')) return;
            var x = e.pageX;
            x -= scroller.parent().offset().left;
            x -= scroller.width()/2;
            var e = jQuery.Event("drag");
            e.custom = 1;
            e.offsetX = x;
            scroller.trigger(e);
            return false;
         });
         
         scroller.bind('drag', function (e) {
            var x=e.offsetX;
                     
            if (e.custom)
            {
               if (is_animating_slider) return;
               is_animating_slider = true;
            }
                     
            anim_o = {
               duration: anim_dur,
               queue: false,
               complete : function () {
                  is_animating_slider = false;
               }
            };
                     
            if (!e.custom) x-=scroller.parent().offset().left;
            
            if (x<0)   x=0;
            if (x>maxw) x=maxw;



            
            if (!e.custom)
            {
               $(this).css({
                  left: x+"px"
               });
            }
            else
            {
               $(this).animate({
                  left: x+"px"
               }, anim_o);
            }
            
            var m=(sc_w-sc_min_w)*(x/maxw);
            
            if (!e.custom)
            {
               sc.css({
                  marginLeft: '-'+m+'px'
               });
            }
            else
            {
               sc.animate({
                  marginLeft: '-'+m+'px'
               }, anim_o);
            }
            
            e.stopPropagation();
            
            //return false;
         });
         
         sc.bind('mousewheel', function (e, delta) {
            //alert(delta);
            $(".jScrollArrow"+( delta > 0 ? "Left" : "Right" ), the_e.parent()).trigger("click");
         });
         
     });
   }
   if ($.jScrollPane)
   {
	   $('.scroll-pane').each(function () {
	      //if ( $(this).attr("sc") )  return;
	      
         $(this).jScrollPane({
		      showArrows:       true,
		      scrollbarWidth:   22,
		      dragMinHeight:    87,
		      dragMaxHeight:    87,
		      topCapHeight:     0,
		      bottomCapHeight:  38,
		      scrollbarOnLeft:  true,
		      reinitialiseOnImageLoad: true
	      });

	      $(this).attr("sc", 1);
	   });
	}
	
	if (prev_location_hash)
	{
	   var prev_id = prev_location_hash.replace('#', '');
	   if (prev_id)
	   {
	      var elem = $(".hash_"+prev_id, $(".pxs_slider > li:first"));
	      if (!elem.length)
	         elem = $("."+prev_id, $(".pxs_slider > li:first"));
	      if (!elem.length)
	         elem = $("#"+prev_id, $(".pxs_slider > li:first"));
	      if (elem.length)
	      {
	         var parent_sc = elem.parents(".scroll-pane");
	         if (parent_sc.length)
	         {
	            var t = elem.offset().top;
	            t -= elem.parents(".post").offset().top;
	            parent_sc[0].scrollTo(t, 0);
	            //parent_sc.css( 'top', +"px" );
	         }
	      }
	   }
	   prev_location_hash = "";
	}
	
	var go_possible = true;
	$(".article_link .comments").unbind("click").click(function () {
	   if (!go_possible)
	      return false;
      var parent_sc = $(this).parents(".scroll-pane");
      if (parent_sc.length)
      {
         var elem = $(".hash_comments", $(this).parents(".post"));
         if (!elem.length)
            elem = $(".hash_respond", $(this).parents(".post"));
         var t = elem.offset().top;
         t -= $(this).parents(".post").offset().top;
         //t -= 30;
         //alert(t);
         if (t > 0)
         {
            go_possible = false;
            parent_sc[0].scrollTo(t, 0);
            setTimeout(function () {
               go_possible = true;
            }, 500);
         }
         //parent_sc.css( 'top', +"px" );
      }	   
	   return false;
	});
   
   $("[placeholder]").each(function () {
      $(this).val( $(this).val().replace( $(this).attr("placeholder"), "" ) );
      $(this).placeholder();
   });
   $("form .button").unbind().click(function () {
      var e=$(this).parents("form");
      e.find("input, textarea").each(function () {
         $(this).unbind();
         $(this).val( $(this).val().replace( $(this).attr("placeholder"), "" ) );
      });
      if (!e.attr("valed"))
      {
         if (e.hasClass("non_ajax"))
         {
            e.validationEngine({
            });
         }
         else
         {
            e.validationEngine({
               ajaxSubmit: true,
               ajaxSubmitFile: e.attr("action")
            });
         }
      }
      e.attr("valed", "1");
      e.submit(); 
      e.find("input, textarea").each(function () {
         $(this).placeholder();
      });      
      return false;
   });
   $("form .do-clear").unbind().click(function () {
      var p_form = $(this).parents(".post");
      p_form.find("input, textarea").each(function () {
         $(this).val("").placeholder();
      });
      $(".formError").remove();
      
      if ($(this).attr("remove") && !$(this).parents(".form_prev_holder").length) 
      {
         move_form_to( $(".form_prev_holder", p_form), p_form );
         $(".form_holder .do-clear").removeAttr('remove');
      }
      
      return false;
   });
   
   /*
      End: Валидация форм
   */
}

$(function () {
   $(".gallery").each(function () {
      if ( !$(this).find(".gallery_item").length)
      {
         $(this).children(".gal_wrapper").remove();
         $(this).parents(".post").find(".jScrollArrowLeft, .jScrollArrowRight, .jScrollPaneTrack").remove();
         $(this).addClass('error_box');
      }
   });
});

$(document).ready(function () {

   $(".comment_meta .comment-1").click(function () {
   
      move_form_to( $(this).parent().parent(), $(this).parents(".comments-b") );
      
      return false;
   });

   /* Всплывающее окошко для навигационной ленты */

   var popup_options = {
      jump_height:        30,
      show_duration:      300,
      hide_duration:      300,
      tout:               200,
      top:                55   // почему-то $("ul.pxs_thumbnails div").position().top дает неправильное значение 
   };
   
   if (!$.browser.msie)
   {
      $("ul.pxs_thumbnails li div").css({
         display:       'none',
         opacity:       0
      });
   }
   
   var touts    = new Array();
   var cur_elem = null;
   var n=0;
   $("ul.pxs_thumbnails li").each(function () {
      $(this).attr("n", ++n);
   });
   
   $("ul.pxs_thumbnails li").hover(function () {
      cur_elem = $("div", this);
      touts[ parseInt($(this).attr("n")) ] = setTimeout(function () {
         if ($.browser.msie)
         {
            cur_elem.show().css({
               bottom:        popup_options.top+"px"
            });
         }
         else
         {
            cur_elem.show().css({
               opacity:    0,
               bottom: ( popup_options.top - popup_options.jump_height )+"px"
            }).animate({
               opacity:    1,
               bottom:        popup_options.top+"px"
            }, {
               duration:   popup_options.show_duration,
               queue:      false,
               complete:   function () {
                  //$(this).hide();
               }
            });
         }
      }, popup_options.tout);
   }, function () {
   
      if (touts[ parseInt($(this).attr("n")) ]) clearTimeout(touts[ parseInt($(this).attr("n")) ]);
   
      if ($.browser.msie)
      {
         $("div", this).hide();
      }
      else
      {
         $("div", this).animate({
            opacity:    0
         }, {
            duration:   popup_options.hide_duration,
            queue:      false,
            complete:   function () {
               $(this).hide();
            }
         });
      }   
   });
   
   /* End: Всплывающее окошко для навигационной ленты */
   
   
   $(window).resize(function () {
      $(".pxs_slider").children().eq(0).css('margin-left', '0px');
   });
   
   
   /* Слайдер, перенес инициализацию из slider.js, добавляю выезжание стрелки */
   
   if ($('#pxs_container').length)
   {
   
      var arrow_duration  = 300;
      var arrow_prev      = $( $(".pxs_slider").children()[0] );
      var arrow_left_init = "-"+$("#pxs_container div.desc").width()+"px";
      
      $(".pxs_slider").children().eq(0).css('margin-left', '-10px');
      
      /*
      $("#pxs_container div.desc:gt(0)").css({
         left: arrow_left_init
      });
      */
     
      $(".pxs_slider script").remove();
     
	   var sl = 0;
	   var link = '';
	   if (window.location.hash)
	      if (window.location.hash.match(/^\#go_page.*$/))
	      {
	         sl = window.location.hash.replace('#go_', '');
	         if ( $("#for_"+sl).length )
	         {
	            var ind = $("#for_"+sl).attr("class");
					var matches = /li_(\d+)/.exec(ind);
					if (matches)
					{
					   ind = matches[1];
					   ind = parseInt( ind );
					}
					else
					{
					   alert("Error. Please report to Dream-Team");
					}
	            if (ind > 0)
	            {
	               link = sl;
                  sl = ind;
	            }
	            else
	            {

	            }
	         }
	      }
	   
	   $('#pxs_container').parallaxSlider({
	      auto: slider_auto,
	      slide: sl,
	      animDone: function (parent) {
	         /*
	         $("div.desc", parent).show().animate({
	            left: '0px'
	         }, {
	            duration: arrow_duration,
	            queue: false, 

	            complete: function () {
	               $("div.desc", arrow_prev).hide().css('left', arrow_left_init);
	               arrow_prev = parent;
	            }
	         });
	         */
	         $(".pxs_slider").show();
	      }
	   });
	   
	   $(window).resize(function () {
	      $(".pxs_slider > li").css({
	         'overflow': 'hidden',
	         'height'  : $(window).height()+"px",
	         'width'  : $(window).width()+"px"
	      });
	   }).trigger("resize");   
	   
      $(".pxs_thumbnails a").click(function () {
         if ( $(this).hasClass("not_clickable") ) 
            return false;
         if (slider_thumb_can_click2)
         {
            slider_thumb_can_click2 = false;
            var p = $(this).parent();
            $(".pxs_thumbnails > li > a").removeClass("act");
            while (1)
            {
               if (p.parent().hasClass("pxs_thumbnails"))
               {
                  p.children("a").addClass("act");
                  break;
               }
               p = p.parent();   
            }
         }
      });
      
      $(".pxs_thumbnails .menu-item-type-custom > a, .pxs_thumbnails li ul li > a").each(function () {
         $(this).unbind('click').click(function () {
            return true;
         });
      });
	   
	   if (link) {
	      $("#"+link).trigger("click");
	   }
	   
	   //$(".pxs_slider").show();
	
	}
   
   /* End: Слайдер */
   
   
   /* 
      Блоки с картинками и на них текст - добавление fade 
   */
   
   var blocks_speed_fade_in  = 300;
   var blocks_speed_fade_out = 300;
   
   if (!$.browser.msie)
   {      
      $(".gallery_item .h-i").css({
         display: 'block',
         opacity: 0
      });
      
      $(".gallery_item").hover(function () {
         $(".h-i", this).animate({
            opacity: 1
         }, {
            duration: blocks_speed_fade_in,
            queue: false,
            complete: function () {
               if ($.browser.msie) this.style.removeAttribute('filter');
            }
         });
      }, function () {
         $(".h-i", this).animate({
            opacity: 0
         }, {
            duration: blocks_speed_fade_out,
            queue: false
         });
      });
   }

   ////////////////////////

   $(".post-i .alignleft_list i").css({
      display: 'block',
      opacity: 0
   });
   
   $(".post-i .alignleft_list").hover(function () {
      if ( !$(this).attr("href") )
         return;
      $("i",  $(this) ).animate({
         opacity: 1
      }, {
         duration: blocks_speed_fade_in,
         queue: false,
         complete: function () {
            if ($.browser.msie) this.style.removeAttribute('filter');
         }
      });
   }, function () {
      $("i", $(this) ).animate({
         opacity: 0
      }, {
         duration: blocks_speed_fade_out,
         queue: false
      });
   });
   
   ////////////////////////////////

   $(".info-block").css({
      display: 'none',
      opacity: 0
   });
   
   $(".inf").each(function () {
      var block = $(".info-block",  $(this).parents(".post-item") );
      var tout_h = false;
      function start_hide() {
         if (tout_h)
            clearTimeout(tout_h);
         tout_h = setTimeout(function () {
            //block.hide(); return;
            block.animate({
               opacity: 0
            }, {
               duration: blocks_speed_fade_out,
               queue: false,
               complete: function () {
                  $(this).css('display', 'none');
               }
            });
         }, 400);
      }
      $(this).hover(function () {
         if (tout_h)
            clearTimeout(tout_h);
         block.css('display', 'block').animate({
            opacity: 1
         }, {
            duration: blocks_speed_fade_in,
            queue: false,
            complete: function () {
               if ($.browser.msie) this.style.removeAttribute('filter');
            }
         });
      }, start_hide);
      block.hover(function () {
         if (tout_h)
            clearTimeout(tout_h);
      },
      start_hide);
   });
   
   /*
      End: Блоки с картинками и на них текст - добавление fade 
   */
   
   
   
   
   upd_ev();
   
   
   /* 
      Цвет меню 
   */
   
   $("#mainmenu li.act").addClass("active");
   
   var n=0;
   $("#mainmenu > li").each(function () {
      $(this).find("a:eq(0)").attr("id", "m"+(++n));
   });
   $("#mainmenu > li").mouseover(function () {
	   return;
      if ( $(this).hasClass('act') )
         return;
      if (Cufon) Cufon.replace('#'+$(this).find("a:eq(0)").attr("id"), {
		      color: '-linear-gradient(#950d38, #dc3560)', textShadow: '1px 1px #000'
      });

   });
   $("#mainmenu > li").mouseout(function () {
	   return;
      if ( $(this).hasClass('act') )
         return;
      if (Cufon) Cufon.replace('#'+$(this).find("a:eq(0)").attr("id"), {
		   color: '-linear-gradient(#b8b4b1, #edebe8)', textShadow: '1px 1px #000',
		   hover: {
			   color: '-linear-gradient(#950d38, #dc3560)', textShadow: '1px 1px #000'
		   }
      });
   });
      
   /*
      End: цвет меню
   */
   
   if (1)
   {
      var popup_options2 = { top: 25 };
      
      var touts2    = new Array();
      var cur_elem2 = null;
      var n2=0;
      $("#mainmenu > li").each(function () {
         if ( !$(this).children("div").length )
            return;
         $(this).attr("n", ++n2).addClass("parent");
      });
      
      $("#mainmenu > li.parent").hover(function () {
         cur_elem2 = $("div", this);
         touts2[ parseInt($(this).attr("n")) ] = setTimeout(function () {
            if ($.browser.msie)
            {
               cur_elem2.show().css({
                  display:    'block',
                  bottom:        popup_options2.top+"px"
               });
            }
            else
            {
               cur_elem2.css({
                  opacity:    0,
                  display:    'block',
                  bottom: ( popup_options2.top + popup_options.jump_height )+"px"
               }).animate({
                  opacity:    1,
                  bottom:        popup_options2.top+"px"
               }, {
                  duration:   popup_options.show_duration,
                  queue:      false
               });
            }
         }, popup_options.tout);
      }, function () {
      
         if (touts2[ parseInt($(this).attr("n")) ]) clearTimeout(touts2[ parseInt($(this).attr("n")) ]);
      
         if ($.browser.msie)
         {
            $("div", this).hide();
         }
         else
         {
            $("div", this).animate({
               opacity:    0
            }, {
               duration:   popup_options.hide_duration,
               queue:      false,
               complete:   function () {
                  $(this).hide();
               }
            });
         }   
      });
   }
   
   $(".gal").attr("rel", "gal[g]");
   if ($.prettyPhoto && $(".gal").length)
   {
      $(".gal").each(function () {
         $(this).attr("rel", "gal[g]")
            .attr("title",  $(this).find("h4").text() );
      });
      $("a[rel=gal\\[g\\]]").prettyPhoto(pf_options);
   }
   
   $(".sh").each(function () {
      var now = 0;
      var maxnow = $(this).children(".item").length-1;
      var ee = $(this);
      $(this).parent().find(".larr, .rarr").click(function () {
         var the_now = now;
         if ( !$(this).hasClass('larr') ) now++; else now--;
         if (now<0) now = maxnow;
         if (now>maxnow) now=0;
         var now_h = ee.height();
         //$(".widget_arr").hide();
         ee.find(".item:eq("+the_now+")").fadeOut(300, function () {
            var gg = ee.find(".item:eq("+now+")");
            gg.show();
            ee.css({ height: 'auto' });
            var new_h = ee.height();
            gg.hide();
            ee.css({ height: now_h }).animate({ height: new_h }, { duration: 300, complete: function () {
               //$(".widget_arr").show();
            } });
            gg.fadeIn(300);
         });
         return false;
      });
   });
   
});

$(window).resize(function () {
   $("body, html").scrollTop(0);
   $(document).scrollTop(0);
   var m = $(window).height();
   //m -= $("ul.pxs_slider > li").height();
   m -= 517;
   m /= 2;
   m += 32;
   $(".pxs_slider .holder").css({
      marginTop: m+"px"
   });
});

$(function () {
   $(window).trigger("resize");
})

$(function () {
   $(".slider_normal").each(function () {
      var parent_elem = $(this);
      
      var one_sl = dt_settings.dots_duration;
      var one_speed = 1500;
      var max_dots = dt_settings.dots_count;
      var dur_sliding = 500;
      
      var one_sl_timeout = false;
      var current_dots = max_dots;
      var first_run = true;

      if ( $(".cycle", parent_elem).children().length == 1 )
      {
         $(".nav_s", parent_elem).hide();
         var e = $(".cycle", parent_elem).children();
         e.show();
         if (e.hasClass('hide_slide'))
            $(".desc_outer", parent_elem).hide();
      }

      $(".nav_s_inner", parent_elem).html("");
      var j;
      for (j=0; j<current_dots; j++) {
         $(".nav_s_inner", parent_elem).append('<a><img src="'+$('input[name=dir_url]', parent_elem).val()+'/images/timer.png" alt="" /></a>');
      }
      
      var dots = $(".nav_s_inner", parent_elem).find("a");

      var prev_c = current_dots;
      
      var one_tick_t = (one_sl - one_speed) / max_dots;
      //one_tick_t = 500;
      
      function populate_ticks(cb) {
         return;
         if (current_dots > prev_c)
            dots.show();
         else
            dots.eq( dots.find(":visible").length-1 ).fadeOut(one_tick_t, cb);
         prev_c = current_dots;
      }
      
      var current_n = 0;
      
      function start_dots()
      {
         current_n++;
         var now_n = current_n;
         function run_dots()
         {
            if (current_n != now_n)
               return;
            //console.log("run dots");
            var vis = current_dots;
            if (vis == 0)
            {
               $(".nav_s_inner", parent_elem).hide();
               $(".cycle", parent_elem).cycle("next");            
            }
            else if (vis > 0)
            {
               var ee = dots.eq( vis-1 );
               if (!ee.is(":visible"))
                  return;
               ee.fadeOut(one_tick_t, run_dots);
            }
            current_dots--;
         }
         run_dots();
      }
      
      function tick_one() {
         return;
         if (one_sl_timeout)
            clearTimeout(one_sl_timeout);
         populate_ticks();
         current_dots--;
         one_sl_timeout = setTimeout(tick_one, one_tick_t);
         if (current_dots == -1)
         {
            $(".nav_s_inner", parent_elem).fadeOut(1, function () {
               $(".cycle", parent_elem).cycle("next");
            });
         }
      }
      
      //tick_one();
      
      var cycle_first_run = true;
      
      var allow_anim = true;
      
      $(".cycle", parent_elem).cycle({
          fx:     'fade', 
          speed:   one_speed, 
          timeout: one_sl,
          parent_elem: parent_elem,
          dur_sliding: dur_sliding,
          before: function () {
            if (cycle_first_run)
            {
               cycle_first_run = false;
               current_dots = max_dots;
               //run_dots();
            }
          },
          after: function (currSlideElement, nextSlideElement, options) {   
            var a=$(nextSlideElement);   
            $(".desc h2", parent_elem).html( a.attr("title") );
            $(".desc .desc_text", parent_elem).html( a.attr("alt") );
            
            var l = $(".desc .desc_text .go_more", parent_elem);
            if (l.length)
            {
               $(".desc .link", parent_elem).attr("href", l.attr("href"));
            }
            else
            {
               $(".desc .link", parent_elem).removeAttr("href");
            }
            
            if (Cufon) Cufon.replace('.desc h2', {
               color: '-linear-gradient(#aeb3b3, #f6f6f6)', textShadow: '1px 1px #000'
            });
            
            if ( $(nextSlideElement).hasClass('hide_slide') )
               $(".desc_outer", parent_elem).hide();
            else
               $(".desc_outer", parent_elem).show();
            
            $(".desc_outer", parent_elem).animate({
               left: 0
            }, {
               duration: dur_sliding,
               queue: false,
               complete: function () {
                  dots.show();
                  $(".nav_s_inner", parent_elem).fadeIn(500, function () {
                     current_dots = max_dots;
                     start_dots();
                     allow_anim = true;
                  });
               }
            });
          }
      }).cycle("pause");
      
      $(".pxs_next, .pxs_prev", parent_elem).not(".carousel .pxs_next, .carousel .pxs_prev").click(function () {
         if (!allow_anim)
            return;
         allow_anim = false;
         if (one_sl_timeout)
            clearTimeout(one_sl_timeout);
         var e = ($(this).hasClass('pxs_next') ? "next" : "prev");
         $(".nav_s_inner", parent_elem).fadeOut(500, function () {
            $(".cycle", parent_elem).cycle(e);
         });
      });
   });   
});

var slideshow_group_counter = 2;

function crea_add_slideshows() {
   //$(dt_settings.highslide).prettyPhoto(pf_options);
   var cc = 0;
   $(dt_settings.highslide).each(function () {
      if (!$(this).attr("href"))
         return;
      cc++;
      
      var tid = 'single_thumb_'+cc;
      $(this).attr("id", tid);
      
      $(this).unbind('click');
      
      this.onclick = function () {
         //conf.slideshowGroup = 'boo';
         var config22 = {};
         $.extend(config22, hs_config2)
         config22.thumbnailId = tid;
         //config22.src = $(this).attr("href");
         //hs.expand(null, config22);
         hs.expand(this, hs_config2);
         return false;
      };
   });
   $(".pxs_slider li, .pxs_slider li .single, .pxs_slider li .gallery_inline").each(function () {
   
      elems = $(dt_settings.highslide_gall, this);
   
      if (elems.length == 0)
         return;

      if (elems.length == 1 && elems.not( $(".gallery_inline a", this) ).length)
         return;
   
      var now_options = slideshow_options;
      var group = 'group'+slideshow_group_counter;
      var tid = 'for_'+group;
      
      slideshow_group_counter++;
      
      elems.eq(0).attr("id", tid);
      
      var slideshow_options_bak = {};
      $.extend(slideshow_options_bak, slideshow_options);
      slideshow_options_bak.slideshowGroup = group;
      hs.addSlideshow(slideshow_options_bak);
      
      elems.each(function () {
         //if ( $(this).hasClass("hs_attached") ) return;
         $(this).addClass("hs_attached");
         if (!$(this).attr("href"))
            return;
         this.onclick = function () {
            var config22 = {};
            $.extend(config22, hs_config1)
            config22.slideshowGroup = 'group1';
            config22.slideshowGroup = group;
            //config22.thumbnailId = tid;
            return hs.expand(this, config22);
            //return hs.expand(this, hs_config1);
         };
      });
   });
};

$(function () {
   $(".pxs_slider > li").addClass("containers");
   $(window).resize(function () {
      //$(".pxs_slider > li > .holder").css('height', $(window).height()+"px");
   }).trigger("resize");
});

$(function () {
   if (!menu_is_clickable)
   {
      $("ul.pxs_thumbnails > li > a").each(function () {
         if ( $(this).parent().children("div").length > 0 )
         {
            $(this).css('cursor', 'default');
            $(this).addClass("not_clickable");
            $(this).click(function () {
               
               return false;
            });
         }
      });
   }
   
   /*
   $(".hash_go").click(function () {
      var h = $(this).attr("href");
      h = h.replace('/^.\#/', '');
      alert(h);
      if (h)
      {
         var e = $(".hash_"+h, $(this).parents(".post"));
         alert(e.length);
         if (e.length)
         {
            alert("ok");
            return false;
         }
      }
   });
   */
});



$(document).ready(function() {
	$(".toggle a.question").click(function (event) {
		event.preventDefault(); 
		$(this).toggleClass("act");
		$(this).next("div.answer").slideToggle("fast", function () {
		   upd_ev();
		});
	});
	
	//setTimeout(upd_ev, 1000);
});


function simple_tooltip(target_items, name){
 $(target_items).each(function(i){
		$("body").append("<div class='"+name+"' id='"+name+i+"'>"+$(this).find('span.tooltip_c').html()+"</div>");
		var my_tooltip = $("#"+name+i);

		$(this).removeAttr("title").mouseover(function(){
					my_tooltip.css({opacity:1, display:"none"}).fadeIn(400);
		}).mousemove(function(kmouse){
				var border_top = $(window).scrollTop();
				var border_right = $(window).width();
				var left_pos;
				var top_pos;
				var offset = 15;
				if(border_right - (offset *2) >= my_tooltip.width() + kmouse.pageX){
					left_pos = kmouse.pageX+offset;
					} else{
					left_pos = border_right-my_tooltip.width()-offset;
					}

				if(border_top + (offset *2)>= kmouse.pageY - my_tooltip.height()){
					top_pos = border_top +offset;
					} else{
					top_pos = kmouse.pageY-my_tooltip.height()-2.2*offset;
					}

				my_tooltip.css({left:left_pos, top:top_pos});
		}).mouseout(function(){
				my_tooltip.css({left:"-9999px"});
		});



	});
}

$(document).ready(function(){
	 simple_tooltip(".tooltip","tooltip_cont");
	 $(".cont_butt").click(function ()
	 {
	    //$("#order_form").submit();
	    return false;
	 });
      if ($.validationEngine) {
         $(".valForm, .uniform").each(function () {
            return;
            if ( $(this).attr("valed") ) return;
            $(this).attr("valed", "1").validationEngine({
               ajaxSubmit: true,
               ajaxSubmitFile: window.location.href
            });
         });
      }
});

$(document).ready(function(){
	$('div.framed').wrapInner( '<div />');
});

$(function(){
   $(window).resize(function () {
       $('.menu_bot ul.pxs_thumbnails').css({ 
         left: ($(window).width() - $('.menu_bot ul.pxs_thumbnails').outerWidth())/2
       }).show();  
   }).trigger("resize");
});

Cufon.CSS.ready(function() {
	$(window).trigger("resize");
   $(".pxs_thumbnails > li > div").each(function () {
      var p = $(this).parent().children("a");
      var d = $(this);
      var pos = 0;
      //pos -= 5;
      //alert(p.width());
      pos += p.outerWidth() / 2;
      pos -= d.width() / 2;
      d.css('left', pos+"px");
   });
   upd_ev();
});


