var buckyballs;(function(){buckyballs={_reviews:false,_placeholder_text:{},_photos:false,_photo_thumbs:false,_photo_preload:{},_photo_main_image:false,_product_slideshow:false,_quotes_slideshow:false,_product_slider:false,_current_hash:false,_cart_hash:false,_slider_slides:false,_slide_width:1003,_timeout:false,_autoplay:false,_freeze:false,_photo_title:false,_photo_html:false,_photo_thumbs:false,_fixed:false,_quantity:{},_shipping_options:{},_shipping_upgrade:false,_shipping_ajax:false,payment_method:false,promo:false,promo_discount:0,products:false,errors:[],_submitting:false,_cubes:false,total:0,prediscount:0,buckycubes_video:false,_cart:false,spares_in_cart:[],_previous_shipping_selection:false,_highest_subtotal:0,enable_shipping_upgrades:true,promo:{code:false,discount_type:false,discount:false,works_on:[],works_on_shipping:[],min_total:0},init:function(){this._init_iframe();this._init_photos();this._init_purple_popup();this._init_reviews();this._init_placeholder();this._init_newsletter();this._init_esc();this._init_buckminster();if($('#product-area-wrap').length){this._init_homepage();}else if($('.cart').length){this._cart=true;this._init_cart();}else{this._set_chromatics(false);this._set_cubes(false);}},_init_cart:function(){this._init_fixed();this._init_templates();this._init_counters();this._init_checkboxes();this._init_remove_item();this._init_promo();this._init_tabs();this._init_same_shipping();this._init_form();this._init_errors();this._init_countries();this._init_next();this._init_shipping_upgrades();if(window.location.href.match('buckycubes')){this._set_cubes(true);}else if(window.location.href.match('chromatics')){this._set_chromatics(true);}else{this._set_chromatics(false);}
this._update_price();},_init_iframe:function(){if(window.location!=window.parent.location){$('a').each(function(i,el){el=$(el);var href=el.attr('href');if(href.match('mailto')){return true;}
if(href.match('#')){var regex=/#!\/(.*)/;var product=regex.exec(href)[1];el.attr('href','/products/'+product);}
href=el.attr('href');if(href.match(/\?/)){el.attr('href',href+'&ref=zoomdoggle');}else{el.attr('href',href+'/?ref=zoomdoggle');}
el.attr('target','_top');});}},_set_cubes:function(on){var images=[];if(on){$('*').removeClass('chromatics');$('*').addClass('cubes');$('.orig_img').hide();$('.chromatics_img').hide();$('.cube_img').show();$('#quotes-cubes').show();$('#quotes').hide();}else{$('*').removeClass('cubes');$('.cube_img').hide();$('.orig_img').show();$('#quotes-cubes').hide();$('#quotes').show();}},_set_chromatics:function(on){var images=[];if(on){$('*').addClass('chromatics');$('.orig_img').hide();$('.cube_img').hide();$('.chromatics_img').show();}else{$('*').removeClass('chromatics');$('.chromatics_img').hide();$('.orig_img').show();}},_init_shipping_upgrades:function(){$('.update_shipping, .counter input').change((function(){this._update_shipping_options();}).bind(this));this._update_shipping_options();},_init_esc:function(){$(document).keydown((function(e){var key=e.keyCode||e.which;if(key==27){this._hide_mask();}}).bind(this));},_update_shipping_options:function(){if(!this.enable_shipping_upgrades){$('#shipping_method').empty();this._shipping_upgrade=false;$('.shipping-options').hide();return;}
var zip=this._get_shipping_zip();var shipping_country=this._get_shipping_country();var total_quantity=0;var free_shipping_items=0;this._shipping_options={};if(!this._quantity){$('#shipping_method').empty();this._shipping_upgrade=false;$('.shipping-options').hide();return;}
var subtotal=0;this._update_price();for(var id in this._quantity){if(this._quantity[id]>0){total_quantity+=this._quantity[id];if(parseInt(this.products[id]['free_shipping'],10)){free_shipping_items+=this._quantity[id];}
var price=parseFloat(this.products[id]['price']);subtotal+=price*this._quantity[id];}}
if($('#shipping_method option').length){this._previous_shipping_selection=$('#shipping_method').val();}
if(zip&&shipping_country.toLowerCase()=='us'&&total_quantity>0&&this.payment_method!='gc'){if(this._shipping_ajax!=false){this._shipping_ajax.abort();}
this._shipping_upgrade=false;$('#shipping_method').val('');this._update_price();this._shipping_ajax=$.get('/ajax/shipping_rates/',{zip:zip,quantity:this._quantity},(function(response){options='';for(var option in response){var option_price='$'+response[option].toFixed(2);if(this.promo.works_on_shipping.indexOf(option)!=-1&&subtotal>=this.promo.min_total){option_price='FREE';}
options+='<option value="'+option+'">'+this._format_shipping_option(option)+': '+option_price+'</option>';}
if(options.length){var standard_price=this._get_shipping_price().toFixed(2);var standard_label='Standard Shipping (2-7 business days)';standard_price='$'+standard_price;if(free_shipping_items>1||(this.promo.works_on_shipping.indexOf('standard')!=-1&&subtotal>=this.promo.min_total)){standard_price='FREE';}
$('#shipping_method').empty().append('<option value="">'+standard_label+': '+standard_price+'</option>').append(options);this._shipping_options=response;if(this._previous_shipping_selection){$('#shipping_method').val(this._previous_shipping_selection);}
$('.shipping-options').show();this._update_price();}else{$('#shipping_method').empty();this._shipping_upgrade=false;$('.shipping-options').hide();}
this._shipping_ajax=false;}).bind(this),'json');}else{$('#shipping_method').empty();this._shipping_upgrade=false;$('.shipping-options').hide();}},_format_shipping_option:function(string){return this.ucwords(string.replace(/_/g,' ').toLowerCase());},ucwords:function(string){return(string+'').replace(/^([a-z])|\s+([a-z])/g,function($1){return $1.toUpperCase();});},_init_buckminster:function(){$('.open-commemorative-edition').click((function(){this._hide_mask();this._show_mask();$('#buckminster-popup').show();}).bind(this));$('#close-buckminster').click((function(){this._hide_mask();}).bind(this));},_init_newsletter:function(){$('#subscribe').click(function(){jQuery.post('/ajax/email/',{email:$('#newsletter-signup').val()},function(response){alert('We Got Your Email! High Five! Look out for news, discounts and all things Bucky');});});},_init_next:function(){$('.next-button').click((function(){var top=0;var step='quantity';for(var id in this._quantity){if(this._quantity[id]>0){step='billing';break;}}
if(step=='billing'){$('input','.billing-info').each(function(i,el){el=$(el);if(el.prop('type')=='checkbox'){return true;}
if(el.val()){step='shipping';return false;}});}
if(step=='shipping'){if(this._get_same_shipping()){step='payment';}else{$('input','.shipping-info').each(function(i,el){el=$(el);if(el.val()){step='payment';return false;}});}}
if(step=='payment'){$('input','.payment-info').each(function(i,el){el=$(el);if(el.prop('type')=='radio'){return true;}
if(el.val()){step='terms';return false;}});}
if(step=='terms'){if($('#terms').prop('checked')){step='';}}
switch(step){case'quantity':top=$('.cart').offset().top;break;case'billing':top=$('.billing-info').offset().top;break;case'shipping':top=$('.shipping-info').offset().top;break;case'payment':top=$('.payment-info').offset().top;break;case'terms':top=$('.terms').offset().top;break;}
if(top>0){$('html, body').animate({scrollTop:top+'px'},500);}}).bind(this));},_init_countries:function(){$('.country').change((function(e){var target=$(e.target);var type=target.hasClass('shipping')?'shipping':'billing';var li=$('.'+type+'_state_fields');if(target.val().toLowerCase()=='us'){$('label',li).html('State');$('.select',li).show();$('select',li).prop('disabled',false).show();$('input',li).prop('disabled',true).hide();}else{$('label',li).html('Province');$('.select',li).hide();$('select',li).prop('disabled',true).hide();$('input',li).prop('disabled',false).show();}}).bind(this)).trigger('change');},_init_errors:function(){$('#close-errors').click((function(){this._hide_mask();$('#errors-container').hide();}).bind(this));this._show_errors();},_init_homepage:function(){this._set_chromatics(false);this._init_slider();this._init_product_slideshow();this._init_quotes_slideshow();},_init_templates:function(){$.template('cart-item','<div class="line cart-item itemid-${itemid}"><div class="left">${quantity} ${name}</div><div class="right">$${price} <a href="javascript:void(0);" id="remove-${itemid}" class="remove">x</a></div><br clear="all" /></div>');},_init_form:function(){$('#order-form').submit((function(e){if(!this._submitting&&this._validate_form()){$('#payment_method').remove();$('#shipping_method').remove();$('#order-form').append('<input type="hidden" name="payment_method" id="payment_method" value="'+this.payment_method+'" />');$('#order-form').append('<input type="hidden" name="shipping_method" id="shipping_method" value="'+this._shipping_upgrade+'" />');setUrchinInputCode(pageTracker);this._submitting=true;return true;}
return false;}).bind(this));$('.update').change((function(){this._update_price();}).bind(this));},_validate_form:function(){this.errors=[];if(!$('#terms').prop('checked')){this.errors.push('You must accept the terms.');}
this._show_errors();return!(this.errors.length);},_show_errors:function(){$('ul','#errors-container').empty();for(var i in this.errors){if(typeof this.errors[i]=='string'){$('ul','#errors-container').append('<li>'+this.errors[i]+'</li>');}}
if(this.errors.length>0){var height=$('#errors-container').height();$('#errors-container').css('margin-top','-'+parseInt(height/2,10)+'px');this._show_mask();$('#errors-container').show();}},_v_center:function(el){var scrollTop=$(document).scrollTop();el.css('top',scrollTop+100+'px');},_init_tabs:function(){$('a','#billing-options').click((function(e){var target=$(e.target);this.payment_method=target.attr('id').split('-')[1];$('#billing-options').removeClass().addClass(this.payment_method);this._update_shipping_options();this._toggle_fields();}).bind(this));$('#option-'+this.payment_method).trigger('click');},_toggle_fields:function(){switch(this.payment_method){case'cc':$('.billing-info').show();if(this._get_same_shipping()){$('.shipping-info').hide();}else{$('.shipping-info').show();}
$('.payment-info').show();break;case'pp':$('.billing-info').hide();$('.shipping-info').show();$('.payment-info').hide();break;case'gc':$('.billing-info').hide();$('.shipping-info').hide();$('.payment-info').hide();break;}
this._update_price();},_init_same_shipping:function(){$('input','.same-shipping').change((function(e){this._toggle_fields();this._update_shipping_options();}).bind(this)).trigger('change');},_get_same_shipping:function(){return $('input','.same-shipping').prop('checked');},_clear_promo:function(){$('#promo_code').val('');this.promo={code:false,type:false,discount_type:false,works_on:[],works_on_shipping:[],min_total:0};this._update_shipping_options();$('#show_promo').show();$('#enter_promo').hide();$('#promo').show();},_init_promo:function(){if(this.promo.code){$('#promo').hide();}
$('#show_promo').click(function(){$(this).hide();$('#enter_promo').show();});$('#promo_code').keydown((function(e){var key=e.keyCode||e.which;if(key==13){$('#apply-promo').trigger('click');return false;}}).bind(this));$('#apply-promo').click((function(){var code=$('#promo_code').val().toLowerCase();$.post('/ajax/promo/',{promo:$('#promo_code').val(),amount:this.prediscount,quantity:this._quantity},(function(response){if(response.length==0){$('#promo_code').val('Invalid Promo Code');$('#promo_code').click(function(){$(this).val('').unbind('click');});this.promo={code:false,type:false,discount_type:false,works_on:[],works_on_shipping:[],min_total:false};}else{$('#promo').hide();this.promo={code:response['code'],discount_type:response['type'],discount:response['discount'],works_on:response['works_on'],works_on_shipping:response['works_on_shipping'],min_total:parseFloat(response['min_total'])};}
this._update_shipping_options();this._update_price();}).bind(this),'json');}).bind(this));},_init_checkboxes:function(){$('.checkbox').each((function(i,el){el=$(el);var checkbox=$('input',el);el.click((function(){if(checkbox.prop('checked')){el.removeClass('checked');checkbox.prop('checked',false);}else{el.addClass('checked');checkbox.prop('checked',true);}
this._update_price();}).bind(this));}).bind(this));},_init_counters:function(){$('.counter input').live('change',((function(){this._update_price();}).bind(this)));$('.increment').live('click',((function(e){var target=$(e.target);var input=target.siblings('input');input.val(parseInt(input.val(),10)+1).trigger('change');}).bind(this)));$('.decrement').live('click',((function(e){var target=$(e.target);var input=target.siblings('input');var new_val=parseInt(input.val(),10)-1;if(new_val<0){new_val=0;}
input.val(new_val).trigger('change');}).bind(this)));},_init_remove_item:function(){$('.remove').live('click',(function(e){var target=$(e.target);var id=target.attr('id');if(id=='remove_promo'){this._clear_promo();}else{var id=id.split('-')[1];var input=$('input[name="quantity['+id+']"]');if(input.prop('type').toLowerCase()=='text'){input.val(0);}else{input.prop('checked',false);input.parent('div').removeClass('checked');}}
this._update_price();}).bind(this));},_update_price:function(){$('.cart-item').remove();var subtotal=0;var quantity={};var free_shipping_items=0;$('.counter input').each((function(i,el){el=$(el);var q=parseInt(el.val(),10);if(q>0){var product_id=this._get_product_id(el);if(this.products[product_id]){quantity[product_id]=q;var spares_id=parseInt(this.products[product_id]['spares_id'],10);if(spares_id&&$.inArray(spares_id,this.spares_in_cart)==-1){this.spares_in_cart.push(spares_id);$('.spares strong:first').after(''+'<div class="spare">'+'<img src="'+this.products[spares_id]['spares_url']+'" />'+'<div class="counter">'+'<input type="text" name="quantity['+spares_id+']" value=" '+this.products[spares_id]['spares_value']+'" />'+'<a href="javascript:void(0);" class="increment"></a>'+'<br />'+'<a href="javascript:void(0);" class="decrement"></a>'+'</div>'+'<div class="spare-details">'+this.products[spares_id]['spares_label']+'  $'+parseFloat(this.products[spares_id]['price']).toFixed(2)+'</div>'+'</div>');}}}}).bind(this));this._quantity=quantity;var total_quantity=0;for(id in quantity){var price=parseFloat(this.products[id]['price']);subtotal+=price*quantity[id];total_quantity+=quantity[id];if(this.products[id]['code'].match(/^COMBO/)){free_shipping_items+=(quantity[id]*2);}else if(parseInt(this.products[id]['free_shipping'],10)){free_shipping_items+=quantity[id];}
$.tmpl('cart-item',{itemid:id,name:this.products[id]['name'],quantity:quantity[id],price:(price*quantity[id]).toFixed(2)}).prependTo('#order-summary .content');}
var shipping=0;if(this._is_shipping_upgrade()&&typeof this._shipping_options[$('#shipping_method').val()]!='undefined'){this._shipping_upgrade=$('#shipping_method').val();shipping=this._shipping_options[this._shipping_upgrade];$('#ship-free').hide();}else{this._shipping_upgrade=false;if(total_quantity>0&&free_shipping_items<2){shipping=parseFloat(this._get_shipping_price());}}
if(this._shipping_upgrade){var shipping_method=this._shipping_upgrade;}else{var shipping_method='standard';}
if(this.promo.works_on_shipping.indexOf(shipping_method)!=-1&&subtotal>=this.promo.min_total){shipping=0;}
if(shipping==0&&total_quantity){$('#shipping-price').html('FREE');if(free_shipping_items){$('#ship-free').hide();}}else{$('#shipping-price').html('$'+shipping.toFixed(2));if(shipping&&!this._is_shipping_upgrade()){$('#ship-free').show();}}
this.prediscount=subtotal;var discount=this._get_discount(subtotal,shipping);if(discount>0){$('#subtotal').before('<div class="line cart-item promo-item"><div class="left">Promo Code</div><div class="right negative">- $'+discount.toFixed(2)+'&nbsp;<a href="javascript:void(0);" id="remove_promo" class="remove">x</a></div><br clear="all" /></div>');subtotal-=discount;}
var tax=this._get_tax(subtotal+shipping);if(tax>0){$('#subtotal').after('<div class="line cart-item"><div class="left">New York State Tax</div><div class="right">$'+tax.toFixed(2)+'</div><br clear="all" /></div>');}
$('#subtotal-price').html('$'+subtotal.toFixed(2));var total=subtotal+shipping+tax;if(total<0){total=0;}
this.total=total;$('#total-price').html('$');setTimeout(function(){$('#total-price').html('$'+total.toFixed(2))},0);},_is_shipping_upgrade:function(){return $('#shipping_method').is(':visible')&&$('#shipping_method').val();},_get_tax:function(amount){var tax=0;var zip=this._get_shipping_zip();if(typeof tax_rates!='undefined'&&typeof tax_rates[zip]!='undefined'){tax_rate=tax_rates[zip];tax_rate+=.04;tax=Math.round(amount*tax_rate*100)/100;}
return tax;},_get_shipping_zip:function(){if(this._get_same_shipping()&&this.payment_method=='cc'){return $('#billing_zip').val();}else{return $('#shipping_zip').val();}},_get_shipping_country:function(){if(this._get_same_shipping()&&this.payment_method=='cc'){return $('#billing_country').val();}else{return $('#shipping_country').val();}},_get_discount:function(subtotal,shipping_price){var discount=0;var discountable_total=0;for(var id in this._quantity){int_id=parseInt(id,10);if(this._quantity[id]>0&&typeof this.promo.works_on[int_id]!='undefined'){var promo_quantity=this.promo.works_on[int_id];if(promo_quantity>0){discountable_quantity=promo_quantity;}else{discountable_quantity=this._quantity[id];}
discountable_total+=parseFloat(this.products[id]['price'])*discountable_quantity;}}
if(this.promo.discount_type=='flat'&&discountable_total>0){discount=this.promo.discount;if(discount>subtotal){discount=subtotal;}}else if(this.promo.discount_type=='percentage'&&discountable_total>0){var percent=this.promo.discount/100;discount=discountable_total*percent;}
if(subtotal<this.promo.min_total){discount=0;}
return discount;},_get_shipping_price:function(){if(this._get_shipping_country().toLowerCase()=='us'){return 5.95;}
return 10.95;},_get_product_id:function(el){return el.attr('name').match(/\[(\d+)\]/)[1];},_init_fixed:function(){this._fixed=$('.fixed');var top=this._fixed.css('top').replace(/px/g,'');var min_offset=this._fixed.offset().top;$(window).scroll((function(){var scroll=$(document).scrollTop();if(scroll>min_offset){var new_top=$(document).scrollTop()-min_offset+10;}else{var new_top=0;}
var max_offset=($('.terms-wrap').offset().top+$('.terms-wrap').height())-this._fixed.height()-95;if(new_top>max_offset){new_top=max_offset;}
this._fixed.stop().animate({top:new_top+'px'},{duration:500,queue:false});}).bind(this));},_init_videos:function(){if(!$('#thumbs').length){return;}
$('.video').click(function(){var video=$(this).attr('id').replace('video-','');var path=video;if(video=='buckyballs'){video='balls';}else if(video=='buckycubes'){video='cubes';}else{video='book';}
$('#video-container').empty().append('<div id="main-video"></div>');var flashvars={file:'/swf/'+video+'.flv',autostart:'true',image:'/images/product-images/'+path+'/video.jpg'};var params={allowfullscreen:'true',allowscriptaccess:'always',wmode:"transparent"};var attributes={id:'video-container',name:'video-container'};swfobject.embedSWF('/js/mediaplayer/player.swf','video-container','580','346','9.0.115','false',flashvars,params,attributes);});},_init_slider:function(){this._product_slider=$('#product-slider');if(!this._product_slider.length){return;}
this._slider_slides=$('.slide',this._product_slider);this._init_videos();this._current_hash=this._strip_hash(window.location.hash);if(!this._current_hash){this._current_hash='originals';}
if(this._current_hash=='purple'||this._current_hash=='blue-green'||this._current_hash=='pink-edition'||this._current_hash=='limited-edtion'){this._current_hash='colors';window.location.hash='!/'+this._current_hash;}
if(this._current_hash=='the-big-book-of-bucky'){this._current_hash='books';window.location.hash='!/'+this._current_hash;}
if(this._current_hash=='originals'){this._current_hash='buckyballs';window.location.hash='!/'+this._current_hash;}
this._set_active(this._current_hash);this._set_slide(this._current_hash,false);$('#previous').click((function(){this._previous_slide();}).bind(this));$('#next').click((function(){this._next_slide();}).bind(this));$(document).keyup((function(e){if(e.keyCode==37){this._previous_slide();return false;}else if(e.keyCode==39){this._next_slide();return false;}}).bind(this));$(window).hashchange((function(){var new_hash=this._strip_hash(window.location.hash);if(new_hash=='purple'||new_hash=='blue-green'||new_hash=='pink-edition'||new_hash=='limited-edtion'){new_hash='colors';window.location.hash='!/'+new_hash;}
if(new_hash=='the-big-book-of-bucky'){new_hash='books';window.location.hash='!/'+new_hash;}
if(new_hash=='originals'){new_hash='buckyballs';window.location.hash='!/'+new_hash;}
if(new_hash!=this._current_hash){this._set_slide(new_hash,true);}}).bind(this));},_next_slide:function(){var index=this._get_index(this._current_hash);var new_index=index+1;if(new_index>this._slider_slides.length-1){new_index=0;}
this._set_slide(this._get_slide(new_index),true);},_previous_slide:function(){var index=this._get_index(this._current_hash);var new_index=index-1;if(new_index<0){new_index=this._slider_slides.length-1;}
this._set_slide(this._get_slide(new_index),true);},_set_timeout:function(){this._clear_timeout();if(this._autoplay){this._timeout=setTimeout(this._next_slide.bind(this),7000);}},_clear_timeout:function(){clearTimeout(this._timeout);},_set_active:function(hash){$('.nav').removeClass('active');$('#nav-'+hash).addClass('active');if(hash.toLowerCase()=='buckycubes'){this._set_cubes(true);}else if(hash.toLowerCase()=='chromatics'){this._set_chromatics(true);}else{this._set_cubes(false);this._set_chromatics(false);}},_get_slide:function(index){return this._slider_slides.eq(index).attr('id').replace(/^slide\-/g,'');},_set_slide:function(slide,animate){if(this._freeze){return;}
if(this.buckycubes_video!==false){if(jwplayer&&jwplayer.pause){jwplayer(this.buckycubes_video).pause(true);}}
var new_index=this._get_index(slide);var new_left=new_index*this._slide_width;if(animate){this._product_slider.animate({scrollLeft:new_left},500);}else{this._product_slider.scrollLeft(new_left);}
this._current_hash=slide;this._set_active(this._current_hash);window.location.hash='!/'+this._get_slide(new_index);$('#quotes .order a').attr('href','/order/'+this._current_hash);this._set_timeout();},_get_index:function(slide){return $('#slide-'+slide).index('.slide',this._product_slider);},_strip_hash:function(hash){return hash.replace(/#!?\//g,'');},_init_quotes_slideshow:function(){this._quotes_slideshow=$('#quotes-slideshow');if(!this._quotes_slideshow.length){return;}
this._quotes_slideshow.cycle({timeout:7000,speed:500,pager:'#quotes-nav',pagerAnchorBuilder:function(idx,slide){slide=$(slide);var src=slide.children('img').attr('src');return'<div class="quote-nav"><a href="javascript:void(0);"><img src="'+src+'" /></a></div>';}});},_init_product_slideshow:function(){this._product_slideshow=$('#product-slideshow');if(!this._product_slideshow.length){return;}
this._product_slideshow.cycle({timeout:8000,fx:'scrollHorz',pager:'#slideshow-nav',pagerAnchorBuilder:function(idx,slide){slide=$(slide);var src=slide.children('img').attr('src');return'<li></li>';},before:function(){if($(this).hasClass('slide1')){var current=$('img',$('.quotes'));var src=current.prop('src');if(src.match('esquire')){setTimeout(function(){current.attr('src','/images/quotes/people.png');},200);}else if(src.match('people')){setTimeout(function(){current.attr('src','/images/quotes/entertainment-weekly.png');},200);}else{setTimeout(function(){current.attr('src','/images/quotes/esquire.png');},200);}}}});},_init_purple_popup:function(){$('.open-purple').click((function(){this._show_mask();$('#purple-popup').show();}).bind(this));$('#close-purple').click((function(){this._hide_mask();$('#purple-popup').hide();}).bind(this));},_set_main_photo:function(index,current_photos){var thumb=this._photo_thumbs.children('img').eq(index);if(thumb.hasClass('video_thumb')){var hash=this._current_hash;this._photo_main_image.empty().append('<div id="main-image-video"></div>');var flashvars={file:'/swf/'+current_photos['video'],autostart:'true',image:'/images/product-images/'+hash+'/video.jpg'};var params={allowfullscreen:'true',allowscriptaccess:'always',wmode:"transparent"};var attributes={id:'main-image-video',name:'main-image-video'};swfobject.embedSWF('/js/mediaplayer/player.swf','main-image-video','533','336','9.0.115','false',flashvars,params,attributes);}else{this._photo_main_image.empty().append(thumb.clone());}},_set_photos:function(hash,current_photos,video_first){if(!current_photos){return;}
this._photo_thumbs.empty();if(current_photos.has_video){for(var i=1;i<=4;i++){this._photo_thumbs.append('<img src="/images/product-images/'+hash+'/'+i+'.jpg" />');}
if(video_first){this._photo_thumbs.prepend('<img class="video_thumb" src="/images/product-images/'+hash+'/video.jpg" />');}else{this._photo_thumbs.append('<img class="video_thumb" src="/images/product-images/'+hash+'/video.jpg" />');}
this._photo_thumbs.children('img:last').addClass('last');}else{for(var i=1;i<=5;i++){this._photo_thumbs.append('<img src="/images/product-images/'+hash+'/'+i+'.jpg" />');}}
this._photo_title.html(current_photos['title']);this._photo_html.html(current_photos['html']);$('#photo-buy-now a').attr('href','/order/'+hash);if(hash=='buckycubes'){$('#photo-buy-now .orig_img').hide();$('#photo-buy-now .cube_img').show();$('#photo-buy-now .chromatics_img').hide();$('#photo-title').addClass('cubes');}else if(hash=='chromatics'){$('#photo-buy-now .orig_img').hide();$('#photo-buy-now .cube_img').hide();$('#photo-buy-now .chromatics_img').show();$('#photo-title').removeClass('cubes');$('#photo-title').addClass('chromatics');}else{$('#photo-buy-now .cube_img').hide();$('#photo-buy-now .orig_img').show();$('#photo-buy-now .chromatics_img').hide();$('#photo-title').removeClass('cubes');$('#photo-title').removeClass('chromatics');}
this._set_main_photo(0,current_photos);this._clear_timeout();this._freeze=true;this._reviews.hide();this._photos.show();this._show_mask();},_init_photos:function(){this._photos=$('#photos');this._photo_thumbs=$('#photo-thumbs');this._photo_main_image=$('#main-image');this._photo_title=$('#photo-title');this._photo_html=$('#photo-html');$('.check-em-out, .watch-the-video, #product-slider .main-image').click((function(e){var target=$(e.target);var current_photos=photos[this._current_hash];this._set_photos(this._current_hash,current_photos,target.hasClass('watch-the-video'));}).bind(this));$('.open_photo').click((function(e){var target=$(e.target);var id=target.attr('id').replace(/^photo/,'');this._current_hash=id;var current_photos=photos[this._current_hash];this._set_photos(this._current_hash,current_photos,false);}).bind(this));$('img',this._photo_thumbs).live('click',((function(e){var target=$(e.target);var index=target.index('#photo-thumbs img');var current_photos=photos[this._current_hash];this._set_main_photo(index,current_photos);}).bind(this)));$('#close-photos').click((function(){this._freeze=false;this._set_timeout();this._photos.hide();this._hide_mask();}).bind(this));},_show_mask:function(){$('.video').hide();var wrap_height=parseInt($('#wrap').css('height').replace(/px/g,''),10);$('#mask').css('height',(wrap_height+50)+'px');$('#mask').show();},_hide_mask:function(){this._freeze=false;$('.overlay').hide();$('.video').show();$('#mask').hide();},_init_reviews:function(){this._reviews=$('#reviews');if(!this._reviews.length){return;}
$('#read-reviews').click((function(){this._clear_timeout();this._freeze=true;this._photos.hide();this._reviews.show();this._show_mask();}).bind(this));$('#close-reviews').click((function(){this._freeze=false;this._set_timeout();this._reviews.hide();this._hide_mask();}).bind(this));},_init_placeholder:function(){if(!$('.placeholder').length){return;}
$('.placeholder').each((function(i,el){el=$(el);this._placeholder_text[el.attr('id')]=el.val();el.focus((function(e){target=$(e.target);if(target.val()==this._placeholder_text[target.attr('id')]){target.val('');}}).bind(this));el.blur((function(e){target=$(e.target);if(target.val()==''){target.val(this._placeholder_text[target.attr('id')]);}}).bind(this));}).bind(this));}};$(function(){buckyballs.init();});})();if(!Function.prototype.bind){Function.prototype.bind=function(obj){var slice=[].slice;var args=slice.call(arguments,1);var self=this;var nop=function(){};var bound=function(){return self.apply(this instanceof nop?this:(obj||{}),args.concat(slice.call(arguments)));};nop.prototype=self.prototype;bound.prototype=new nop();return bound;};}
if(!Array.prototype.indexOf){Array.prototype.indexOf=function(searchElement){"use strict";if(this===void 0||this===null){throw new TypeError();}
var t=Object(this);var len=t.length>>>0;if(len===0){return-1;}
var n=0;if(arguments.length>0){n=Number(arguments[1]);if(n!==n){n=0;}else if(n!==0&&n!==window.Infinity&&n!==-window.Infinity){n=(n>0||-1)*Math.floor(Math.abs(n));}}
if(n>=len){return-1;}
var k=n>=0?n:Math.max(len-Math.abs(n),0);for(;k<len;k++){if(k in t&&t[k]===searchElement){return k;}}
return-1;}}
(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('<iframe tabindex="-1" title="empty"/>').hide().one("load",function(){r||l(a());n()}).attr("src",r||"javascript:0").insertAfter("body")[0].contentWindow;h.onpropertychange=function(){try{if(event.propertyName==="title"){q.document.title=h.title}}catch(s){}}}};j.stop=k;o=function(){return a(q.location.href)};l=function(v,s){var u=q.document,t=$.fn[c].domain;if(v!==s){u.title=h.title;u.open();t&&u.write('<script>document.domain="'+t+'"<\/script>');u.close();q.location.hash=v}}})();return j})()})(jQuery,this);(function(a){var r=a.fn.domManip,d="_tmplitem",q=/^[^<]*(<[\w\W]+>)[^>]*$|\{\{\! /,b={},f={},e,p={key:0,data:{}},h=0,c=0,l=[];function g(e,d,g,i){var c={data:i||(d?d.data:{}),_wrap:d?d._wrap:null,tmpl:null,parent:d||null,nodes:[],calls:u,nest:w,wrap:x,html:v,update:t};e&&a.extend(c,e,{nodes:[],parent:d});if(g){c.tmpl=g;c._ctnt=c._ctnt||c.tmpl(a,c);c.key=++h;(l.length?f:b)[h]=c}return c}a.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(f,d){a.fn[f]=function(n){var g=[],i=a(n),k,h,m,l,j=this.length===1&&this[0].parentNode;e=b||{};if(j&&j.nodeType===11&&j.childNodes.length===1&&i.length===1){i[d](this[0]);g=this}else{for(h=0,m=i.length;h<m;h++){c=h;k=(h>0?this.clone(true):this).get();a.fn[d].apply(a(i[h]),k);g=g.concat(k)}c=0;g=this.pushStack(g,f,i.selector)}l=e;e=null;a.tmpl.complete(l);return g}});a.fn.extend({tmpl:function(d,c,b){return a.tmpl(this[0],d,c,b)},tmplItem:function(){return a.tmplItem(this[0])},template:function(b){return a.template(b,this[0])},domManip:function(d,l,j){if(d[0]&&d[0].nodeType){var f=a.makeArray(arguments),g=d.length,i=0,h;while(i<g&&!(h=a.data(d[i++],"tmplItem")));if(g>1)f[0]=[a.makeArray(d)];if(h&&c)f[2]=function(b){a.tmpl.afterManip(this,b,j)};r.apply(this,f)}else r.apply(this,arguments);c=0;!e&&a.tmpl.complete(b);return this}});a.extend({tmpl:function(d,h,e,c){var j,k=!c;if(k){c=p;d=a.template[d]||a.template(null,d);f={}}else if(!d){d=c.tmpl;b[c.key]=c;c.nodes=[];c.wrapped&&n(c,c.wrapped);return a(i(c,null,c.tmpl(a,c)))}if(!d)return[];if(typeof h==="function")h=h.call(c||{});e&&e.wrapped&&n(e,e.wrapped);j=a.isArray(h)?a.map(h,function(a){return a?g(e,c,d,a):null}):[g(e,c,d,h)];return k?a(i(c,null,j)):j},tmplItem:function(b){var c;if(b instanceof a)b=b[0];while(b&&b.nodeType===1&&!(c=a.data(b,"tmplItem"))&&(b=b.parentNode));return c||p},template:function(c,b){if(b){if(typeof b==="string")b=o(b);else if(b instanceof a)b=b[0]||{};if(b.nodeType)b=a.data(b,"tmpl")||a.data(b,"tmpl",o(b.innerHTML));return typeof c==="string"?(a.template[c]=b):b}return c?typeof c!=="string"?a.template(null,c):a.template[c]||a.template(null,q.test(c)?c:a(c)):null},encode:function(a){return(""+a).split("<").join("&lt;").split(">").join("&gt;").split('"').join("&#34;").split("'").join("&#39;")}});a.extend(a.tmpl,{tag:{tmpl:{_default:{$2:"null"},open:"if($notnull_1){_=_.concat($item.nest($1,$2));}"},wrap:{_default:{$2:"null"},open:"$item.calls(_,$1,$2);_=[];",close:"call=$item.calls();_=call._.concat($item.wrap(call,_));"},each:{_default:{$2:"$index, $value"},open:"if($notnull_1){$.each($1a,function($2){with(this){",close:"}});}"},"if":{open:"if(($notnull_1) && $1a){",close:"}"},"else":{_default:{$1:"true"},open:"}else if(($notnull_1) && $1a){"},html:{open:"if($notnull_1){_.push($1a);}"},"=":{_default:{$1:"$data"},open:"if($notnull_1){_.push($.encode($1a));}"},"!":{open:""}},complete:function(){b={}},afterManip:function(f,b,d){var e=b.nodeType===11?a.makeArray(b.childNodes):b.nodeType===1?[b]:[];d.call(f,b);m(e);c++}});function i(e,g,f){var b,c=f?a.map(f,function(a){return typeof a==="string"?e.key?a.replace(/(<\w+)(?=[\s>])(?![^>]*_tmplitem)([^>]*)/g,"$1 "+d+'="'+e.key+'" $2'):a:i(a,e,a._ctnt)}):e;if(g)return c;c=c.join("");c.replace(/^\s*([^<\s][^<]*)?(<[\w\W]+>)([^>]*[^>\s])?\s*$/,function(f,c,e,d){b=a(e).get();m(b);if(c)b=j(c).concat(b);if(d)b=b.concat(j(d))});return b?b:j(c)}function j(c){var b=document.createElement("div");b.innerHTML=c;return a.makeArray(b.childNodes)}function o(b){return new Function("jQuery","$item","var $=jQuery,call,_=[],$data=$item.data;with($data){_.push('"+a.trim(b).replace(/([\\'])/g,"\\$1").replace(/[\r\t\n]/g," ").replace(/\$\{([^\}]*)\}/g,"{{= $1}}").replace(/\{\{(\/?)(\w+|.)(?:\(((?:[^\}]|\}(?!\}))*?)?\))?(?:\s+(.*?)?)?(\(((?:[^\}]|\}(?!\}))*?)\))?\s*\}\}/g,function(m,l,j,d,b,c,e){var i=a.tmpl.tag[j],h,f,g;if(!i)throw"Template command not found: "+j;h=i._default||[];if(c&&!/\w$/.test(b)){b+=c;c=""}if(b){b=k(b);e=e?","+k(e)+")":c?")":"";f=c?b.indexOf(".")>-1?b+c:"("+b+").call($item"+e:b;g=c?f:"(typeof("+b+")==='function'?("+b+").call($item):("+b+"))"}else g=f=h.$1||"null";d=k(d);return"');"+i[l?"close":"open"].split("$notnull_1").join(b?"typeof("+b+")!=='undefined' && ("+b+")!=null":"true").split("$1a").join(g).split("$1").join(f).split("$2").join(d?d.replace(/\s*([^\(]+)\s*(\((.*?)\))?/g,function(d,c,b,a){a=a?","+a+")":b?")":"";return a?"("+c+").call($item"+a:d}):h.$2||"")+"_.push('"})+"');}return _;")}function n(c,b){c._wrap=i(c,true,a.isArray(b)?b:[q.test(b)?b:a(b).html()]).join("")}function k(a){return a?a.replace(/\\'/g,"'").replace(/\\\\/g,"\\"):null}function s(b){var a=document.createElement("div");a.appendChild(b.cloneNode(true));return a.innerHTML}function m(o){var n="_"+c,k,j,l={},e,p,i;for(e=0,p=o.length;e<p;e++){if((k=o[e]).nodeType!==1)continue;j=k.getElementsByTagName("*");for(i=j.length-1;i>=0;i--)m(j[i]);m(k)}function m(j){var p,i=j,k,e,m;if(m=j.getAttribute(d)){while(i.parentNode&&(i=i.parentNode).nodeType===1&&!(p=i.getAttribute(d)));if(p!==m){i=i.parentNode?i.nodeType===11?0:i.getAttribute(d)||0:0;if(!(e=b[m])){e=f[m];e=g(e,b[i]||f[i],null,true);e.key=++h;b[h]=e}c&&o(m)}j.removeAttribute(d)}else if(c&&(e=a.data(j,"tmplItem"))){o(e.key);b[e.key]=e;i=a.data(j.parentNode,"tmplItem");i=i?i.key:0}if(e){k=e;while(k&&k.key!=i){k.nodes.push(j);k=k.parent}delete e._ctnt;delete e._wrap;a.data(j,"tmplItem",e)}function o(a){a=a+n;e=l[a]=l[a]||g(e,b[e.parent.key+n]||e.parent,null,true)}}}function u(a,d,c,b){if(!a)return l.pop();l.push({_:a,tmpl:d,item:this,data:c,options:b})}function w(d,c,b){return a.tmpl(a.template(d),c,b,this)}function x(b,d){var c=b.options||{};c.wrapped=d;return a.tmpl(a.template(b.tmpl),b.data,c,b.item)}function v(d,c){var b=this._wrap;return a.map(a(a.isArray(b)?b.join(""):b).filter(d||"*"),function(a){return c?a.innerText||a.textContent:a.outerHTML||s(a)})}function t(){var b=this.nodes;a.tmpl(null,null,null,this).insertBefore(b[0]);a(b).remove()}})(jQuery)
