jQuery.fn.equalHeights = function() {
	jQuery(this).each(function(){
		var currentTallest = 0;
		jQuery(this).children().each(function(i){
			if (jQuery(this).height() > currentTallest) {currentTallest = jQuery(this).height();}
		});
    currentTallest=currentTallest+"px";
		jQuery(this).children('div').css({'height': currentTallest}); 
	});
	return this;
};

function Equal() {
  jQuery('.eq').equalHeights();
}

function hideShowDesc(id) {
  jQuery(id).mouseover(function(){
    jQuery(id+" .featured-entry").css('display','block')
  });
  jQuery(id).mouseout(function(){
    jQuery(id+" .featured-entry").css('display','none')
  })
}
        
function center_img_o(obj,nw){
    var ml;
    var w=obj.width();
    ml=Math.ceil((w-nw)/2);
    ml=ml*-1;
    var ml1=ml+'px';
    obj.css({'marginLeft' : ml1});
    obj.css({'marginRight' : ml1});
}

function center_img_v(obj,nh){
    var mt;
    var h=obj.height();
    mt=Math.ceil((h-nh)/2);
    mt=mt*-1;
    var mt1=mt+'px';
    obj.css({'marginTop' : mt1});
    obj.css({'marginBottom' : mt1});
}

function resizeAndCenter(id,width,height,src) {
  jQuery("#r-"+id).load(function() {
    var rbox=width/height;
    var img=new Image();
    img.src=src;
    var rimg=img.width/img.height;
    var mleft=((height*rimg)-width)/2;
    mleft=mleft*(-1);
    if(rimg>rbox){
      jQuery("#r-"+id).attr("height",height).css("marginLeft",mleft+"px");
    }
    else {
      var rimg=img.height/img.width;
      var mtop=((width*rimg)-height)/2;
      mtop=mtop*(-1);
      jQuery("#r-"+id).attr("width",width).css("marginTop",mtop+"px");
    }
  });
}

function resizeAndCenterInv(id,width,height,src) {
  jQuery("#r-"+id).load(function() {
    var rbox=width/height;
    var img=new Image();
    img.src=src;
    var rimg=img.width/img.height;
    var mleft=((height*rimg)-width)/2;
    mleft=mleft*(-1);
    if(rimg<rbox){
      jQuery("#r-"+id).attr("height",height).css("margin-left",mleft+"px");
    }
    else {
      var rimg=img.height/img.width;
      var mtop=((width*rimg)-height)/2;
      mtop=mtop*(-1);
      jQuery("#r-"+id).attr("width",width).css("margin-top",mtop+"px");
    }
  });
}

function overlay_box_photo() {
  /**
     * Funzione che muove le immagini della photo gallery
     * IMPORTANTE!! Funziona solo su classe .image-overlay
     */
    var $fPhoto = jQuery('.image-overlay').parent();
    $fPhoto.css('background-color','#000000');
    jQuery('.zoom-icon, .more-icon').css({'opacity':'0','visibility':'visible'});
    
    $fPhoto.hover(function(){
        jQuery(this).stop(true, true).animate({top: -10}, 500).find('img.f-photo-img').stop(true, true).animate({opacity: 0.7},500);
        jQuery(this).find('.zoom-icon').stop(true, true).animate({opacity: 1},400);
        jQuery(this).find('.more-icon').stop(true, true).animate({opacity: 1},400);
    }, function(){
        jQuery(this).find('.zoom-icon').stop(true, true).animate({opacity: 0},400);
        jQuery(this).find('.more-icon').stop(true, true).animate({opacity: 0},400);
        jQuery(this).stop(true, true).animate({top: 0}, 500).find('img.f-photo-img').stop(true, true).animate({opacity: 1},500);
    });
}

function gamesCarousel(starPoint){
  jQuery('#box-matches-home').jcarousel({
          vertical: true,
          animation: 500,
          scroll: 1,
          start: starPoint
  });
  jQuery('#inner-box-2 .jcarousel-container-vertical').addClass('jcarousel-home');
}

function gamesCarouselTeam(starPoint){
  jQuery('#box-matches-team').jcarousel({
          vertical: false,
          animation: 500,
          scroll: 1,
          start: starPoint
  });
  jQuery('#int-middle-team .jcarousel-container-horizontal').addClass('jcarousel-team');
}

function showRanking(){
  jQuery('#content-rank-home').children().hide();
  var showRank = jQuery('#team-rank').val();
    jQuery(showRank).show();
}

function SizeVideo() {
  jQuery('#boxVideo div object, #boxVideo div object embed').attr('height','402').attr('width','634');
}

function fancySearch() {
  jQuery('.zoom-icon.fancybox').fancybox();
}

function getGameInfoVivaldi(path,m_id){
  jQuery('#gameInfoBox').html("").dialog("destroy");
  jQuery('#gameInfoBox').load(path+'/matches_page.php?m_id='+m_id, function() {
    jQuery('#gameInfoBox').dialog({
      modal: true,
      open: initialize,
      width: 1038,
      height: 500,
      show: "fade",
      hide: "fade"
    });
    jQuery('#map_wrapper').addClass('bg-color2');
  })
}

