var widthClassOptions = [];
var widthClassOptions = ({
		bestseller       : 'bestseller_default_width',
		newproduct       : 'newproduct_default_width',
		featured         : 'featured_default_width',
		special          : 'special_default_width',
		additional       : 'additional_default_width',
		related          : 'related_default_width',
		upsell	         : 'upsell_default_width',
		crosssell        : 'crosssell_default_width',
		brand			 : 'brand_default_width',
		blog			 : 'blog_default_width',
		category_blog	 : 'category_default_width',
		parallex		 : 'parallex_default_width',
		test 			 : 'test_default_width',
		sidehatneka 	 : 'sidehatneka_default_width'
		
});

var $k =jQuery.noConflict();
$k(document).ready(function(){
	$k('input[type="checkbox"]').tmMark(); 
	$k('input[type="radio"]').tmMark();
	
	$k(".form-language select").selectbox();	
	$k(".tm_top_currency select").selectbox();
	$k(".limiter select").selectbox();
	$k(".sort-by select").selectbox();
	$k(".form-search select").selectbox();
	$k(".block-brand-nav select").selectbox();
	
	
	$k('.mega_menu .block-title').click(function() {
		$k('.mega_menu .block-content').slideToggle("slow");
		$k('.mega_menu .mega_bkg').toggleClass('active');
	});

	$k('.mega_menu').click(function() {
		$k('.mega_menu').toggleClass('active');
	});

	$k(".block-content>li>.menu:even").css("background","#f7f7f7");
	$k(".block-content>li>.menu.seeall .subparentmenu-hover .menu:even").css("background","#f7f7f7");
	
	$k('.cart-label').click(function() {
    	 $k('#panel').slideToggle('fast');
    	 $k("#panel").parent().toggleClass('active').parent().find().slideToggle('fast');
  	});  
	
	$k('.nav-responsive').click(function() {
		$k('#nav-mobile').slideToggle();
		$k('.nav-responsive div').toggleClass('active');		
    });
	
	$k("#category-treeview").treeview({
		animated: "slow",
		collapsed: true,
		unique: true		
	});
	
	$k("#category-treeview li.active").addClass('collapsable');
	$k("#category-treeview li.active").removeClass('expandable');
	$k("#category-treeview li.active > .hitarea").addClass('collapsable-hitarea');
	$k("#category-treeview li.active > .hitarea").removeClass('expandable-hitarea');
	$k("#category-treeview li.active > ul").css('display','block');
	
	
	$k('.blog-carousel li:odd').addClass('last');
	$k('.blog-carousel li:even').addClass('first');
	$k(".blog-carousel .last").find(".blog-right").each(function(i){
   		$k(this).prependTo($k(this).parent().parent().find(".product-image-inner-blog"));
 	});
	
	
	$k('#additional-carousel').owlCarousel({
		items: 4,
		singleItem: false,
		navigation: true,
		navigation: true,
		navigationText: ['', ''],
		pagination: false,
		itemsDesktop : [1350,4],
		itemsDesktopSmall :	[979,3],
		itemsTablet :	[767,3],
		margin:10
	});	
	

	 $k(".tab:not(:first)").hide();
	 
	 //to fix u know who
	 $k(".tab:first").show();
	 
	 //when we click one of the tabs
	 $k(".tabbernav  li  a").click(function(){
	
	 //get the ID of the element we need to show
	 stringref = $k(this).attr("href").split('#')[1];
	 
	 //hide the tabs that doesn't match the ID
	 $k('.tab:not(#'+stringref+')').hide();
	 //fix
	 if ($k.browser.msie && $k.browser.version.substr(0,3) == "6.0") {
	 $k('.tab#' + stringref).show();
	 }
	 else
	 //display our tab fading it in
	 $k('.tab#' + stringref).fadeIn();
	 
	 //stay with me
	 return false;
	 });
	 
	 $k(".tabbernav a").click(function(){
	$k(".tabbernav a").removeClass("selected");
	$k(this).addClass("selected");
	productListAutoSet();	
	}); 	
	 	     
	
	$k(".tab_product:not(:first)").hide();
	 
	 //to fix u know who
	 $k(".tab_product:first").show();
	 
	 //when we click one of the tabs
	 $k(".tabbernav_product  li  a").click(function(){
	
	 //get the ID of the element we need to show
	 stringref = $k(this).attr("href").split('#')[1];
	 
	 //hide the tabs that doesn't match the ID
	 $k('.tab_product:not(#'+stringref+')').hide();
	 //fix
	 if ($k.browser.msie && $k.browser.version.substr(0,3) == "6.0") {
	 $k('.tab_product#' + stringref).show();
	 }
	 else
	 //display our tab fading it in
	 $k('.tab_product#' + stringref).fadeIn();
	 
	 //stay with me
	 return false;
	 });
	 $k(".tabbernav_product a").click(function(){
		$k(".tabbernav_product a").removeClass("selected");
		$k(this).addClass("selected");
		productListAutoSet();
		  
	}); 
	 
		 
	 $k(".lightbox").fancybox({
		'frameWidth' : 890,
    	'frameHeight' : 630,
		openEffect  : 'fade',
		closeEffect : 'fade',
		helpers: {
        	title: null
    	}
	});
	 

});
	$k(window).load(function() {	
  $k("#spinner").fadeOut("slow");
   $k('.page-title').prependTo('.column-left-breadcrumbs');
   $k('.page-title').prependTo('.col2-left-layout .breadcumb-main');
});
	

