// ------------------------------ //
//         C O N T E N T S        //
// ++++++++++++++++++++++++++++++ //

//	0. Declare global variables
//  1. init prod gallery slider
//  2. init instagram and related products slider
//  3. Accordion->Tabs Functionality
//  4. Switch Colour Swatches // Switch Size Options
//	4A. Toggle Size
//  5. Product Video
//  6. Zoom
//	7. Afterpay Popup
//	8. Reviews Section
//	9. Ratings
//	10. Add to Wishlist
//	11. Check in store popup
//	12. Change location popup
//	13. Submit Review form
//	14. Toggle share icons
//	15. WIN popup
//	16. Add To Cart
//	17. Add To Bag
//	18. Check Instore
//	19. Trigger Product Review
//	20. Hot/Cold Switch
//	21. Product Gallery Functions



// ------------------------------ //
// 0. Declare global variables    //
// ------------------------------ //

var ga_galleryslider = {
	infinite: true,
	slidesToShow: 1,
	slidesToScroll: 1,
	arrows: false,
	dots: true,
	infinite: false,
	touchMove: false
}

var ga_instagramslider = {
	slidesToShow: 6,
	responsive: [
		{
			breakpoint: 1024,
			settings: {
				slidesToShow: 4,
				slidesToScroll: 4
			}
		},
		{
			breakpoint: 750,
			settings: {
				slidesToShow: 3,
				slidesToScroll: 3,
				centerMode: true
			}
		}
	]
}

var ga_relatedslider = {
	slidesToShow: 6,
	responsive: [
		{
			breakpoint: 1024,
			settings: {
				slidesToShow: 4,
				slidesToScroll: 4
			}
		},
		{
			breakpoint: 750,
			settings: {
				slidesToShow: 2,
				slidesToScroll: 2,
				centerMode: true
			}
		}
	]
}

// window width to fix resize() bug on ios
var windowWidth = $(window).width();



// ------------------------------ //
// 1. init prod gallery slider    //
// ------------------------------ //

// function initProductSlider() {
// 	if ( $('body').hasClass('mobile') ) {

// 		if ( $('.hotColdSwitch').length ) {
// 			// ** account for multiple sliders
// 			// loop through multiple sliders
// 			$('.prodGallery').each(function(index, value) {
// 				// declare this variable
// 				var lo_this = $(this);

// 				// check its active and if its init
// 				// unslick any inactive sliders too if any
// 				if ( lo_this.hasClass('slick-initialized') ) {
// 					lo_this.slick('unslick');
// 					return;
// 				}

// 			});

// 			// init slick on the mobile gallery if it has the active class
// 			$('.prodGallery.is-active').slick(ga_galleryslider);
// 			// $('.prodGalleryWrap').removeClass('is-overflowed');
// 		} else {
// 			// unslick if the slider has been initalised
// 			if($('.prodGallery').hasClass('slick-initialized')) {
// 				return;
// 			} else {
// 				$('.prodGallery').slick(ga_galleryslider);
// 			}
// 		}

// 	} else {
// 		// if ( $('.hotColdSwitch').length ) {
// 		// 	// unslick if the slider has been initalised
// 		// 	if($('.prodGallery').hasClass('slick-initialized')) {
// 		// 		return;
// 		// 	} else {
// 		// 		$('.prodGallery').slick(ga_galleryslider);
// 		// 	}
// 		// } else {
// 			// if($('.prodGallery').hasClass('slick-initialized')) {
// 			// 	$('.prodGallery').slick('unslick');
// 			// }
// 		// }

// 		$('.prodGallery').each(function(index, value) {
// 			if ( $(this).hasClass('slick-initialized') ) {
// 				$(this).slick('unslick');
// 			}
// 		});
// 	}
// }

