Subversion Repositories SmartDukaan

Rev

Rev 3232 | Rev 3446 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

$(function(){
        
        function markBestPrice(trNode)  {
                var tdBestPrice = $(trNode).children('td')[1];
                var saholicPrice = parseInt(tdBestPrice.innerHTML);
                var bestPrice = saholicPrice;

                $(trNode).find('a[href!="#"]').each(function(index, a){
                        var price = parseInt(a.innerHTML);
                        
                        if (price < bestPrice)  {
                                bestPrice = price;
                                tdBestPrice = $(a).parent();
                        }
                });
                $(tdBestPrice).addClass('best');
                
                if (bestPrice < saholicPrice)   $($(trNode).children()[0]).addClass('red');
        }

        $('tbody tr').each(function(index, e)   {
                var class_tr = index % 2 == 0 ? 'even' : 'odd';
                $(e).addClass(class_tr);
                markBestPrice(this);
        });

        var baseUrl = {
                'flipkart': 'http://www.flipkart.com',
                'homeshop18': '',
                'infibeam': 'http://www.infibeam.com',
                'letsbuy': ''
        };
        
        $('.conflict').click(function(){
                $(this).children('a')
                        .removeAttr('href')
                        .css({'text-decoration': 'underline', 'cursor': 'pointer'});
                var data = eval("{results: " + $(this).attr('data') + "}");
                var text = '<table>';
                
                for (i in data) {
                        text += '<tr>';
                        text += '<td>' + data[i]['name'] + '</td>';
                        text += '<td><a target="_blank" href="' + baseUrl[data[i]['source']] + data[i]['url'] + '">' + data[i]['price'] + '</a></td>';
                        text += '</tr>';
                }
                text += '</table>';
                $.facebox(text);
        });
});