﻿$.fn.og_gallery=function(variables,init){variables=$.extend({galleryID:'',object:''},variables);init=$.extend({processURL:'',processParameters:'',backResponse:function(){},ajaxResponse:''},init);dynamics=$.extend({galleryCount:'',pictureCount:'',currentGallery:'',containerWidth:0,thumbContainerWidth:0,galleryFlag:false},init);var gallery={initialize:function(){var e=$(variables.object);init.processURL='og_gallery.asp?action=allGalleries';init.backResponse=function(){if(init.ajaxResponse=='error'){$(e).html('An error occured.');}else{var feedback=init.ajaxResponse;pathArray=feedback.split("||");dynamics.galleryCount=Math.round(pathArray.length/3);$(variables.object).append('<div id="gallery-content"></div>');$(variables.object).append('<div id="gallery-thumbs"></div>');$('#gallery-thumbs').append('<div id="image-objects"></div>');$('#gallery-thumbs').append('<div id="close"><img src="images/close.png"/></div>');$(variables.object).append('<div id="image-container"></div>');var i=0;while(i<pathArray.length-1){$('#gallery-content').append('<div class="thumb" gallery="'+pathArray[i+2]+'"><img src="images/galleries/'+pathArray[i+2]+'/thumbs/'+pathArray[i+1]+'" /><span>'+pathArray[i]+'</span></div>');i=i+3;}i=0;$('div.thumb').css({position:'absolute',cursor:'pointer'});$('div.thumb span').css({float:'left',width:'150px',position:'absolute','font-family':"Tahoma",'font-size':'11px',color:'#fff'});var imageWidth=$('div.thumb img').width();var imageHeight=$('div.thumb img').height();$('div.thumb img').css({float:'left',width:imageWidth*2+'px',height:imageHeight*2+'px',position:'absolute'});$('div.thumb').each(function(){$(this).css({left:(imageWidth+140)*i+'px'});$(this).find('img').css({top:'0px',left:'0px'});$(this).find('span').css({top:(imageHeight*2)+10+'px',left:'0px'});i++;dynamics.containerWidth=(imageWidth+140)*i;});$('#gallery-content').css({position:'absolute',top:($(window).height()-108-84)-110-35+'px'});$('#image-objects').css({position:'absolute',top:'0px',left:'0px','z-index':'2',opacity:1});$('#image-container').css({position:'absolute',top:'0px',left:'0px','z-index':'-1'});$('#close').css({opacity:0,position:'absolute',top:'50px',left:(($(window).width()-40)/2)-17+'px','z-index':'1',cursor:'pointer'});$(variables.object).mousemove(function(e){mousePosition=e.pageX;currentStage=$(window).width()-80;if(!dynamics.galleryFlag){if(currentStage<dynamics.containerWidth){a=(dynamics.containerWidth-currentStage)/(currentStage-75);b=50-(mousePosition*a);$('#gallery-content').stop().css({left:b+'px'});}else{$('#gallery-content').stop().animate({left:dynamics.containerWidth-52+'px'},100,"easeout");}}});$('#close').mouseover(function(){$(this).animate({opacity:1},200,"easeout");}).mouseout(function(){$(this).animate({opacity:0.2},200,"easeout");}).click(function(){gallery.closeGallery();});$('div.thumb').mouseover(function(){index=$(this).attr('gallery');$('.thumb[gallery!='+index+']').stop().animate({opacity:0.2},600,"easeout");}).mouseleave(function(){$('div.thumb').stop().animate({opacity:1},600,"easeout");}).click(function(){gallery.change(index);});}};ajax.get();},change:function(id){if(!dynamics.galleryFlag){dynamics.galleryFlag=true;$('#gallery-content').animate({top:$(window).height()+'px'},1500,"easeout");init.processURL='og_gallery.asp?action=singleGallery&galleryID='+id+'';init.backResponse=function(){if(init.ajaxResponse=='error'){$(e).html('An error occured.');}else{var feedback=init.ajaxResponse;pathArray=feedback.split("||");var i=0;$('#image-objects').html('');while(i<pathArray.length-1){$('#image-objects').append('<div class="thumb image" path="'+pathArray[i]+'"><img src="images/galleries/'+id+'/thumbs/'+pathArray[i]+'" /></div>');i=i+2;}gallery.loadImage(pathArray[0],id);i=0;$('div.thumb.image').css({position:'absolute',cursor:'pointer',opacity:0});var imageWidth=$('div.thumb.image img').width();var imageHeight=$('div.thumb.image img').height();$('div.thumb.image img').css({float:'left',width:imageWidth*1+'px',height:imageHeight*1+'px',position:'absolute'});$('div.thumb.image').each(function(){$(this).css({left:(imageWidth+1)*i+'px'});$(this).find('img').css({top:'0px',left:'0px'});i++;dynamics.thumbContainerWidth=(imageWidth+1)*i;});$('#close').show();$('#image-objects').css({opacity:1});$('div.thumb.image').show().animate({opacity:1},500,"easeout");$('#close').animate({opacity:0.2},500,"easeout");$('#gallery-thumbs').mousemove(function(e){mousePosition=e.pageX;currentStage=$(window).width()-80;if(dynamics.galleryFlag){if(currentStage<dynamics.thumbContainerWidth){a=(dynamics.thumbContainerWidth-currentStage)/(currentStage-75);b=50-(mousePosition*a);$('#image-objects').stop().css({left:b+'px'});}else{$('#image-objects').animate({left:(($(window).width()-40)/2)-(dynamics.thumbContainerWidth/2)+'px'},500,"easeout");}}});$('div.thumb.image').mouseover(function(){if(dynamics.galleryFlag){$('.thumb.image').stop().animate({opacity:0.2},600,"easeout");$(this).stop().animate({opacity:1},1,"easeout");}}).mouseleave(function(){if(dynamics.galleryFlag){$('.thumb.image').stop().animate({opacity:1},600,"easeout");}}).click(function(){gallery.loadImage($(this).attr('path'),id);});}};ajax.get();}else{}},loadImage:function(imageID,galleryID){var image=new Image();$('#image-container').show().animate({opacity:0},500,"linear",function(){$('#progress').show();$(image).load(function(){$('#image-container').html('').append(image);var imageWidth=$(image).width();var imageHeight=$(image).height();var stageWidth=$(window).width()-40;var stageHeight=$(window).height()-108-84;$('#image-container').css({top:(stageHeight/2)-(imageHeight/2)+'px',left:(stageWidth/2)-(imageWidth/2)});$('#loader').stop().animate({opacity:0},200,"linear");$('#image-container').animate({opacity:1},500,"linear",function(){$('#progress').hide();});}).attr('src','images/galleries/'+galleryID+'/larges/'+imageID+'');});},closeGallery:function(){$('#gallery-content').stop().animate({top:($(window).height()-108-84)-110-35+'px'},200,"easeout",function(){dynamics.galleryFlag=false;$('#close').animate({opacity:0},500,"easeout",function(){$('#close').hide();});$('#image-container').animate({opacity:0},500,"easeout",function(){$('#image-container').hide();});$('div.thumb.image').animate({opacity:0},500,"easeout",function(){$('div.thumb.image').hide();});});}};var ajax={get:function(){var sb=init.processURL.replace('%40','@');$.post(sb,function(data){init.ajaxResponse=data;init.backResponse();});return;}};gallery.initialize();};