function initProductSlider() {

	if ( $('body').hasClass('mobile') ) {
		if ( $('.hotColdSwitch').length ) {
			function loopSliders(callback) {
				// ** account for multiple sliders
				$('.prodGallery').each(function(index, value) {
					var lo_this = $(this);

					// check if slider has been init and unslick them all
					// also check other galleries if there is more than one
					if ( lo_this.hasClass('slick-initialized') ) {
						lo_this.slick('unslick');
					}
				});
				callback();
			}

			function runProdSlider() {
				// init the gallery with .is-active
				$('.prodGallery.is-active').slick(ga_galleryslider);
				// $('.prodGallery.is-active').slick('slickGoTo', $('.prodGallery.is-active .prodGalleryItemVideo').index() );
				$('.prodGalleryWrap').removeClass('is-overflowed');
			}

			loopSliders(runProdSlider);

		} else {
			// unslick if the slider has been initalised
			if($('.prodGallery').hasClass('slick-initialized')) {
				$('.prodGallery').slick('unslick');
				$('.prodGallery').slick(ga_galleryslider);
				return;
			} else {
				$('.prodGallery').slick(ga_galleryslider);
			}
			$('.prodGalleryWrap').removeClass('is-overflowed');
		}
	} else {
		if ( $('.hotColdSwitch').length ) {
			// ** account for multiple sliders
			// loop through multiple sliders
			$('.prodGallery').each(function() {
				var lo_this = $(this);

				if ( lo_this.hasClass('slick-initialized') ) {
					lo_this.slick('unslick');
				}
			});
		} else {
			if($('.prodGallery').hasClass('slick-initialized')) {
				$('.prodGallery').slick('unslick');
			}
		}
	}


}


// ------------------------------------------------ //
// 2. init instagram and related products slider    //
// ------------------------------------------------ //

function loadProductInsta() {
	if ( $('.prodInsta').length ) {
		$('.prodInsta').slick(ga_instagramslider);
	}

	if ( $('.relatedProds').length ) {
		$('.relatedProds').slick(ga_relatedslider);
	}
}



// ------------------------------------------------ //
// 3. Accordion->Tabs Functionality                 //
// ------------------------------------------------ //

$(document).on('click', '.s-tabTitle', function() {
	var li_child = $(this).data('tab');

	if ( $('body').hasClass('desktop') ) {

		// tabs
		if ( $(this).next('.s-tabContent').css('display') === 'block' ) {
			return;
		} else {
			$(this).parent().find('.s-tabContent').hide();
			$(this).parent().find('.s-tabContent[data-tab="'+li_child+'"]').show();

			$('.s-tabTitle').removeClass('is-active');
			$(this).addClass('is-active');
		}

	} else {
		// accordion
		if ( $(this).next('.s-tabContent').css('display') === 'block' ) {
			$(this).next('.s-tabContent').slideUp();
		} else {
			$(this).parent().find('.s-tabContent').slideUp();
			$(this).parent().find('.s-tabContent[data-tab="'+li_child+'"]').slideDown();
		}
	}
});

$(window).on('resize', function() {
	if ( gs_osname === 'iOS' ) {
		if ( ($(window).width) != windowWidth ) {
			windowWidth = $(window).width;
			if ( $('body').hasClass('desktop') ) {
				$('.s-toTabs .s-tabContent').removeAttr('style');
				$('.s-toTabs .s-tabContent[data-tab=1]').css('display', 'block');
			}
		}
	} else {
		if ( $('body').hasClass('desktop') ) {
			$('.s-toTabs .s-tabContent').removeAttr('style');
			$('.s-toTabs .s-tabContent[data-tab=1]').css('display', 'block');
		}
	}
});



