


hs.graphicsDir = '/usr/system/plugins/highslide-full/graphics/';

hs.showCredits = false;

var area = 0;


$.fn.shuffleChildren = function() {
    $.each(this.get(), function(index, el) {
        var $el = $(el);
        var $find = $el.children();

        $find.sort(function() {
            return 0.5 - Math.random();
        });

        $el.empty();
        $find.appendTo($el);
    });
};


if (typeof(Cufon) != "undefined")

{



Cufon('#nav > li > a, #nav > li > span > a', {

  color: '#000000', textShadow: '1px 1px #f7f7f7'

});

Cufon('#nav > li.act > a', {

  color: '#9f070c', textShadow: '1px 1px #f7f7f7'

});

Cufon('.news-home a', {

  color: '#000000', textShadow: '1px 1px #f7f7f7',

   hover: {

	color: '#ab0a10', textShadow: '1px 1px #f7f7f7'

  }

});

Cufon('h1, h2, h3, h4, h5', {

  color: '-linear-gradient(#000000, #3d3d3d)', textShadow: '1px 1px #fff'

});

Cufon('.header', {
  color: '-linear-gradient(#000000, #3d3d3d)', textShadow: '1px 1px #fff'
});

Cufon('.l-blocks a:not(.l-blocks .sub a, .l-blocks.act a)', {

   color: '#000000', textShadow: '1px 1px #f7f7f7',
   hover: {
	color: '#ab0a10', textShadow: '1px 1px #f7f7f7'
  }

 });


  Cufon('.l-blocks.act a:not(.l-blocks.act .sub a)', {

	color: '#ab0a10', textShadow: '1px 1px #f7f7f7'

});



Cufon('.tab-tab li', {

  color: '-linear-gradient(#000000, #3d3d3d)', textShadow: '1px 1px #fff',

   hover: {

	color: '#9f070c', textShadow: '1px 1px #f7f7f7'

  }
});



Cufon('.tab-tab li.act', {

  color: '#ab0a10', textShadow: '1px 1px #fff'

});
Cufon('.title', {

  color: '-linear-gradient(#000000, #3d3d3d)', textShadow: '1px 1px #fff',

   hover: {

	color: '#9f070c', textShadow: '1px 1px #f7f7f7'

  }



});

Cufon('.desk-head', {

  color: '#f8f8f8', textShadow: '1px 1px #000'

});

}



function fix_pos()

{

   if ( !$("#slider-main-ul").length )

   {

      return;

   }

   var tot = $("#slider-main-ul").children("li").length;

   var one_w = 265;

   var w = tot * one_w;

   var m = 0;

   if ( $(window).width() < w )

   {

      m = $(window).width() / 2 - w / 2;

   }

   else

   {

      m = $(window).width() / 2 - w / 2;

   }

   $("#slider-images-wrapper").css('margin-left', m+"px");

   $("#slider-images-wrapper").css('width', w+"px");

   $("#slider-main-ul").css('width',(w+100)+"px");

   $(".main_bg").css({

      //width: $(window).width()+"px",
      width: '100%',

      overflow: "hidden"

   });

}



function fix_els() {

   if (1)

   {

      //$("#slider-main-ul").children("li:not(:first)").remove();

      var tot = $("#slider-main-ul").children("li").length;

      if (!tot) return;

      var one_w = 265;

      var w = tot * one_w;

      while ( w < $(window).width() )

      {

         $("#slider-main-ul").append( $("#slider-main-ul").children("li").clone() );

         tot = $("#slider-main-ul").children("li").length;

         w = tot * one_w;

         //alert(" append ");

      }
      
      $("#slider-main-ul li ul li").each(function () {
         $(this).shuffleChildren();
         //alert( $(this).html() );
      });

   }

   

   fix_pos();

}



