//FANCYBOX title
/*kp*/
function formatFancyboxTitle(title, currentArray, currentIndex, currentOpts) {
    return '<div>' +
    (title && title.length ? '<b style=\"float:left;\">' + title.substr(0,title.indexOf('--')-1) + '</b><br /><span style=\"float:left;\">' + title.substr(title.indexOf('--')+2) + '</span>' : '' )
    + ' (' + (currentIndex + 1) + '/' + currentArray.length + ' kép)</div>';
}

//BMI calculatorbox
/*kp*/
function calculateBMIbox() {
  var l = $('#bmiboxl').val();
  var m = $('#bmiboxm').val();
  if ((l < 50) || (l > 300)) {
    alert ("Hibásan adta meg testmagasságát!");
    $('#bmiboxl').focus();
    return;
  }
  if ((m < 30) || (m > 300)) {
    alert ("Hibásan adta meg testsúlyát!");
    $('#bmiboxm').focus();
    return;
  }

  l = l / 100;
  var bmi = m / l / l;
  bmi = Math.round(bmi*10) / 10;
  var message = "Az Ön testtömeg indexe:<br /><b>" + bmi; + "</b>";
  if (bmi < 20) { message = message + " (sovány)"; }
  if ((bmi >= 20) && (bmi <= 25)) { message = message + " (normál súly)"; }
  if ((bmi > 25) && (bmi <= 30)) { message = message + " (túlsúlyos)"; }
  if ((bmi > 30) && (bmi <= 35)) { message = message + " (elhízott)"; }
  if (bmi > 35) { message = message + " (kórosan elhízott)"; }

  $('#bmiboxres').css("display","block");
  $('#bmiboxres').html(message);
}

//font size
/*kp*/
fontSizeTags = 'p,h2,h3,h4,h5,span,td,th,a,li,label';
function increaseFontSize() {
  $(fontSizeTags).each(function(i){
    s = $(this).css('font-size') + "";
    s = parseInt(s.replace("px",""));
    $(this).css('font-size',s+2+'px');
  });
}
function decreaseFontSize() {
  $(fontSizeTags).each(function(i){
    s = $(this).css('font-size') + "";
    s = parseInt(s.replace('px',''));
    $(this).css('font-size',s-2+'px');
  });
}




