$(document).ready(function(){
	$("#top_10>li>ol").hide();
	$("#top_10>li>a").toggle(function(){
		$(this).addClass("active"); 
		}, function () {
		$(this).removeClass("active");
	});
	$("#top_10>li>a").click(function(){
		$(this).next("#top_10>li>ol").slideToggle("slow,");
	});
	// rotate banner in header
	$('#banner').innerfade({
		speed: 'slow',
		timeout: 4000,
		type: 'sequence',
		containerheight: '34px'
	});	
	// Toggle All Models
	//$("#toggle_all_models ul").hide();		
	
	$("#toggle_models").one('click',function () {
		
		// add a loading class
		$(this).addClass('loading_sm');
		
		// get the query string from rel
		var queryString = $(this).attr('rel');
		
		// load content
		//$('#toggle_model_results').load('/api/memory.cfm?'+queryString+'',function(){
		//	$('#toggle_models').removeClass('loading_sm'); // remove loading class
		//});
		
		// make the ajax call
		$.ajax({
			type: "GET",
			url: "/api/memory.cfm?"+queryString+"",
			cache: false,
			dataType: 'html',
			beforeSend: function(){
				$('#toggle_model_results').empty();
			},
			success: function(data) {
				$('#toggle_model_results').empty().append(data);
				$('#toggle_models').removeClass('loading_sm');
			},
			error: function(msg){
				$('#toggle_model_results').empty().append('An error occurred');
				$('#toggle_models').removeClass('loading_sm');
			}
		});

		return false;
		
	});	
	
	// IMPROVE THIS PAGE
	// get the improvePage link and (using javascript) append the pop=1 param
	$('a#improvePage').each(function(intIndex){
		var theURL = $(this).attr("href");
		var newURL = theURL + "&pop=1";
		$(this).attr("href",newURL);	
	});	
	// when the improve page form is submitted
	$('form[name=improvePageForm]').live('submit',function(){
		var formData = $('form[name=improvePageForm]').serialize(); $.ajax({type: 'POST',url: '/contact/action/improve.cfm',cache: false,data: formData,dataType: 'script',beforeSend:function(){$('div#formOutput').remove();},success: function(data){if(error){$('form[name=improvePageForm]').before(output);}else{ $('form[name=improvePageForm]').before(output); $('form[name=improvePageForm]').remove(); } },error: function(xhr){alert(xhr.StatusText);}}); return false;
	});	
	
	// add to wishlist -- when not authenticated we are showing an additional div to allow the user to login or create account
	$('a#addToWishlistNotAuthenticated').click(function(){
		$(this).remove();
		$('.addToWishlistNotAuthenticated').show();
		return false;
	});
	// add to wishlist -- when add to wishlist link is clicked
	$('#addToWishlist').click(function(){
		// get the form name
		var formName = $(this).parents("form").attr('name');
		// add a hidden var that tells our action template that this item is for the wishlist
		$('form[name='+formName+']').append('<input type="hidden" name="ADD_TO_WISHLIST" value="1" />').submit();
		return false;
	});
	
	// create account
	$('form[name=createAccount].post-inline').live('submit',function(){
		var formData = $('form[name=createAccount]').serialize(); 
		$.ajax({type: 'POST',url: '/account/action/insert.cfm',cache: false,data: formData,dataType: 'script',beforeSend:function(){$('div#formOutput').remove();},success: function(data){if(error){$('form[name=createAccount]').before(output);}else{ $('form[name=createAccount]').before(output); $('form[name=createAccount]').remove(); } },error: function(xhr){alert(xhr.StatusText);}}); return false;
	});		
	
	// login
	$('form[name=loginUser].post-inline').live('submit',function(){
		var formData = $('form[name=loginUser]').serialize(); 
		$.ajax({type: 'POST',url: '/account/action/login.cfm',cache: false,data: formData,dataType: 'script',beforeSend:function(){$('div#formOutput').remove();},success: function(data){if(error){$('form[name=loginUser]').before(output);}else{ $('form[name=loginUser]').before(output); $('form[name=loginUser]').remove(); } },error: function(xhr){alert(xhr.StatusText);}}); return false;
	});
	
});