// -------------------------------------------------- //
// 4. Switch Colour Swatches   //
// -------------------------------------------------- //
$(document).on('click', '.j-colourChange', function() {

	var lb_mainproduct = ($(this).hasClass('j-mainProduct')) ? 1 : 0;

	var classname = 'j-mainProduct';
	var prepend = '';

	if (!lb_mainproduct){
		classname = 'j-completeProduct';

		var completethelookindex = $(this).data('completethelookindex');
		prepend = '[data-completethelookindex=' + completethelookindex + ']';
	}

	var completethelookindex = $(this).data('completethelookindex');

	$(this).parent().find(prepend + '.s-swatch.' + classname).removeClass('j-active');
	$(this).addClass('j-active');

	var ls_colourkey = $(this).data('colour-key');
	var li_productid = $(this).data('productid');

	var ls_colour = $(this).data('colour');

	var ls_datalayer = $(this).data('layer');

	if (window.dataLayer && typeof ls_datalayer != 'undefined') {

		ls_datalayer.event = "fbchangecolour";
		psdatalayer.facebook = ls_datalayer.facebook;

		window.dataLayer.push(ls_datalayer);
	}

	/*
	*
	* Colour updates
	*
	*/

	// update colour text
	$(prepend + '.currentColourText').html(ls_colour);

	// if main product, ajax update the product stock for selected colour
	if (lb_mainproduct) {
		$('.checkInstoreLabel').attr('data-colour', ls_colour);
		update_storeoptions(li_productid, ls_colour);
	}

	// Anytime click "j-colourChange", all elements with "j-toggleColour" class will be toggled
	$(prepend + '.j-toggleColour.' + classname).addClass('j-hidden');
	$(prepend + '.j-toggleColour.' + classname + '[data-colour-key="' + ls_colourkey +'"]').removeClass('j-hidden');


	// update image gallery
	if (lb_mainproduct) {

		var lb_comingsoon = $(this).data('comingsoon');

		$.get('/gallery?i='+li_productid+'&c='+escape(ls_colour) +'&cs='+ lb_comingsoon, function(data) {
			$('.prodGalleryWrap').html(data);

			// init image gallery slider
			initProductSlider();
			loadProductVideo();
		});
	}
	else {
		// update "CTL" product image
		$.get('/gallery-ctl?i='+li_productid+'&c='+escape(ls_colour), function(data) {
			$(prepend + '.completeLookThumb').html(data);
		});
	}


	// update URL with new colour url
	var ls_url = $(this).data('product-url');
	if (typeof ls_url !== 'undefined') {
		history.pushState(null, null, ls_url);
	}



	/*
	*
	* Size / barcode updates
	*
	*/

	// Get the element that was selected for the size
	var selectedSizeElement = $('.j-toggleColour.j-sizeChange'+ prepend + '.' + classname + '[data-colour-key="' + ls_colourkey +'"] li.j-selected');

	// If there is none selected, don't update anything else
	if (!selectedSizeElement.length){

		// Clear the add to cart button if there is no size set so we
		// display the 'please select a size' message
		$('.j-atcBtn').data('barcode', '');

		//Make sure a price from this colour is visible
		var ls_firstbarcode = $('.sizeDropdown[data-colour-key="' + ls_colourkey +'"] li:not(.j-disabled)').first().data('barcode');
		$(prepend + '.priceBlock').addClass('j-hidden');
		$(prepend + '.priceBlock[data-barcode="' + ls_firstbarcode + '"]').removeClass('j-hidden');

		return;
	}

	toggleSizeContent(selectedSizeElement.parent(), lb_mainproduct);
});


// ------------------ //
// 4A. Toggle Size   //
// ------------------ //
$(document).on('click', '.s-listToggler', function() {
	$(this).closest('.s-defStyledSelWrap').find('ul').slideToggle();
});

$(document).on('click', '.j-sizeChange li', function() {

	if ($(this).hasClass('j-disabled')) {
		return false;
	}

	var lb_mainproduct = ($(this).parent().hasClass('j-mainProduct')) ? 1 : 0;
	var _parent = $(this).parent();

	_parent.find('li').removeClass('j-selected');
	$(this).addClass('j-selected');

	_parent.slideToggle();
	updateSizeText($(this));

	toggleSizeContent(_parent, lb_mainproduct);

	$('.j-sizeError').hide();
});

function updateSizeText(po_selected) {

	var _this = po_selected;
	var ls_size = _this.html();
	_this.closest('.s-defStyledSelWrap').find('.s-listToggler').html(ls_size);
} //updateSizeText

function toggleSizeContent(po_select, pb_mainProduct) {

	if ( typeof pb_mainProduct == 'undefined' ) {
        pb_mainProduct = true;
    }

	var _this = po_select;

	classname = 'j-mainProduct';
	var prepend = '';

	if (!pb_mainProduct){
		classname = 'j-completeProduct';

		var completethelookindex = $(po_select).data('completethelookindex');
		prepend = '[data-completethelookindex=' + completethelookindex + ']';
	}


	// get size and barcode differently
	var ls_size = _this.find('.j-selected').data('size');
	var li_barcode = _this.find('.j-selected').data('barcode');


	// Anytime change "j-sizeChange", all elements with "j-toggleSize" class will be toggled
	$(prepend + '.j-toggleSize.' + classname).addClass('j-hidden');
	$(prepend + '.j-toggleSize.'+ classname +'[data-barcode="'+ li_barcode +'"]').removeClass('j-hidden');

	// updte barcode on ATC button

	$(prepend + '.j-atcBtn.' + classname).attr('data-barcode', li_barcode);

	// update barcode on Notify buttin
	$(prepend + '.j-notifyBtn').attr('data-barcode', li_barcode);



	// manually update WL icon
	if ( $(prepend + '.j-toggleSize.'+ classname +'[data-barcode="'+ li_barcode +'"][data-inwishlist]').length ) {

		// if IS in WL
		if ($(prepend + '.j-toggleSize.'+ classname +'[data-barcode="'+ li_barcode +'"]').attr('data-inwishlist') == 1 ) {
			$('.wishlistHeart').addClass('j-active');
		}
		else {
			$('.wishlistHeart').removeClass('j-active');
		}

	}

} //toggleBarcodeContent


