/* ASHER ROTH STORE TEMPLATE */
/* Store Javascript
----------------------------------------------------------------------------- */


/* READY FUNCTION
----------------------------------------------------------------------------- */


	$(document).ready(function() {
	
		markup();
	
	});


/* LOAD FUNCTION
----------------------------------------------------------------------------- */


	$(window).load(function() {
	

/* STORE FUNCTIONALITY
----------------------------------------------------------------------------- */


		if (section == "store") {
		
		
			// SUB-DEPARTMENTS
			$('#subcategories').each(function() {
		
				var category = $('#subcategories h3').text();
				$('#subcategories ul').find('a:contains("Everything")').parent().remove();
				$('#subcategories ul').appendTo('#departments li:has(a:contains("' + category + '"))');
				$('#subcategories').remove();
		
			});
			
			// PLUGIN: CLIQUE FORMS
			try {
			$('.widget-item.search input#query').cliqueForms({ placeholder: "Search Store" });
			$('.widget-item.search input#query').css('visibility', 'visible'); // Will not chain to previous function?
			$('#mailing_list_entry_email').cliqueForms({ placeholder: "Enter Your Email Address" });
			$('#mailing_list_entry_mobile').cliqueForms({ placeholder: "Enter Your Mobile Number" });
			} catch (error) { alert('Error: Missing Clique Forms Plugin'); }

			// PLUGIN: CLIQUE ITEM WIDGET
			try {
			$('div.widget-item.display:not(.photos, .gift)').cliqueItemWidget({

				checkStock: false,
				pressure: false,
				browser: 'thumbnails', // thumbnails / slideshow
				removeEmptyThumbs: true, // Removes rows of empty thumbnails
				viewer: true, // Shows enlarged images
				preview: false, // Preview enlarged images when hovering thumbnails
				zoom: 'drag' // loupe / drag / none

			});
			$('.widget-item.browse.tooltip').cliqueItemWidget();
			$('.widget-item.filter').cliqueItemWidget();
			} catch (error) { alert('Error: Missing Clique Item Plugin'); }

			// PLUGIN: CLIQUE ALERT WIDGET
			try { $('div.widget-alert.added').cliqueAlertWidget(); } catch (error) { alert('Error: Missing Clique Alert Plugin'); }

			// PLUGIN: CLIQUE UPLOADER
			if (page == "item" && $('#review').length > 0) { try { $('#review').cliquePhotoUploader(); } catch (error) { alert('Error: Missing Clique Uploader Plugin'); } }
			
			// PLUGIN: CLIQUE ACTIONS (Replaces submit buttons with text links)
			try { $('input[type=submit]').cliqueActions(); } catch (error) { alert('Error: Missing Clique Actions Plugin'); }
			
			// MAILING LIST
			$('#optin ul.actions li input.save').attr('value','Get Updates');
			$('#optin ul.actions li a.submit').text('Get Updates');
			
			// CART
			$('div#cart span:contains("You have")').remove();
			
		}
		

		
	
/* POPUP EXTERNAL LINKS
----------------------------------------------------------------------------- */


		$('a[rel=external]').click(function(){
		
			link = $(this).attr('href');
			window.open(link);
			return false;
	
		});
	

/* STORE FUNCTIONS
----------------------------------------------------------------------------- */

		cufon();
		tabs();
		killTabs();
		
	});
	
	
/* FUNCTION: CUFON
----------------------------------------------------------------------------- */


	function cufon() {

		// Gunplay
		Cufon.replace('#departments h3, h2, div.widget-order h4, div#welcome h3, body.section-help h3, body.section-help h4, body.section-store div.widget-account h3, body.section-store div.widget-account h4, body.section-legal h4, body.section-legal h3, div.widget-alert h3, #giftcards h3, #optin h3:not(#optin div.widget-subscribe h3), #departments li a:not(li li a), #sidebar div#cart h3, div.widget-alert h3, h3.shop, #title h2, #help h3, div.widget-cart.modify h3, #sidebar div#customer div.customer h3', { fontFamily: 'Gunplay', hover: true });
		
		// Reveal Text
		$('#departments h3, h2, div.widget-order h4, #page-receipt h3, div#welcome h3, body.section-help h3, body.section-help h4, body.section-store div.widget-account h3, body.section-store div.widget-account h4, body.section-legal h4, body.section-legal h3, div.widget-alert h3, #giftcards h3, #optin h3:not(#optin div.widget-subscribe h3), #departments li a:not(li li a), #sidebar div#cart h3, div.widget-alert h3, h3.shop, #title h2, div.widget-item.display div.topic h3, #help h3, div.widget-cart.modify h3, div.widget-order.receipt h3, #sidebar div#customer div.customer h3').css('visibility', 'visible');
	
	}
	

/* FUNCTION: KILL TABS
----------------------------------------------------------------------------- */ 


	function killTabs() {

		// REMOVE EMPTY JAVASCRIPT TAB AND PANE
		$('div.tabbed').not(".static, .ajax").children('ul.tabs').children('li').each(function() {

			var pane = $(this).children('a').attr('href');

			if ( $(this).parent().parent().find(pane).children('*').length == 0 ) {

				$(this).remove();
				$(this).parent().parent().find(pane).remove();

			}

		});

		// REMOVE TABBED PANEL
		$('div.tabbed').not(".static, .ajax").children('ul.tabs').each(function() {

			if ($(this).children('li').length == 0) {

				$(this).parent().remove();

			}

		});

	}


/* FUNCTION: INITIALIZE TABS
----------------------------------------------------------------------------- */


	function tabs() {

		// JAVASCRIPT TABS
		$('div.tabbed').not("#features, .ajax, .static, #media").children('ul.tabs').tabs({

			fxSlide: false,

			click: function() {

			}, load: function() {

				truncate();

			}, show: function() {

				truncate();

			}

		});

		// AJAX TABS
		$('div.tabbed.ajax > ul.tabs').tabs({

			fxSlide: false,

			click: function() {

				loading('start');

			}, load: function() {

				truncate();
				loading('stop');
				chat();

			}, show: function() {

				truncate();
				loading('stop');
				chat();

			}

		});

	}
	
	
/* FUNCTION: MARKUP CHANGES
----------------------------------------------------------------------------- */


	function markup() {
	
		$('#cart a.change').text('View Cart');
		
	}


