(function(){
var jQuerythumbSelector = '.griditem img';
var jQcontainer = '#info-container';
var fallback = 'http://assets.viggleassets.com:80/assets/5/f/5/0/5f5063d4051ce1f211bf8ec412f2761b.jpg';
var loaderAnim = 'http://assets.viggleassets.com:80/assets/e/1/7/7/e177f09167126fab1ffaff81475aa002.gif';
function loadSingleImage(index,fallback){
var item = Viggle.gallery_images[index];
//Load shows info
if(window.Viggle.page == 'shows'){
$('#bpo').html(item.bpo);
$('#show-title').html(item.title);
$('#broadcast-info').html(
item.day+' | '+
item.time+item.ampm+' | '+
item.network
);
$('#show-description').html(item.description);
}
//Load rewards info
else if(window.Viggle.page == 'rewards'){
$('#reward-title').html(item.title);
$('#teaser').html(item.teaser);
$('#reward-info').html(item.info);
}
//New
if(typeof item.img == 'string'){
//Show loader
$(jQcontainer).children('img').css('visibility','hidden');
window.Viggle.loader_img.css('visibility','visible');
var img = new Image();
img.style.top='0';
img.style.left='0';
img.style.position = 'absolute';
img.id = 'Viggle_gallery_img_'+index;
img.onload = function(e){
item.img = img;
$(jQcontainer).prepend($(img).css('visibility','hidden'));
window.Viggle.loader_img.css('visibility','hidden');
$(img).css('visibility','visible');
//Hide loader
};
try{
img.src = item.img;
}
catch(err){
img.src = fallback;
}
}
//We already have it loaded
else{
$(jQcontainer).children('img').css('visibility','hidden');
$(item.img).css('visibility','visible');
}
}
function loadAllImages(fallback){
var createCompleteLoader = function(i){
return function(e){
Viggle.gallery_images[i].img = this;
$(jQcontainer).prepend($(this).css('visibility','hidden'));
}
};
//Have first already from page generation, so will be duplicated.
for(var i=0; i');
window.Viggle.loader_img = $('');
if(is_mobile(navigator.userAgent)){
; //Image 0 already loaded by server. No more preloading needed.
}
else{
loadAllImages();
}
if(window.Viggle.page == 'rewards'){
jQcontainer = '#reward-image-container';
}
$(jQcontainer).append(window.Viggle.default_gallery_img).append(window.Viggle.loader_img);
//Set up click handlers
$(jQuerythumbSelector)
.each(function(i,e){$(this).data('index',i)})
.click(function(e){loadSingleImage($(this).data('index'));});
}
if(window.Viggle !== undefined && window.Viggle.gallery_images !== undefined){
initilizeImages();
}
})();