fW(document).ready(function(){		
	aarcadeGlobalBind();
	if(fW('#product_main').hasClass('do_fade')) {
		var fadeLow = 100;
		var fadeHigh = 200;
	} else {
		var fadeLow = 0;
		var fadeHigh = 0;	
	}
	fW('.images_nav a').click(function(event){
		event.preventDefault();
		var theClick = fW(this);
		var navWRAP = fW(this).closest('.images_nav');
		var imgWRAP = fW('.image_wrap').first();
		var clickIND = fW(this).attr('data-imgind');
		var activeDIV = fW('.image_wrap').first().find('.active').first();
		var activeIND = activeDIV.attr('data-imgind');
		if(clickIND != activeIND) {
			activeDIV.fadeOut(fadeLow, function(){
				fW(this).removeClass('active');
				imgWRAP.find('.product_img').removeClass('active');
				imgWRAP.find('.product_img[data-imgind="'+ clickIND +'"]').first().fadeIn(fadeHigh, function(){
					fW(this).addClass('active');
					navWRAP.find('a').removeClass('nav_active');
					theClick.addClass('nav_active');
				});
			});
		}
	});
	fW('#images_next_nav').click(function(event){
		event.preventDefault();
		var navWRAP = fW(this).closest('.images_nav');
		var imgWRAP = fW('.image_wrap').first();
		var activeDIV = fW('.image_wrap').first().find('.active').first();
		var nextDIV = activeDIV.next('.product_img');
		var nextDIVURL = activeDIV
		if(isEmpty(nextDIV)) nextDIV = imgWRAP.find('.product_img').first();
		if(! isEmpty(nextDIV)) {
			activeDIV.fadeOut(fadeLow, function(){
				fW(this).removeClass('active');
				imgWRAP.find('.product_img').removeClass('active');
				nextDIV.fadeIn(fadeHigh, function(){
					fW(this).addClass('active');
					var nextIND = nextDIV.attr('data-imgind');
					navWRAP.find('a').removeClass('nav_active');
					if(! isEmpty(nextIND) ) navWRAP.find('a[data-imgind="'+ nextIND +'"]').first().addClass('nav_active');
				});
			});
		}
	});	
	fW('#images_prev_nav').click(function(event){
		event.preventDefault();
		var navWRAP = fW(this).closest('.images_nav');
		var imgWRAP = fW('.image_wrap').first();
		var activeDIV = fW('.image_wrap').first().find('.active').first();
		var nextDIV = activeDIV.prev('.product_img');
		if(isEmpty(nextDIV)) nextDIV = imgWRAP.find('.product_img').last();
		if(! isEmpty(nextDIV)) {
			activeDIV.fadeOut(fadeLow, function(){
				fW(this).removeClass('active');
				imgWRAP.find('.product_img').removeClass('active');
				nextDIV.fadeIn(fadeHigh, function(){
					fW(this).addClass('active');
					var nextIND = nextDIV.attr('data-imgind');
					navWRAP.find('a').removeClass('nav_active');
					if(! isEmpty(nextIND) ) navWRAP.find('a[data-imgind="'+ nextIND +'"]').first().addClass('nav_active');
				});
			});
		}
	});
	if(fW('#product-options').hasClass('advanced') && fW('select#option option').length) {
		var js_sel = '';		
		fW('select#option option').each(function(index){
			var js_sel_hyphen = fW(this).text().indexOf(' -');
			if(js_sel_hyphen != -1)
				var js_sel_text = fW(this).text().substr(0, fW(this).text().indexOf(' -') );
			else
				var js_sel_text = fW(this).text();
			if(js_sel_text.length > 34)
				var js_sel_trunc = fW.trim(js_sel_text.substr(0, 36)) + "…";
			else
				var js_sel_trunc = js_sel_text;				 	
			js_sel += '<div class="js_opt num_'+ index +'" data-val="'+ fW(this).val() +'" data-text="'+ js_sel_text +'" data-trunc="'+ js_sel_trunc +'"><span class="js_opt_t">'+ js_sel_trunc +'</span><span class="js_opt_p"><span>'+ window.stCurrency +'</span>'+ fW(this).attr('data-mon') +'</span><span class="down_arr"></span><span class="clear"></span></div>';
		});
		fW('#product-options').append('<div id="js_sel"><div id="js_sel_inner">'+ js_sel +'</div></div>');
		fW('select#option').hide();
		fW('#js_sel').find('.js_opt.num_0').addClass('on');
		fW('#js_sel_inner').mouseleave(function(){
			fW(this).closest('#js_sel').find('.js_opt').each(function(){
				var jsTe = fW(this).attr('data-text');
				var jsTr = fW(this).attr('data-trunc');
				if(jsTe != jsTr) fW(this).find('.js_opt_t').text(jsTr);
			});
			fW(this).closest('#js_sel').removeClass('on');
		});
		fW('#js_sel').find('.js_opt').click(function(){
			if(fW(this).closest('#js_sel').hasClass('on')) {
				if(!fW(this).hasClass('on')) {
					var thisVal = fW(this).attr('data-val');
					fW(this).addClass('on').siblings().removeClass('on');
					fW(this).closest('#product-options').find('select#option option').val(thisVal);
				}
				fW(this).closest('#js_sel').removeClass('on');
				fW(this).closest('#js_sel').find('.js_opt').each(function(){
					var jsTe = fW(this).attr('data-text');
					var jsTr = fW(this).attr('data-trunc');
					if(jsTe != jsTr) fW(this).find('.js_opt_t').text(jsTr);
				});
			} else {
				fW(this).closest('#js_sel').find('.js_opt').each(function(){
					var jsTe = fW(this).attr('data-text');
					var jsTr = fW(this).attr('data-trunc');
					if(jsTe != jsTr) fW(this).find('.js_opt_t').text(jsTe);
				});
				fW(this).closest('#js_sel').addClass('on');
			}
		});
	} else if(fW('#product-options').hasClass('radio') && fW('#product-options li').length) {
		fW('#product-options input:checked').closest('label').addClass('on');
		fW('#product-options input').click(function(){
			fW('#product-options label').removeClass('on');
			fW('#product-options input:checked').closest('label').addClass('on');
		});
	}
	fW('td.item_options .remove_btn').bind('click', function(event){
		event.preventDefault();
		fW(this).closest('td').siblings('.item_qty').first().find('input').first().val('0');
		fW('#cart_form').submit();
	});
	fW('button.checkout_btn').bind('click', function(event){
		event.preventDefault();
		fW('#cart_form').attr('action', '/cart?checkout=1');
		fW('#cart_form').submit();
	});
	var gIEv = getInternetExplorerVersion();
	if(!isEmpty(gIEv) && gIEv != -1 && gIEv <= 7) {
		jQuery('#products .shop_thumb_img_holder img').click(function(){
			var linkURI = jQuery(this).closest('a').attr('href');
			if(!isEmpty(linkURI)) location.href = linkURI;
		});
	}
	fW('.product_img a').colorbox({speed: 300, maxWidth: '90%', maxHeight: '96%'});
	fW('a.colorbox').each(function(){
		var boxType = fW(this).attr('data-type');
		if(isEmpty(boxType)) {
			fW(this).colorbox({speed: 300, maxWidth: '90%', maxHeight: '96%'});
		} else if (boxType == 'webpage') {
			var boxWidth = fW(this).attr('data-width');
			if(isEmpty(boxWidth)) boxWidth = "80%";
			var boxHeight = fW(this).attr('data-height');
			if(isEmpty(boxHeight)) boxHeight = "80%";
			var boxBG = fW(this).attr('data-background');
			if(isEmpty(boxBG)) boxBG = "#ffffff";
			var overBG = fW(this).attr('data-overlay');
			if(isEmpty(overBG)) overBG = "#dddddd";
			fW(this).colorbox({ speed: 300, width:boxWidth, height:boxHeight, iframe:true, maxWidth: '90%', maxHeight: '96%',
				onComplete:function(){ disableWindowScroll(); fW("#cboxLoadedContent").css('background-color', boxBG); fW("#cboxOverlay").css('background-color', overBG); },
				onClosed:function(){ enableWindowScroll(); }
			});	
		} else {
			fW(this).colorbox({speed: 300, maxWidth: '90%', maxHeight: '96%'});		
		}
	});
	var cookieCheck = fW.cookies.get('aarcookiecheck');
	if(cookieCheck != 'yes') {
		fW.cookies.set('aarcookiecheck', 'yes');
		cookieCheck = fW.cookies.get('aarcookiecheck');
		if(cookieCheck != 'yes') {
			fW('#wrap').before('<div class="public_notice no_cookie" style="background-color: #cc0000;"><div class="notice_inner"><strong>Please <a href="http://goo.gl/Xtfb9" target="_blank">enable Cookies on your web browser</a> to use this web site!</strong></div></div>');
		}
	}
	var canonicalURI = fW('link[rel="canonical"]').first().attr('href'); 
	if( !isEmpty (canonicalURI) ) {
		if(canonicalURI.search("http://theme.aarcadethemes.com/") != -1) { aarcadePreviewSetup(); }
	}
});
fW(window).load(function(){
	if(fW('.slide_show').length) {
		var nivoJar = new Array();
		fW('.slide_show').each(function(index){
			nivoJar[index] = fW(this);
			fW(this).children('br').remove();
			fW(this).find('.nivo-html-caption').each(function(){
				var captionContent = fW.trim(fW(this).html());
				var captionContentnobr = captionContent.replace(/^(<br\s*\/?>\s*)+/i, '');
				var captionContentnobr = captionContentnobr.replace(/(<br\s*\/?>\s*)+$/i, '');
				if(isEmpty(captionContentnobr)) {
					fW(this).prev().removeAttr('title').find('img').removeAttr('title');
					fW(this).remove();
				} else {
					if(captionContent != captionContentnobr) fW(this).html(captionContentnobr);
					fW(this).closest('.slide_main').find('.slide_caption_main').append(fW(this));
				}
			});
			slideProceed(nivoJar[index]);
		});
	}
});
function aarcadeGlobalBind() {
	fW('.hide-if-no-js').show();
	fW('.hide-if-js').fadeOut(200, function(){
			fW(this).hide();
	});
	fW("a[href^='#']").unbind('click').bind('click', function(event) { 
		event.preventDefault();
		var anchornameraw = fW(this).attr("href");
		var anchorname = anchornameraw.substr(1);
		if (fW("a[name=" + anchorname + "]").length) {
			scrolltopanchor = fW("a[name=" + anchorname + "]").offset().top;
		} else {
			scrolltopanchor = fW("#" + anchorname).offset().top;
		}
		if (anchorname != "top_of_page") {
			scrolltopanchor = scrolltopanchor - 30;
		}
		fW("html, body").animate({
			scrollTop: scrolltopanchor
			}, 800);
		return false;
	});
	fW('.nav_menu').each(function(){
		fW(this).find('.bul').removeClass('no');
		fW(this).find('ul').first().children('li').slice(2).each(function(){
			var chkT = 0;
			chkT = fW(this).closest('.nav_menu').attr('data-lit');
			firstbulW = fW(this).closest('.nav_menu').attr('data-bulw');
			if(isEmpty(chkT)) {
				var firstli = fW(this).closest('.nav_menu').find('li').first();
				var firstliP = firstli.position();
				chkT = firstliP.top + 8;
				if(!isEmpty(chkT)) fW(this).closest('.nav_menu').attr('data-lit', chkT);
				else chkT = 0;
				var firstbul = fW(this).closest('.nav_menu').find('li .bul').first();
				firstbulW = parseInt(firstbul.css('padding-left')) + parseInt(firstbul.css('padding-right')) + parseInt(firstbul.width());
				if(!isEmpty(firstbulW)) fW(this).closest('.nav_menu').attr('data-bulw', firstbulW);
				else firstbulW = 0;
			}
			var liPosition = fW(this).position();
			if(liPosition.top > chkT) {
				chkT = liPosition.top + 8;
				fW(this).closest('.nav_menu').attr('data-lit', chkT);
				fW(this).find('.bul').addClass('no');
				var liNewPos = fW(this).position();
				if(liPosition.top != liNewPos.top) {
					fW(this).before('<li class="bul_rep" style="width: '+ firstbulW +'px;"></li>');
				}
			}
		});
	});
	fW('li.drpdwn').each(function(){
		var drpdwnUl = fW(this).find('ul').first();
		if(!isEmpty(drpdwnUl)) {
			var aL = fW(this).find('a').first().position().left;
			if(isEmpty(aL)) aL = fW(this).find('.link_text').first().position().left;
			var uaL = parseInt(drpdwnUl.find('a').first().css('padding-left'));
			var thisL = aL - uaL;
			drpdwnUl.css('left', thisL + 'px');
			var drpdwnUlH = drpdwnUl.height();
			var drpMaxH = 330;
			if(!isEmpty(drpdwnUlH) && drpdwnUlH > drpMaxH) {
				fW(this).addClass('drpbig');
				drpdwnUl.children().not(':last').append(', ');
				var drpdwnUlP = parseInt(drpdwnUl.css('padding-left'));
				var thisL = aL - drpdwnUlP;
				drpdwnUl.css('left', thisL + 'px');
				drpdwnUlH = drpdwnUl.height();
				drpdwnUlW = drpdwnUl.width();
				wpls = 10;
				while(!isEmpty(drpdwnUlH) && drpdwnUlH > drpMaxH) {
					if(wpls > 680) break;
					drpdwnUl.width(drpdwnUlW + wpls);
					drpdwnUlH = drpdwnUl.height();
					wpls++;
				}
				drpdwnUlW = drpdwnUl.width();
				var drpL = fW(this).offset().left;
				var contL = fW('#container').offset().left;
				var contW = fW('#container').width();
				if(!isEmpty(drpdwnUlW) && !isEmpty(drpL) && !isEmpty(contL)) {
					drpdwnUlR = drpdwnUlW + aL + drpL - contL;
					chkW = isEmpty(contW) ? 950 : (contW);
					chkX = chkW - drpdwnUlR;
					if(chkX < 0) drpdwnUl.css('left', chkX + 'px');
				}
				var drpT = fW(this).offset().top;
				var contT = fW('#container').offset().top;
				var contH = fW('#container').height();
				if(!isEmpty(drpdwnUlH) && !isEmpty(drpT) && !isEmpty(contT)) {
					drpdwnUlB = drpdwnUlH + drpT;
					chkH = isEmpty(contH) ? 300 : (contH - 30);
					contB = chkH + contT;
					if(drpdwnUlB > contB) drpdwnUl.css({
						'top' : 'auto',
						'bottom' : '94%'
					});
				}
			}
		}
	});
	fW('li.drpdwn').unbind('mouseenter').bind('mouseenter', function(){
		fW(this).find('ul').first().hide().fadeIn(200);
	});
	fW('li.drpdwn').unbind('mouseleave').bind('mouseleave', function(){			
		fW(this).find('ul').first().fadeOut(150);
	});
	var formJar = new Array();
	fW('form').each(function(i) {
		fW(this).find('input[type="text"]').each(function(k) {
			formJarIndex = i + '-' + k;
			fW(this).attr('data-ind', formJarIndex);
			formJar[formJarIndex] = fW(this).val();
		});
	});
	fW('input[type="text"]').unbind('click').bind('click', function() {
		var formJarIndex = fW(this).attr('data-ind');
		if(formJarIndex) {
			if(fW(this).val() == formJar[formJarIndex]) fW(this).val('');
		}
		if(fW(this).closest('.form_wrap').hasClass('news_form')) {
			if(isEmpty(fW('#news_instr').length)) {
				var newsL = 152 - parseInt(fW(this).closest('.form_wrap').width());
				var newsR = '';
				if(newsL < 14) { newsR = ' style="right:'+ (8-newsL) +'px;"'; newsL = 14; }
				fW(this).closest('.form_wrap').append('<div id="news_instr"'+newsR+'><span class="pnt" style="margin-left:'+newsL+'px;"></span><span class="msg">enter your e-mail address</span></div>');
			}
			fW('#news_instr').fadeIn(300);
		}
	});
	fW('input[type="text"]').unbind('blur').bind('blur', function() {
		var formJarIndex = fW(this).attr('data-ind');
		if(formJarIndex) {
			if(! fW(this).val().length ) fW(this).val(formJar[formJarIndex]);
		}
		fW('#news_instr').fadeOut(200);
	});	
}
function isEmpty(mixed_var) {
    var key; 
    if (mixed_var === "" || mixed_var === 0 || mixed_var === "0" || mixed_var === null || mixed_var === false || typeof mixed_var === 'null' || typeof mixed_var === 'undefined' || mixed_var.length === 0) { return true; } 
    if (typeof mixed_var == 'object') {
        for (key in mixed_var) { return false; }
        return true;
    }
    return false;
}
function isAppleDevice() {
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)))
		return true;
	return false;
}
function disableWindowScroll() {
	var top = fW(window).scrollTop();
	var left = fW(window).scrollLeft();
	fW(window).bind('scroll', function(e){
		e.preventDefault();		
		fW(this).scrollTop(top).scrollLeft(left);
		return false;
	});
}
function enableWindowScroll() {
	fW(window).unbind('scroll');
}
function oc(a) {
	var o = {};
	for(var i=0;i<a.length;i++) { o[a[i]]=''; }
	return o;
}
function loadImagesThenProceed(slideContainer, slideNumber) {
	var imagesLoaded = 0;
	slideContainer.find('img').each(function(){
		fW(this).load(function() { imagesLoaded++; 
			loadImagesCallback(slideContainer, imagesLoaded, slideNumber);
		});
	});
}
function slideProceed(slideContainer) {
	var rawTheme = slideContainer.attr('data-theme');
	var boxTheme = 1;
	var vTheme = 1;
	if(!isEmpty(rawTheme)) {
		var exTheme = rawTheme.split('-');
		vTheme = isEmpty(exTheme[0]) ? 0 : parseInt( exTheme[0] );
		boxTheme = isEmpty(exTheme[1]) ? 0 : parseInt( exTheme[1] );
	}
	var slideMaxWidth = 0;
	var slideMaxHeight = 0;
   	slideContainer.find('img').each(function(){
		if(this.width > slideMaxWidth) slideMaxWidth = this.width;
		if(this.height > slideMaxHeight) slideMaxHeight = this.height;
	});
	var slideContainerWidth = parseInt( slideContainer.closest('.slide_main').width() );
	slideMaxWidth = parseInt( slideMaxWidth );
	slideMaxHeight = parseInt( slideMaxHeight );
	if(boxTheme == 2) var slideCheckWidth = slideMaxWidth + 2;
	else if(boxTheme == 3) var slideCheckWidth = slideMaxWidth + 8;
	else slideCheckWidth = slideMaxWidth;
	if(slideCheckWidth > slideContainerWidth) {
		var adjustMargin = parseInt( (slideContainerWidth - slideCheckWidth) / 2 );
		var adjustMarginVal = adjustMargin + 'px';
		slideContainer.closest('.slide_wrap').animate({marginLeft: adjustMarginVal}, 200);
	}
	if(!isEmpty(slideMaxWidth))
		slideContainer.width(slideMaxWidth).closest('.slide_wrap').width(slideMaxWidth);
	if(!isEmpty(slideMaxHeight))
		slideContainer.height(slideMaxHeight).closest('.slide_wrap').height(slideMaxHeight);
	var nivoEffects = ['sliceDown', 'sliceDownLeft', 'sliceUp', 'sliceUpLeft', 'sliceUpDown', 'sliceUpDownLeft', 'fold', 'fade', 'random', 'slideInRight', 'slideInLeft', 'boxRandom', 'boxRain', 'boxRainReverse', 'boxRainGrow', 'boxRainGrowReverse'];	
	var vEffect = slideContainer.attr('data-effect') in oc(nivoEffects) ? slideContainer.attr('data-effect') : 'fade';
	var vManual = slideContainer.attr('data-manual') == 'yes' ? true : false;
	if(vManual || (vTheme >= 2 && vTheme <= 9)) {
		var vNav = true; 			// Next & Prev navigation
		var vNavhide = false; 		// Only show on hover
		var vControl = false; 		// 1,2,3... navigation
		var vControlThumb = false;	// Use thumbnails for Control Nav
		if(vTheme >= 4 && vTheme <= 9) slideContainer.closest('.slide_main').addClass('theme_arrows');
	} else if(vTheme >= 10 && vTheme <= 11) {
		var vNav = false;
		var vNavhide = false;
		var vControl = true;
		var vControlThumb = false;
		slideContainer.closest('.slide_main').addClass('theme_buttons');
	} else if(vTheme == 12) {
		var vNav = false;
		var vNavhide = false;
		var vControl = true;
		var vControlThumb = true;
		slideContainer.closest('.slide_main').addClass('theme_buttons');
		if(!isEmpty(slideMaxWidth) && !isEmpty(slideMaxHeight)) {
			var thumbPadBottom = Math.ceil( slideMaxHeight / slideMaxWidth * 75 );
			slideContainer.closest('.slide_main').css('padding-bottom', thumbPadBottom + 'px');
		}
	} else {
		var vNav = false;
		var vNavhide = false;
		var vControl = false;
		var vControlThumb = false;
	}
	slideContainer.nivoSlider({
		effect: vEffect,
		animSpeed: 500,
		pauseTime: 4000,
		directionNav: vNav,
		directionNavHide: vNavhide,
		controlNav: vControl,
		controlNavThumbs: vControlThumb,
		controlNavThumbsFromRel: true,
		pauseOnHover:false,
		manualAdvance: vManual
	});
	if(!isEmpty(vTheme)) slideContainer.closest('.slide_main').addClass('theme_' + vTheme);
	if(!isEmpty(boxTheme)) slideContainer.closest('.slide_main').addClass('box_' + boxTheme);
}
function getInternetExplorerVersion() {
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
function aarcadePreviewSetup() {
	fW('td.item_options .remove_btn').unbind('click').bind('click', function(event){
		event.preventDefault();
		aarcadePreviewAlert();
	});
	fW('button.checkout_btn').unbind('click').bind('click', function(event){
		event.preventDefault();
		aarcadePreviewAlert();
	});
	fW('form').unbind('submit').bind('submit', function(event){
		event.preventDefault();
		aarcadePreviewAlert();
		return false;
	});
}
function aarcadePreviewAlert() {
	alert('This function is not enabled for Previews');
}
(function(d, s, id) {
	var js, fjs = d.getElementsByTagName(s)[0];
	if (d.getElementById(id)) {return;}
	js = d.createElement(s); js.id = id;
	js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
	fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
(function() {
	var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
	po.src = 'https://apis.google.com/js/plusone.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