$(document).ready(function() {



   $(window).resize(fix_pos);

	

	$("li.parent div ul li a").each(function () {

	   $(this).hover(function ()

	   {

	      $(this).find("i").animate({

	         width: '10px'

	      }, {

	         duration: 100,

	         queue: false

	      });

	   }, function ()

	   {

	      $(this).find("i").animate({

	         width: '0px'

	      }, {

	         duration: 100,

	         queue: false

	      });

	   })

	});

	

	$("li.parent").each(function () {

	   var e=$(this).find("div");

	   var h=e.height();

	   e.show().css({

	      height: '0px',

	      overflow: 'hidden'

	   });

	   $(this).hover(function () {

	      e.animate({

	         height: h+"px"

	      }, {

	         duration: 250,

	         queue: false

	      });

	   }, function () {

	      e.animate({

	         height: "0px"

	      }, {

	         duration: 250,

	         queue: false

	      });

	   });

	});

	

});





/// images fade

$(function () {

	

	if ( area == 2 )

	{

	   return;

	}

	

	var anim_duration = 1500;

	

	var els = $("#slider-main-ul li li");

	

	if (!els.length) return;

	

	function rest()

	{

	   var hh;

	   // 

	   // 40% - количество блоков для анимации

	   //

	   for (hh=0; hh<Math.round( $("#slider-main-ul li li").length / 100 * 40 ); hh++)

	   {

         setTimeout(random_image_fade, Math.round( Math.random()*anim_duration )+100);

	   }

      setTimeout(rest, 6000);

	}

	

	function random_image_fade()

	{

		var rand = Math.round( Math.random()*els.length );

		//rand = 0;

		var li = $(els[ rand ]);

		if ( li.hasClass("animating") )

		{

		   //rest();

			return;

		}

		

		if ( li.find("a").length == 1 )

		{

		   return;

		}

		

		li.addClass("animating");

		var visible = li.find("a:visible");

		var curr = visible.index();

		var news = curr+1;

		if ( news >= li.find("a").length )

		   news = 0;

		var newslide = li.find("a");

		

		newslide.css({

			zIndex: 1

		});

		

		newslide = $( newslide[news] );

		

		//alert( newslide.length );



      var conseq = true;

		

		function anim_next()

		{

		   newslide

		       .css({

				   zIndex: 5,

				   display: 'block',

				   opacity: 0

			   })

			   .animate({

				   opacity: 1

			   }, {

				   duration: anim_duration,

				   complete: function () {

					   //rest();

					   visible.css({

						   display: 'none'

					   });

					   li.removeClass("animating");

				   }

			   })

		   ;

		}

		

		visible

		    .css({

				zIndex: 5,

				display: 'block',

				opacity: 1

			})

			.animate({

				opacity: 0

			}, {

				duration: anim_duration,

				complete: function () {

               if ( !conseq )

                  anim_next();

				}

			})

		;

		

		if (conseq)

		{

         anim_next();

		}

		else

		{

		   newslide

		       .css({

				   zIndex: 5,

				   display: 'none',

				   opacity: 0

			   });

		}

	}

	

	/*

	var i;

	for (i=0; i<10; i++)

   	rest();

   */

   rest();

	

	$(".image-all").each(function () {

	   if ( !$(this).attr("href") || ( $(this).attr("href") == '#' ) )

	   {

	      $(this).attr("href", $(this).children("img").attr("src"));

	   }

	   $(this).unbind("click");

	   this.onclick = function () {

	      hs.expand(this, hs_config2);

	      return false;

	   }

	   var b = $(this).children("span");

      if ($.browser.msie && $.browser.version < 9)
      {
      
      }

      else
      {
      
	   b.css({

	      display: 'none',

	      opacity: 0

	   });

	   $(this).hover(function () {

	      b.parent().addClass("animating");

	      b.css('display', 'block')

	      .animate({

	         opacity: 1

	      }, {

	         duration: 500,

	         queue: false

	      });

	   }, function () {

	      b.parent().removeClass("animating");

	      b.animate({

	         opacity: 0

	      }, {

	         duration: 500,

	         queue: false, 

	         complete: function () {

	            b.css('display', 'none');

	         }

	      });

	   });
      
      }

	});

	

});



/*

  $(".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);

         });

  });

*/

  

// go up arrow

