$(document).ready(function(){
	$('.fe-cat-home').each(function() {
		var tallest = 0;
		$(this).children().each(function() {
			var height = $(this).height();
			if (height > tallest) {
				tallest = height;	
			}
		});
		$(this).children().height(tallest);		
	});
	
	
	$('#languages').hide();
	$('#info-lang').show();
	$('#info-lang').click(function(){
		$('#languages').slideToggle();
	});
        
	$("body").click(function (evt) {
		var target = evt.target;
		if(target.id !== 'info-lang'){ $("#languages").hide(); }                
	});
	
	/* Navigation Item Width FiX Begin */
	$('#navi').children().each(function(index) {
	   
	   var MaxMenuWidth = $(this).width();
	   var CountMenuItems = $(this).children().length;
	   var ItemWidth = (MaxMenuWidth / CountMenuItems) - 1;
	   
	   ItemWidth = Math.floor(ItemWidth);
	   $(this).children().width(ItemWidth);
	   
	   var CurrentItemsWidth = (ItemWidth + 1) * CountMenuItems;
	   var LastItemWidth = (MaxMenuWidth - CurrentItemsWidth) + ItemWidth;
	 
	   $(this).children().last().width(LastItemWidth);
  
       });
       /* Navigation Item Width FiX End */
	
	/* Tabs Definition Begin */
	if ($('.tabs-holder').length) {tabsControl('.tabs-holder', '.productslide');}
	/* Tabs Definition End */
	
	/* Slideshow Definition Begin */
	if ($('#slide-featured').length) {$('#slide-featured').SlideShow(900);}
	if ($('#slide-bestsellers').length) {$('#slide-bestsellers').SlideShow(900);}
	if ($('#slide-recently').length) {$('#slide-recently').SlideShow(900);}
	if ($('#product-tabs-related').length) {$('#product-tabs-related').SlideShow(900);}
	if ($('#product-tabs-recommends').length) {$('#product-tabs-recommends').SlideShow(900);}
	if ($('#tab-recently').length) {$('#tab-recently').SlideShow(900);}
	
	
	if ($('#slide-cat-featured').length) {$('#slide-cat-featured').SlideShow(680);}
	if ($('#slide-cat-bestsellers').length) {$('#slide-cat-bestsellers').SlideShow(680);}
	if ($('#slide-cat-recently').length) {$('#slide-cat-recently').SlideShow(680);}
	/* Slideshow Definition End */

	/* Slider Reduced Price Begin */	
	$('.r-price-content').hide();
	$('.r-price-control').click(function(){	
		$(this).next().slideToggle();
	});
	/* Slider Reduced Price End */	
	
	/* Product Image Zoom Begin */
	if ($('.jqzoom').length) {
		$('.jqzoom').jqzoom({
	    zoomType: 'standard',
	    zoomWidth: 490,
	    zoomHeight: 510,
	    xOffset: 27,
	    yOffset: 0,
	    lens:true,
	    preloadImages: false,
	    alwaysOn:false,
	    title:false
	  });
  }
	/* Product Image Zoom End */
	
	ToggleCaptcha();
	
});

/* News Letter Captcha Begin */
function ToggleCaptcha() {
	var InputBox = $('#semail');
	var ContentDiv = $('#captcha-wrapper');
	
	if (!InputBox.length || !ContentDiv.length) {return;}
	
	InputBox.focus(function() {
		ContentDiv.show(170);
		if( $(this).attr('value') == $(this).attr('defaultValue') ){
        $(this).attr('value', '');
    };	
	});
	
	InputBox.blur(function() {
		if( $(this).attr('value') == '' ){
        $(this).attr('value', $(this).attr('defaultValue') );
    };
		setTimeout(function(){ContentDiv.hide(170)}, 10000);	
	});
}
/* News Letter Captcha End */