// ------------------ //
// 5. Product Video   //
// ------------------ //

//PRODUCT: product video
function loadProductVideo() {
	// check if a video exists on the page
	if ( $('.prodVideo').length ) {
		// account for multiple videos
		$('.prodVideo').each(function() {
			var lo_video = $(this)[0];
			var lo_videowrapper = $(this).closest('.prodVideoOuter');
			var lo_galleryitem = $(this).closest('.prodGalleryItemVideo');
			var lo_playbutton = lo_galleryitem.find('.videoTrigger');

			function playVideo() {
				lo_video.play();
				lo_galleryitem.addClass('is-playing');
			}

			// play video automatically on desktop
			if ( lo_video.paused && $('body').hasClass('desktop') ) {
				playVideo();
			}

			// pause video automatically on mobile
			if ( $('body').hasClass('mobile') ) {
				lo_video.pause();
				lo_galleryitem.removeClass('is-playing');
			}

			// play video when clicking on the play button
			lo_playbutton.on('click', function(e) {
				playVideo();
			});

			// pause video when clicking on the video when its playing
			$(lo_video).on('click', function(){
				if ( !lo_video.paused ) {
					lo_video.pause();
					lo_galleryitem.removeClass('is-playing');
				}
			});

			// make sure video is paused when paused
			$(lo_video).on('pause', function() {
				lo_galleryitem.removeClass('is-playing');
			});

			// make sure video is play when played
			$(lo_video).on('play', function() {
				playVideo();
			});

		});
	}

}

function repositionProductGalleryItem() {
	console.log('resposition skipped');
	return;
}



// ------------------ //
// 6. Zoom            //
// ------------------ //

//-- zoom popup on desktop
$(document).on('click', '[data-action="magnify"]', function() {

	var li_imageid = $(this).data('id');

	lo_data = {};
	lo_data.z = li_imageid;

	if ( !$('body').hasClass('mobile') ) {
		loadpopup('zoomPop', '/zoom-popup', lo_data);
	}
});

$(document).on('click', '.zoomPop', function() {
	liftcurtain();
});

//-- zoom on mobile
$(document).ready(function() {
	if ( $('body').hasClass('mobile') ) {
		$('div.pinchzoom').each(function () {
	        new RTP.PinchZoom($(this), {});
	    });
	}
});



// ------------------ //
// 7. Afterpay Popup  //
// ------------------ //

$(document).on('click', '.afterpayPopLink', function() {
	var value = $(this).data('value');
	po_data = {};
	po_data.v = value;
	loadpopup('afterpayPopup', '/afterpay-popup', po_data);
});



// -------------------- //
// 8. Reviews Section   //
// -------------------- //

$(document).on('click', '.reviewAdd', function() {
	$('.newReview').toggle();
});

$(document).on('click', '.newReviewClose', function() {
	$('.newReview').hide();
});

$(document).on('click', '.reviewShow', function() {
	var li_showing = parseInt($('.reviewRow:visible' ).length);
	var li_total = parseInt($('.reviewRow' ).length);
	var li_toshow = parseInt(li_showing + 5);

	for ( var i=0; i<li_toshow; i++ ) {
		$('.reviewRow:nth-child('+ parseInt(i+1) +')').css('display', 'block');
	}

	if ( li_toshow >= li_total ) {
		$(this).addClass('j-hidden');
	}
});



// -------------------- //
// 9. Ratings           //
// -------------------- //

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

// 	$('.ratingStars').each(function() {

// 		if ( $(this).hasClass('j-readonly') ) {
// 			$(this).raty({
// 				starType: 'li',
// 				readOnly: true
// 			});
// 		} else {
// 			$(this).raty({
// 				starType: 'li'
// 			});
// 		}

// 	});
// });