function cornerMap() {
  jQuery('#map_canvas > div > div > div > div:nth-child(9) > div').css('overflow','hidden');
  jQuery('#map_canvas > div > div > div > div:nth-child(9) > div').addClass('border-radius');
  jQuery('#map_canvas > div > div > div > div:nth-child(8) > div').css('overflow','hidden');
  jQuery('#map_canvas > div > div > div > div:nth-child(8) > div').addClass('border-radius');
}

function getAvatar(src,name,surname) {
  jQuery('#avatar-video').attr('src',src).attr('alt', name+' '+surname);
}

function wrapBoxVideo() {
  jQuery('#boxVideo div').wrap('<div class="border-radius">');
}

function carouselSponsor(auto) {
  jQuery('#box-sponsors').jcarousel({
          vertical: false,
          animation: 5000,
          scroll: 1,
          auto: auto,
          wrap: "circular"
  });
  jQuery('#box-canale .jcarousel-container-horizontal').addClass('jcarousel-sponsor');
}

function carouselTopNotice(auto){
  jQuery('#box-txt-notice').jcarousel({
          vertical: false,
          animation: 5000,
          scroll: 1,
          auto: auto,
          wrap: "circular"
  });
  jQuery('#box-notice-top .jcarousel-container-horizontal').addClass('jcarousel-top-notice');
}

jQuery(document).ready(function(){
    
  overlay_box_photo();

  jQuery('#nav ul li a, #nav2 ul li a').addClass('fg3');

  jQuery('#nav-content ul li a, #nav-content2 ul li a, #respond h3, #text-desc-boxVideo #desc-boxVideo p, .quick-nav .login-box div form label').addClass('webfont-Rockwell');

  jQuery('#respond div, #respond p, #text-desc-boxVideo #desc-boxVideo p span').addClass('cantarell');

  jQuery('.desc-picture-home .desc a, .navigation .floatleft a, .navigation .floatright a').addClass('fg');

  jQuery('#boxVideo div, .quick-nav .login-box div').addClass('border-radius');

  jQuery('.quick-nav .login-box div').addClass('bg-color');

  jQuery('#nav-content ul.sf-menu > li > a, #nav-content2 ul.sf-menu > li > a').hover(function(){
    jQuery('#nav-content ul.sf-menu > li ul, #nav-content2 ul.sf-menu > li ul').css('left','-50%');
  });

  jQuery('#nav-content ul.sf-menu li ul li a, #nav-content2 ul.sf-menu li ul li a').hover(function(){
    jQuery('#nav-content ul.sf-menu li ul li ul, #nav-content2 ul.sf-menu li ul li ul').css('left','12em').css('top','-5px');
  });

  jQuery('#carousel-home').jcarousel({
          vertical: false,
          animation: 1000,
          scroll: 1
  });
  jQuery('#carousel-top-home .jcarousel-container-horizontal').addClass('jcarousel-home');

  jQuery('#list-article').jcarousel({
          vertical: true,
          animation: 1000,
          scroll: 1
  });
  jQuery('#int-left-col-single .jcarousel-container-vertical').addClass('jcarousel-single');

  jQuery('#album-photo').jcarousel({
          vertical: false,
          animation: 1000,
          scroll: 1
  });
  jQuery('#int-album-photogallery .jcarousel-container-horizontal').addClass('jcarousel-photogallery');

  var nli=jQuery('#carousel-home li').length;
  nli=nli*294;
  jQuery('#carousel-home').css('width', nli+'px');

  jQuery('.jcarousel-home').wrap('<div class="bg-color2 border-radius">');

  jQuery(".fancybox-video").fancybox({
                'type': "iframe",
                'autoDimension': true,
                'showCloseButton': true,
                'autoScale': true,
                'frameWidth': 622,
                'frameHeight': 374,
                'hideOnContentClick': false,
                'overlayColor': '#000',
                'overlayOpacity': '0.7'
              });

  center_img_v(jQuery('.box-desc-event.center'),387);

  center_img_v(jQuery('#text-right-shop .box-shop-desc'),189);

  center_img_v(jQuery('#box-middle-shop-details'),390);

  center_img_v(jQuery('#text-p-details-h #p-details .entry-info'),548);

  center_img_v(jQuery('#text-p-details-w #p-details .entry-info'),365);

  var tName=jQuery('#last-match .no-logo');
  tName.each(function(){
    center_img_v(jQuery(this),52);
  });

  var tName=jQuery('.list-player li .roster-player');
  tName.each(function(){
    center_img_v(jQuery(this),63);
  });

  jQuery('#btn-submit-login').addClass('bg-color2 fg');

  jQuery(window).load(function(){
    SizeVideo();
    center_img_v(jQuery('#text-desc-boxVideo #desc-boxVideo'),136);
    wrapBoxVideo();
    var tName=jQuery('#result-match .no-logo');
    tName.each(function(){
      center_img_v(jQuery(this),48);
    });
  })
    
});