/* Tabs Control Functions Begin */
function tabsControl(tabHolder, tabContainer){
	$(tabHolder).css('overflow', 'hidden');
	
	var FirstTabHeight = $(tabContainer).height();
	
	$(tabHolder).css('height', FirstTabHeight);
	
	$(tabContainer).hide();
	$(tabContainer+':first').show();
	
	$('#tab-control li:first').addClass("active").show();

  $("#tab-control li").click(function() {	
		if ($(this).hasClass('active')) {return false;}
	
		$("#tab-control li").removeClass("active");
		$(this).addClass("active");
		$(tabContainer).hide();
		
		var activeTab = $(this).find("a").attr("href");
		
		$(activeTab).fadeIn();
		
		var activeTabHeight = $(activeTab).height()+'px';
		
		$(tabHolder).css('height', activeTabHeight);
		
		$(activeTab).fadeIn();	
			
		return false;
	});	
	
	$("#rating-tab-link").click(function() {
		
		if ($('#tab-feedback').hasClass('active')) {return false;}
		
		$("#tab-control li").removeClass("active");
		$('#tab-feedback').addClass("active");
		$(tabContainer).hide();
		
		var activeTab = $('#tab-feedback').find("a").attr("href");
		
		$(activeTab).fadeIn();
		
		var activeTabHeight = $(activeTab).height()+'px';
		
		$(tabHolder).css('height', activeTabHeight);
		
		$(activeTab).fadeIn();	
			
		return false;
	});
	
}
/* Tabs Control Functions End */


/* Slide Show Functions Begin */
jQuery.fn.SlideShow = function(SlideWidth) {
  
  var currentPosition = 0;
  var currentId = $(this).attr('id');
  
  var slides = $('#' + currentId + ' .slide');
  var numberOfSlides = slides.length;

  $('#'+currentId+' .slidesholder').css('overflow', 'hidden');
  $('#'+currentId+' .slidesholder').css('width', SlideWidth);

  slides.wrapAll('<div class="slideInner"></div>').css({'float' : 'left', 'width' : SlideWidth});

  $('#'+currentId+' .slideInner').css('width', SlideWidth * numberOfSlides);

  $('#'+currentId)
    .prepend('<span class="control leftControl">Clicking moves left</span>')
    .append('<span class="control rightControl">Clicking moves right</span>');

  $('#'+currentId + ' .control')
    .bind('click', function(){
		currentClass = $(this).attr('class');
		currentPosition = (currentClass=='control rightControl') ? currentPosition+1 : currentPosition-1;
		
		if (currentPosition > (numberOfSlides - 1)) {currentPosition = (numberOfSlides - 1);}
		if (currentPosition == -1) {currentPosition = 0;}

    $('#'+currentId+' .slideInner').animate({
      'marginLeft' : SlideWidth*(-currentPosition)
    });
  });  	
};
/* Slide Show Functions End */


/* Sorting product order Begin */
function funcSwitchCustomerSortField(sort_id) {
	var uri = new Object();
	txs_getURL(uri);

	var r_url = "http://"+uri.dom;
	if (uri.path) {
		r_url += "/"+uri.path+"/";
	}
	if (uri.file) {
		if (!uri.path) {
			r_url += "/";
		}
		r_url += uri.file;
	}
		
	if (uri.args != "") {
		var args = ""+uri.args;
		if (args.search(/sort=[\w]+/) == -1) {
			args += "&"+sort_s_links[sort_id];
		} else {
			args = args.replace(/sort=[\w]+/, sort_s_links[sort_id]);
		}
		if (args.search(/sort_direction=/) == -1) {
			args += "&"+sort_sd_links[sort_id];
		} else {
			args = args.replace(/sort_direction=(?:1|0)/, sort_sd_links[sort_id]);
		}
		
		r_url += "?"+args;
	} else {
		r_url += "?"+sort_s_links[sort_id];
		if (sort_sd_links[sort_id]) {
			r_url += "&"+sort_sd_links[sort_id];
		}
	}
	
	document.location = r_url;

}

function txs_getURL(uri) {
	uri.dir = location.href.substring(0,location.href.lastIndexOf('\/'));
	uri.dom = uri.dir; if (uri.dom.substr(0,7) == 'http:\/\/') uri.dom = uri.dom.substr(7);
	uri.path = ''; var pos = uri.dom.indexOf('\/'); if (pos > -1) {uri.path = uri.dom.substr(pos+1); uri.dom = uri.dom.substr(0,pos);}
	uri.page = location.href.substring(uri.dir.length+1,location.href.length+1);
	pos = uri.page.indexOf('?');if (pos > -1) {uri.page = uri.page.substring(0, pos);}
	pos = uri.page.indexOf('#');if (pos > -1) {uri.page = uri.page.substring(0, pos);}
	uri.ext = ''; pos = uri.page.indexOf('.');if (pos > -1) {uri.ext =uri.page.substring(pos+1); uri.page = uri.page.substr(0,pos);}
	uri.file = uri.page;
	if (uri.ext != '') uri.file += '.' + uri.ext;
	if (uri.file == '') uri.page = 'index';
	uri.args = location.search.substr(1).split("?");
	return uri;
}
/* Sorting product order End */