function mobileHeaderLink(){  
	$k(".tm_headerlinkmenu" ).addClass('toggle');	 
	$k(".tm_headerlinkmenu .headertoggle_img").click(function(){
	$k(this).parent().toggleClass('active').parent().find('.tm_headerlinks').slideToggle("fast");
	});
}
$k(document).ready(function(){mobileHeaderLink();});


function footerToggleMenu(){
	
	if ($k(window).width() < 980)
	{
		$k("#footer .mobile_togglemenu").remove();
		$k("#footer h6").append( "<a class='mobile_togglemenu'>&nbsp;</a>" );
		$k("#footer h6").addClass('toggle');
		$k("#footer .mobile_togglemenu ").click(function(){
			$k(this).parent().toggleClass('active').parent().find('ul').toggle('slow');
		});

	}else{
		$k("#footer h6").parent().find('ul').removeAttr('style');
		$k("#footer h6").removeClass('active');
		$k("#footer h6").removeClass('toggle');
		$k("#footer .mobile_togglemenu").remove();
	}	
}
$k(document).ready(function(){footerToggleMenu();});
$k(window).resize(function(){footerToggleMenu();}); 

function sidebarToggleColumn(){
	
	if ($k(window).width() <980){	 
		$k('.sidebar .mobile_togglecolumn').remove();
		$k(".sidebar .block-title" ).append( "<span class='mobile_togglecolumn'>&nbsp;</span>" );		 
		$k(".sidebar .block-title" ).addClass('toggle');		 
		$k(".cms-home .sidebar.col-right .block-title" ).removeClass('toggle');	 
		$k(".sidebar .mobile_togglecolumn").click(function(){
			
			$k(this).parent().toggleClass('select').parent().find('.block-content').toggle('slow');
		});
	}
	else{ 
		$k(".sidebar .block-title" ).parent().find('.block-content').removeAttr('style');		 
		$k(".sidebar .block-title" ).removeClass('toggle');		 
		$k(".sidebar .block-title" ).removeClass('select');
		$k('.sidebar .mobile_togglecolumn').remove();		 
	}
}
$k(document).ready(function(){sidebarToggleColumn();});
$k(window).resize(function(){sidebarToggleColumn();});