function loadProductStars() {
	$('.ratingStars').each(function() {

		if ( $(this).hasClass('j-readonly') ) {
			$(this).raty({
				starType: 'li',
				readOnly: true
			});
		} else {
			$(this).raty({
				starType: 'li'
			});
		}

	});
}



// -------------------- //
// 10. Add to Wishlist  //
// -------------------- //

/*
Moved to javascript-js
to share logic with category page
*/

// ------------------------- //
// 11. Check in store popup  //
// ------------------------- //

$(document).on('click', '[data-action="change-store"]', function() {
	loadpopup('changeStorePop', '/change-store-popup');
});



// -------------------------- //
// 12. Change location popup  //
// -------------------------- //

$(document).on('click', '[data-action="change-location"]', function(e) {
	e.preventDefault();

	loadpopup('changeLocationPop', '/change-location-popup');

});


$(document).on('submit', '.changeLocationForm', function(e) {

	e.preventDefault();

	$.post('/change-location-popup?a=update', $(this).serializeArray(), function(lo_result){

		if (lo_result.success){
			update_deliveryoptions();
			liftcurtain();
		}

	});
});


function update_deliveryoptions(){

	$('#delivery-options').html('Loading...');

	var lo_request = $('.priceBlock').not('j-hidden').data();
	lo_request.productprice = lo_request.price;

	$.get('/delivery-options', lo_request, function(ls_result){
		$('#delivery-options').html(ls_result);
	});

}


$(document).on('submit', '.changeStoreForm', function(e) {

	e.preventDefault();

	// get productid and colour
	var productid = $('.j-colourChange.j-mainProduct.j-active').data('productid');
	var colour = $('.j-colourChange.j-mainProduct.j-active').data('colour');

	$.post('/change-store-popup?a=update', $(this).serializeArray(), function(lo_result){

		if (lo_result.success){
			update_storeoptions(productid, colour);
			liftcurtain();
		}

	});
});


function update_storeoptions(productid, colour) {

	// update if the area is open
	if ( $('.checkInstoreDrop').css('display') == 'block' ) {

		$('.checkInstoreDrop').html('Loading...');

		$.post('/check-instore', {productid:productid, colour:colour}, function(ls_result){
			$('.checkInstoreDrop').html(ls_result);
		});

	}

}



// -------------------------- //
// 13. Submit Review form     //
// -------------------------- //

$(document).on('submit', '.newReviewForm', function(e) {

	e.preventDefault();

	if ($(this).attr('data-busy') == 1) {
		return false;
	}

	$(this).data('busy', 1);

	var ls_action = $(this).attr('action');
	var form = $(this);
	var formData = form.serialize();

	$('.reviewSuccess').text('').addClass('j-hidden');

	// submit form
	$.ajax({
		url: ls_action,
		type: 'post',
		dataType: 'json',
		data: formData,
		success: function(po_result) {

			$(this).data('busy', 0);

			if (po_result.success) {
				$('.reviewSuccess.s-success').text(po_result.message).removeClass('j-hidden');
				form[0].reset();
			}
			else {
				$('.reviewSuccess.s-error').html(po_result.errors).removeClass('j-hidden');
			}
		},
		error: function() {}
	});

});

// add Raty selection to custom form input field
$(document).on('click', '.s-stars > li', function() {
	$(this).parent().next('input[type="hidden"]').val( $(this).data('alt') )
});



// -------------------------- //
// 14. Toggle share icons     //
// -------------------------- //
$(document).on('click', '.j-share', function() {
	$(this).parent().find('.shareDrop').toggleClass('j-active');
});



// ---------------- //
// 15. WIN popup    //
// ---------------- //
$(document).on('click', '.check-wit', function(e) {

	e.preventDefault();

	var li_barcode = $('.j-atcBtn.j-mainProduct').attr('data-barcode');
	var ls_size = $('.j-sizeChange.j-mainProduct:visible select').find(':selected').data('size');
	var ls_colour = $('.j-colourChange.j-mainProduct.j-active').attr('data-colour');

	var ls_url = '/win-check?i=' +li_barcode + '&s=' + ls_size + '&c=' + ls_colour;

	loadpopup('', ls_url);

});


