Function.prototype.bind = function() {

    var method = this, args = playphone.array(arguments), object = args.shift();
    
    return function() {
    
        return method.apply(object, args.concat(playphone.array(arguments)));
    }
}

playphone = {

    version: '1.0.0.0',

    $: function(element) {
    
        return document.getElementById(element);
    },
    
    default_button: function(object, script) {
    
        playphone.$(object).onkeypress = function(e) {
        
            e = e || event;
            
            if (e.keyCode == 13 || e.which == 13) {
            
                script();
            }
        }
    },
    
    array: function(iterable) {
    
        if (!iterable) return [];
        
        if (iterable.toArray) {
        
            return iterable.toArray();
        
        } else {
        
            var results = [];
            
            for (var i = 0, length = iterable.length; i < length; i++) {
            
                results.push(iterable[i]);
            }
            
            return results;
        }
    },
    
    parse_xml: function(string) {
    
        if (window.ActiveXObject) {
            
            var object = new ActiveXObject("Microsoft.XMLDOM");
            
            object.async = "false";
            object.loadXML(string);
            
        } else {
            
            var parser = new DOMParser();
            var object = parser.parseFromString(string, "text/xml");
        }
        
        return object.documentElement;
    },
    
    config_url: function(url) {
       
        url = url.replace(/& /g, '');
        url = url.replace(/&/g, '');
        url = url.replace(/\(TM\)/g, '');
        url = url.replace(/\(c\)/g, '');
        url = url.replace(/\(+/g, '');
        url = url.replace(/\)+/g, '');
        url = url.replace(/\. +/g, '-');
        url = url.replace(/\.+/g, '-');
        url = url.replace(/\\+/g, '');
        url = url.replace(/\u00AE/g, '');
        url = url.replace(/\u2122/g, '');
        url = url.replace(/|/g, '');
        url = url.replace('/', '-');
        url = url.replace(/!/g, '');
        url = url.replace(/"/g, '');
        url = url.replace(/%/g, '');
        url = url.replace(/\?+/g, '');
        url = url.replace(/\'+/g, '');
        url = url.replace(/,/g, '');
        url = url.replace(/- /g, '');
        url = url.replace(/ -/g, '');
        url = url.replace(/--/g, '-');
        url = url.replace(/:/g, '');
        url = url.replace(/;/g, '');
        url = url.replace(/\++/g, '');
        url = url.replace(/\*+/g, '');
        url = url.replace(/_/g, '');
        url = url.replace(/ /g, '-');
        url = url.replace(/  /g, '-');
        url = url.replace(/--/g, '-');
        
        return url;
    }
}

playphone.object = {

    create: function() {
    
        return function() { }
    },
    
    extend: function(destination, source) {
    
        for (var property in source) {
            
            destination[property] = source[property];
        }
        
        return destination;
    }
}
    
playphone.ajax = function() {

    this.response = null;
    
    this.cache = function(url) {
        var dt = new Date();
        if(url.indexOf("?")>=0){
            return url + "&" + encodeURI(Math.random() + "_" + dt.getTime());
        }else{ return url + "?" + encodeURI(Math.random() + "_" + dt.getTime());}
    }
    
    this.create = function() {
    
        try { return new XMLHttpRequest() } catch(e) {}
        try { return new ActiveXObject('Microsoft.XMLHTTP') } catch(e) {}
        try { return new ActiveXObject('Msxml2.XMLHTTP') } catch(e) {}
        
        return null;
    }
           
    this.request = function(url, responders) {
        
        this.responders = responders;
    
        this.transport = this.create();
        
        this.transport.onreadystatechange = this.on_state_change.bind(this);
        
        this.transport.open('get', url, true);
        this.transport.send(null);
    }
    
    this.on_state_change = function() {
    
        if (this.transport.readyState == 4) {
            
            playphone.ajax.response = this.transport.responseText;
            
            var success = !this.transport.status || (this.transport.status >= 200 && this.transport.status < 300);
            
            try {
                
                var responder = this.responders[success ? 'on_success' : 'on_failure'];
                               
                responder.apply(responder, [playphone.ajax.response]);
                
            } catch(e) { }
        
        } else {
        
            try {
        
                var responder = this.responders['on_loading'];
                
                responder.apply(responder);
                
            } catch(e) { }
        }
    }
}

playphone.paging = function() {

    
    this.url = null; this.current_page = 1; this.pages_count = 0; this.items_per_page = 0; this.items_count = 0; this.container = 'list'; this.item_template;
    
    this.button_first = {
    
        id: 'btnFirst',
        enable_class: '',
        disable_class: '',
        
        enable: function() {
        
            playphone.$(this.id).className = this.enable_class;
        },
        
        disable: function() {
        
            playphone.$(this.id).className = this.disable_class;
        }
    }
    
    this.button_previous = {
    
        id: 'btnPrevious',
        enable_class: '',
        disable_class: '',
        
        enable: function() {
        
            playphone.$(this.id).className = this.enable_class;
        },
        
        disable: function() {
        
            playphone.$(this.id).className = this.disable_class;
        }
    }
    
    this.button_next = {
    
        id: 'btnNext',
        enable_class: '',
        disable_class: '',
        
        enable: function() {
        
            playphone.$(this.id).className = this.enable_class;
        },
        
        disable: function() {
        
            playphone.$(this.id).className = this.disable_class;
        }
    }
    
    this.button_last = {
    
        id: 'btnLast',
        enable_class: '',
        disable_class: '',
        
        enable: function() {
            
            playphone.$(this.id).className = this.enable_class;
        },
        
        disable: function() {
        
            playphone.$(this.id).className = this.disable_class;
        }
    }
    
    this.paging = {
    
        id: 'paging'
    }
    
    this.info = {
    
        id: null
    }
    
    this.order_by = {
    
    
        id: null,
        filters: [],
        selected: ''
    }
    
    this.alternate_item = {
    
        enable: null,
        template: null
    }
    
    this.rating = {
    
        id: '',
        enable: false,
        type: 'True'
    }
    
    this.first = function() {
        
        if (this.current_page > 1) {
        
            this.move(1);
        }
    }
    
    this.previous = function() {
    
        if (this.current_page > 1) {
        
            this.move(this.current_page - 1);
        }
    }
    
    this.next = function() {
    
        if (this.current_page < this.pages_count) {
        
            this.move(this.current_page + 1);
        }
    }
    
    this.last = function() {
    
        if (this.current_page < this.pages_count) {
        
            this.move(this.pages_count);
        }
    }
    
    this.move = function(page) {
        
        if (page != undefined) {
        
            this.current_page = page;
        
        } else {
        
            page = this.current_page;
        }
        
        new playphone.ajax().request(this.url + '&PerPage=' + this.items_per_page + '&Page=' + page + (this.order_by.selected ? '&OrderBy=' + this.order_by.selected : ''), { on_success: this.print.bind(this) });
    }
    
    this.print = function(response) {
                
        var response = playphone.parse_xml(response);
                            
        var item = response.getElementsByTagName('Item');
        
        this.items_count = response.getAttribute('ItemsCount');
        this.pages_count = Math.ceil(this.items_count / this.items_per_page);
        
        playphone.$(this.container).innerHTML = '';
        
        for (var i = 0; i < item.length; i++) {
            
            if (this.alternate_item.enable) {
            
                if (i % 2 == 0) {
                
                    var code = this.item_template;
                    
                } else {
                
                    var code = this.alternate_item.template;
                }
            
            } else {
            
                var code = this.item_template;
            }
            
            while (code.indexOf('<property') > -1) {
                
                var open_tag = '<property';
                var close_tag = '</property>';
                
                var tag = code.substring(code.indexOf(open_tag), code.indexOf(close_tag) + close_tag.length);
                
                var start = code.slice(0, code.indexOf(tag));
                var end = code.slice(code.indexOf(tag) + tag.length, code.length);
                
                tag = playphone.parse_xml(tag);
                
                if (tag.getAttribute('options')) {
                
                    var options = tag.getAttribute('options').split(',');
                    
                    for (j in options) {
                    
                        try {
                            
                            var option = options[j].split(',');
                            
                            switch (option[0]) {
                            
                                case 'limit':
                                    var text = item[i].getElementsByTagName(tag.getAttribute('valueOf'))[0].childNodes[0].nodeValue;
                                    var text = text.replace(/\&+/g, '&amp;');
                                    code = start + (text.length > option[1] ? text.substring(0, option[1]) + '...' : text) + end;
                                    break;
                                case 'cleanUrl':
                                    if (option[1]) 
                                    { 
                                        code = start + playphone.config_url(item[i].getElementsByTagName(tag.getAttribute('valueOf'))[0].childNodes[0].nodeValue) + end;
                                    }
                                    break;
                                case 'urlEncode':
                                    if (option[1]) { code = start + encodeURIComponent(item[i].getElementsByTagName(tag.getAttribute('valueOf'))[0].childNodes[0].nodeValue) + end; }
                                    break;
                                case 'autoIncrement':
                                    if (option[1]) { code = start + i + end; }
                                    break;
                            }
                        
                        } catch (e) {
                            
                            code = start + playphone.config_url(item[i].getElementsByTagName(tag.getAttribute('valueOf'))[0].childNodes[0].nodeValue)  + end;
                        }
                    }
                    
                } else {
                
                    try {
                        
                        code = start + item[i].getElementsByTagName(tag.getAttribute('valueOf'))[0].childNodes[0].nodeValue + end;
                        
                    } catch (e) {
                    
                        code = start + 'null' + end;
                    }
                }
            }
            
            while (code.indexOf('<conditional') > -1) {
            
                var open_tag = '<conditional';
                var close_tag = '</conditional>';
                
                var tag = code.substring(code.indexOf(open_tag), code.indexOf(close_tag) + close_tag.length);
                
                var start = code.slice(0, code.indexOf(tag));
                var end = code.slice(code.indexOf(tag) + tag.length, code.length);
                
                tag = playphone.parse_xml(tag);
                
                var check_for = tag.getAttribute('checkFor').split(',');
                var value_for = tag.getAttribute('valueFor').split(',');
                
                for (var j = 0; j < check_for.length; j++) {
                
                    try {
                        
                        if (check_for.length == 1 && check_for[j] != 'null') {
                        
                            if (item[i].getElementsByTagName(tag.getAttribute('valueOf'))[0].childNodes[0].nodeValue == check_for[j]) {
                                
                                code = start + value_for[j] + end;
                                
                            } else {
                            
                                code = start + value_for[j + 1] + end;
                            }
                            
                        } else if (check_for[j] == 'null') {
                            
                            if (item[i].getElementsByTagName(tag.getAttribute('valueOf'))[0].childNodes[0] == undefined) {
                                
                                code = start + value_for[j] + end;
                                
                            } else {
                            
                                code = start + value_for[j + 1] + end;
                            }
                        
                        } else if (item[i].getElementsByTagName(tag.getAttribute('valueOf'))[0].childNodes[0].nodeValue == check_for[j]) {
                            
                            code = start + value_for[j] + end;
                        }
                        
                    } catch (e) {
                    
                        code = start + 'null' + end;
                    }
                }
            }
            
            playphone.$(this.container).innerHTML += code;
            
            if (this.rating.enable) {
            
                playphone.rating.create({container: this.rating.id + i, image_off: urlStaticServer + '/Images/star-off.png', image_on: urlStaticServer + '/Images/star-hover.png', image_hover: urlStaticServer + '/Images/star-on.png', length: 5, value: item[i].getElementsByTagName('Rating')[0].childNodes[0].nodeValue, item_id: item[i].getElementsByTagName('ItemId')[0].childNodes[0].nodeValue, enable: this.rating.type});
            }
        }
				
        this.do_paging();
    }
    
    this.do_paging = function() {
        
        var playphone_paging = this;
        
        playphone.$(this.button_first.id).onclick = function() { playphone_paging.first(); };
        playphone.$(this.button_previous.id).onclick = function() { playphone_paging.previous(); };
        playphone.$(this.button_next.id).onclick = function() { playphone_paging.next(); };
        playphone.$(this.button_last.id).onclick = function() { playphone_paging.last(); };
        
        if (this.order_by.filters.length > 0) {
        
            playphone.$(this.order_by.id).innerHTML = '';
        
            for (var filter in this.order_by.filters) {
                
                var li = document.createElement('li');
                var a = document.createElement('a');
                a.href = 'javascript:void(0)';
                a.onclick = function() { playphone_paging.order_by.selected = this.innerHTML; playphone_paging.move(1); };
                a.innerHTML = this.order_by.filters[filter];
                a.id = this.order_by.filters[filter];
                
                if (a.id == playphone_paging.order_by.selected)
                     a.className = 'active';
                
                li.appendChild(a);
                playphone.$(this.order_by.id).appendChild(li);
            }
        }
        
        if (this.pages_count > 1) {
        
            if (this.current_page == 1) {
            
                this.button_first.disable();
                this.button_previous.disable();
                this.button_next.enable();
                this.button_last.enable();
            
            } 
            
            if (this.current_page > 1) {
            
                this.button_first.enable();
                this.button_previous.enable();
                this.button_next.enable();
                this.button_last.enable();
            
            }
            
            if (this.current_page == this.pages_count) {
            
                this.button_first.enable();
                this.button_previous.enable();
                this.button_next.disable();
                this.button_last.disable();
            }
            
            if (this.info.id)
                playphone.$(this.info.id).innerHTML = (this.items_per_page * this.current_page - this.items_per_page + 1) + ' - ' + ((this.items_per_page * this.current_page) > this.items_count ? this.items_count : (this.items_per_page * this.current_page)) + ' of ' + this.items_count;
            
            if (this.pages_count <= 8) {
            
                playphone.$(this.paging.id).innerHTML = '';
                
                for (var i = 0; i < this.pages_count; i++) {
                
                    var li = document.createElement('li');
                    var a = document.createElement('a');
                    a.href = 'javascript:void(0)';
                    a.className = 'tab';
                    a.innerHTML = i;
                    
                    li.appendChild(a);
                    playphone.$(this.paging.id).appendChild(li);
                }
            
            } else {
            
                playphone.$(this.paging.id).innerHTML = '';
                
                for (var i = 0; i < 9; i++) {
                
                    var li = document.createElement('li');
                    var a = document.createElement('a');
                    a.href = 'javascript:void(0)';
                    a.className = 'tab';
                    a.innerHTML = i;
                    
                    li.appendChild(a);
                    playphone.$(this.paging.id).appendChild(li);
                }
            }
        
        } else {
        
            this.button_first.disable();
            this.button_previous.disable();
            this.button_next.disable();
            this.button_last.disable();
            
            if (this.info.id)
                playphone.$(this.info.id).innerHTML = (this.items_per_page * this.current_page - this.items_per_page + 1) + ' - ' + this.items_count + ' of ' + this.items_count;
            
            playphone.$(this.paging.id).innerHTML = '';
            
            var li = document.createElement('li');
            var a = document.createElement('a');
            a.href = 'javascript:void(0)';
            a.className = 'tab';
            a.innerHTML = '1';
            
            li.appendChild(a);
            playphone.$(this.paging.id).appendChild(li);
        }
        
        var a = playphone.$(this.paging.id).getElementsByTagName('a');
        
        if (this.current_page <= 8 && this.pages_count > 0) {
        
            for (var i = 0; i < a.length; i++) {
                
                if (i < 9) {
                
                    a[i].innerHTML = i + 1;
                
                } else {
                
                    a[i].innerHTML = '...';
                }
            }
        }
        
        if (this.current_page > 8) {
        
            a[0].innerHTML = '...';
            a[1].innerHTML = this.current_page - 3;
            a[2].innerHTML = this.current_page - 2;
            a[3].innerHTML = this.current_page - 1;
            a[4].innerHTML = this.current_page;
            a[5].innerHTML = this.current_page + 1;
            a[6].innerHTML = this.current_page + 2;
            a[7].innerHTML = this.current_page + 3;
            a[8].innerHTML = '...';
        }
        
        if (this.current_page > (this.pages_count - (8 - 1)) && this.pages_count > 8) {
        
            a[0].innerHTML = '...';
            a[1].innerHTML = this.pages_count - 7;
            a[2].innerHTML = this.pages_count - 6;
            a[3].innerHTML = this.pages_count - 5;
            a[4].innerHTML = this.pages_count - 4;
            a[5].innerHTML = this.pages_count - 3;
            a[6].innerHTML = this.pages_count - 2;
            a[7].innerHTML = this.pages_count - 1;
            a[8].innerHTML = this.pages_count;
        }
        
        for (var i = 0; i < a.length; i++) {
        
            a[i].className = 'tab';
            
            if (a[i].innerHTML == this.current_page) {
            
                //a[i].focus();
                
                if (a[i].innerHTML < 10) {
                
                    a[i].className += ' short';
                
                } else if (a[i].innerHTML < 100) {
                
                    a[i].className += ' medium';
                
                } else {
                
                    a[i].className += ' full';
                }
            }
            
            if (!isNaN(a[i].innerHTML) && a[i].innerHTML != this.current_page) {
            
                a[i].onclick = function() { playphone_paging.move(parseInt(this.innerHTML)); };
            
            } else {
            
                a[i].style.cursor = 'default';
                a[i].style.textDecoration = 'none';
            }
        }
        this.w_delete();
    }
    // Delete Wishlist
    this.w_delete = function(){
       
        var playphone_paging = this;
                                         
        var elems = playphone.$(this.container).getElementsByTagName('a');
        
        for (field in elems){
            
            try {
                var elemento = elems[field].ref;
                var elemento = elems[field].getAttribute("ref");
            }catch(e){}
            
            
            if (elemento){
            
                elems[field].onclick = function(){
                   var wpage = 1;
                   if (playphone_paging.current_page > 1){
                        wpage = Math.ceil((playphone_paging.items_count-1) / playphone_paging.items_per_page);
                   }else{
                        wpage = playphone_paging.current_page
                   }
                                     
                   new playphone.ajax().request('/WishlistDelete.aspx?ItemId=' + this.getAttribute('ref') + '&PerPage=' + playphone_paging.items_per_page + '&Page=' + wpage + (playphone_paging.order_by.selected ? '&OrderBy=' + playphone_paging.order_by.selected : ''), { on_success: playphone_paging.print.bind(playphone_paging) });
            
                } 
            }
        } 
    }
}

playphone.suggest = function() {

    // public variables
    this.url = null;
    this.object = null;
    this.delay = 0.3;
    this.container = 'suggestions';
    this.node = 'SearchSuggest';
    this.nodes_to_select = [];
    this.format_result = null;
    this.markup = '';
    
    // private variables
    this.timeout = null;
    
    // methods
    this.initialize = function() {
        
        document.forms[0].autocomplete = 'false';
        
        playphone.$(this.container).style.display = 'none';
        
        document.onclick = function() { 
        
            playphone.$(this.container).style.display = 'none';
        
        }.bind(this)
        
        this.object.onkeypress = this.key_pressed.bind(this);
        this.object.onkeydown = this.key_down.bind(this);
    }
    
    this.index = -1;
    this.last_index = -1;
    this.items = playphone.$(this.container).getElementsByTagName('div');
    
    this.key = null;
    
    this.key_down = function(e) {
    
        this.key = (window.event) ? event.keyCode : e.keyCode;
    }
    
    this.key_pressed = function() {
    
        clearTimeout(this.timeout);
        
        if (this.key == 27) {
        
            playphone.$(this.container).style.display = 'none';
            
            return;
        
        } else if (this.key == 13) {
        
            if (this.index != -1) {
            
                while (this.items[this.index].attributes['selectable'] === undefined) {
                    
                    this.index++;
                }
                
                location.href = this.items[this.index].attributes['url'].value;
            
            } else {
            
                location.href = '/Search.aspx?Query=' + this.object.value;
                
            }
            
            return false;
        
        } else if (this.key == 38) {
        
            this.move_up();
            
            return;
        
        } else if (this.key == 40) {
        
            this.move_down();
            
            return;
        
        } else {
        
            this.index = -1; this.last_index = -1;
            
            this.timeout = setTimeout(function() { this.get_results(); }.bind(this), this.delay * 1000);
        }
    }
    
    this.move_down = function() {
    
        if (this.index < this.items.length - 1) {
            
            if (this.index < this.last_index) {
            
                this.index = this.last_index;
            }
            
            this.index++;
            
            if (this.items[this.index].attributes['selectable'] === undefined) {
            
                this.move_down();
            
            } else {
            
                if (this.last_index > -1) {
                
                    this.items[this.last_index].className = this.items[this.last_index].className.replace(' on', '');
                }
            
                this.items[this.index].className += ' on';
                
                this.last_index = this.index;
            }
        }
    }
    
    this.move_up = function() {
    
        if (this.index > 0) {
            
            this.index--;
            
            if (this.items[this.index].attributes['selectable'] === undefined) {
            
                this.move_up();
            
            } else {
            
                if (this.last_index > -1) {
                
                    this.items[this.last_index].className = this.items[this.last_index].className.replace(' on', '');
                }
            
                this.items[this.index].className += ' on';
                
                this.last_index = this.index;
            }
        }
    }
    
    this.get_results = function() {
    
        new playphone.ajax().request(this.url + '?Query=' + this.object.value, {on_success: this.show_results.bind(this)});
    }
    
    this.show_results = function(response) {
    
        last_content_type = -1;
    
        var xml = playphone.parse_xml(response);
        
        var nodes = xml.getElementsByTagName(this.node);
        
        this.markup = '';
        
        for (var i = 0; i < nodes.length; i++) {
            
            var result_item = [];
            
            for (var j = 0; j < this.nodes_to_select.length; j++) {
            
                try {
                
                    result_item[j] = nodes[i].getElementsByTagName(this.nodes_to_select[j])[0].childNodes[0].nodeValue;
                
                } catch (e) {
                
                    result_item[j] = null;
                }
            }
            this.format_result(result_item);
        }
        if(nodes.length != '0'){
            this.markup += '</div>'
            this.markup += '<a href="/Search.aspx?Query=' + this.object.value + '" class="view">View all search results</a>';
            
            playphone.$(this.container).innerHTML = this.markup
        };
        
        if (playphone.$(this.container).style.display == 'none') {
        
            playphone.$(this.container).style.display = 'block';
        }
    }
}

//Rating
playphone.rating = function(options) {
	
	this.id = options.container;
	this.container = playphone.$(options.container);
	this.image_on = new Image().src = options.image_on;
	this.image_off = new Image().src = options.image_off;
	this.image_hover = new Image().src = options.image_hover;
	this.length = options.length || 5;
	this.value = options.value || 0;
	this.enable = options.enable;
	this.images = [];
	this.is_initialized = false;
	this.item_id = options.item_id;
}

playphone.rating.items = [];

playphone.rating.create = function(options) {

	var rating = new playphone.rating(options);
	
	playphone.rating.items[rating.id] = rating;
	
	rating.render();
	
	return rating;
}

playphone.rating.prototype.render = function() {
	
	if (this.value == 0 && this.enable.toLowerCase() == 'none')
	{
	    this.container.innerHTML = "N/A";
	}
	else
	{	
	    for (var i = 1; i <= this.length; i++) {
    		
		    if (this.value >= i) {
    			
			    image = this.image_on;

		    } else {
    			
			    image = this.image_off;
		    }
    		
		    var index = document.images.length;

            if (this.enable.toLowerCase() == 'true' || !this.enable) {

		        var onclick = ' onclick="playphone.rating.click(this, \'' + this.id + '\')"';
		        var onmouseover = ' onmouseover="playphone.rating.over(this, \'' + this.id + '\')"';
		        var onmouseout = ' onmouseout="playphone.rating.out(this, \'' + this.id + '\')"';		    
    		
		    } else if (this.enable.toLowerCase() == 'false') {
    		
		        var onclick = ' onclick="showPopup(\'/Login.aspx\')"';
    		
		    } else if (this.enable.toLowerCase() == 'none') {
    		
		        this.container.className += ' nocursor';
		    }
    		
		    var image_id = 'rating.' + this.id + '.#' + i;

            this.container.innerHTML += '<img width="11" height="11" style="float:left; overflow:hidden" id="' + image_id + '" ' + onclick + onmouseover + onmouseout + '>';

		    this.images[i] = playphone.$(image_id);
    		
		    this.images[i].src = image;
		    this.images[i].setAttribute('imageSrc', image);
		    this.images[i].setAttribute('imageHover', this.image_hover);
		    this.images[i].setAttribute('value', i + ',' + this.item_id);
	    }
	}
	
    if (!this.is_initialized) {
    	
        this.initialize(this);
    }
}

playphone.rating.prototype.initialize = function(rating) {
	
	for (var i = 1; i < rating.length; i++) {
		
		var image_id = 'rating.' + this.id + '.#' + i;
		
		var image = playphone.$(image_id);
		
		rating.images[i] = image;
	}
	
	rating.is_initialized = true;
}

playphone.rating.over = function(source, id) {
	
	var rating = playphone.rating.items[id];

	var value = source.getAttribute('value').split(',')[0];
	
	for (var i = 1; i <= rating.length; i++) {
		
		if (value >= i) {
		
			//rating.images[i].src = rating.image_hover;
			
			playphone.$(rating.images[i].id).src = rating.image_hover;
		
		} else {
			
			//rating.images[i].src = rating.image_off;
			
			playphone.$(rating.images[i].id).src = rating.image_off;
		}
	}
 }
 
 playphone.rating.out = function(source, id) {
 	
	var rating = playphone.rating.items[id];

    var value = rating.value;
	
	for (var i = 1; i <= rating.length; i++) {
		
		if (value >= i) {
			
			//rating.images[i].src = rating.image_on;
			
			playphone.$(rating.images[i].id).src = rating.image_on;
		
		} else {
			
			//rating.images[i].src = rating.image_off;
			
			playphone.$(rating.images[i].id).src = rating.image_off;
		}
	}
 }
 
 playphone.rating.click = function(source, id) {
 	
	var rating = playphone.rating.items[id];
	
	rating.value = source.getAttribute('value').split(',')[0];
	
	new playphone.ajax().request('/ItemRating.aspx' + '?ItemId=' + source.getAttribute('value').split(',')[1] + '&Rating=' + rating.value, {on_success: function() {playphone.rating.out(source, id);}});
 }