

$(document).ready(function(){

	// beta - delete later
	$('#beta').click(function(){
		var location = $(this).find('a').attr('href');
		window.location = location;
	});
	
	// member menu dropdown
	$('#member-menu>li').hover(function(){
		$(this).find('ul').stop(true,true).fadeIn('fast');
	},
	function(){
		$(this).find('ul').stop(true,true).animate({opacity: 1.0}, 500).fadeOut('slow');
	});
	
	// notices
	$('.notice,.error,.success').not('.nofade').hide().fadeIn('fast',function(){
		$(this).animate({opacity: 1.0}, 5000).fadeOut(5000);
	});
	
	if(!jQuery.browser.msie){
		// magazine
		$('.magazine .article').hover(function(){
			$(this).find('p').stop(true,true).fadeIn('slow');	
		},function(){
			$(this).find('p').fadeOut('slow');
		});
	}
		
	// Add an empty header and footer element to items with the class '.box'
	$('.box,.box_dark,.box_flat,.box_flat_odd,.box_inset,.box_dark').prepend('<div class="header"></div>').append('<div class="footer"></div>');
	
	// text fields
	// Wrap all form fields in a span so we can do sliding doors on them
	textfields = $('input[type=text], input[type=password]').not('.spmchecker,input[name=stock_search]');
	textfields.wrap('<span class="textfield"></span>');
	$('span.textfield').prepend('<span></span>');
	
	// textfields change color on focus
	$('input[type=text], input[type=password]').attr('class','light').focus(function(){
		$(this).attr('class','dark');
	});
	
	$('input[type=text], input[type=password]').blur(function(){
		$(this).attr('class','light');
	});
	
	// Search focus/blur clear
	$('#searchfield').focus(function(){
		if($(this).attr('value') == "Search Antiques"){ $(this).attr('value','');}
	});
	
	// Search focus/blur clear
	$('#searchfield').blur(function(){
		if($(this).attr('value') == ""){ $(this).attr('value',"Search Antiques"); }
	});
	
	// Search focus/blur clear
	$('#homesearch').focus(function(){
		if($(this).attr('value') == "FIND the perfect piece"){ $(this).attr('value','');}
	});
	
	// Search focus/blur clear
	$('#homesearch').blur(function(){
		if($(this).attr('value') == ""){ $(this).attr('value',"FIND the perfect piece"); }
	});
	
	// Email fields
	$('[name=email]').focus(function(){
		if($(this).attr('value') == 'name@domain.com'){ $(this).attr('value',''); }
	});
	
	$('[name=email]').blur(function(){
		if($(this).attr('value') == ''){ $(this).attr('value','name@domain.com'); }
	});
	
	// antique thumbs title tip
	$('.antiques .thumb').hover(function(){
		$('.antiques .thumb h3').hide();
		$(this).find('h3').stop(true,true).fadeIn('fast');
	},
	function(){
		$(this).find('h3').fadeOut('fast');
	});
	
	// antique inquire form
	$('#antique-inquire-form').jqm({modal: false, trigger: '.show-inquire-form'});
	$('#antique-inquire-form').jqmAddClose('.hide-inquire-form'); 
	
	// antiques single view multiple images
	$('#img-select a').click(function(e){
		e.preventDefault();
		
		// unselect button
		$('#img-select a').removeClass('current');
		$(this).addClass('current');
		
		// change large image
		var image = $(this).attr('href');
		$('.antique-single > img.large-img').attr('src', image);
	});

  	
  	// categories expander
  	$('div#categories .cols-1-4th').expander({
  		slicePoint: 500,
  		expandText: '[Show All]',
  		userCollapseText: '[Less]'
  	});
  	
  	//dealer signup TOU POPUP
	$('button.dealer_submit').attr('type','button');
	$('button.dealer_submit').click(function(event){event.preventDefault();});
	$('#dealer_agreement').jqm({modal: true, trigger: 'button.dealer_submit'});
	
	// deal ADMIN TOU POPUP
	$('#dealer_agreement2').jqm({modal: true});
	$('#dealer_agreement2').ready(function(){
		$('#dealer_agreement2').jqmShow();
	});
  	
  	// captions
  	$('.single img, .page img').jcaption({
		//Element to wrap the image and caption in
		wrapperElement: 'span',
		
		//Class for wrapper element
		wrapperClass: 'caption',
		
		//Caption Element
		captionElement: 'p',
		
		//Attribute of image to use as caption source
		imageAttr: 'title',
	
		//If true, it checks to make sure there is caption copy before running on each image
		requireText: true,
		
		//Should inline style be copied from img element to wrapper
		copyStyle: true,
		
		//Strip inline style from image
		removeStyle: true,
		
		//Strip align attribute from image
		removeAlign: true,
		
		//Assign the value of the image's align attribute as a class to the wrapper
		copyAlignmentToClass: true,
	
		//Assign the value of the image's float value as a class to the wrapper
		copyFloatToClass: true,
	
		//Assign a width to the wrapper that matches the image
		autoWidth: true,
		
		//Animate on hover over the image
		animate: false,
		
		//Show Animation
		show: {opacity: 'show'},
		showDuration: 200,
		
		//Hide Animation
		hide: {opacity: 'hide'},
		hideDuration: 200	
	});
	
	// antique description expander
	//$('div.antique-details p.description').expander({
	//	slicePoint:       200,  // default is 100
	//	expandText:         '[more&hellip;]', // default is 'read more...'
	//	collapseTimer:    0, // re-collapses after 5 seconds; default is 0, so no re-collapsing
	//	userCollapseText: '[^less]'  // default is '[collapse expanded text]'
  	//});
});