$(function () {

   $(".go_up").click(function () {

      $("html:not(:animated)"+( ! $.browser.opera ? ",body:not(:animated)" : "")).animate({scrollTop: 0}, 500);

      return false;

   });

});

// end go up arrow



$(document).ready(function() {

	$('#coda-slider-1').codaSlider();

});



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();

    });

};



jQuery(document).ready(function() {

    jQuery('#mycarousel').jcarousel({

        auto: 2,

        wrap: 'circular',

        initCallback: mycarousel_initCallback

    });

});



$(function () {

   $("#nav ul").each(function () {

      $(this).wrap('<div />');

      $(this).after('<i></i>');

      $(this).children("li:first").addClass("first");

   });

});





// menu



var menu_timeout_open = false;

var menu_timeout_close = false;



var menu_speed_show = 300;

var menu_show_timeout = 300;



$(function () {



   $("#nav li").each(function () {

      var sub_ul = $(this).children("div");

      

      if (!sub_ul.length)

      {

         $(this).hover(function () {

            if (menu_timeout_open)

               clearTimeout(menu_timeout_open);

         },

         function () {

         });

         return;

      }

      

      var anim_prop = 'left';

      

      prev_left = 25;

      //prev_left2 = 155;

      prev_left2 = 175;

      var is_level2 = (sub_ul.parent().parent().attr("id") == "nav" ? 0 : 1);

      

      //prev_left = 172;

      

      var new_left = parseInt( prev_left );

      var init_left = new_left+20;



      var new_left2 = parseInt( prev_left2 );

      var init_left2 = new_left2+20;



      if ($.browser.msie)

      {

         sub_ul.css({

            display: 'none'

         });

      }

      else

      {

         sub_ul.css({

            display: 'none',

            opacity: 0

         });

      }

      

      $(this).hover(function () {

         if (menu_timeout_open)

            clearTimeout(menu_timeout_open);

         

         menu_timeout_open = setTimeout(function () {

            sub_ul.find("div").hide();

            if ($.browser.msie)

            {

               sub_ul.show();

            }

            else

            {

               if (is_level2)

               {

                  sub_ul.css({

                     display: 'block',

                     opacity: 0,

                     left: init_left2

                  }).animate({

                     opacity: 1,

                     left: new_left2

                  }, {

                     duration: menu_speed_show,

                     queue: false,

                     complete: function () {

                        if ($.browser.msie) this.style.removeAttribute('filter');

                     }

                  });

               }

               else

               {

                  sub_ul.css({

                     display: 'block',

                     opacity: 0,

                     top: init_left



                  }).animate({

                     opacity: 1,

                     top: new_left

                  }, {

                     duration: menu_speed_show,

                     queue: false,

                     complete: function () {

                        if ($.browser.msie) this.style.removeAttribute('filter');

                     }

                  });

               }

            }

         }, menu_show_timeout);

      },

      function () {

         sub_ul.hide();

      });

   });

   

   $("#nav").hover(function () { },function () {

      //$("#nav div").hide();

      if (menu_timeout_open)

         clearTimeout(menu_timeout_open);

   });

   

   $("#nav div").each(function () {

      var tout_hide = false;

      var d = $(this);

      d.hover(function () {

         if (tout_hide)

            clearTimeout(tout_hide);

      },

      function () {

         tout_hide = setTimeout(function () {

            d.hide();

         }, 500);

      });

   });



});



// end menu



$(function () {

   var init_left = 224;

   var delta_left = 20;

   $(".l-blocks").each(function () {

      var b = $(this).find(".sub");

      if (!b.length) return;

      var p = $(this);


         if ( $.browser.msie && $.browser.version < 9 ) {

      b.css({

         left: (init_left + delta_left)+"px"

      });
      } else {
      b.css({

         opacity: 0,

         left: (init_left + delta_left)+"px"

      });
      
      
      }

      p.hover(function () {

         if ( $.browser.msie && $.browser.version < 9 )

         {

            b.css({

               display: 'block',

               left: init_left+"px"

            });

            return;

         }

         b.css({

            display: 'block'

         }).animate({

            opacity: 1,

            left: init_left+"px"

         }, {

            duration: menu_speed_show,

            queue: false,

            complete: function () {

               if ($.browser.msie) this.style.removeAttribute('filter');

            }

         });

      }, function () {

         if ( $.browser.msie && $.browser.version < 9 )

         {

            b.css({

               display: 'none'

            });

            return;

         }

         b.animate({

            opacity: 0,

            left: (init_left + delta_left)+"px"

         }, {

            duration: menu_speed_show,

            queue: false,

            complete: function () {

               b.css({

                  display: 'none'

               });

            }

         });

      });

   });

});