function menuResponsive(){
	 
	if ($k(window).width() < 980){ 
		$k('#advancedmenu').css('display','none');
		$k('.advanced_nav').css('display','none');
		$k('.nav-responsive').css('display','block');
		 var elem = document.getElementById("nav");
				 if(typeof elem !== 'undefined' && elem !== null) {
					document.getElementById("nav").id= "nav-mobile";
		
		if($k('.main-navigation').hasClass('treeview')!=true){
			$k(".nav-inner").addClass('responsive-menu');			 
			$k(".nav-inner #nav-mobile").treeview({
				animated: "slow",
				collapsed: true,
				unique: true		
			});
			$k('.nav-inner #nav-mobile a.active').parent().removeClass('expandable');
			$k('.nav-inner #nav-mobile a.active').parent().addClass('collapsable');
			$k('.nav-inner #nav-mobile .collapsable ul').css('display','block');
		}
	  } 	 
	}else{
		$k('#advancedmenu').css('display','block');
		$k('.advanced_nav').css('display','block');
		$k('.nav-responsive').css('display','none');	
		$k(".nav-inner .hitarea").remove();
		$k(".nav-inner").removeClass('responsive-menu');	 
		$k("#nav-mobile").removeClass('treeview');
		$k(".nav-inner ul").removeAttr('style');
		$k('.nav-inner li').removeClass('expandable');
		$k('.nav-inner li').removeClass('collapsable');		 
		 var elem = document.getElementById("nav-mobile");
			 if(typeof elem !== 'undefined' && elem !== null) {
				document.getElementById("nav-mobile").id= "nav";
		}
	}
}
$k(document).ready(function(){menuResponsive();});
$k(window).resize(function(){menuResponsive();});


function productCarouselAutoSet() { 
	$k(".main .product-carousel, .additional-carousel .product-carousel, .container-width .product-carousel, .testimonial .product-carousel").each(function() {
		var objectID = $k(this).attr('id');
		var myObject = objectID.replace('-carousel','');
		if(myObject.indexOf("-") >= 0)
			myObject = myObject.substring(0,myObject.indexOf("-"));		
		if(widthClassOptions[myObject])
			var myDefClass = widthClassOptions[myObject];			
		else
			var myDefClass= 'grid_default_width';
		var slider = $k(".main #" + objectID + ", .additional-carousel #"+ objectID + ", .container-width #"+ objectID + ", .testimonial #"+ objectID);		
		slider.sliderCarousel({
			defWidthClss : myDefClass,
			subElement   : '.slider-item',
			subClass     : 'product-block',
			firstClass   : 'first_item_tm',
			lastClass    : 'last_item_tm',
			slideSpeed : 200,
			paginationSpeed : 800,
			autoPlay : false,
			stopOnHover : false,
			goToFirst : true,
			goToFirstSpeed : 1000,
			goToFirstNav : true,
			pagination : false,
			paginationNumbers: false,
			responsive: true,
			responsiveRefreshRate : 200,
			baseClass : "slider-carousel",
			theme : "slider-theme",
			autoHeight : true
		});
		
		var nextButton = $k(this).parent().find('.next');
		var prevButton = $k(this).parent().find('.prev');
		nextButton.click(function(){
			slider.trigger('slider.next');
		})
		prevButton.click(function(){
			slider.trigger('slider.prev');
		})
	});
}
$k(window).load(function(){productCarouselAutoSet();});
//$k(document).ready(function(){productCarouselAutoSet();});


function productListAutoSet() { 
	
	$k("ul.products-grid").each(function(){	
	var objectID = $k(this).attr('id');
		if(objectID.length >0){		
			if(widthClassOptions[objectID.replace('-grid','')])
				var myDefClass= widthClassOptions[objectID.replace('-grid','')];
			}else{ 
			var myDefClass= 'grid_default_width';			
		}	
		$k(this).smartColumnsRows({
			defWidthClss : myDefClass,
			subElement   : 'li',
			subClass     : 'product-block'
		});
	});		
}
$k(window).load(function(){productListAutoSet();});
$k(window).resize(function(){productListAutoSet();}); 

