
var initLeftHeight = false;
function body_content_resized(){
  var curCH = $('#contentHolder').height();
  if ( !initLeftHeight ) initLeftHeight = $('.left_bg').height();
  if ( curCH>initLeftHeight ) {
    $('.left_bg').css('height', curCH+30);
  }else{
    $('.left_bg').css('height', initLeftHeight);
  }
  $('.left_bg').css('height', $('#box-wrap').height());
}

jQuery(document).ready(function(){
	$('.products .row-item:last .thumb').addClass('last_row');
  
  $('.productRow').inrow({item1:'.productDescriptionCell',item2:'.productNameCell',item3:'.productImageCell',item4:'.productPriceCell' });
  $('.jcarousel').inrow({item1:'.product-name'}); 
  $('.rowCategory').inrow({item1:'.categoryCellDiv'}); 
  
  $('.catalog li:last').css('border-bottom','none');
  
  
  $('select:not([id])').each(function(i){
    $(this).attr('id', 'selectId'+i)
  })
  
  $('.contentBoxContents:last').css('border-bottom', 'none');
  $('.reviewsBox:last').css('border-bottom', 'none');
  
  
  if($("#slider img").length>1){
    jQuery('#slider').nivoSlider({pauseTime:8000, controlNavAlt:true});
  }
  $('.catalog li ul > li:odd').addClass('liOdd');
  $('.catalog li ul > li:even').addClass('liEven');
  body_content_resized();
  $('.backtop').click(function() {
    window.scrollTo(0,0);
 
    // don't change the hash if not needed
    return false;
});
 /* $('.breadcrumb a:last').addClass('highlight');*/
  $('.breadcrumb').children().last().addClass('highlight');
  /*$('.mainBanner').close();*/

    var $pimain_image = $('.productImage img');
//    if ( $pimain_image.length>0 ) {
//      mheight = $pimain_image.attr('height');
//      mwidth = $pimain_image.attr('width');
//      if ( typeof main_image_w!= 'undefined' && main_image_w>0 ){
//        $pimain_image.css('width', main_image_w);
//      }else{
//        $pimain_image.css('width', mwidth);
//      }
//      if ( typeof main_image_h!= 'undefined' && main_image_h>0 ){
//        $pimain_image.css('max-height', main_image_h);
//      }else{
//        $pimain_image.css('max-height', mheight);
//      }
//      $pimain_image.removeAttr('width');
//      $pimain_image.removeAttr('height');
//
//    }
 
    if ( $('.extra_div a.extra_link').length>0 ) {
//      $('.extra_div a.extra_link').lightBox();
	  $('.productImage a').lightBox();
      $('.productImage a').click(function(){
        var f_href = this.href;
        var haveClicked = false;
        $('.extra_div a.extra_link').each( function() {

          if ( !haveClicked || this.href==f_href ) {
            $(this).click();
            haveClicked = true;
          }
        } );
        return false;
      });
    }else{
      $('.productImage a').lightBox();
    }
    $('.additionalImages a').click(function(){
      $('.additionalImages a').removeClass('active');
      $(this).addClass('active');
      var href = $(this).attr('href');
      var iwidth = $("img", this).attr('width');
      var iheight= $("img", this).attr('height');
	  var iscale;
		if ( typeof main_image_w!= 'undefined' && main_image_w>0 && typeof sm_image_w!= 'undefined' && sm_image_w>0 ) {
			iscale = (main_image_w / sm_image_w );
		} else {
			iscale = 4;
		}

      //$('.productImage img').attr('src', href);
      $('.productImage img').attr({'src': href, 'width': iwidth*iscale, 'height': iheight*iscale});
      $('.productImage a').attr({title: $(this).attr('title'), href: href});
      return false;
    });

    var preloadImage = new Image();
    $('.additionalImages a').each(function(){
      var href = $(this).attr('href');
      preloadImage.src = href;
    })
    $('.additionalImages a:first').click();
    
    var tabContainers = $('div.tabsInfo > div'); 
    tabContainers.hide().filter(':first').show(); 
    
    $('ul.tabNavigation a').click(function () {
        tabContainers.hide(); 
        tabContainers.filter(this.hash).show(); 
        $('ul.tabNavigation a').removeClass('selected'); 
        $(this).addClass('selected');
        body_content_resized();
        return false;
    }).filter(':first').click();
    
    var tabContainers1 = $('div.tabsInfo1 > div'); 
    //tabContainers1.hide().filter(':first').show();
    if (tabContainers1.length>0) {
      //$(window).bind('load',function(){ alert('a'); body_content_resized();} );
    }
    
    tabContainers1.css({position:'absolute',left:'-10000px',top:'-10000px'}).filter(':first').css({position:'',left:'',top:''});
    $('ul.tabNavigation1 a').click(function () {
        //tabContainers1.hide();
        tabContainers1.css({position:'absolute',left:'-10000px',top:'-10000px'});
        //tabContainers1.filter(this.hash).show(); 
        tabContainers1.filter(this.hash).css({position:'',left:'',top:''}); 
        $('ul.tabNavigation1 a').removeClass('selected'); 
        $(this).addClass('selected'); 
        body_content_resized();
        return false;
    }).filter(':first').click();
});

/*function makeInput(){
  jQuery(function(){
    $('input[type="text"]:not(.inp, .inputBorder), input[type="password"]:not(.inp, .inputBorder)').addClass('inputBorder').wrap('<span class="inputWrapRight"><span class="inputWrap"></span></span>');
  })
}
makeInput();*/


var params = {
    changedEl: ".contact_lang select",
    visRows: 8,
    scrollArrows: true
}
cuSel(params);


jQuery(document).ready(function(){
  jQuery('.login').each(function(){
    box_height = 0;
    jQuery(this).find('.logBox').each(function(){
    if (jQuery(this).height() > box_height){
        box_height = jQuery(this).height();
          }
      })
      jQuery(this).find('.logBox').css({'height':box_height+'px'})
   })
})


/* tabs listing mode switch */
function initTabs()
{
	var sets = document.getElementsByTagName("ul");
	for (var i = 0; i < sets.length; i++)
	{
		if (sets[i].className.indexOf("tabset") != -1)
		{
			var tabs = [];
			var links = sets[i].getElementsByTagName("a");
			for (var j = 0; j < links.length; j++)
			{
				if (links[j].className.indexOf("tab") != -1)
				{
					tabs.push(links[j]);
					links[j].tabs = tabs;
					var c = document.getElementById(links[j].href.substr(links[j].href.indexOf("#") + 1));
					if (c) if (links[j].className.indexOf("active") != -1) c.style.display = "block";
					else c.style.display = "none";
					links[j].onclick = function ()
					{
						var c = document.getElementById(this.href.substr(this.href.indexOf("#") + 1));
						if (c)
						{
							for (var i = 0; i < this.tabs.length; i++)
							{
								var tab = document.getElementById(this.tabs[i].href.substr(this.tabs[i].href.indexOf("#") + 1));
								if (tab)
								{
									tab.style.display = "none";
								}
								this.tabs[i].className = this.tabs[i].className.replace("active", "");
							}
							this.className += " active";
							c.style.display = "block";
							return false;
						}
					}
				}
			}
		}
	}
}
if (window.addEventListener)
	window.addEventListener("load", initTabs, false);
else if (window.attachEvent && !window.opera)
	window.attachEvent("onload", initTabs);
