function AmazonLib() {this.search=function() {var query=$amazon_jq('[name="amazon_search"]').val();if(query=='') return;$amazon_jq('#amazon_search_results').html('');$amazon_jq('#amazon_search_results').addClass('amazon_search_loading');var data={action:'amazon_search',security:amazon_nonce,search:query};$amazon_jq.post(ajaxurl,data,amazon_lib.searchSuccess,'html').error(amazon_lib.searchFailed);return false;} this.searchSuccess=function(response) {$amazon_jq('#amazon_search_results').removeClass('amazon_search_loading');$amazon_jq('#amazon_search_results').html(response);} this.searchFailed=function() {$amazon_jq('#amazon_search_results').removeClass('amazon_search_loading');$amazon_jq('#amazon_search_results').html('Search results could not be retrieved');} this.newWindow=function() {$amazon_jq('.new_window').attr('target','_blank');$amazon_jq('.new_window').attr('title','open in a new window');} this.fieldInfo=function(link_id,div_id) {$amazon_jq(link_id).hover(function(){$amazon_jq(div_id).css('display','block');},function(){$amazon_jq(div_id).css('display','none');});} this.expand=function() {var asin=$amazon_jq(this).attr('id');$amazon_jq('.'+asin).removeClass('cache_sub');$amazon_jq(this).removeClass('cache_expand');$amazon_jq(this).addClass('cache_collapse');$amazon_jq(this).unbind('click');$amazon_jq(this).click(amazon_lib.collapse);} this.collapse=function() {var asin=$amazon_jq(this).attr('id');$amazon_jq('.'+asin).addClass('cache_sub');$amazon_jq(this).addClass('cache_expand');$amazon_jq(this).removeClass('cache_collapse');$amazon_jq(this).unbind('click');$amazon_jq(this).click(amazon_lib.expand);} this.addField=function() {var index=Number($amazon_jq('[name="template_field_index"]').val());$amazon_jq('#post_fields').append('Field Name: ');$amazon_jq('#post_fields').append('Default Value:

');index++;$amazon_jq('[name="template_field_index"]').val(index);} this.selectTemplate=function() {var temp_id=$amazon_jq('[name="amazon_post_template_select"]').val();var old_temp_id=$amazon_jq('#amazon_current_template').val();if(temp_id=='') {$amazon_jq('#amazon_tools_template_fields').css('display','none');return;} var template_fields={};$amazon_jq('.amazon_tools_field').each(function(index){template_fields[this.name]=$amazon_jq(this).val();});var data={action:'amazon_change_template',security:amazon_nonce,current_template:old_temp_id,new_template:temp_id,post_id:amazon_post_id,fields:template_fields};$amazon_jq.post(ajaxurl,data,amazon_lib.ajaxSuccess,'html').error(ajaxError);} this.ajaxSuccess=function(response) {$amazon_jq('#amazon_tools_template_fields').css('display','block');if(response==0) {$amazon_jq('#amazon_post_fields_container').html('Could not retrieve custom fields. Save this post to view custom fields.');} else {$amazon_jq('#amazon_post_fields_container').html(response);}} this.ajaxError=function() {$amazon_jq('#amazon_tools_template_fields').css('display','block');$amazon_jq('#amazon_post_fields_container').html('Could not retrieve custom fields. Save this post to view custom fields.');} this.newWindow();}