(function($) {
function pollSubmitted(success) {
if(success) {
success = success.split('!');
var c = $.cookie('poll');
$.cookie('poll',(c?c+',':'')+success[0]);
var results = success[1].split(',');
$('#scroll').find('.result span').css({ width:0, marginLeft:15 }).end().find('.result em').hide().end().animate({ top:-174 }, 300, function() {
$('.result span').each(function(i) {
var r = results[i].split('-');
$(this).siblings('em').text(r[0]*2+'%').fadeIn();
$(this).animate({ width:r[0], marginLeft:r[1] }, 400);
});
});
}
}
function managePoll() {
$('#poll').find('button').click(function() {
var val=$('input[type=radio]:checked').val();
if(val) $.get('/ajax-data.php', { action:'poll', value:val }, pollSubmitted);
return false;
});
}
function addPopularProducts() {
var h = '';
$(h).appendTo('#popular-products').change(function() { if(this.value) window.location = '/models/'+this.value; });
};
$(document).ready(function() {
$('#poll p a').click(function() { $('#scroll').animate({ top:-174 }, 300); return false; });
$('.more').remove();
managePoll();
addPopularProducts();
var h = '';
$(h).appendTo('#amt').change(function() { if(this.value) window.location = '/models/amt/'+this.value; });
var h = '';
$(h).appendTo('#mpc').change(function() { if(this.value) window.location = '/models/mpc/'+this.value; });
var h = '';
$(h).appendTo('#polar-lights').change(function() { if(this.value) window.location = '/models/polar-lights/'+this.value; });
var h = '';
$(h).appendTo('#nascar').change(function() { if(this.value) window.location = '/models/nascar/'+this.value; });
});
})(jQuery);