function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3')?g+' ff3':is('gecko/')?g:/opera(\s|\/)(\d+)/.test(ua)?'opera opera'+RegExp.$2:is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);




setInterval(function(){
  $('#jcart-header-top').html($('#jcart-header').html());
  $('#jcart-subtotal-top').html($('#jcart-subtotal').html());
}, 100);


$(document).ready(function(){






   //$("#subscribe_from").validate();

    $(".isVideo:first").css("paddingTop", "0");

    $.fn.exists = function(){
    	return $(this).length>0;
    	return $(this)=obj;
    }


    $("#htext1").css({
      marginTop:-$("#htext1").height()/2
    })

      $(".middle-category-description img").eq(0).wrap("<div id='midImageHolder' class='rounded'></div>");
      $("#pageWithArticlesAsSubcatsContentBlock img").eq(0).wrap("<div id='midImageHolder' class='rounded'></div>");



   $(".specifics table td:even").addClass("graybg");

   $(".print").click(function(){
        //var window_content = $(".richtext").html();

        var window_content = $("#description_content").html();
        div = document.createElement('div');
        div.innerHTML = window_content;
        $(div).find("form, a").remove();

        var window_content =  "<img src='" + $('#main_image').attr('src') + "' />" + div.innerHTML + "<br />" + $(".richtext:first").html();
        var window_center = $(window).width()/2-300 + 'px';
        var printPopup=window.open("","myWin","menubar,scrollbars,left="+ window_center+",top=90px,height=400px,width=600px");
        printPopup.document.write(window_content);
        printPopup.print();
    });


$(".home #nav li").addClass("isParent");
$(".home #nav li li").removeClass("isParent");

   $(".rounded").append("<span class='atl'>&nbsp;</span><span class='atr'>&nbsp;</span><span class='abl'>&nbsp;</span><span class='abr'>&nbsp;</span>");

    $(".bullet").append("<span class='the_bullet'></span>");


    $("a[href='#']").attr("href", "javascript:void(0);")



  /* $(".home #nav li").hover(function(){
        $("#nav li").removeClass("nav_hovered");
        $("#tm").hide();

        $("#tm ul").hide();

        if($(this).hasClass("isParent")){
            $(this).addClass("nav_hovered");
            $("#tm").show();
            var index = $("#nav li.isParent").index(this);
            if($.browser.msie){
              $("#tm ul").eq(index).css("display", "inline");
            }
            else{
              $("#tm ul").eq(index).css("display", "inline-block");
            }

        }
        else{$("#tm").hide();}

   });*/

$(".DropDown").each(function(){
    var DropActiveHTML = $(this).find("li.active").html();
    var DropActiveValue = $(this).find("li.active").attr("title");
    $(this).find("span").html(DropActiveHTML);
    $(this).find("input").val(DropActiveValue);
});


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

     $(this).find("ul").toggle();

  });

    $(".DropDown").hover(function(){$(this).removeClass("OBJDropDown")}, function(){$(this).addClass("OBJDropDown")});



  $(".DropDown ul li").hover(function(){$(this).addClass("hover")}, function(){$(this).removeClass("hover")});



  $(".DropDown ul li").click(function(){

      var DropItemHTML = $(this).html();
      var DropItemValue = $(this).attr("title");
      $(this).parents(".DropDown").find("input").val(DropItemValue);
      $(this).parents(".DropDown").find("span").html(DropItemHTML);



  });
    $("body").click(function(){

     $(".OBJDropDown ul").hide();

  });

  $(".tabs").each(function(){
     var index = $(".tabs").index(this);
     $(this).attr("id", "tab-" + index);
     $(this).find(".tab-nav li:first").addClass("active");
     $(this).find(".tab:first").show();
  });


  if($("#midImageHolder img").length==0){
     //$("#midImageHolder").hide();
  }


  $(".tab-nav li").click(function(){
    if($(this).hasClass("active")){}
    else{
      var tabHolder = $(this).parents(".tabs");
      var tabHolderID = tabHolder.attr("id");
      var currentLIs = $("#" + tabHolderID).find(".tab-nav li");
      currentLIs.removeClass("active");
      $(this).addClass("active")
      var index = currentLIs.index(this);
      $("#" + tabHolderID).find(".tab").hide();
      $("#" + tabHolderID).find(".tab").eq(index).show();
    }

  });
  //$("body").append("<div id='modal'></div");
  var overlay = document.createElement('div');
  overlay.id='overlay';
  document.body.appendChild(overlay);

  var modal = document.createElement('div');
  modal.id='modal';
  document.body.appendChild(modal);



  $(".thumbs a").click(function(){
     var new_src = $(this).attr("href");
     $("#main_image").attr("src", new_src);
     var for_modal_box = $(this).attr("hreflang");
     $("#main_image_link, .zoom").attr("href", for_modal_box);


     return false;
  });

  $("#main_image_link, .zoom").click(function(){
      $("#overlay").show();
      var mImg = $(this).attr("href");
      var mImage = new Image();
      document.getElementById('modal').appendChild(mImage);
      mImage.onload = function(){
         $("#modal").append("<span class='mw_close_eng' onclick='$(this).parent().empty().css(\"visibility\", \"hidden\").removeAttr(\"style\");$(\"#overlay\").hide();'>Затвори</span>");
           var mWidth = this.offsetWidth;
           var mHeight = this.offsetHeight;
           $("#modal").css("top", ($(window).scrollTop() + $(window).height()/2) + 'px');
           $("#modal img").css("width", "100%");
           $("#modal").css("visibility", "visible");
           $("#modal").animate({width:mWidth, marginLeft: -mWidth/2}, 'normal', function(){
                 $("#modal").animate({height:mHeight, marginTop: (-mHeight/2)}, 'normal');
           });

      }
      mImage.src=mImg;

      return false;
  });
  $("#overlay, .closeModal").click(function(){
       $("#modal").css("visibility", "hidden").empty().removeAttr("style");
       $("#modal-jcart").hide();
       $(this).hide();
  });






  $(".sidenav li").addClass("child");
  $(".sidenav li:has(ul)").removeClass("child");
  $(".sidenav li:has(ul)").addClass("parent");
  $(".sidenav li.parent").each(function(){
       $(this).find("a:first").addClass("parentAnchor");
  });


   $(".sidenav a.active").next("ul:first").show();
   $(".sidenav a.active").parents("ul").show();



  $(".Xsidenav li a.parentAnchor").click(function(){
        var item = $(this).parent().find("ul:first");
        var has_sub_nav = true;
        if(item.exists()){
          has_sub_nav = false;
          item.slideToggle()
        }
        return has_sub_nav;
  });

  $(".inner #nav li.isParent").hover(function(){
        var index = $(".inner #nav li.isParent").index(this);
        $(".inner #nav li.isParent").removeClass("nav_hovered");
        $("#subNav ul").hide();
        $(this).addClass("nav_hovered");

        var cLeft = $(this).offset().left;
        var nLeft = $(this).parent().offset().left;
        $("#subNav ul").eq(index).css("left", (cLeft - nLeft)+ 'px');
        $("#subNav ul").eq(index).fadeIn("fast");
  });

  var f_width = $("#footer_nav").width();
  $("#footer_nav").css("marginLeft", -(f_width/2) + 'px');

  $(".relcenter").each(function(){
    var hWidth = $(this).width()/2;
    var hRWidth = $(this).parent().width()/2;
    $(this).css("marginLeft", (hRWidth-hWidth))
  });
  $(".optionTime").hover(function(){
         $(this).addClass("hover");
  }, function(){
        $(this).removeClass("hover");

  });

  $(".minutes span").hover(function(){
         $(this).addClass("hover");
  }, function(){
        $(this).removeClass("hover");
  });


  $(".optionTime span").click(function(){
        $("#inputClock").val($(this).parents(".optionTime").attr("title") + ":" +  $(this).html())
  });


  $(".middle-category-description #midImageHolder").append("<div class='shadow shadow_top'></div><div class='shadow shadow_bottom'></div>");

  $("#pageWithArticlesAsSubcatsContentBlock #midImageHolder").append("<div class='shadow shadow_top'></div><div class='shadow shadow_bottom'></div>");




