// -------------------- Hover effekt -----------------------
$(function() {
   $('#product_offers a').each(function() {
      $(this).hover(
         function() {
            $(this).stop().animate({
               opacity: 1.0
            }, 500);
         },
         function() {
            $(this).stop().animate({
               opacity: 0.8
            }, 800);
         })
   });
});

$(function() {
   $('.thumbnail_bg').each(function() {
      $(this).hover(
         function() {
            $(this).stop().animate({
               opacity: 1.0
            }, 500);
         },
         function() {
            $(this).stop().animate({
               opacity: 0.8
            }, 800);
         })
   });
});
// ------------------ bgpos a menühöz ----------------------
/**
 * jquery bgpos - @author Alexander Farkas v. 1.21
 */

(function($) {
        if(!document.defaultView || !document.defaultView.getComputedStyle){ // IE6-IE8
                var oldCurCSS = jQuery.curCSS;
                jQuery.curCSS = function(elem, name, force){
                        if(name === 'background-position'){
                                name = 'backgroundPosition';
                        }
                        if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
                                return oldCurCSS.apply(this, arguments);
                        }
                        var style = elem.style;
                        if ( !force && style && style[ name ] ){
                                return style[ name ];
                        }
                        return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
                };
        }

        var oldAnim = $.fn.animate;
        $.fn.animate = function(prop){
                if('background-position' in prop){
                        prop.backgroundPosition = prop['background-position'];
                        delete prop['background-position'];
                }
                if('backgroundPosition' in prop){
                        prop.backgroundPosition = '('+ prop.backgroundPosition;
                }
                return oldAnim.apply(this, arguments);
        };

        function toArray(strg){
                strg = strg.replace(/left|top/g,'0px');
                strg = strg.replace(/right|bottom/g,'100%');
                strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
                var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
                return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
        }

        $.fx.step. backgroundPosition = function(fx) {
                if (!fx.bgPosReady) {
                        var start = $.curCSS(fx.elem,'backgroundPosition');

                        if(!start){//FF2 no inline-style fallback
                                start = '0px 0px';
                        }

                        start = toArray(start);

                        fx.start = [start[0],start[2]];

                        var end = toArray(fx.options.curAnim.backgroundPosition);
                        fx.end = [end[0],end[2]];

                        fx.unit = [end[1],end[3]];
                        fx.bgPosReady = true;
                }
                //return;
                var nowPosX = [];
                nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
                nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
                fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

        };
})(jQuery);

// -------------------- Menü animáció ----------------------

$(function(){

   $('#animated_menu_items a')
   .css( {backgroundPosition: "0px 0px"} )
   .mouseover(function(){
      $(this).stop().animate({backgroundPosition:"(0px 66px)"}, {duration:500})
   })
   .mouseout(function(){
      $(this).stop().animate({backgroundPosition:"(0px -22px)"}, {duration:300,complete:function(){
            $(this).css({backgroundPosition: "0px 0px"})
         }})
   })
});
// ----------------------- Sharing -------------------------
function facebookshare() {
   left = (screen.width/2)-325;
   top = (screen.height/2)-200;
   u=location.href;
   t=document.title;
   window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=650,height=400,top='+top+', left='+left+'');
   return false;
}
function iwiwshare() {
   left = (screen.width/2)-325;
   top = (screen.height/2)-200;
   u=location.href;
   t=document.title;
   window.open('http://iwiw.hu/pages/share/share.jsp?u='+encodeURIComponent('http://www.magyardob.hu/')+'&t='+encodeURIComponent('Béres Kézműves Műhely: hangszerek,konyhai eszközök,lakberendezési tárgyak'),'iwiwshare','toolbar=0,status=0,location=1, width=650,height=400,scrollbars=1,top='+top+', left='+left+'');
   return false;
}
// ----------------------- Slideshow -----------------------
function slideShow() {
   var $active = $('#slideshow img.active');
   if ( $active.length == 0 ) $active = $('#slideshow img:last');
   var $next =  $active.next().length ? $active.next()
   : $('#slideshow img:first');
   $active.addClass('last-active');
   $next.css({
      opacity: 0.0
   })
   .addClass('active')
   .animate({
      opacity: 1.0
   }, 2500, function() {
      $active.removeClass('active last-active');
   });
}
$(function() {
   setInterval( "slideShow()", 3200 );
});

// -------------------- Offers animáció --------------------
$(document).ready(function() {
   $("#product_offers ul li a").fancybox({
      'opacity'		: true,
      'overlayShow'	: true,
      'transitionIn'	: 'elastic',
      'transitionOut'	: 'elastic',
      'titlePosition'	:	'over',
      'overlayColor'		: '#8f6b47',
      'overlayOpacity'	: 0.7,
      'onComplete'	:	function() {
         $("#fancybox-wrap").hover(function() {
            $("#fancybox-title").show();
         }, function() {
            $("#fancybox-title").hide();
         });
      }
   });
   // ------------------- Galéria animáció -----------------
   $(".thumb a").fancybox({
      'opacity'		: true,
      'overlayShow'	: true,
      'transitionIn'	: 'fade',
      'transitionOut'	: 'none',
      'titlePosition'	:	'over',
      'overlayColor'		: '#8f6b47',
      'overlayOpacity'	: 0.7,
      'onComplete'	:	function() {
         $("#fancybox-wrap").hover(function() {
            $("#fancybox-title").show();
         }, function() {
            $("#fancybox-title").hide();
         });
      }
   });
   // ------------ Termék hanggal iframe-ben ---------------
   $(".thumb_sound a").fancybox({
      'overlayShow'	: true,
      'overlayColor'		: '#8f6b47',
      'overlayOpacity'	: 0.7,
      'transitionIn'		: 'fade',
      'transitionOut'		: 'none',
      'titlePosition'       : 'inside',
      'type'				: 'iframe',
      'width'				: 780,
      'height'			: 580
   });
   // ----------------- Kapcsolat animáció -----------------

   $(".contact").fancybox({
      'overlayShow'	: true,
      'overlayColor'		: '#8f6b47',
      'overlayOpacity'	: 0.7,
      'transitionIn'		: 'none',
      'transitionOut'		: 'none',
      'type'				: 'iframe',
      'width'				: 600,
      'height'			: 580
   });
});
// ------------------- Form ellenőrzés ---------------------
function validate_form(){
        var $name = document.getElementById('name');
        var $email = document.getElementById('e-mail');
        if(isAlphabet($name, "Ellenőrizze a beírtakat! Kérjük, töltse ki helyesen a név mezőt!"))
        {
          if(emailValidator($email, "Ellenőrizze a beírtakat! Adjon meg pontos e-mail címet!"))
          {
            return true;
          }
        }
        return false;
      }
      function isAlphabet(elem, helperMsg){
        var alphaExp = /^[a-zA-ZáÁéÉíÍóÓöÖőŐüÜűŰ ]+$/;
        if(elem.value.match(alphaExp)){
          return true;
        }else{
          alert(helperMsg);
          elem.focus();
          return false;
        }
      }
      function emailValidator(elem, helperMsg){
        var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
        if(elem.value.match(emailExp)){
          return true;
        }else{
          alert(helperMsg);
          elem.focus();
          return false;
        }
      }



