- ;jQuery.RBGStart = function(RBGSettings){
- RBGSettings = jQuery.extend({
- styleURL: '',
- jsonURL: '',
- baseURL: ''
- }, RBGSettings);
- var cssURL = RBGSettings.baseURL+RBGSettings.styleURL,
- jsonURL = RBGSettings.baseURL+RBGSettings.jsonURL;
- function addCss() {
- $('head').append('<link>');
- $('head').children(':last').attr({ rel: 'stylesheet', type: 'text/css', href: cssURL, id: 'RBGCssFile' });
- };
- function buildBase() {
- if ($('#RBGCssFile').length) return; else addCss();
- $('body').append('<div>').children(':last').attr({ id: 'RBGFader' });
- $('#RBGFader').append('<div id="RBG-Box"></div>').children('#RBG-Box').hide();
- $('#RBG-Box').append('<a href="#" class="hideRBG">X</a>');
- $('#RBG-Box').append('<div id="RBG-View"></div>');
- $('#RBG-Box').append('<div id="RBG-Control"></div>');
- $('#RBG-Control').append('<ul id="RBG-Thumbs"></ul>');
- };
- function getItems() {
- $.getJSON(jsonURL,function(json){
- var lastPic = $('#RBG-View').children('.RBG-Pic:last'),
- lastVid = $('#RBG-View').children('.RBG-Vid:last'),
- lastSpecs = $('#RBG-View').children('.RBG-Specs:last');
- // Check for pictures
- if (json.pictures.picture === undefined) null;
- else {
- $.each(json.pictures.picture,function(i,s){
- if (s.imgURL === undefined) {
- null;
- } else {
- if (s.title === undefined && s.thumbURL === undefined) {
- null;
- } else {
- $('#RBG-View').append('<div class="RBG-Pic" id="opt-'+(i+1)+'">');
- lastPic.css({
- background: 'url("'+s.imgURL+'") no-repeat center',
- width: s.width,
- height: s.height
- }).attr('id', 'opt-'+ (i+1));
- if (s.title === undefined) null;
- else lastPic.append('<h1 class="RBG-Title"><a title="'+s.title+'" href="'+s.hrefURL+'">'+s.title+'</a></h1>');
- $.each(json,function(key,val) {
- if (key == 'title' || key == 'hrefURL' || key == 'imgURL' || key == 'thumbURL' || key == 'height' || key == 'width' || key == 'description' ) null;
- else {
- lastPic.append('<span class="RBG-Specs"><'+key+'</span>');
- lastSpecs.append('<var>'+val+'</var>');
- };
- });
- if (s.description === undefined) null;
- else lastPic.append('<div class="RBG-Desc">'+s.description+'</div>');
- if (s.thumbURL === undefined) $('#RBG-Thumbs').append('<li><a href="#opt-'+(i+1)+'" title="'+s.title+'">'+s.title+'</a></li>');
- else $('#RBG-Thumbs').append('<li><a href="#opt-'+(i+1)+'" title="'+s.title+'"><img width="80px" height="80px" title="'+s.title+'" alt="'+s.title+'" src="'+s.thumbURL+'" /></a></li>');
- };
- };
- });
- };
- if (json.videos.video === undefined) null;
- else {
- $.each(json.videos.video,function(i,s){
- if (s.vidURL === undefined) {
- null;
- } else {
- if (s.title === undefined && s.thumbURL === undefined) {
- null;
- } else {
- $('#RBG-View').append('<div class="RBG-Pic" id="opt-'+(i+1)+'">');
- lastVid.css({
- background: 'url("'+s.bgURL+'") no-repeat center',
- width: s.width,
- height: s.height
- }).attr('id', 'opt-'+ (i+1));
- if (s.title === undefined) null;
- else lastVid.append('<h1 class="RBG-Title"><a title="'+s.title+'" href="'+s.hrefURL+'">'+s.title+'</a></h1>');
- $.each(json,function(key,val) {
- if (key == 'title' || key == 'hrefURL' || key == 'imgURL' || key == 'thumbURL' || key == 'height' || key == 'width' || key == 'description' ) null;
- else {
- lastVid.append('<span class="RBG-Specs"><'+key+'</span>');
- lastSpecs.append('<var>'+val+'</var>');
- };
- });
- if (s.description === undefined) null;
- else lastVid.append('<div class="RBG-Desc">'+s.description+'</div>');
- if (s.thumbURL === undefined) $('#RBG-Thumbs').append('<li><a href="#opt-'+(i+1)+'" title="'+s.title+'">'+s.title+'</a></li>');
- else $('#RBG-Thumbs').append('<li><a href="#opt-'+(i+1)+'" title="'+s.title+'"><img width="80px" height="80px" title="'+s.title+'" alt="'+s.title+'" src="'+s.thumbURL+'" /></a></li>');
- };
- };
- });
- };
- });
- };
- function readyGal() {
- // Hide all content, and only show one to activate tabs
- $('.RBG-Pic').hide(); //Hide all content
- $('#RBG-Thumbs li:first').addClass('active').show();
- $('.RBG-Pic:first').show();
- // After RBG-Box is hidden JQuery will turn it back in to a block,
- // so before fading it in turn it in to an inline-block
- $('#RBG-Box').css({display: 'inline-block'}).delay(150).show();
- $('#RBGFader').fadeIn(300); // In case the fader is hidden in the CSS hidden
- };
- function clearGal() { $('RBG-View').empty(); };
- function errorMsg(message) {
- $('#RGB-Box').html('<h1>Failure! Here is why:<h1><p>'+message+'</p>');
- };
- function startGal() {
- if($('.RGB-Pic, .RGB-Vid').length) clearGal(); else buildBase();
- if(getItems() === null) errorMsg('Either the items in the JSON are lacking titles or thumbs or the file is not compliant with RGB:<br><b>'+RBGSettings.baseURL+RBGSettings.jsonURL+'</b>');
- readyGal();
- };
- $(document).ready(function(e){
- $(document).keyup(function(e) {
- if (e.keyCode == 27) { $('#RBGFader').fadeOut(300); } // Escape to Hide RBGFader
- });
- // Tab function control start
- $('#RBG-Thumbs li').click(function() {
- if ($(this).hasClass('active'))
- return false; // Tab already selected
- $('#RBG-Thumbs li').removeClass('active');
- $(this).addClass('active');
- $('.RBG-Pic').hide();
- var activeTab = $(this).find('a').attr('href');
- $(activeTab).fadeIn();
- return false;
- });
- // Tab function control end
- $('.hideRBG').click(function(){
- $('#RBGFader').fadeOut(300);
- });
- $('.showRBG').click(function(){
- $('#RBGFader').fadeIn(300);
- });
- });
- };