$(".products_categories_main .sqrt:even").append("<span class='objBordTR'></span>");


$(".trow .sqrt").append("<span class='objBordT'></span>");

$(".trow .sqrt:nth-child(3n)").removeClass("bord_right");

var all_trow_sqrt = $(".trow .sqrt").length;
//alert()

$(".trow .sqrt").eq(all_trow_sqrt-1).find(".objBordT").remove();
$(".trow .sqrt").eq(all_trow_sqrt-2).find(".objBordT").remove();
$(".trow .sqrt").eq(all_trow_sqrt-3).find(".objBordT").remove();

 $("a.btn").hover(function(){
     $(this).addClass("btnhover")
 }, function(){
     $(this).removeClass("btnhover")
 });


 $("#subscribe_from").submit(function(){
   if($("#subscribe_field").val()==""){
     return false;
   }
 });

 $(".xsubmit").click(function(){
   $(this).parents("form").submit();
   return false;
 });

 mw={}
 mw.cart = {}
 mw.cart.show = function(){
   $("#overlay").show();
   $("#modal-jcart").css({
     "top":$(window).scrollTop() + ($(window).height())/2-208,
     "display":"block"

   });
 }
 mw.cart.hide = mw.cart.close = function(){
   $("#overlay").hide();
   $("#modal-jcart").hide();
 }



  var about_mihh = $("#pageWithArticlesAsSubcatsContentBlock #midImageHolder img").height();
  var about_mihw = $("#pageWithArticlesAsSubcatsContentBlock #midImageHolder img").width();
  $("#pageWithArticlesAsSubcatsContentBlock #midImageHolder").css({
    "width":about_mihw,
    "height":about_mihh,
    "clear":"both",
    "marginBottom":"15px"
  });

  var mihh = $(".middle-category-description #midImageHolder img").height();
  var mihw = $(".middle-category-description #midImageHolder img").width();
  $(".middle-category-description #midImageHolder").css({
    "width":mihw,
    "height":mihh,
    "clear":"both",
    "marginBottom":"15px"
  });


 $(window).load(function(){

    var mihh = $(".middle-category-description #midImageHolder img").height();
    var mihw = $(".middle-category-description #midImageHolder img").width();
    $(".middle-category-description #midImageHolder").css({
      "width":mihw,
      "height":mihh,
      "clear":"both",
      "marginBottom":"15px"
    });


  var about_mihh = $("#pageWithArticlesAsSubcatsContentBlock #midImageHolder img").height();
  var about_mihw = $("#pageWithArticlesAsSubcatsContentBlock #midImageHolder img").width();
  $("#pageWithArticlesAsSubcatsContentBlock #midImageHolder").css({
    "width":about_mihw,
    "height":about_mihh,
    "clear":"both",
    "marginBottom":"15px"
  });





 });
  pm_length = $(".products_categories_main .sqrt").length;

  $(".products_categories_main div.sqrt").eq(pm_length-1).css("background", "none");
 $(".products_categories_main div.sqrt").eq(pm_length-2).css("background", "none");

  $(".tabs .newstabs:last-child").css("background", "none");


   $(".modal-cart-box").click(function(){

       $("#modalbox").css({"top": ($(window).scrollTop() + ($(window).height())/2-200)} );
       $("#modalbox").show();
       $("#overlay").show();
      return false;
   });

   $(".modal_close").click(function(){
     $("#modalbox").hide();
     $("#overlay").hide();
   });


 $(".jcart .xsubmit").click(function(){
     $(this).ajaxStop(function(){
        //Modal.mwoverlay();
        Modal.box('<h2 style="text-align:center;font:bold 17px Tahoma;padding:15px 0;">Продуктът е добавен успешно.</h2>', 320, 60);
        setTimeout(function(){
          $("#modalbox").animate({'opacity':'hide'}, function(){
            $(this).removeAttr('style');
          });
        }, 700);
     });
 });

 $(".mw_add_product").click(function(){
    var rel = $(this).attr("rel");
    $(rel).submit();
    setTimeout(function(){
        mw.cart.show();
    }, 500);
 });



});//end doc ready









function checkFormEvents(){
   $("#events_form").find("input[type='text'], textarea").each(function(){
      if($(this).hasClass("error")){
        $(this).parent().addClass("iError");
        $(this).parent().attr("fillcolor", "#B81F4D");
      }
      else{
          $(this).parent().removeClass("iError");
          $(this).parent().attr("fillcolor", "#ffffff");
      }
   })
}
setInterval("checkFormEvents()", 200)






















