

$(function() {
    try {
        $(".product_list").tablesorter({ 
            sortList: [[0,0]],
            widgets: ['zebra'],
            widthFixed: true,
            textExtraction: function(td) {
                var text = $(td).find('h2').html() || $(td).html() || ''
                return text.replace(' st', '').replace(':-', '')
            }
        });
    }
    catch(e) {

    }    
    $.jGrowl.defaults.position = 'center'
})


function printPage() {
    var href = window.location.href
    if(href.indexOf('#') !== -1) {
        href = href.substr(0, href.lastIndexOf('#'))
    }
    var prefix = href.indexOf('?') === -1 ? '?' : '&'
    window.open(href + prefix + 'print=1','print','width=700,height=500,scrollbars=yes,resizable=yes');
}

// =================
// = Ljusihus cart =
// =================
var Ljuscart = null
$(function() {
    
    // window.document.body.addEventListener('contextmenu', function(e) { e.preventDefault(); return false; })
    
    
    Ljuscart = Persistent.extend({
        init: function(name) {
            this._super(name)
            this.items = []
        },
        get: function(id) {
            for(var i in this.items) {
                if(this.items[i].id == id) {
                    return this.items[i]
                }
            }        
            return this.items[id]
        },
        add: function(id, comment) {
            for(var i in this.items) {
                if(this.items[i].id == id) {
                    $.jGrowl('<p>Produkten finns redan i Min Lista</p><p><a href="/min_lista" style="color: #65bade">Gå till Min lista</a></p> ')
                    return false
                }
            }
            this.items.push({id: id, comment: comment || ''})
            $.jGrowl('<p>Produkten tillagd i Min Lista</p><p><a href="/min_lista" style="color: #65bade">Gå till Min lista</a></p> ')
            return this
        },
        remove: function(id) {
            index = null
            for(var i in this.items) {
                if(this.items[i].id == id) {
                    this.items.splice(i, 1)
                    break
                }
            }
            return this
        },
        empty: function() {
            this.items = []
            return this
        }
    })

})