// tabs



$(function () {

   var tab_speed = 700;

   //var tab_speed = 2000;

   $(".tab-block").each(function () {

      var allow_move = true;

      var block = $(this);

      var menu = $(this).find(".tab-tab");

      var tabs = $(this).find(".txt");

      menu.find("a").click(function () {

         var this_a = $(this);

         

         var ind = $(this).parent().index();

         

         var old_tab = block.find(".txt.act");

         var new_tab = $( tabs[ind] );

         

         if ( old_tab.index() == new_tab.index() )

            return false;

         

         if (!allow_move) return false;

         

         allow_move = false;

         

         menu.find("li").removeClass("act");

         

         var old_h = old_tab.find(".txt_c").height();

         

         new_tab.css('display', 'block');

         var new_h = new_tab.find(".txt_c").height();

         //alert(new_h); return false;

         new_tab.css('display', 'none');

         

         //alert( old_h + " -> " + new_h + " ");

         

         new_tab.find(".txt_c").css('height', new_h+"px");

         

         old_tab

            .find(".txt_c")

            .css({

               height: old_h+"px"

            })

            .animate({

               height: new_h+"px"

            }, {

               duration: tab_speed, 

               queue: false,

               complete: function () {

                  old_tab.hide();

                  old_tab.find(".txt_c").css('height', 'auto');

                  new_tab.find(".txt_c").css('opacity', 0);

                  new_tab.css('display', 'block');

                  //return;

                  this_a.parent().addClass("act");

                  old_tab.removeClass("act");

                  new_tab.addClass("act");

Cufon('.tab-tab li', {

  color: '-linear-gradient(#000000, #3d3d3d)', textShadow: '1px 1px #fff',

   hover: {

	color: '#9f070c', textShadow: '1px 1px #f7f7f7'

  }



});



Cufon('.tab-tab li.act', {

  color: '#ab0a10', textShadow: '1px 1px #fff'

});

                  new_tab.find(".txt_c").animate({

                     opacity: 1

                  }, {

                     duration: tab_speed, 

                     queue: false,

                     complete: function () {

                        if ($.browser.msie) this.style.removeAttribute('filter');

                        allow_move = true;

                     }

                  });

               }

            });

            

         old_tab

            .find(".txt_c")

            .animate({

               opacity: 0

            }, {

               duration: tab_speed, 

               queue: false,

               complete: function () {

               

               }

            });

         

         return false;

      });

   });

});



$(document).ready(function () {

   $("a.highslide").click(function() {

      return hs.expand(this);

   });

   $("input[type=button]").each(function () {

      if ($(this).attr('href') && !$(this).hasClass('order')) {

        $(this).click(function () {

           window.location.href=$(this).attr('href');

        });

      }

   });

   $(".order").click(function() {

      make_order($(this).attr('rel'));

      return false;

   });

   if ($.validationEngine) {

      $(".valForm").validationEngine({

         ajaxSubmit: true,

         ajaxSubmitFile: $(".valForm").attr('action')

      });

   }

   $(".go_search").click(function() {

      $("#top_search").submit();

      return false;

   });

   $("a.submit").each(function () {

      $(this).click(function () {

         $(this).parents("form:eq(0)").submit();

         return false;

      });

   });

});





