//====================================================
// PASTE INTO HEAD:
/***
<script type="text/javascript" src="includes/ajax/best_price.js" ></script>
***/
//
// EXAMPLE:
//    <span id="fred" class="best_price" brand="Blitz" categories_id="8535" ></span>
//
//====================================================

function best_price( settings ){

	var m = jQuery.extend({
	   id             : 'best_price',
	   container      : this,
	   target         : undefined,
	   brand          : "",
     categories_id  : 0,
     url            : 'includes/ajax/best_price.php',
	   guid           : parseInt(Math.random()*1000000)
	}, settings || {});

  m.target = document.getElementById(m.id);

  jQuery.post
  (
    m.url,

    {
      action        : 'best_price',
      brand         : m.brand,
      categories_id : m.categories_id,
      products_id   : m.products_id
    },

    function(retval){
        //console.log('best_price(retval)='+retval)
        m.target.innerHTML = retval;
    } // function(retval)

  ) // $.post

} // function

//====================================================

function best_price_init(){
    jQuery('.best_price').each( function(dummy)
        {
        var id            = this.id;

        var brand         = '';
        var categories_id = '';
        var products_id   = '';
        var url           = 'includes/ajax/best_price.php';
        
        
        try{
            brand = this.attributes['brand'].value;
        } catch(err) {
            brand = '';
        }
        try{
            categories_id = this.attributes['categories_id'].value;
        } catch(err) {
            categories_id = '';
        }
        try{
            products_id = this.attributes['products_id'].value;
        } catch(err) {
            products_id = '';
        }
        try{
            url = this.attributes['url'].value;
        } catch(err) {
            // SKIP
        }

        jQuery('#'+id).html(  best_price( {id:id, brand:brand, categories_id:categories_id, products_id:products_id, url:url} )  );
        }
    );
} // function

jQuery(window).load(function() {
    best_price_init();
} );

//====================================================
