// ----------------------------------------------------------------------------------- // // Gallerybox 1.0 // Author: Dinesk Kumar V // Created: 01-02-09 // // For more information, visit: // http://sam-sys.com/gallerybox.html // // ----------------------------------------------------------------------------------- (function(jQuery) { jQuery.fn.galleryBox = function(settings) { settings = jQuery.extend({ // Settings to configure the jQuery galleryBox plugin olayBgColor: '#000', olayOpacity: 0.8, imgResizeSpeed: 600, initContentWidth: 200, initContentHeight: 200, contentWidth: 300, contentHeight: 400, timeoutTimer: false, keyToClose: 'c', // (string) (c = close) Letter to close the jQuery galleryBox interface. keyToPrev: 'p', // (string) (p = previous) Letter to show the previous image keyToNext: 'n', // (string) (n = next) Letter to show the next image. imgArray: [], galArray: [], imgActive: 0, galActive: 0 },settings); var jQueryObj = this; function _initialize() { _start(this,jQueryObj); return false; } function _start(objClicked,jQueryObj) { jQuery('embed, object, select').css({ 'visibility' : 'hidden' }); settings.imgArray.length = 0; settings.galArray.length = 0; settings.imgActive = 0; settings.galActive = 0; var thumpath =''; gallname=''; var myRE = /(\[(\w|\.|\/|\-|\:)+\])/g; if ( jQueryObj.length == 1 ) { //thuminfo = objClicked.rel.split(" "); thuminfo = jQueryObj[i].rel.match(myRE); if(thuminfo.length>1)thumpath = thuminfo[1].substring(1,thuminfo[1].length-1); if(thuminfo.length>0)gallname = thuminfo[0].substring(1,thuminfo[0].length-1); settings.imgArray.push(new Array(new Array(objClicked.getAttribute('href'),thumpath,objClicked.getAttribute('title')))); settings.galArray.push(gallname); } else { for ( var i = 0; i < jQueryObj.length; i++ ) { thumpath=''; gallname=''; thuminfo = jQueryObj[i].rel.match(myRE); if(thuminfo.length>1)thumpath = thuminfo[1].substring(1,thuminfo[1].length-1); if(thuminfo.length>0)gallname = thuminfo[0].substring(1,thuminfo[0].length-1); galkey = jQuery.inArray(gallname,settings.galArray); if(galkey<0) { settings.imgArray.push(new Array(new Array(jQueryObj[i].getAttribute('href'),thumpath,jQueryObj[i].getAttribute('title')))); settings.galArray.push(gallname); } else { settings.imgArray[galkey].push(new Array(jQueryObj[i].getAttribute('href'),thumpath,jQueryObj[i].getAttribute('title'))); } if(objClicked.getAttribute('href') == jQueryObj[i].getAttribute('href')) { galkey = jQuery.inArray(gallname,settings.galArray); settings.imgActive = settings.imgArray[galkey].length-1; settings.galActive = galkey; } } } _buildBox(); _buildEvents(); _buildBottomImg(); _buildContentArea(); _LoadImage(); } function _buildBox() { jQuery('body').append('
Category
'+settings.galArray[settings.galActive]+' - '+settings.imgArray[settings.galActive][settings.imgActive][2]+'
'); for ( var i = 0; i < settings.galArray.length; i++ ) jQuery('#gallerybox-menubox-item').append(''+settings.galArray[i]+''); if(jQuery.browser.msie){ jQuery('#gallerybox-overlay').css({ backgroundColor: settings.olayBgColor, opacity: settings.olayOpacity, width: jQuery(document.body).width(), height: jQuery(document.body).height() }).fadeIn(); jQuery('#gallerybox-bottombox').css({width:'98%'}); }else{ jQuery('#gallerybox-overlay').css({ backgroundColor: settings.olayBgColor, opacity: settings.olayOpacity, width: jQuery(document).width(), height: jQuery(document).height() }).fadeIn(); } jQuery('#gallerybox-outter').css({ width: jQuery(window).width(), height: jQuery(window).height(), top: jQuery(window).scrollTop(), left: jQuery(window).scrollLeft() }); jQuery('#gallerybox-bottombox').css({top: jQuery('#gallerybox-outter').height() - (jQuery('#gallerybox-bottombox').height() + 20)}); settings.contentWidth = jQuery('#gallerybox-outter').width()-380; settings.contentHeight = jQuery('#gallerybox-outter').height() - (jQuery('#gallerybox-bottombox').height() + 70); } function _buildEvents(){ jQuery('#gallerybox-overlay').click(function() { _closeBox(); }); jQuery('#gallerybox-outter').click(function(event) { if(event.target.id=='gallerybox-outter') _closeBox(); else return false; }); jQuery('#gallerybox-image').load(function (event) {_trasformBox(); }); jQuery('#gallerybox-bottombox').mousemove(function(event) { var position = jQuery('#gallerybox-bottombox').position(); var gwd = jQuery('#gallerybox-bottombox').width(); var iwd = jQuery('#gallerybox-bottombox-in').width(); if(iwd>gwd) { var ratio = (100/gwd )*(event.clientX - position.left-10); var leftc = ((iwd - gwd)/100)* ratio; jQuery('#gallerybox-bottombox').scrollLeft(leftc); } }); jQuery(window).resize(function() { clearTimeout(settings.timeoutTimer); if(jQuery.browser.msie) jQuery('#gallerybox-overlay').css({width: jQuery(document.body).width(), height: jQuery(document.body).height()}); else jQuery('#gallerybox-overlay').css({width: jQuery(document).width(), height: jQuery(document).height()}); jQuery('#gallerybox-outter').css({width: jQuery(window).width(), height: jQuery(window).height()}); jQuery('#gallerybox-bottombox').css({top: jQuery('#gallerybox-outter').height() - (jQuery('#gallerybox-bottombox').height() + 20)}); settings.contentWidth = jQuery('#gallerybox-outter').width()-380; settings.contentHeight = jQuery('#gallerybox-outter').height() - (jQuery('#gallerybox-bottombox').height() + 70); settings.timeoutTimer=setTimeout(function(){_LoadImage();},200); }); jQuery(window).scroll(function() { jQuery('#gallerybox-outter').css({top: jQuery(window).scrollTop(), left: jQuery(window).scrollLeft()}); }); jQuery('#gallerybox-outter').mousewheel(function(event, delta) { return false; }); jQuery('#gallerybox-menubox').toggle(function(){ jQuery('#gallerybox-menubox-item').fadeIn('normal'); },function(){ jQuery('#gallerybox-menubox-item').fadeOut('fast'); }); jQuery('#gallerybox-menubox-item a').click(function(){ _loadGallery(this); }); jQuery('#gallerybox-content-left').click(function() { if(settings.imgActive>0) { settings.imgActive--; prv = jQuery('a.gallerybox_b_img_s').prev(); jQuery('a.gallerybox_b_img_s').removeClass('gallerybox_b_img_s').addClass('gallerybox_b_img'); prv.addClass('gallerybox_b_img_s'); _LoadImage(); } }); jQuery('#gallerybox-content-right').click(function() { if(settings.imgActive < settings.imgArray[settings.galActive].length-1) { settings.imgActive++; nxt = jQuery('a.gallerybox_b_img_s').next(); jQuery('a.gallerybox_b_img_s').removeClass('gallerybox_b_img_s').addClass('gallerybox_b_img'); nxt.addClass('gallerybox_b_img_s'); _LoadImage(); } }); } function _buildBottomImg(){ gallerybox_bottombox = jQuery('#gallerybox-bottombox-in'); jQuery('a.gallerybox_b_img, a.gallerybox_b_img_s').remove(); gallerybox_bottombox.css({width:60 * settings.imgArray[settings.galActive].length+5}); for ( var i = 0; i < settings.imgArray[settings.galActive].length; i++ ) { if(settings.imgActive==i) gallerybox_bottombox.append(''); else gallerybox_bottombox.append(''); /*gallerybox_bottombox.append('');*/ } jQuery('a.gallerybox_b_img, a.gallerybox_b_img_s').click(function() { settings.imgActive = parseInt(this.getAttribute('rel')); jQuery('a.gallerybox_b_img_s').removeClass('gallerybox_b_img_s').addClass('gallerybox_b_img'); this.className = 'gallerybox_b_img_s'; _LoadImage(); }); } function _buildContentArea(){ topc = (jQuery('#gallerybox-outter').height()-(settings.initContentHeight+ jQuery('#gallerybox-bottombox').height()))/2; leftc = (jQuery('#gallerybox-outter').width()-settings.initContentWidth)/2 pstop = ((settings.initContentHeight - 150)/2) + topc; jQuery('#gallerybox-content').css({ width: settings.initContentWidth, height: settings.initContentHeight, top: topc, left: leftc }); jQuery('#gallerybox-content-left').css({width: 150, height: 150, top: pstop, left: leftc, opacity:1}); jQuery('#gallerybox-content-right').css({width: 150, height: 150, top: pstop,left: (settings.initContentWidth + leftc-150), opacity:1 }); } function _loadGallery(obj){ jQuery('#gallerybox-menubox').trigger('click'); settings.galActive = parseInt(obj.getAttribute('rel')); settings.imgActive = 0; jQuery('#gallerybox-bottombox-in').empty(); _buildBottomImg(); _LoadImage(); } function _LoadImage(){ jQuery('#gallerybox-content,#gallerybox-image,#gallerybox-content-left,#gallerybox-content-right').stop(); jQuery('#gallerybox-image-overlay').fadeIn('slow', function() { jQuery('#gallerybox-image').css({width:'',height:''}); jQuery('#gallerybox-image').attr('src', settings.imgArray[settings.galActive][settings.imgActive][0]); }); var position = jQuery('#gallerybox-content').position(); pstop = ((jQuery('#gallerybox-content').height()- 150)/2) + position.top; psleft = (jQuery('#gallerybox-content').width()/2) + position.left; jQuery('#gallerybox-content-left').animate({top:pstop, left: psleft-75},500,function(){jQuery('#gallerybox-content-left').hide()}); jQuery('#gallerybox-content-right').animate({top:pstop, left: psleft-75},500,function(){jQuery('#gallerybox-content-right').hide()}); jQuery('#gallerybox-title').html(settings.galArray[settings.galActive] + ' - ' + settings.imgArray[settings.galActive][settings.imgActive][2]); } function _trasformBox() { var wd = jQuery('#gallerybox-image').width(); var hd = jQuery('#gallerybox-image').height(); var ratio = 100; if(settings.contentWidth0){ jQuery('#gallerybox-content-left').css({ top:pstop, left: psleft-75, backgroundImage : "url("+settings.imgArray[settings.galActive][settings.imgActive-1][1]+")" }).show(); jQuery('#gallerybox-content-left').animate({top:pstop, left: position.left -170 },settings.imgResizeSpeed); } if(settings.imgActive < settings.imgArray[settings.galActive].length-1){ jQuery('#gallerybox-content-right').css({ top:pstop, left: psleft-75, backgroundImage : "url("+settings.imgArray[settings.galActive][settings.imgActive+1][1]+")" }).show(); jQuery('#gallerybox-content-right').animate({top:pstop, left:yleft+10},settings.imgResizeSpeed); } } function _closeBox() { jQuery('#gallerybox-content,#gallerybox-image,#gallerybox-content-left,#gallerybox-content-right').stop(); jQuery('#gallerybox-outter').remove(); jQuery('#gallerybox-overlay').fadeOut(function() { jQuery('#gallerybox-overlay').remove(); }); jQuery('embed, object, select').css({ 'visibility' : 'visible' }); } return this.unbind('click').click(_initialize); }; })(jQuery); jQuery(document).ready(function () { jQuery("a[rel^='gallerybox']").galleryBox(); });