function mobileTabToggle(){
	//alert($(window).width());
	if ($k(window).width() < 768)
	{	
		
		$k(".padder .mobile_togglemenu").remove();
		$k(".padder h6").append( "<h5 class='mobile_togglemenu'>&nbsp;</h5>" );
		$k(".padder h6").addClass('toggle');
		$k(".padder .mobile_togglemenu").click(function(){
			$k(this).parent().toggleClass('active').parent().find('ol').toggle('fast');
		});

	}else{
		$k(".padder h6").parent().find('ol').removeAttr('style');
		$k(".padder h6").removeClass('active');
		$k(".padder h6").removeClass('toggle');
		$k(".padder .mobile_togglemenu").remove();
	}	
}
$k(document).ready(function(){mobileTabToggle();});
$k(window).resize(function(){mobileTabToggle();});



function headerfix() {
 		if ($k(window).width() < 979){
	 			if ($k(this).scrollTop() >140) {
					// alert("1");
							$k(".header").addClass('smaller'); 
							$k(".header-bottom").addClass('fix');
							//$k(".nav-container").appendTo('.header .container-width');
							$k(".nav-container").insertBefore('.header-left');
							
				}else{    //alert("2");
		 					$k(".header").removeClass('smaller'); 
							$k(".header-bottom").removeClass('fix');
							$k(".nav-container").insertBefore('.static-link');
						
				}
		}else{  //alert("3");
			$k(".header").removeClass('smaller');
			$k(".header-bottom").removeClass('fix');
			$k(".nav-container").insertBefore('.static-link');
			
		}
		

}
// jQuery(document).ready(function() {headerfix();});
// jQuery(window).resize(function() {headerfix();});
// jQuery(window).scroll(function() {headerfix();});



$k(window).load(function(){
			
					 
	var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent);
	if(!isMobile) {
		if($k(".parallex").length){  $k(".parallex").sitManParallex({  invert: false });};    
	}else{
		$k(".parallex").sitManParallex({  invert: true });
		
		}	
		
		
	var str1 = $k('.tm_top_currency .sbSelector').text();
	var str2 = $k('.form-language .sbSelector').text();
	
	$k('.tm_top_currency .sbHolder .sbOptions li').each(function() {
			var newtext1 = $k(this);
  			var curr = newtext1.find('a');
			var sample1 = curr.text();
			
			if(str1 === sample1){
				$k(this).addClass('selected');
			}
	});
	
	$k('.form-language .sbHolder .sbOptions li').each(function() {
			var newtext2 = $k(this);
  			var lang = newtext2.find('a');
			var sample2 =	lang.text();
			
			if(str2 === sample2){
				$k(this).addClass('selected');
			}	
	});
	
	
});

$k(document).ready(function() {	

$k("body").append("<a class='top_button' title='Back To Top' href=''>TOP</a>");

$k(window).scroll(function () {
	if ($k(this).scrollTop() > 70) {
		
		$k('.top_button').fadeIn();
	} else {
		$k('.top_button').fadeOut();
	}
});

// scroll body to 0px on click
$k('.top_button').click(function () {
	$k('body,html').animate({
		scrollTop: 0
	}, 800);
	return false;
});
});

/* more */
	//  	jQuery(function($k){
	// if (($k(window).width() > 1201) && ($k(window).width() < 1450)){
	// 	var max_elem = 8;
	// }
	// else if(($k(window).width() > 1024) && ($k(window).width() < 1200)){
	// 	var max_elem = 6;
	// }
	// else if(($k(window).width() > 980) && ($k(window).width() < 1023)){
	// 	var max_elem = 6;
	// }
	// else {var max_elem = 15;}

	// 	//console.log(max_element);
	// 	var items = $k('#advancedmenu .menu');
	// 	//console.log(itemss);
	// 	var surplus = items.slice(max_elem, items.length);
	// 	//console.log(max_element);
	// 	surplus.wrapAll('<div class="level-top hidden_menu menu"><div class="category-wrapper"><ul>');
	// 	$k('.hidden_menu').prepend('<div class="parentMenu"><a href="" class="level-top"><span>Show All Category</span></a></div>');
	// });

