$(document).ready(function(){

	$('#page-holder').css('padding-top', $('#header-wrap').height());


	$('#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(); }                
	});

	/* Menu Begin Definition */
	var config = {sensitivity: 3, interval: 100, over: menuHoverOver, timeout: 200, out: menuHoverOut};

	$("ul#navi-main-categories li .sub-holder").css({'display':'none'});
	$("ul#navi-main-categories li").hoverIntent(config);
	/* Menu Definition End */
	
	/* Tabs Definition Begin */
	if ($('.tab-holder1').length) {tabsControl('.tab-holder1', '.productslide');}
	if ($('.tab-holder2').length) {tabsControl('.tab-holder2', '.productslide');}
	if ($('.tab-holder3').length) {tabsControl('.tab-holder3', '.productslide');}
	/* Tabs Definition End */
	
	
	/* Slideshow Definition Begin */
	if ($('#slideshow-featured').length) {$('#slideshow-featured').SlideShow(900);}
	if ($('#slideshow-bestsellers').length) {$('#slideshow-bestsellers').SlideShow(900);}
	if ($('#slideshow-rviewed').length) {$('#slideshow-rviewed').SlideShow(900);}
	
	if ($('#product-tabs-related').length) {$('#product-tabs-related').SlideShow(900);}
	if ($('#product-tabs-recommends').length) {$('#product-tabs-recommends').SlideShow(900);}
	
	if ($('#slideshow-cat-featured').length) {$('#slideshow-cat-featured').SlideShow(680);}
	if ($('#slideshow-cat-bestsellers').length) {$('#slideshow-cat-bestsellers').SlideShow(680);}
	if ($('#slideshow-cat-rviewed').length) {$('#slideshow-cat-rviewed').SlideShow(680);}
	
	if ($('#tabs-also-bought').length) {$('#tabs-also-bought').SlideShow(900);}
	/* Slideshow Definition End */
	
	/* Product Image Zoom Begin */
	if ($('.jqzoom').length) {
		$('.jqzoom').jqzoom({
	    zoomType: 'standard',
	   /* zoomWidth: 490,*/
	    zoomWidth: 350,
		zoomHeight: 293,
	   /* zoomHeight: 529,*/
	    xOffset: 30,
	    yOffset: 0,
	    lens:true,
	    preloadImages: false,
	    alwaysOn:false,
	    title:false
	  });
  }
	/* Product Image Zoom End */
	
	/* Reviews Content Switch Start */	
	$('#rev-n1').click(function() {
      $('.rev-form').hide();
      var ReviewsTabHeight = $('.rev-reviews').height() + 120;
      $('.tab-holder3').css('height', ReviewsTabHeight);
     	$('.rev-reviews').show();
     	//$('.rev-reviews').css('height', $('.rev-reviews').height());
      //$('.rev-reviews').fadeIn('fast', function() { });    
   });
   
   $('#rev-n2').click(function() {
      $('.rev-reviews').hide();
      $('.tab-holder3').css('height', '500');
     	$('.rev-form').show();
     	//$('.rev-form').css('height', $('.rev-form').height());
     	//$('.rev-form').fadeIn('fast', function() { });
   })
   /* Reviews Content Switch End */
  
});

/* Menu Functions Begin */
function menuHoverOver(){
	
	var activeItemWidth = $(this).width()+'px';
	
	$(this).css('width', activeItemWidth);
	$(this).addClass('current');
	
	var menuColumnCount = $(this).find(".sub-menu").children('.sub-column').size();
	var menuColumnWidth = $(this).find('.sub-column').width();
	var menuHolderWidth = menuColumnCount * menuColumnWidth;
	
	$(this).find(".sub-holder").css('width',  menuHolderWidth);
	
	var activePageWidth = $('#page').width();
	var activeMenuWidth = $(this).find(".sub-holder").width();
	var activeOffset = $(this).position().left;
	var activeMenuSpace = activeOffset + activeMenuWidth;
	
	if (activeMenuSpace > activePageWidth){
		var activeMenuDifference = (activePageWidth - activeMenuSpace) - 3;
		$(this).find(".sub-holder").css('left', activeMenuDifference);
	}
	
	$(this).find(".sub-holder").stop().fadeTo(0, 1).show();
}

function menuHoverOut(){ 
 	$(this).removeClass('current');
  $(this).find(".sub-holder").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
    $(this).hide(); 
	});
}
/* Menu Functions 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 */


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 */


/* Menu Functions Begin */ 
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);
/* Menu Functions End */
