// JavaScript Document
jQuery(document).ready(function() {
	
	var storePrimaViewPortWidth = '',
		storePrimaViewPortHeight = '',
		storePrimaChangeNavBg = true,
		storePrimaSliderCurrentItem = '',
		storePrimaSliderMove = false,
		storeprimaTabMargins = {},
		storeprimaSliderHeights = [],
		storeprimaSliderHeight = 0;		;

	function storePrimaViewport(){

		storePrimaViewPortWidth = jQuery(window).width(),
		storePrimaViewPortHeight = jQuery(window).outerHeight(true);	
		
		jQuery('.menu-container, .site-buttons').removeAttr('style');
		jQuery('#masthead').addClass('site-header-bg');
		
		if( storePrimaViewPortWidth > 1200 ){
			
			jQuery('.main-navigation').removeAttr('style');
			
			var storePrimaSiteHeaderHeight = jQuery('.site-header').outerHeight();
			var storePrimaSiteHeaderWidth = jQuery('.site-header').width();
			var storePrimaSiteHeaderPadding = ( storePrimaSiteHeaderWidth * 2 )/100;
			var storePrimaMenuHeight = jQuery('.menu-container').height();
			
			var storePrimaMenuButtonsHeight = jQuery('.site-buttons').height();
			
			var storePrimaMenuPadding = ( storePrimaSiteHeaderHeight - ( (storePrimaSiteHeaderPadding * 2) + storePrimaMenuHeight ) )/2;
			var storePrimaMenuButtonsPadding = ( storePrimaSiteHeaderHeight - ( (storePrimaSiteHeaderPadding * 2) + storePrimaMenuButtonsHeight ) )/2;
		
			
			jQuery('.menu-container').css({'padding-top':storePrimaMenuPadding});
			jQuery('.site-buttons').css({'padding-top':storePrimaMenuButtonsPadding});
			
			if( storePrimaJs.frontpage ){
			   
				jQuery('#masthead').removeClass('site-header-bg');
			   
			}else{
			   
				jQuery('.site-header').addClass('site-header-bg').css({'position':'static'});
				
			}
			
		}	
	
	}
	
	function storeprimaTabsSetup(){
		
		jQuery('.storeprima-tabs-one-content-inner, .storeprima-tabs-one-content-rated, .storeprima-tabs-one-content-sales, .storeprima-tabs-one-content-viewed').removeAttr('style');
		
		var storeprimaTabWidth = jQuery('.storeprima-tabs-one-content-inner').width();
		var storeprimaTabPadding = ( storeprimaTabWidth * 20 )/100;
		
		
		jQuery('.storeprima-tabs-one-content-inner').css({'width':((3 * storeprimaTabWidth) + ( 3 * storeprimaTabPadding ))});
		jQuery('.storeprima-tabs-one-content-rated, .storeprima-tabs-one-content-sales, .storeprima-tabs-one-content-viewed').css({'width':storeprimaTabWidth, 'margin-right':storeprimaTabPadding, 'display':'block'});
		
		storeprimaTabMargins['rated'] = 0;
		storeprimaTabMargins['sales'] = ( storeprimaTabWidth + storeprimaTabPadding );
		storeprimaTabMargins['viewed'] = ( storeprimaTabWidth + storeprimaTabPadding ) * 2;
		
	}
	
	function storeprimaSlideHeights(){
		
			jQuery('.storeprima-slider-one-container .storeprima-slider-one-item').each(function(){
				
				storeprimaSliderHeights.push(jQuery(this).outerHeight());
				
			});
			
			storeprimaSliderHeight = Math.max.apply(Math, storeprimaSliderHeights);
			jQuery('.storeprima-slider-one-container .storeprima-slider-one-item-overlay').css({'min-height':storeprimaSliderHeight});			
		
	}	
	
	jQuery('.site-branding .search-button').on('click', function(e){
		
		e.preventDefault();
		if( storePrimaViewPortWidth > 1200 ){

			jQuery('.fullSearchContainer').css({'height':storePrimaSiteHeaderHeight,'position':'fixed','top':'0','left':'0'}).fadeIn(500);
		
		}else{
			jQuery('.main-navigation').slideToggle();
			jQuery('.site-search input[type="text"]').focus();
		}	
		
				
	});

	jQuery('.site-branding .menu-button').on('click', function(e){
		
		e.preventDefault();
		if( storePrimaViewPortWidth > 1200 ){

		}else{
			jQuery('.main-navigation').slideToggle();
		}				
		
				
	});	



	jQuery('.site-buttons .search-button').on('click', function(e){

		e.preventDefault();
		
		if( storePrimaViewPortWidth > 1200 ){

		
			jQuery('.fullSearchContainer').css({'height':storePrimaViewPortHeight,'position':'fixed','top':'0','left':'0','z-index':'99'}).fadeIn(500, function(){
				
				var fullSearchContainerHeight = jQuery('.fullSearchFieldContainer').height();
				var fullSearchContainerPadding = ( storePrimaViewPortHeight - fullSearchContainerHeight ) / 2;
			
			
				jQuery('.fullSearchFieldContainer').css({'padding-top':fullSearchContainerPadding}).fadeIn(1000);
				jQuery('.fullSearchFieldInnerContainer input[type="text"]').focus();
				
			});
		
		}	
		
				
	});	
	
	jQuery('.fullSearchContainerClose').on('click', function(){
		
		if( storePrimaViewPortWidth > 1200 ){

			jQuery('.fullSearchContainer').fadeOut(1000, function(){
				jQuery('.fullSearchContainer, .fullSearchFieldContainer').removeAttr('style');
			});
		
		}	
		
				
	});
	
	jQuery('.fullSearchFieldInnerContainer a').on('click', function(e){
		
		e.preventDefault();
		
		if( storePrimaViewPortWidth > 1200 ){

			jQuery('.fullSearchContainer').fadeOut(1000, function(){
				jQuery('.fullSearchContainer, .fullSearchFieldContainer').removeAttr('style');
			});
			
			jQuery('.site-buttons .search-button').focus();
		
		}	
		
				
	});
	
	jQuery('.storeprima-tabs-one-heading span').on('click', function(){
		
		var storeprimaTabName = jQuery(this).attr('data-storeprima-tab');
		jQuery('.storeprima-tabs-one-heading span').removeClass('storeprima-tabs-active');
		jQuery(this).addClass('storeprima-tabs-active');
		
		console.log(storeprimaTabName);
		console.log(storeprimaTabMargins);
		
		jQuery('.storeprima-tabs-one-content-inner').animate(
		
			{
				'margin-left': '-' + storeprimaTabMargins[storeprimaTabName],
			},
			2000,
			function(){
				
			}
		
		);
		
	});		
	
	function storePrimaScroll(){
		
		if( storePrimaJs.frontpage ){
		   
			var storePrimaScroll = jQuery(window).scrollTop();

			if( storePrimaViewPortWidth > 1200 ){

				if( storePrimaScroll > ( storePrimaViewPortHeight - 150 ) ){

					if( true == storePrimaChangeNavBg ){

						if( false === jQuery('#masthead').hasClass("site-header-bg") ){

						   storePrimaChangeNavBg = false;

						   jQuery('#masthead').animate(

							   {'opacity':0},
							   1000,
							   function(){
								   jQuery('#masthead').addClass('site-header-bg').animate(

									   {'opacity':1},
									   1000,
									   function(){
										   storePrimaChangeNavBg = true;
									   }

								   );
							   }

						   );

						}					

					}

				}else{

					if( true == storePrimaChangeNavBg ){

						if( true === jQuery('#masthead').hasClass("site-header-bg") ){

						   storePrimaChangeNavBg = false;

						   jQuery('#masthead').animate(

							   {'opacity':0},
							   1000,
							   function(){
								   jQuery('#masthead').removeClass('site-header-bg').animate(

									   {'opacity':1},
									   1000,
									   function(){
										   storePrimaChangeNavBg = true;
									   }

								   );
							   }

						   );

						}					

					}				

				}

			}		   
		   
		}
		
	}	

    var storePrimaOwl = jQuery("#store-prima-owl-basic");
         
    storePrimaOwl.owlCarousel({
             
      	slideSpeed : 300,
      	paginationSpeed : 400,
      	singleItem:true,
		navigation : false,
      	pagination : true,
      	navigationText : false,
		afterInit: function(){

		}
         
    });	
	
    var storePrimaProductOwl = jQuery("#storeprima-slider-container");
         
    storePrimaProductOwl.owlCarousel({
             
      	slideSpeed : 300,
      	paginationSpeed : 400,
      	singleItem:true,
		navigation : false,
      	pagination : true,
      	navigationText : false,
		afterInit: function(){

			storeprimaSlideHeights();
			
		}
         
    });		
	
    var storePrimaTestimonialsOwl = jQuery("#store-prima-testimonials");
         
    storePrimaTestimonialsOwl.owlCarousel({
             
      	slideSpeed : 300,
      	paginationSpeed : 400,
      	singleItem:true,
		navigation : false,
      	pagination : false,
      	navigationText : false,
         
    });	
	
	jQuery('.store-prima-testimonials-nav-prev').on('click', function(e){
		
		e.preventDefault();
		storePrimaTestimonialsOwl.trigger('owl.prev');
		//storePrimaOwl.trigger('owl.next');
		
	});
	
	jQuery('.store-prima-testimonials-nav-next').on('click', function(e){
		
		e.preventDefault();
		storePrimaTestimonialsOwl.trigger('owl.next');
		//storePrimaOwl.trigger('owl.next');
		
	});	
	
	jQuery(window).on("resize",function(){
		
		storePrimaViewport();
		storeprimaTabsSetup();
		
	});
	
	jQuery(window).on("load", function() {

		storeprimaSlideHeights();
		
	});	
	
	storePrimaViewport();
	storeprimaTabsSetup();
	jQuery(window).on("scroll", storePrimaScroll);
	
});		