﻿$(document).ready(function(){$("a[rel='external']").attr("target","_blank");var root=window.location.host;initSlider();initSubnav();initFBFrame();initNutrInfo();initGameNav();initGameEmbed();initWTB();initPromoSlider();});function initSlider(){var slider=$('#slider');var nav=$('#feature-nav');var count=slider.find('li').size();var navcount=$(nav).find('li').size();if(slider.length>0){if(count<=1){$('.anythingSlider').anythingSlider({autoPlay:false,hashTags:false,buildNavigation:false,pauseOnHover:false,animationTime:400});}else{$('.anythingSlider').anythingSlider({delay:8000,navigationFormatter:formatText,hashTags:false,buildNavigation:false,pauseOnHover:false,animationTime:400});}
if(navcount>1){$(nav).find('.wrapper').jCarouselLite({btnPrev:"#back",btnNext:"#forward",circular:false,visible:1,start:0});}
if(navcount>3){$(nav).find('.arrow').show();}
if(count>1){$('#rollover').show();$('a#nav-close').click(function(e){hideNav();e.preventDefault();});$('a#rollover').click(function(e){showNav();$('#nav-close').show();e.preventDefault();});}
$(nav).find('ul li').each(function(i){$(this).find('a').click(function(e){$('.anythingSlider').anythingSlider(i+1);e.preventDefault();});});}}
function showNav(){$('#rollover').fadeOut();$('#feature-nav').stop().animate({height:68},500,'swing');}
function hideNav(){$('#rollover').fadeIn();$('#feature-nav').stop().animate({height:0},500,'swing');}
function formatText(index,panel){var item=$('#slider');var alts=new Array();$(item).find('li').each(function(i){var tip=$(this).find('.label').text();alts.push(tip);});return'<a href="#" id="feature'+index+'" title="'+alts[index-1]+'" ><img alt="'+alts[index-1]+'" src="images/featured-'+index+'-thumb.jpg" /><span>'+alts[index-1]+'</span></a>';}
function initSubnav(){$('#navigation ul li').hover(function(){$(this).addClass('hover').find('a').addClass('hover');var newHeight=$(this).find('ul.subnav').height();var newWidth=$(this).find('ul.subnav').width();$(this).find('div.subnav-outer').stop().animate({height:newHeight+36,width:newWidth+30},200);},function(){$(this).removeClass('hover');$(this).find('a').removeClass('hover');$(this).find('div.subnav-outer').stop().animate({height:0},100);});}
function initFBFrame(){var el=$('#fb-fan');if(el.length>0){$('#fb-fan').append('<iframe scrolling="no" frameborder="0" src="http://www.facebook.com/connect/connect.php?id=74936643518&connections=0&stream=0&css=http://'+window.location.host+'/skin/styles/fb.css?3" allowtransparency="true" style="border: none; width: 220px; height: 65px;"></iframe>');}}
function initNutrInfo(){var list=$('#product-list');var outer=$('#NutritionalInfo');var container=$('#NutritionalInfo .inner');var curImg=$('#img-display img').attr('src');var curAlt=$('#img-display img').attr('alt');if(list.length>0){$('#product-list a').click(function(e){target=$(this).attr('href');$.ajax({url:target,success:function(html){$(container).html(html);$('#NutritionalInfo').fadeIn();}});curImg='images/products/'+$(this).attr('id')+'-detail.jpg';curAlt=$(this).find('img').attr('alt');e.preventDefault();});$(outer).find('a.close').click(function(e){$(outer).fadeOut();e.preventDefault();});$(list).find('a').hover(function(){$('#img-display').find('img').replaceWith('<img src="images/products/'+$(this).attr('id')+'-detail.jpg" alt="'+$(this).find('img').attr('alt')+'" />');},function(){$('#img-display').find('img').replaceWith('<img src="'+curImg+'" alt="'+curAlt+'" />');})}}
function initGameNav(){var nav=$('#game-nav');var navcount=$(nav).find('li').size();if(nav.length>0){$(nav).find('a img').css({opacity:.6});$(nav).find('a').hover(function(){$(this).find('img').css({opacity:1});},function(){$(this).find('img').css({opacity:.6});});if(navcount>5){$(nav).find('.arrow').show();}
$(nav).find('.wrapper').jCarouselLite({btnPrev:"#back",btnNext:"#forward",circular:false,visible:5,start:0});$('body.gamepage #content-sub').hover(function(){showGameNav();},function(){hideGameNav();})}}
function showGameNav(){$('#rollover').fadeOut(500);$('#game-nav').stop().animate({height:97},500,'swing');}
function hideGameNav(){$('#rollover').fadeIn(800);$('#game-nav').stop().animate({height:0},500,'swing');}
function initGameEmbed(){var gamepage=$('body.gamepage');var ExpressInstallUrl='/flash/expressInstall.swf';if(gamepage.length>0){$(gamepage).append('<script type="text/javascript" src="/scripts/swfobject.js"></script>');game=new Object();game.id=$('body').attr('id');switch(game.id){case'ocd':game.filePath='/BCN/games/tunnelofdoom/doom.swf';game.flashvars={environVar:"http://"+window.location.host+"/"};game.width=420;game.height=522;$('#flashContainer').css({width:game.width,height:game.height});game.wMode="transparent";flashBase='';break;case'ddpp':game.filePath='/flash/ddpp.swf';game.flashvars={};game.width=696;game.height=522;$('#flashContainer').css({width:game.width,height:game.height});game.wMode="transparent";flashBase='';break;case'cf':game.filePath='/flash/cubeFishing.swf';game.flashvars={};game.width=696;game.height=522;$('#flashContainer').css({width:game.width,height:game.height});game.wMode="transparent";flashBase='';break;case'ftf':game.filePath='/flash/main.swf';game.flashvars={};game.width=696;game.height=522;$('#flashContainer').css({width:game.width,height:game.height});game.wMode="transparent";flashBase='';break;case'ett':game.filePath='/flash/cttg.swf';game.flashvars={};game.width=955;game.height=544;$('#flashContainer').css({width:game.width,height:game.height});game.wMode="opaque";flashBase='';break;case'gg':game.filePath='/BCN/games/gigapixel/krpano.swf';game.flashvars={pano:'/BCN/games/gigapixel/gigapixel.xml',test:'asdfasdf',license:'/license/gigapixel-license.txt'};game.width=520;game.height=630;$('#flashContainer').css({width:game.width,height:game.height});game.wMode="opaque";flashBase='';break;case'bfp':game.filePath='/BCN/games/ButterfingerPalooza/rtr_shell.swf';game.flashvars={videoDefaultPath:'rtr_video_default.swf',gamePath:'rtr_game.swf',userId:'15',baseurl:window.location.host,hash:'fa99a263178586e7f52bce907b111012',Highscore:'12345'};game.width=682;game.height=691;$('#flashContainer').css({width:game.width,height:game.height});game.wMode="transparent";flashBase='/BCN/games/ButterfingerPalooza/';break;}
swfobject.embedSWF(game.filePath,"flashContent",game.width,game.height,"9.0.0",ExpressInstallUrl,game.flashvars,{menu:"false",allowScriptAccess:"sameDomain",wmode:game.wMode,base:flashBase});}}
function initWTB(){var link=$('a.where-to-buy');$(link).click(function(e){popup($(this).attr('href'),'whereToBuy',728,650);e.preventDefault();});}
function popup(url,name,width,height){var oWindow=window.open(url,name,"height="+height+", width="+width+", top=100, left=100, resizable=yes, scrollable=yes, scrollbars=yes");if(oWindow==null){alert("Your popup blocker wont allow you access to this window.");}else{}}
function initPromoSlider(){var el=$('body.promotions');if($(el).length>0){if($(el).find('#promotions-list li').size()>3){$(el).find('.wrapper').jCarouselLite({btnPrev:"#back",btnNext:"#forward",circular:false,visible:3,start:0});$(el).find('#content-main .arrow').show();}}}
(function($){$.anythingSlider=function(el,options){var base=this;base.$el=$(el);base.el=el;base.currentPage=1;base.timer=null;base.playing=false;base.$el.data("AnythingSlider",base);base.init=function(){base.options=$.extend({},$.anythingSlider.defaults,options);base.$wrapper=base.$el.find('> div').css('overflow','hidden');base.$slider=base.$wrapper.find('> ul');base.$items=base.$slider.find('> li');base.$single=base.$items.filter(':first');if(base.options.buildNavigation)base.buildNavigation();base.singleWidth=base.$single.outerWidth();base.pages=base.$items.length;base.$items.filter(':first').before(base.$items.filter(':last').clone().addClass('cloned'));base.$items.filter(':last').after(base.$items.filter(':first').clone().addClass('cloned'));base.$items=base.$slider.find('> li');base.buildNextBackButtons();if(base.options.autoPlay){base.playing=!base.options.startStopped;base.buildAutoPlay();};if(base.options.pauseOnHover){base.$el.hover(function(){base.clearTimer();},function(){base.startStop(base.playing);});}
if((base.options.hashTags==true&&!base.gotoHash())||base.options.hashTags==false){base.setCurrentPage(1);};};base.gotoPage=function(page,autoplay){if(autoplay!==true)autoplay=false;if(!autoplay)base.startStop(false);if(typeof(page)=="undefined"||page==null){page=1;base.setCurrentPage(1);};if(page>base.pages+1)page=base.pages;if(page<0)page=1;var dir=page<base.currentPage?-1:1,n=Math.abs(base.currentPage-page),left=base.singleWidth*dir*n;base.$wrapper.filter(':not(:animated)').animate({scrollLeft:'+='+left},base.options.animationTime,base.options.easing,function(){if(page==0){base.$wrapper.scrollLeft(base.singleWidth*base.pages);page=base.pages;}else if(page>base.pages){base.$wrapper.scrollLeft(base.singleWidth);page=1;};base.setCurrentPage(page);});};base.setCurrentPage=function(page,move){if(base.options.buildNavigation){base.$nav.find('ul li .cur').removeClass('cur');$(base.$navLinks[page-1]).addClass('cur');}else{$('#feature-nav').find('.cur').removeClass('cur');$('#feature-nav ul').find('li:eq('+(page-1)+')').addClass('cur');};$('#feature-nav').find('.cur').removeClass('cur');$('#feature-nav').find('li:eq('+(page-1)+')').addClass('cur');if(move!==false)base.$wrapper.scrollLeft(base.singleWidth*page);base.currentPage=page;};base.goForward=function(autoplay){if(autoplay!==true)autoplay=false;base.gotoPage(base.currentPage+1,autoplay);};base.goBack=function(){base.gotoPage(base.currentPage-1);};base.gotoHash=function(){if(/^#?panel-\d+$/.test(window.location.hash)){var index=parseInt(window.location.hash.substr(7));var $item=base.$items.filter(':eq('+index+')');if($item.length!=0){base.setCurrentPage(index);return true;};};return false;};base.buildNavigation=function(){base.$nav=$("<div id='feature-nav'></div>").appendTo(base.$el);base.$items.each(function(i,el){var index=i+1;var $a=$("<li></li>");if(typeof(base.options.navigationFormatter)=="function"){$a.html(base.options.navigationFormatter(index,$(this)));}else{$a.text(index);}
var $newa=$a.find('a');$newa.click(function(e){base.gotoPage(index);if(base.options.hashTags)
base.setHash('featured-'+index);e.preventDefault();});base.$nav.append($a);});base.$nav.wrapInner('<ul></ul>');base.$navLinks=base.$nav.find('ul li a');};base.buildNextBackButtons=function(){var $forward=$('<a class="arrow forward">></a>'),$back=$('<a class="arrow back"><</a>');$back.click(function(e){base.goBack();e.preventDefault();});$forward.click(function(e){base.goForward();e.preventDefault();});base.$wrapper.after($back).after($forward);};base.buildAutoPlay=function(){base.$startStop=$("<a href='#' id='start-stop'></a>").html(base.playing?base.options.stopText:base.options.startText);base.$el.append(base.$startStop);base.$startStop.click(function(e){base.startStop(!base.playing);e.preventDefault();});base.startStop(base.playing);};base.startStop=function(playing){if(playing!==true)playing=false;base.playing=playing;if(base.options.autoPlay)base.$startStop.toggleClass("playing",playing).html(playing?base.options.stopText:base.options.startText);if(playing){base.clearTimer();base.timer=window.setInterval(function(){base.goForward(true);},base.options.delay);}else{base.clearTimer();};};base.clearTimer=function(){if(base.timer)window.clearInterval(base.timer);};base.setHash=function(hash){if(typeof window.location.hash!=='undefined'){if(window.location.hash!==hash){window.location.hash=hash;};}else if(location.hash!==hash){location.hash=hash;};return hash;};base.init();};$.anythingSlider.defaults={easing:"swing",autoPlay:true,startStopped:false,delay:3000,animationTime:600,hashTags:true,buildNavigation:true,pauseOnHover:true,startText:"Start",stopText:"Stop",navigationFormatter:null};$.fn.anythingSlider=function(options){if(typeof(options)=="object"){return this.each(function(i){(new $.anythingSlider(this,options));options.hashTags=false;});}else if(typeof(options)=="number"){return this.each(function(i){var anySlide=$(this).data('AnythingSlider');if(anySlide){anySlide.gotoPage(options);}});}};})(jQuery);(function($){$.fn.jCarouselLite=function(o){o=$.extend({btnPrev:null,btnNext:null,btnGo:null,mouseWheel:false,auto:null,speed:200,easing:null,vertical:false,circular:true,visible:3,start:0,scroll:1,beforeStart:null,afterEnd:null},o||{});return this.each(function(){var b=false,animCss=o.vertical?"top":"left",sizeCss=o.vertical?"height":"width";var c=$(this),ul=$("ul",c),tLi=$("li",ul),tl=tLi.size(),v=o.visible;if(o.circular){ul.prepend(tLi.slice(tl-v-1+1).clone()).append(tLi.slice(0,v).clone());o.start+=v}var f=$("li",ul),itemLength=f.size(),curr=o.start;c.css("visibility","visible");f.css({overflow:"hidden",float:o.vertical?"none":"left"});ul.css({margin:"0",padding:"0",position:"relative","list-style-type":"none","z-index":"1"});c.css({overflow:"hidden",position:"relative","z-index":"2",left:"0px"});var g=o.vertical?height(f):width(f);var h=g*itemLength;var j=g*v;f.css({width:f.width(),height:f.height()});ul.css(sizeCss,h+"px").css(animCss,-(curr*g));c.css(sizeCss,j+"px");if(o.btnPrev)$(o.btnPrev).click(function(){return go(curr-o.scroll)});if(o.btnNext)$(o.btnNext).click(function(){return go(curr+o.scroll)});if(o.btnGo)$.each(o.btnGo,function(i,a){$(a).click(function(){return go(o.circular?o.visible+i:i)})});if(o.mouseWheel&&c.mousewheel)c.mousewheel(function(e,d){return d>0?go(curr-o.scroll):go(curr+o.scroll)});if(o.auto)setInterval(function(){go(curr+o.scroll)},o.auto+o.speed);function vis(){return f.slice(curr).slice(0,v)};function go(a){if(!b){if(o.beforeStart)o.beforeStart.call(this,vis());if(o.circular){if(a<=o.start-v-1){ul.css(animCss,-((itemLength-(v*2))*g)+"px");curr=a==o.start-v-1?itemLength-(v*2)-1:itemLength-(v*2)-o.scroll}else if(a>=itemLength-v+1){ul.css(animCss,-((v)*g)+"px");curr=a==itemLength-v+1?v+1:v+o.scroll}else curr=a}else{if(a<0||a>itemLength-v)return;else curr=a}b=true;ul.animate(animCss=="left"?{left:-(curr*g)}:{top:-(curr*g)},o.speed,o.easing,function(){if(o.afterEnd)o.afterEnd.call(this,vis());b=false});if(!o.circular){$(o.btnPrev+","+o.btnNext).removeClass("disabled");$((curr-o.scroll<0&&o.btnPrev)||(curr+o.scroll>itemLength-v&&o.btnNext)||[]).addClass("disabled")}}return false}})};function css(a,b){return parseInt($.css(a[0],b))||0};function width(a){return a[0].offsetWidth+css(a,'marginLeft')+css(a,'marginRight')};function height(a){return a[0].offsetHeight+css(a,'marginTop')+css(a,'marginBottom')}})(jQuery);