$(document).on('submit', '#win-check-form', function(e) {

	e.preventDefault();

	var url = $(this).attr('action'),
	suburb = $('#win-suburb').val(),
	postcode = $('#win-postcode').val();

	$.ajax({
 		url: url+'&u='+suburb+'&p='+postcode+'&r=1',
 		type: 'get',
 		success: function (data) {
 			$('#get-it-result').html(data);
 		}
 	});

});



// ------------------ //
// 16. Add To Cart    //
// ------------------ //

$(document).on('click', '.j-atcBtn', function() {

	var li_barcode = $(this).attr('data-barcode');

	if (li_barcode == ''){

		$('.j-sizeError').html('Please select a size');
		$('.j-sizeError').show();
		setTimeout(function(){
			$('.j-sizeError').hide();
		}, 2000);
		return;
	}

	peppercheckout.globals.$eventbus.$emit('addproducttocart', {
		'variantid': li_barcode,
		'quantity': 1
	});

	return false;
});



// ------------------ //
// 17. Add To Bag     //
// ------------------ //

$(window).on('scroll', function() {
	var li_add = document.querySelector('.buttonRowAddCart').getBoundingClientRect().top - 77;
	var li_returns = document.querySelector('.deliveryReturns').getBoundingClientRect().top - 77;

	if ( li_add < 0 ) {
		$('body').addClass('j-fixedaddcart');
	}

	if ( li_returns > 0 ) {
		$('body').removeClass('j-fixedaddcart');
	}
});



// ------------------ //
// 18. Check Instore  //
// ------------------ //

$(document).on('click', '.checkInstoreLabel', function() {

	if ( $(this).next().css('display') == 'block' ) {
		$(this).next().slideUp();
	} else {
		$('.checkInstoreDrop').html('Loading....');
		$(this).next().slideDown();

		var ls_colour = $(this).attr('data-colour');
		var li_productid = $(this).data('productid');

		$.get('/check-instore?productid='+li_productid+'&colour='+escape(ls_colour), function(data) {
			$('.checkInstoreDrop').html(data);
		});
	}

});



// -------------------------- //
// 19. Trigger Product Review //
// -------------------------- //

function loadProductReview() {
	if (location.search) {
		var params = {};

		var parts = location.search.substring(1).split('&');

		for (var i = 0; i < parts.length; i++) {
			var nv = parts[i].split('=');
			if (!nv[0]) {
				continue;
			}
			params[nv[0]] = nv[1] || true;
		} // for


		if ('utm_campaign' in params) {
			if (params['utm_campaign'].indexOf('review-win') !== -1) {
				setTimeout(function(){
					document.getElementById('j-prodInfoBlock').scrollIntoView();
					$('.s-tabTitle[data-tab="3"]').click();
					$('.reviewAdd').click();
				}, 2000);
			}
		}
	}
}



// -------------------------- //
// 20. Hot/Cold Switch        //
// -------------------------- //

$(document).on('click', '.j-switch-season', function() {

	var _this = $(this);
	_this.toggleClass('is-hot');

	var season = _this.hasClass('is-hot') ? 'hot' : 'cold';

	$('.prodGallery--hot, .prodGallery--cold').toggleClass('is-active');

	initProductSlider();

	$(window).resize();

	setCookie('PRODSEASON', season, 7); // 7 days

	if (window.dataLayer) {

		if ( ecom != undefined
			&& ecom.hasOwnProperty('detail')
			&& ecom.detail.hasOwnProperty('products')
			&& ecom.detail.products[0] != undefined) {

			window.dataLayer.push({
				'event': 'eventTracking',
				'eventcategory': 'Product',
				'eventaction': 'HotColdSwitch',
				'eventlabel' : ecom.detail.products[0].id + ' - ' + season ,
			});

		}

	}

});

function setCookie(cname, cvalue, exdays) {
	var d = new Date();
	d.setTime(d.getTime() + (exdays*24*60*60*1000));
	var expires = "expires="+ d.toUTCString();
	document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}



// ------------------------------- //
// 21. Product Page Functions      //
// ------------------------------- //

function loadProductPage() {
	loadProductInsta();
	loadProductStars();
	loadProductReview();
	loadProductVideo();
	initProductSlider();
}



$(document).ready(function() {
	loadProductPage();

	$(window).on('resize', function() {
		if ( gs_osname === 'iOS' ) {
			if ( ($(window).width) != windowWidth ) {
				windowWidth = $(window).width;
				initProductSlider();
			}
		} else {
			initProductSlider();
		}
	}).resize();

});