$(document).ready(function(){

  // google maps
  googledirectionsInitialize();

  //calculator slide
  $(".calculatorPage .item h3 a").click(function(){
    $(this).parents(".item:eq(0)").siblings(".item").find(".containerBottom").slideUp();
    $(this).parents(".item:eq(0)").find(".containerBottom").slideToggle();

    return false;
  });


  //fancybox
  $("a[rel=gallery], a.fancybox").fancybox({   /*kp*/
    'titleShow' : true,
    'transitionIn' : 'elastic',
    'transitionOut' : 'elastic',
    'easingIn' : 'easeOutBack',
    'easingOut' : 'easeInBack',
//    'titlePosition' : 'over'
    'titlePosition' : 'inside',
    'titleFormat' : formatFancyboxTitle
  });


  //carousel
  $(".galleryContainer").jcarousel();


  //Facebook like box
  $(".facebookBox").html('<iframe src="http://www.facebook.com/plugins/likebox.php?href=http%3a%2f%2fwww.facebook.com%2fpages%2f%c3%81lmaim-otthona%2f161871367259977&amp;width=250&amp;connections=10&amp;stream=false&amp;header=true&amp;height=350" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width: 250px;  height: 350px;  margin-bottom: 10px;" allowTransparency="true"></iframe>');

  $(".facebookBoxEnportal").html('<iframe src="http://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FMinden-ami-alakformalas-testepites-egeszseges-dieta%2F151459808215811&amp;width=250&amp;connections=10&amp;stream=false&amp;header=true&amp;height=350" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width: 250px;  height: 350px;  margin-bottom: 10px;" allowTransparency="true"></iframe>');

  $(".profilFacebookBox").html('<iframe src="http://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fcukorbeteg&amp;width=195&amp;connections=10&amp;stream=false&amp;header=true&amp;height=365" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width: 195px;  height: 365px;  margin-bottom: 10px;" allowTransparency="true"></iframe>');


  //tooltip
  $(".calendarContainer a").tooltip({
    track: false,
    delay: 0,
    showURL: false,
    opacity: 1,
    fixPNG: true,
    showBody: " - ",
    top: -10,
    left: -70
  });


  if($.cookie('mvb')!=1) {

  //custom input
  $(".voteBox input, .votePage input, .calculatorPage .containerBottom input").uniform();


  //header menu
  $(".headerMenu h2").hover(
		function() {
		  $(this).find("ul").show();
		},
		function() { $(this).find("ul").hide()}
	);

  }

  //input focus
  $("input").focus(function(){
    t = $(this);

    if (
      t.val() == "Felhasználó név"  ||
      t.val() == "Search"  ||
      t.val() == "Kereső"
      ) {
        t.val("");
      }
  }).blur(function(){
    t = $(this);

    var eredetiErtek = t[0].defaultValue;

    if (t.val() == "") {t.val(eredetiErtek);}
  });


  //HIR LAPOZO

  //config variables
  var autoscroll_on = true;
  var autoscroll_speed = 5000; //speed in millisec
  var newsbox_width = 420; //width in pixels


  //script variables
  var news_num = $(".newsSlider .item").length;
  var pos = 0;
  var max_pos = (newsbox_width * news_num) * - 1;
  $(".newsSlider .sliderAbsolute").css({width: news_num*newsbox_width});

  /******SCRIPT FUNCTIONS START******/
  function reset_active_class () {
    $(".newsSlider .sliderControl").find(".active").removeClass("active");
  }


  //move right function
  function move_right (multi) {
    pos = pos + (newsbox_width*multi);

    return pos;
  }


  //move left function
  function move_left (multi) {
    pos = pos - (newsbox_width*multi);
      
    return pos;
  }    
  /******SCRIPT FUNCTIONS END******/
  

  
  /******AUTO SCROLL START******/
  if (autoscroll_on == true && news_num > 2) {
    var timer;
    var i = 0;


    //autoscroll function
    function autoscroll () {
      timer = setInterval(next, autoscroll_speed);
      
      return timer;
    }

    
    //scrolls to 0 position
    function resetslide () {
      $(".newsSlider .sliderAbsolute").animate({left: "0px"}, 'normal','easeInQuad');
    }
    
    
    
    //scrolls items right
    function next () {
      //when last item displayed autoscroll starts over 
      if (pos == max_pos + newsbox_width) {
        resetslide ();
        pos = 0; 
        
        reset_active_class ();
        $(".newsSlider .sliderControl a:eq(0)").addClass("active");
        $(".newsSlider .sliderControl").find(".active").next("a").find(".left").hide();
      }
      
      else {
        $(".newsSlider .sliderAbsolute").animate({left: "" + move_left (1) + "px"}, 'normal','easeInQuad');
        
        reset_active_class ();         
        
        if (pos == 0) {
          $(".newsSlider .sliderControl a:eq(0)").addClass("active");
          $(".newsSlider .sliderControl").find(".active").next("a").find(".left").hide();
        }
        
        for (i = 1; i < news_num; i++) {
          if (pos == newsbox_width * i * -1) {
            $(".newsSlider .sliderControl a:eq(" + i + ")").addClass("active");
            $(".newsSlider .sliderControl").find(".active").next("a").find(".left").hide();
          }
            
        }   
      }
    }
    

    //hover function, stops autoscroll on mouseover / starts autoscroll on mouseout
    $(".newsSlider").hover(
      function() {clearInterval(timer);},
      function() {autoscroll ();}
    );
    
    autoscroll ();
  }
  /******AUTO SCROLL END******/
  
  
  //bind click function to page buttons
  $(".newsSlider .sliderControl a").click(function(){
    k = $(this).prevAll().length;
    
    if (k < news_num) {
      var activelink = $(".newsSlider .sliderControl").find(".active").prevAll().length;
      var pagenum = k;
      var linknum = k-1;
      var diff = pagenum - activelink;

      reset_active_class ();

      if (diff > 0) {
        $(".newsSlider .sliderAbsolute").animate({left: "" + move_left (diff) + "px"}, 'normal','easeInQuad');
      }

      if (diff < 0) {
        $(".newsSlider .sliderAbsolute").animate({left: "" + move_right (-diff) + "px"}, 'normal','easeInQuad');
      }



      //highlights active page link
      reset_active_class ();

      for (i = 0; i < news_num; i++) {
        if (pos == newsbox_width * i * -1) {
          $(".newsSlider .sliderControl a:eq(" + i + ")").addClass("active");
          $(".newsSlider .sliderControl").find(".active").next("a").find(".left").hide();
        }
      }

      return false;
    }
  });



  //termek LAPOZO

  //config variables
  var autoscroll_on1 = true;
//  var autoscroll_speed1 = 5000; //speed in millisec
  var autoscroll_speed1 = 5000; //speed in millisec
  var newsbox_width1 = 155; //width in pixels


  //script variables
  var news_num1 = $(".ajanloSlider .ajanloItem").length;
  var pos1 = 0;
  var max_pos1 = (newsbox_width1 * news_num1) * - 1;
  $(".ajanloSlider .sliderAbsolute").css({width: news_num1*newsbox_width1});

  //move right function
  function move_right1 (multi1) {
    pos1 = pos1 + (newsbox_width1*multi1);

    return pos1;
  }


  //move left function
  function move_left1 (multi1) {
    pos1 = pos1 - (newsbox_width1*multi1);

    return pos1;
  }
  /******SCRIPT FUNCTIONS END******/



  /******AUTO SCROLL START******/
  if (autoscroll_on1 == true && news_num1 > 3) {
    var timer1;
    var i = 0;


    //autoscroll function
    function autoscroll1 () {
      timer1 = setInterval(next1, autoscroll_speed1);
      
      return timer1;
    }

    
    //scrolls to 0 position
    function resetslide1 () {
      $(".ajanloSlider .sliderAbsolute").animate({left: "0px"}, 'normal','easeInQuad');
    }
    
    
    
    //scrolls items right
    function next1 () {
      //when last item displayed autoscroll starts over 
      if (pos1 == max_pos1 + 3*newsbox_width1) {
        resetslide1 (); 
        pos1 = 0; 
      }
      
      else {
        $(".ajanloSlider .sliderAbsolute").animate({left: "" + move_left1 (1) + "px"}, 'normal','easeInQuad');
      }
    }
    

    //hover function, stops autoscroll on mouseover / starts autoscroll on mouseout
    $(".ajanloSlider").hover(
      function() {clearInterval(timer1);},
      function() {autoscroll1 ();}
    );
    
    autoscroll1 ();
  }
  /******AUTO SCROLL END******/     

});