function hs_alert(msg) {

   id=new Date().getTime();

   $("body").append('<div class="highslide-html-content" id="s'+id+'" style="width: 400px; color: #000; height: 230px;">'+

'<div style="text-align: right;"><a href="javascript:void(0);" onclick="return hs.close(this)" style="color: #000;" id="c'+id+'"></a></div>'+

'<div class="highslide-body" style="text-align: center;">'+

'<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>'+

msg+

'</div>'+

'</div>');

   if (!hs.htmlExpand) {

      alert(msg);

      return;

   }

   //alert(msg);

   hs.htmlExpand(null, {

      contentId: "s"+id,

      transitions: ['fade'],

      slideshowGroup: 'group2'

   });

}



var performing_login=0;

function perform_login() {

   if (performing_login) return false;

   performing_login=1;

   var form = $("#login_form");

   request_data="email="+encodeURIComponent(form.find("input[name=email]").val())+"&pass="+encodeURIComponent(form.find("input[name=pass]").val());

   //alert(request_data);

   $.ajax({

      url: form.attr("action"),

      type: "GET",

      dataType: "json",

      data: request_data,

      error : function () {

         hs_alert("Error during log in");

      },

      success : function (v) {

         performing_login=0;

         if (v.error) {

            //alert(v.error);

            hs_alert(v.error);

         }

         else {

            url=form.find("input[name=return_url]").val();

            hs_alert(lang == "ru" ? "Вход на сайт..." : "Вхід на сайт...");

            if (url) {

               //alert(url);

               parent.window.location.href=url;

            }

            else {

               //alert("reload");

               parent.window.location.reload();

            }

         }

      }

   });

   return false;

}



$(function () {

   $(".log_button").click(function () {

      form = $(this).parents(".log_form");

      perform_login();

      return false;

   });

   $(".log_form").submit(function () {

      form = $(this);

      perform_login();

      return false;

   });

   $(".log_form input").keypress(function (e) {

      if (e.which == 13){

         form = $(this).parents(".log_form");

         perform_login();

         return false;

      }

   });

});



$(function () {

   /* 

      Блоки с картинками и на них текст - добавление fade 

   */

   

   var blocks_speed_fade_in  = 300;

   var blocks_speed_fade_out = 300;

   

   $(".for_foto a, .imgPrev a").each(function () {

      var a = $(this);

      $("i", a).css({

         display: 'block',

         opacity: 0

      });

      

      a.hover(function () {

         $("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

         });

      });

   });

   

   /*

      End: Блоки с картинками и на них текст - добавление fade 

   */

});



$(function () {

   var nn = 0;

   $("#nav > li > a").each(function () {

      $(this).attr("id", "a"+nn);

      nn++;

      $(this).hover(function () {

         Cufon("#"+$(this).attr("id"), {

           color: '#9f070c', textShadow: '1px 1px #f7f7f7'

         });

      }, function () {

         if ( $(this).parent().hasClass("act") )

            return;

         Cufon("#"+$(this).attr("id"), {

           color: '#000000', textShadow: '1px 1px #f7f7f7'

         });

      });

   });

})

$(function(){
	
    $('#nav > li:not(.act, .home) > a').each(function(){
        
        $(this).wrap('<span>');

        $(this).before($(this).clone().removeClass().addClass('hoverMenu'));

    });
    
    $('#nav li').hover(function(){
    
        $(this).find('.hoverMenu').stop().animate({marginTop:'0px'}, {queue:false, duration: 200, easing: ''});

    },
    
    function(){
    
        $(this).find('.hoverMenu').stop().animate({marginTop:'-32px'}, {queue:false, duration: 200, easing: ''});

    });
    
});
$(function(){
	
    $('.l-blocks:not(.act) .l-block a').each(function(){
        
        $(this).wrap('<span>');

        $(this).before($(this).clone().removeClass().addClass('hoverMenu'));

    });
    
    $('.l-blocks .l-block').hover(function(){
    
        $(this).find('.hoverMenu').stop().animate({marginTop:'4px'}, {queue:false, duration: 200, easing: ''});

    },
    
    function(){
    
        $(this).find('.hoverMenu').stop().animate({marginTop:'-28px'}, {queue:false, duration: 200, easing: ''});

    });
    
});


$(function () {
	var viewport = $(window).width();
//	alert(viewport);
	$("table .main_bg").css("max-width", viewport);
});
