﻿$(document).ready(function() {
	//Init Left navigation
	$("ul.sf-menu").superfish({
		//animation: {height:'show'},   // slide-down effect without fade-in
		delay: 1200,               // 1.2 second delay on mouseout
		onBeforeShow: function() {
			if (this.length > 0) {
				var bottom = this.closest('td').position().top + this.parent().position().top + $(this).height();
				var windowBottom = $(window).scrollTop() + $(window).height();
				//alert(bottom + ', ' + windowBottom); // > windowBottom
				if (bottom > windowBottom) {
					this.css('margin-top', (windowBottom - bottom) + 'px');
				}
			}
		},
		onHide: function() {
			this.css('margin-top', '');
		}
	});

	//Init chat buttons
	var _lpChatBtn = $('#_lpChatBtn').click(function() {
		lpButtonCTTUrl = 'https://server.iad.liveperson.net/hc/35482552/?cmd=file&file=visitorWantsToChat&site=35482552&imageUrl=https://images.liveperson.com/lp/35482552&referrer=' + escape(document.location);
		lpButtonCTTUrl = (typeof (lpAppendVisitorCookies) != 'undefined' ? lpAppendVisitorCookies(lpButtonCTTUrl) : lpButtonCTTUrl);
		lpButtonCTTUrl = ((typeof (lpMTag) != 'undefined' && typeof (lpMTag.addFirstPartyCookies) != 'undefined') ? lpMTag.addFirstPartyCookies(lpButtonCTTUrl) : lpButtonCTTUrl);
		window.open(lpButtonCTTUrl, 'chat35482552', 'width=475,height=400,resizable=yes');
		return false;
	});
	$('img', _lpChatBtn)[0].src = 'https://server.iad.liveperson.net/hc/35482552/?cmd=repstate&site=35482552&channel=web&&ver=1&imageUrl=https://images.liveperson.com/lp/35482552';
});

//Function used for color swatches
function switchColor(sender, groupID, price, isSale, salePrice, volumePrice) {
	var prodName = sender.getAttribute('prodname');
	var imagePath = sender.getAttribute('image');
	var descr = sender.getAttribute('descr');

	var holder = $('#holder_' + groupID)[0];
	if (typeof (holder.imageLink) == 'undefined') {
		holder.imageLink = $('a.prodNameImage', holder)[0];
		holder.image = $('img', holder.imageLink)[0];
		holder.nameLink = $('a.prodNameLink', holder)[0];
		holder.price = $('.priceHolder', holder)[0];
	}

	holder.imageLink.href = holder.nameLink.href = sender.href;
	holder.nameLink.innerHTML = prodName;
	holder.image.src = imagePath;
	holder.image.alt = descr;

	var priceHolder = $('.priceHolder', holder);
	var strPrice = "Price:&nbsp;&nbsp;"
	if (isSale == 1)
		strPrice += "<span class='saleOldPrice'>";

	strPrice += "$" + price.toFixed(2, 10);

	if (isSale == 1)
		strPrice += "</span><br /><span class='saleNewPrice'>Sale Price: $" + salePrice.toFixed(2, 10) + "</span>";

	if (volumePrice > 0)
		strPrice += "<br /><span style='color:#FF0000;'>with volume discount as low as $" + volumePrice.toFixed(2, 10) + " each.</span>"

	holder.price.innerHTML = strPrice;
}