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 Scroller(classScroll) {
  jQuery(classScroll).jScrollPane({
      showArrows : true,
      scrollbarWidth : 11,
      scrollbarMargin : -1
    }).parent().mouseover(function(){
                  jQuery(this).children('.jScrollPaneTrack').show();
                }).mouseout(function(){
                    jQuery(this).children('.jScrollPaneTrack').hide();
                  });
}

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({'min-height': currentTallest}); 
	});
	return this;
};

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

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

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

jQuery(document).ready(function(){
  
  jQuery('.box-shop').addClass('eq');
  
  var hShopDetails = jQuery('.box-img').height();
  var hInfoShopDetails = jQuery('.box-info-item-shop').height();
  var mTopInfoShopDetails = (hShopDetails-hInfoShopDetails)/2;
  jQuery('.box-info-item-shop').css('padding-top',mTopInfoShopDetails+'px');
  
  jQuery('.box-album-photogallery ul').jcarousel({
            vertical: false,
            animation: 1000,
            scroll: 4
  });
  jQuery('.photo-gallery-page .left-col .jcarousel-container-horizontal').addClass('jcarousel-photogallery');
  
  jQuery('#videogallery-thumb ul').jcarousel({
            vertical: false,
            animation: 1000,
            scroll: 1
  });
  jQuery('#videogallery-thumb .jcarousel-container-horizontal').addClass('jcarousel-videogallery');
  
  
  jQuery(window).load(function(){
    jQuery('.eq').equalHeights();
    
    SizeVideo();
    
    var hBoxImgEvent = jQuery('.box-img-event').height();
    var hImgEvent = jQuery('.box-img-event img').height();
    var mTopImgEvent = (hBoxImgEvent-hImgEvent)/2;
    jQuery('.box-img-event img').css('marginTop',mTopImgEvent-15+'px');
    
    jQuery('.box-shop-img').each(function(){
      var hBoxShop = jQuery(this).height();
      var ImgShop = jQuery(this).find('img');
      var hImgShop = jQuery(this).find('img').height();
      var DescShop = jQuery(this).parent().children('.box-shop-desc').find('p');
      var hDescShop = jQuery(this).parent().children('.box-shop-desc').find('p').height();
      if(hImgShop<hDescShop) {
        var mTopShop = (hBoxShop-hImgShop)/2;
        ImgShop.css('marginTop',mTopShop-15+'px');
      }
      else {
        var mTopShop = (hBoxShop-hDescShop)/2;
        DescShop.css('marginTop',mTopShop-15+'px');
      }
    })
  })
})

