function dancer( product_id,token )
{
	this.product_id = product_id;
	this.token = token;
	//alert('getjhere');
	if( $(this.token) ){
		this.visibility = $(this.token).style.visibility;
		if( !stristr( this.token,'price' ) && !stristr( this.token,'cart' ) )
			$(this.token).style.visibility = 'hidden';		
		
	}
}

dancer.prototype.dance = function(data)
{
	
	var dancer_data = eval('data[\'product_'+this.product_id+'\']');	
	var salelable = eval('dancer_data[\'saleable\']' );
		
	if( this.token == 'topcartlink' ){		
		$$('.top-link-cart').each(function (el){			
			el.innerHTML = stripslashes(dancer_data['topcartlink'] );
		});
	}else{	
		if( eval('dancer_data[\''+this.token+'\']' ) ){
			$(this.token).innerHTML = stripslashes(dancer_data[this.token] );
		}else{
			if( $(this.token) ){
				if( eval('dancer_data[\'saleable\']' )){
					
					if( this.token == 'availability' ){				
						$(this.token).innerHTML = 'Availability: <span>In stock<span>';
						$(this.token).className="availability in-stock";
					}
				}else{
					if( this.token == 'availability' ){				
						$(this.token).innerHTML = 'Availability: <span>Out of stock<span>';
						$(this.token).className="availability out-of-stock";
					}
				}
			}
		}
	
		if( $(this.token) ){
			$(this.token).style.visibility = this.visibility;
		}	
	}
}

function stripslashes (str) {    
    return (str + '').replace(/\\(.?)/g, function (s, n1) {
        switch (n1) {
        case '\\':
            return '\\';
        case '0':
            return '\u0000';
        case '':
            return '';
        default:
            return n1;
        }
    });
}


function stristr (haystack, needle, bool) {   
    var pos = 0; 
    haystack += '';
    pos = haystack.toLowerCase().indexOf((needle + '').toLowerCase());
    if (pos == -1) {
        return false;
    } else {
        if (bool) {
            return haystack.substr(0, pos);
        } else {
            return haystack.slice(pos);
        }
    }
}
