/*
 * CSS Image gallery
 * 1.03
 * Copyright(c) 2007, DMXzone.com.
 * 
 */


(function($)
{$.delayedTask=function(fn,scope,args)
{var nTimeoutId=null;this.delay=function(time,newFn,newScope,newArgs)
{if(nTimeoutId)
{clearTimeout(nTimeoutId);}
fn=newFn||fn;scope=newScope||scope;args=newArgs||args;nTimeoutId=setTimeout(function(){fn.call(scope,args);},time);}
this.cancel=function()
{if(nTimeoutId)
{clearTimeout(nTimeoutId);nTimeoutId=null;}}}
if(!$.fn.stop){$.fn.stop=function(){this.each(function(){$.dequeue(this,"fx");});return this;};}})(jQuery);function hImgRes(src)
{this.src=src;this.loaded=false;this.loading=false;this.toString=function(){return this.src};}
jQuery.dmxGallery={aMessages:{missingList:'The list with images is missing'},bDebug:true,build:function(hOptions)
{return this.each(function()
{var hG=this;if(!this.id)
{this.id='dmxZoneGallery_'+(jQuery.dmxGallery.counter++);}
var sId=this.id;var hDMXGalleryOptions={width:500,height:380,containerTag:'div',containerClass:'dmxGallery',imageHolderClass:'dmxImageHolder',prevLinkText:'previous',nextLinkText:'next',playLinkText:'play',pauseLinkText:'pause',prevLinkClass:'dmxPrevious',nextLinkClass:'dmxNext',playLinkClass:'dmxPlay',pauseLinkClass:'dmxPause',swapImageClass:'dmxSwap',thumbWidth:95,thumbHeight:80,thumbPadding:5,thumbHolderHeight:80,thumbHolderWidth:'auto',thumbHolderPosition:'right',thumbHolderHorizontal:false,thumbHolderVertical:true,thumbShowOnHover:false,thumbListHidden:true,captionPosition:'top',playerDelay:3,autoPlay:false,showInfoMessage:false,autosize:true,loaded:0,messageHidden:true,captionOpacity:40,imgIndex:0,preloadTreshold:2,allPreloaded:false}
if(hOptions)
{hG.options=jQuery.extend(hDMXGalleryOptions,hOptions);}
$(this).attr('tabIndex',-1);var hList=$('ul',this);if(hList.length==0)
{jQuery.dmxGallery.debug($.dmxGallery.aMessages.missingList);return;}
var hHolder=$('.'+hDMXGalleryOptions.imageHolderClass,this);if(hHolder.length==0)
{hHolder=$('<div class="'+hDMXGalleryOptions.imageHolderClass+'" />').append($('ul',this)).appendTo($(this));}
$(this).height(hDMXGalleryOptions.height+'px');$(this).width(hDMXGalleryOptions.width+'px');hG.thumbList=[];hG.imageList=[];hG.linkList=[];$(hHolder).find('ul').css('display','none');$(hHolder).find('ul li').each(function(nI)
{var hImg=$(this).find('.image');hG.imageList.push(new hImgRes(hImg.attr('src')));var hLink=hImg.parent().get(0);if(hLink&&hLink.tagName&&hLink.tagName.toUpperCase()=='A'){hG.linkList.push(hLink);}
else{hG.linkList.push(null);}
$('img',this).remove();})
var hThumbList=$('#'+sId+'_thumb');if(hThumbList.length>0)
{$(hThumbList).find('ul li').each(function(nI)
{hG.thumbList.push(new hImgRes($(this).find('img').attr('src')));})
$(hThumbList).empty();}
else
{hG.thumbList=hG.imageList;}
hThumbList=$.dmxGallery.buildThumbnailList(hG);$.dmxGallery.buildMessage(hG);hG.options.messageHide=new $.delayedTask(function(){$.dmxGallery.doHideMessage(hG)})
$.dmxGallery.buildImageHolders(hG);$.dmxGallery.buildCaption(hG);$.dmxGallery.buildGalleryNavigation(hG);$.dmxGallery.buildWaiting(hG);window.setTimeout(function(){$.dmxGallery.showImage(hG,0)},10);$.dmxGallery.showMessage(hG,'loading images...');$.dmxGallery.hideMessage(hG);hG.options.player=new $.delayedTask(function(){$.dmxGallery.nextImage(hG);$.dmxGallery.play(hG)})
this.focus();$(hG).keydown(function(event)
{jQuery.event.fix(event);if(event.keyCode==37)
{$.dmxGallery.previousImage(hG);}
if(event.keyCode==39)
{$.dmxGallery.nextImage(hG);}});hG.options.thumbsHide=new $.delayedTask(function(){$.dmxGallery.hideThumbnailList(hG);})
hG.options.thumbsShow=new $.delayedTask(function(){$.dmxGallery.showThumbnailList(hG);})
$(hG).hover(function(event)
{jQuery.event.fix(event);if(hG.options.thumbShowOnHover)
{hG.options.thumbsHide.cancel();hG.options.thumbsShow.delay(100);}},function(event)
{jQuery.event.fix(event);if(hG.options.thumbShowOnHover&&!hG.options.swapping)
{hG.options.thumbsShow.cancel();hG.options.thumbsHide.delay(400);}})
$(hThumbList).keydown(function(event)
{jQuery.event.fix(event);if(event.keyCode==37)
{$.dmxGallery.scrollThumbnailList(hG,'left');event.preventDefault();event.stopPropagation();return false;}
if(event.keyCode==39)
{$.dmxGallery.scrollThumbnailList(hG,'right');event.preventDefault();event.stopPropagation();return false;}});$(this).bind('focus',function(){$(this).addClass('dmxGalleryFocused')});if(hG.options.autoPlay)
{$.dmxGallery.play(hG);}});},pngFix:function(elm)
{if($.browser.msie&&$.browser.version<7){if(elm.currentStyle.backgroundImage.indexOf('.png')!=-1){elm.runtimeStyle.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+elm.currentStyle.backgroundImage.split('\"')[1]+", sizingMethod='crop')";elm.runtimeStyle.backgroundImage="none";}else if(elm.tagName=='IMG'&&elm.src.indexOf('.png')!=-1){elm.runtimeStyle.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+src+", sizingMethod='scale')";elm.src="transparent.gif";}}},buildGalleryNavigation:function(hGallery)
{var hG=hGallery;var hImgCon=$(hG).find('.imageMainContainer:first');var prev=$('<a href="javascript:;" class="'+hG.options.prevLinkClass+'" />').click(function(){$(hG).focus();$.dmxGallery.previousImage(hG)}).appendTo(hImgCon).append($('<span />').html(hG.options.prevLinkText));var next=$('<a href="javascript:;" class="'+hG.options.nextLinkClass+'" />').click(function(){$(hG).focus();$.dmxGallery.nextImage(hG)}).appendTo(hImgCon).append($('<span />').html(hG.options.nextLinkText));var play=$('<a href="javascript:;" class="'+hG.options.playLinkClass+'" />').click(function(){$(hG).focus();$.dmxGallery.play(hG)}).appendTo(hImgCon).append($('<span />').html(hG.options.playLinkText));var pause=$('<a href="javascript:;" class="'+hG.options.pauseLinkClass+'" />').css({display:'none'}).click(function(){$(hG).focus();$.dmxGallery.pause(hG)}).appendTo(hImgCon).append($('<span />').html(hG.options.pauseLinkText));$.dmxGallery.pngFix(prev.get(0));$.dmxGallery.pngFix(next.get(0));$.dmxGallery.pngFix(play.get(0));$.dmxGallery.pngFix(pause.get(0));},buildImageHolders:function(hGallery)
{var hG=hGallery;var sId=hGallery.id;var hThumbList=$('#'+sId+'_thumb');var nLeft=0,nTop=0;var nWidth=$(hG).width();var nHeight=$(hG).height();var mcCss={left:parseInt($(hG).css('paddingLeft'))||0,top:parseInt($(hG).css('paddingTop'))||0,right:parseInt($(hG).css('paddingRight'))||0,bottom:parseInt($(hG).css('paddingBottom'))||0,overflow:'hidden',position:'absolute'};if(!hG.options.thumbShowOnHover){switch(hG.options.thumbHolderPosition)
{case'left':mcCss.left+=hG.options.thumbHolderWidth
+parseInt(hThumbList.css('paddingLeft'))||0
+parseInt(hThumbList.css('paddingRight'))||0
+parseInt(hThumbList.css('marginLeft'))||0
+parseInt(hThumbList.css('marginRight'))||0;break;case'right':mcCss.right+=hG.options.thumbHolderWidth
+parseInt(hThumbList.css('paddingLeft'))||0
+parseInt(hThumbList.css('paddingRight'))||0
+parseInt(hThumbList.css('marginLeft'))||0
+parseInt(hThumbList.css('marginRight'))||0;break;case'top':mcCss.top+=hG.options.thumbHolderHeight
+parseInt(hThumbList.css('paddingTop'))||0
+parseInt(hThumbList.css('paddingBottom'))||0
+parseInt(hThumbList.css('marginTop'))||0
+parseInt(hThumbList.css('marginBottom'))||0;break;case'bottom':mcCss.bottom+=hG.options.thumbHolderHeight
+parseInt(hThumbList.css('paddingTop'))||0
+parseInt(hThumbList.css('paddingBottom'))||0
+parseInt(hThumbList.css('marginTop'))||0
+parseInt(hThumbList.css('marginBottom'))||0;break;}}
var mainCont=$('<div class="imageMainContainer" id="'+sId+'_c0" />').appendTo(hGallery).css(mcCss);var hIC1=$('<div class="imageContainer" id="'+sId+'_1" />').appendTo(mainCont).hide();var hIC2=$('<div class="imageContainer" id="'+sId+'_2" />').appendTo(mainCont).hide();if(($.browser.msie&&$.browser.version<7)||($.browser.msie&&!$.boxModel))
{var wCorrection='this.parentNode.style.pixelWidth - (parseInt(this.parentNode.currentStyle.borderTopWidth) || 0) - (parseInt(this.parentNode.currentStyle.borderBottomWidth) || 0) - this.style.pixelTop - this.style.pixelBottom';var hCorrection='this.parentNode.style.pixelHeight - (parseInt(this.parentNode.currentStyle.borderTopWidth) || 0) - (parseInt(this.parentNode.currentStyle.borderBottomWidth) || 0) - this.style.pixelTop - this.style.pixelBottom';if(hG.options.thumbHolderVertical)
{if($.boxModel)
{wCorrection='this.parentNode.style.pixelWidth - (parseInt(this.currentStyle.borderLeftWidth) || 0) - (parseInt(this.currentStyle.borderRightWidth) || 0)';if(!hG.options.thumbShowOnHover)wCorrection+=' - '+hG.options.thumbHolderWidth;hCorrection='this.parentNode.style.pixelHeight - (parseInt(this.currentStyle.borderBottomWidth) || 0) - (parseInt(this.currentStyle.borderTopWidth) || 0)';}
hThumbList.get(0).style.setExpression('height',hCorrection);}
else
{if($.boxModel)
{wCorrection='this.parentNode.style.pixelWidth - (parseInt(this.currentStyle.borderLeftWidth) || 0) - (parseInt(this.currentStyle.borderRightWidth) || 0)';hCorrection='this.parentNode.style.pixelHeight - (parseInt(this.currentStyle.borderBottomWidth) || 0) - (parseInt(this.currentStyle.borderTopWidth) || 0)';if(!hG.options.thumbShowOnHover)hCorrection+=' - '+hG.options.thumbHolderHeight;}
hThumbList.get(0).style.setExpression('width',wCorrection);}
mainCont.get(0).style.setExpression('width',wCorrection);mainCont.get(0).style.setExpression('height',hCorrection);}
mainCont.mousewheel(function(event,delta)
{if(delta>0)
{$.dmxGallery.previousImage(hG);}
if(delta<0)
{$.dmxGallery.nextImage(hG);}
hG.focus();});},buildWaiting:function(hGallery)
{$('<div class="dmxWaiting" />').css({width:$(hGallery).width(),height:$(hGallery).height()}).appendTo(hGallery);},showWaiting:function(hGallery)
{$('.dmxWaiting',hGallery).css({display:'block'});$('.dmxWaiting',hGallery).animate({opacity:1});},hideWaiting:function(hGallery)
{$('.dmxWaiting',hGallery).animate({opacity:0},'fast','linear',function(){$('.dmxWaiting',hGallery).css({display:'none'})});},buildMessage:function(hGallery)
{var mOpac=0.5;if(!hGallery.options.showInfoMessage)mOpac=0;var hM=$('<div class="message" />').css({opacity:mOpac}).appendTo(hGallery);hM.css({top:$(hGallery).height()-hM.height()});},showMessage:function(hGallery,sMessage)
{if(hGallery.options.showInfoMessage)
{var hM=$(hGallery).find('div.message');var nH=$(hGallery).height();var nMH=hM.height();if(hGallery.options.messageHidden)
{hM.animate({top:nH-nMH,opacity:0.5},'slow');}
hM.text(sMessage);hGallery.options.messageHide.cancel();hGallery.options.messageHidden=false;}},hideMessage:function(hGallery)
{if(hGallery.options.messageHide)
hGallery.options.messageHide.delay(1000);},doHideMessage:function(hGallery)
{var hM=$(hGallery).find('div.message');var nH=$(hGallery).height();$(hM).animate({top:nH,opacity:0},'slow');hGallery.options.messageHidden=true;},buildCaption:function(hG)
{var hImgCon=$(hG).find('.imageMainContainer:first');var hCaption=$('<div class="imageCaption" />').appendTo(hImgCon);var nCH=hCaption.height();var nCTop;if(hG.options.captionPosition=='bottom')
{nCTop=$(hG).height();}
else
{nCTop=-$(hCaption).height();}
var nLeft=0;hCaption.css({top:nCTop,left:nLeft,width:'100%',opacity:hG.options.captionOpacity/100});},showCaption:function(hG)
{if(!$.dmxGallery.captionHidden(hG))
{$.dmxGallery.hideCaption(hG,true);return;}
var hCaption=$('div.imageCaption',hG);var hElements=$(hG).find('div.dmxImageHolder').find('ul li');if(hElements.eq(hG.options.imgIndex).find('h3').length>0||hElements.eq(hG.options.imgIndex).find('p').length>0)
{var nH=$(hG).height();hCaption.find('h3').remove();hCaption.find('p').remove();hElements.eq(hG.options.imgIndex).find('h3').clone().appendTo(hCaption);hElements.eq(hG.options.imgIndex).find('p').clone().appendTo(hCaption);$(hCaption).css({display:'block'})
var nCTop;if(hG.options.captionPosition=='bottom')
{nCTop=nH+hCaption.height();if(!hG.options.thumbShowOnHover)
{if(hG.options.thumbHolderHorizontal)
{nCTop-=hG.options.thumbHolderHeight;}}}
else
{nCTop=-hCaption.height();}
hCaption.css({'top':nCTop});if(hG.options.captionPosition=='bottom')
{nCTop-=2*hCaption.height();}
else
{nCTop=0;}
window.setTimeout(function(){hCaption.animate({top:nCTop,opacity:hG.options.captionOpacity/100},'slow')},100);}},hideCaption:function(hG,bShow)
{var hCaption=$('div.imageCaption',hG);var nCTop;if(hG.options.captionPosition=='bottom')
{nCTop=$(hG).height();}
else
{nCTop=-$(hCaption).height();}
if(bShow)
{hCaption.animate({top:nCTop,opacity:0},'slow','linear',function(){$(hCaption).css({display:'none'});$.dmxGallery.showCaption(hG)});}
else
{hCaption.animate({top:nCTop,opacity:0},'slow');}},captionHidden:function(hG)
{var hCaption=$('div.imageCaption',hG);var nH=$(hG).height();var nTop=parseInt(hCaption.css('top'))||0;if($(hCaption).css('display')=='none'||nH==nTop)
{return true;}
return false;},buildThumbnailList:function(hGallery)
{var hG=hGallery;var sId=hG.id;var nW=$(hG).width();var nH=$(hG).height();var hDim=$(hG).offset({border:true,padding:true});var hTT=hDim.top+nH-hG.options.thumbHolderHeight;if(hG.options.thumbHolderPosition=='top'||hG.options.thumbHolderPosition=='bottom')
{hG.options.thumbHolderHorizontal=true;hG.options.thumbHolderVertical=false;}
var hThumbList=$('#'+sId+'_thumb');if(hThumbList.length==0)
{hThumbList=$('<div class="dmxThumbList" id="'+sId+'_thumb" />');}
hThumbList.css({left:'auto',top:'auto',right:'auto',bottom:'auto'});if(hG.options.thumbHolderVertical)
{hThumbList.addClass('dmxThumbListVertical');}
hG.options.thumbHolderHeight=hG.options.thumbHeight+2*hG.options.thumbPadding;hG.options.thumbHolderWidth=hG.options.thumbWidth+2*hG.options.thumbPadding;var tlLeft=parseInt($(hG).css('paddingLeft'))||0;var tlTop=parseInt($(hG).css('paddingTop'))||0;var tlRight=parseInt($(hG).css('paddingRight'))||0;var tlBottom=parseInt($(hG).css('paddingBottom'))||0;switch(hG.options.thumbHolderPosition)
{case'top':hThumbList.css({right:tlRight,left:tlLeft,top:tlTop,width:'auto',height:hG.options.thumbHolderHeight});break;case'bottom':hThumbList.css({right:tlRight,left:tlLeft,bottom:tlBottom,width:'auto',height:hG.options.thumbHolderHeight});break;case'left':hThumbList.css({top:tlTop,left:tlLeft,bottom:tlBottom,width:hG.options.thumbHolderWidth,height:'auto'});break;case'right':hThumbList.css({top:tlTop,right:tlRight,bottom:tlBottom,width:hG.options.thumbHolderWidth,height:'auto'});break;}
var hUL=$('<ul />');hThumbList.append(hUL).appendTo(hG);var nTW=0;var nTH=0;$.each(hG.thumbList,function(nI,hImage)
{var hItem=$('<li />').css({width:hG.options.thumbWidth,height:hG.options.thumbHeight,margin:hG.options.thumbPadding,display:'inline'});var hLink=$('<a href="#" />').css({width:hG.options.thumbWidth,height:hG.options.thumbHeight}).click(function(){$.dmxGallery.showImage(hG,nI);return false;}).appendTo(hItem);hItem.appendTo(hUL);if($.boxModel){hLink.css({width:hG.options.thumbWidth
-parseInt(hLink.css('borderLeftWidth'))||0
-parseInt(hLink.css('borderRightWidth'))||0,height:hG.options.thumbHeight
-parseInt(hLink.css('borderTopWidth'))||0
-parseInt(hLink.css('borderBottomWidth'))||0});}else{hLink.css({width:hG.options.thumbWidth,height:hG.options.thumbHeight});}
hLink.hover(function(){var theLink=this;window.setTimeout(function(){if(jQuery){if(jQuery.boxModel){$(theLink).css({width:hG.options.thumbWidth
-parseInt(hLink.css('borderLeftWidth'))||0
-parseInt(hLink.css('borderRightWidth'))||0,height:hG.options.thumbHeight
-parseInt(hLink.css('borderTopWidth'))||0
-parseInt(hLink.css('borderBottomWidth'))||0});}else{$(theLink).css({width:hG.options.thumbWidth,height:hG.options.thumbHeight});}}},1);},function(){var theLink=this;window.setTimeout(function(){if(jQuery){if(jQuery.boxModel){$(theLink).css({width:hG.options.thumbWidth
-parseInt(hLink.css('borderLeftWidth'))||0
-parseInt(hLink.css('borderRightWidth'))||0,height:hG.options.thumbHeight
-parseInt(hLink.css('borderTopWidth'))||0
-parseInt(hLink.css('borderBottomWidth'))||0});}else{$(theLink).css({width:hG.options.thumbWidth,height:hG.options.thumbHeight});}}},1);});var hGImage=$('<img />');hGImage.load(function(){hImage.loaded=true;hG.options.loaded++;$.dmxGallery.showMessage(hG,'loaded '+hG.options.loaded+' images');$.dmxGallery.hideMessage(hG);hItem.css("backgroundImage",'url( "'+$(this).attr('src')+'" )');hItem.css("backgroundPosition",'center center');}).attr('src',hImage.toString());nTW+=hG.options.thumbWidth+2*hG.options.thumbPadding;nTH+=hG.options.thumbHeight+2*hG.options.thumbPadding;});if(hG.options.thumbHolderVertical)
hUL.css({height:nTH,left:0,top:0});else
hUL.css({width:nTW,left:0,top:0});var leftElm=$('<a href="javascript:;" class="'+hG.options.prevLinkClass+'" />').click(function(event)
{$.dmxGallery.scrollThumbnailList(hG,'left');event.preventDefault();event.stopPropagation();return false;}).appendTo(hThumbList).append($('<span />').html(hG.options.prevLinkText));var rightElm=$('<a href="javascript:;" class="'+hG.options.nextLinkClass+'" />').click(function(event)
{$.dmxGallery.scrollThumbnailList(hG,'right');event.preventDefault();event.stopPropagation();return false;}).appendTo(hThumbList).append($('<span />').html(hG.options.nextLinkText));$.dmxGallery.pngFix(leftElm.get(0));$.dmxGallery.pngFix(rightElm.get(0));hThumbList.mousewheel(function(event,delta)
{if(delta>0)
{$.dmxGallery.scrollThumbnailList(hG,'left',200);}
if(delta<0)
{$.dmxGallery.scrollThumbnailList(hG,'right',200);}
hG.focus();});return hThumbList;},hideThumbnailList:function(hG)
{var sId=hG.id;var hThumbList=$('#'+sId+'_thumb');hG.options.thumbListHidden=true;hThumbList.animate({opacity:0},200);},showThumbnailList:function(hG)
{if(!hG.options.thumbListHidden)
{return}
var sId=hG.id;var hThumbList=$('#'+sId+'_thumb');hG.options.thumbListHidden=false;hThumbList.animate({opacity:1},200);},initThumbnailListEvents:function(hG)
{var sId=hG.id;var hThumbList=$('#'+sId+'_thumb');var hList=hThumbList.find('ul');hThumbList.mousemove(function(event)
{$.event.fix(event);});hThumbList.mouseout(function(event)
{$.event.fix(event);});},scrollThumbnailList:function(hG,sDirection,nSpeed)
{var sId=hG.id;var theSpeed=nSpeed?nSpeed:400;if(hG.options.scrollingThumbnails)
{return;}
var hThumbList=$('#'+sId+'_thumb');var hList=hThumbList.find('ul');var nW=$(hG).width();var nH=$(hG).height();var nLL=parseInt($(hList).css('left'));if(!nLL){nLL=0;$(hList).css({left:0});}
var nLW=$(hList).outerWidth();var nLT=parseInt($(hList).css('top'));if(!nLT){nLT=0;$(hList).css({top:'0px'});}
var nLH=$(hList).outerHeight();var nNL;var nScrollWidth=nW;var nScrollHeight=nH;if(hG.options.thumbHolderHorizontal)
{switch(sDirection)
{case'left':if(nLL<0)
{nNL=nLL+Math.min(nScrollWidth,Math.abs(nLL));hG.options.scrollingThumbnails=true;$(hList).animate({left:nNL},theSpeed,'linear',function(){hG.options.scrollingThumbnails=false;});}
break;case'right':if(Math.abs(nLL)<nLW-nW)
{nNL=nLL-Math.min(nScrollWidth,Math.abs(nLW-nW+nLL));hG.options.scrollingThumbnails=true;$(hList).animate({left:nNL},theSpeed,'linear',function(){hG.options.scrollingThumbnails=false;});}
break;}}
else if(hG.options.thumbHolderVertical)
{switch(sDirection)
{case'left':if(nLT<0)
{nNL=nLT+Math.min(nScrollHeight,Math.abs(nLT));hG.options.scrollingThumbnails=true;$(hList).animate({top:nNL},theSpeed,'linear',function(){hG.options.scrollingThumbnails=false;});}
break;case'right':if(Math.abs(nLT)<nLH-nH)
{nNL=nLT-Math.min(nScrollHeight,Math.abs(nLH-nH+nLT));hG.options.scrollingThumbnails=true;$(hList).animate({top:nNL},theSpeed,'linear',function(){hG.options.scrollingThumbnails=false;});}
break;}}},fixThumbnailListPosition:function(hG)
{var sId=hG.id;if(hG.options.scrollingThumbnails)
{return;}
var hThumbList=$('#'+sId+'_thumb');var nW=$(hThumbList).width();var hList=hThumbList.find('ul');var nLL=parseInt($(hList).css('left'));if(!nLL){nLL=0;$(hList).css({left:0});}
var nLW=$(hList).outerWidth();var nNL=nLW+nLL;if(nNL<nW)
{$(hList).animate({left:nW-nLW},1000,'linear',function(){hG.options.scrollingThumbnails=false;});}},markThumbnail:function(hGallery,nId)
{var hG=hGallery;var sId=hG.id;var hThumbList=$('#'+sId+'_thumb');var hThumbLinks=hThumbList.find('ul a');hThumbLinks.removeClass('selected');hThumbLinks.eq(nId).addClass('selected');$.dmxGallery.scrollMarkedThumbIntoView(hG,nId);},scrollMarkedThumbIntoView:function(hGallery,nId)
{var hG=hGallery;var sId=hG.id;var hThumbList=$('#'+sId+'_thumb');var hThumbLinks=hThumbList.find('ul a');var nW=$(hThumbList).width();var nH=$(hThumbList).height();var hList=hThumbList.find('ul');var nLL=parseInt($(hList).css('left'))||0;var nLT=parseInt($(hList).css('top'))||0;var nLW=$(hList).outerWidth();var nNL=nLW+nLL;var nThumbLeft,nThumbTop;var nTW=hG.options.thumbWidth+2*hG.options.thumbPadding;var nTH=hG.options.thumbHeight+2*hG.options.thumbPadding;if(hG.options.thumbHolderHorizontal)
{nThumbLeft=nId*nTW;if((nThumbLeft+nLL)<0)
{$(hList).animate({left:-nThumbLeft},300,'linear',function(){hG.options.scrollingThumbnails=false;});}
if((nThumbLeft+nLL+nTW)>nW)
{$(hList).animate({left:-nThumbLeft+nW-nTW},300,'linear',function(){hG.options.scrollingThumbnails=false;});}}else if(hG.options.thumbHolderVertical)
{nThumbTop=nId*nTH;if((nThumbTop+nLT)<0)
{$(hList).animate({top:-nThumbTop},300,'linear',function(){hG.options.scrollingThumbnails=false;});}
if((nThumbTop+nLT+nTH)>nH)
{$(hList).animate({top:-nThumbTop+nH-nTH},300,'linear',function(){hG.options.scrollingThumbnails=false;});}}
$.dmxGallery.fixThumbnailListPosition(hG);},nextImage:function(hGallery)
{var hG=hGallery;hG.options.imgIndex+=1;var hElements=$(hG).find('div.dmxImageHolder').find('ul li');if(hG.options.imgIndex>=hElements.length)
{hG.options.imgIndex=0;}
$.dmxGallery.swapImages(hG,hG.options.imgIndex);},previousImage:function(hGallery)
{var hG=hGallery;hG.options.imgIndex-=1;var hElements=$(hG).find('div.dmxImageHolder').find('ul li');if(hG.options.imgIndex<0)
{hG.options.imgIndex=hElements.length-1;}
$.dmxGallery.swapImages(hG,hG.options.imgIndex);},play:function(hGallery)
{var hG=hGallery;$('a.dmxPause',hG).css({display:''});$('a.dmxPlay',hG).css({display:'none'});hG.options.player.delay(hG.options.playerDelay*1000);},pause:function(hGallery)
{var hG=hGallery;$('a.dmxPause',hG).css({display:'none'});$('a.dmxPlay',hG).css({display:''});hG.options.player.cancel();},swapImages:function(hGallery,nId)
{var hG=hGallery;hG.options.swapping=true;var hHolder=$('.'+hG.options.imageHolderClass,hG);$('div.imageContainer',hG).eq(1).empty();var hImage=$('<img id="'+$(hG).find('.imageContainer').eq(1).attr('id')+'_image'+'" border="0" />');$(hG).find('.imageContainer').eq(1).append(hImage);if(hG.linkList[nId]){hImage.wrap(hG.linkList[nId]);}
if(!hG.imageList[nId].loaded)
{hG.imageList[nId].loading=true;hImage.load(function()
{hG.imageList[nId].loading=false;hG.imageList[nId].loaded=true;$.dmxGallery.hideWaiting(hG);$.dmxGallery.doSwapImages(hG);if(hG.options.autosize)
{$.dmxGallery.resizeGalleryToContent(hG);}
else
{window.setTimeout(function(){$.dmxGallery.showCaption(hG)},100);}
hG.options.swapping=false;}).attr('src',hG.imageList[nId]);}
else
{hImage.attr('src',hG.imageList[nId]);$.dmxGallery.hideWaiting(hG);$.dmxGallery.doSwapImages(hG);if(hG.options.autosize)
{$.dmxGallery.resizeGalleryToContent(hG);}
else
{window.setTimeout(function(){$.dmxGallery.showCaption(hG)},100);}
hG.options.swapping=false;}
$.dmxGallery.markThumbnail(hGallery,nId);$.dmxGallery.preloadImages(hG,nId);if(typeof soundManager!='undefined')
{try
{soundManager.play('gallery');}
catch(hE)
{}}},doSwapImages:function(hGallery)
{var hG=hGallery;$('div.imageContainer',hG).eq(1).insertBefore($('div.imageContainer',hG).eq(0));$('div.imageContainer',hG).eq(0).fadeIn(1000);$('div.imageContainer',hG).eq(1).fadeOut(1000);},showImage:function(hGallery,nId)
{var hG=hGallery;$.dmxGallery.showWaiting(hG);hG.options.imgIndex=nId;$.dmxGallery.swapImages(hG,hG.options.imgIndex);},preloadImages:function(hGallery,nCurrentId)
{if(hGallery.options.allPreloaded)
{return;}
for(var nI=0;nI<hGallery.imageList.length;nI++)
{if(!hGallery.imageList[nI].loaded)
{break;}}
if(nI==hGallery.imageList.length)
{hGallery.options.allPreloaded=true;return;}
function getIds(hImageList,nCurrentId,nTreshold)
{var aIds=[];var nCId=1;nTreshold=nTreshold>hImageList.length?Math.floor(hImageList.length/2):nTreshold;while(nCId<=nTreshold)
{aIds[aIds.length]=nCurrentId-nCId<0?hImageList.length+nCurrentId-nCId:nCurrentId-nCId;aIds[aIds.length]=nCurrentId+nCId>=hImageList.length?(nCurrentId+nCId)%hImageList.length:nCurrentId+nCId;nCId++;}
return aIds;}
var aIds=getIds(hGallery.imageList,nCurrentId,hGallery.options.preloadTreshold);var nId;while(aIds.length>0)
{nId=aIds.shift();if(!hGallery.imageList[nId].loaded)
{hGallery.imageList[nId].loading=true;var hImage=$('<img />');hImage.load(function()
{hGallery.imageList[nId].loading=false;hGallery.imageList[nId].loaded=true;}).attr('src',hGallery.imageList[nId]);}}},resizeGalleryToContent:function(hG)
{var sId=hG.id;var hThumbList=$('#'+sId+'_thumb');var hMIC=$('div.imageMainContainer:first',hG);var hIC=$('div.imageContainer:first',hG);var sIId=hIC.attr('id')+'_image';var hImage=$('#'+sIId);if($(hG).width()==hImage.width()&&$(hG).height()==hImage.height())
{window.setTimeout(function(){$.dmxGallery.showCaption(hG)},10);return;}
else
{var gWidth=hImage.width();var gHeight=hImage.height();if(!hG.options.thumbShowOnHover)
{if(hG.options.thumbHolderHorizontal)
{gHeight+=hG.options.thumbHolderHeight
+parseInt(hThumbList.css('paddingTop'))||0
+parseInt(hThumbList.css('paddingBottom'))||0
+parseInt(hThumbList.css('marginTop'))||0
+parseInt(hThumbList.css('marginBottom'))||0;}
else if(hG.options.thumbHolderVertical)
{gWidth+=hG.options.thumbHolderWidth
+parseInt(hThumbList.css('paddingLeft'))||0
+parseInt(hThumbList.css('paddingRight'))||0
+parseInt(hThumbList.css('marginLeft'))||0
+parseInt(hThumbList.css('marginRight'))||0;}
if(!$.boxModel){gHeight+=parseInt($(hG).css('paddingTop'))||0
+parseInt($(hG).css('paddingBottom'))||0
+parseInt($(hG).css('borderTopWidth'))||0
+parseInt($(hG).css('borderBottomWidth'))||0
+parseInt($(hG).css('marginTop'))||0
+parseInt($(hG).css('marginBottom'))||0;gWidth+=parseInt($(hG).css('paddingLeft'))||0
+parseInt($(hG).css('paddingRight'))||0
+parseInt($(hG).css('borderLeftWidth'))||0
+parseInt($(hG).css('borderRightWidth'))||0
+parseInt($(hG).css('marginLeft'))||0
+parseInt($(hG).css('marginRight'))||0;}
if($.boxModel&&$.browser.msie&&$.browser.version<7){gHeight+=parseInt(hMIC.css('borderTopWidth'))||0
+parseInt(hMIC.css('borderBottomWidth'))||0
gWidth+=parseInt(hMIC.css('borderLeftWidth'))||0
+parseInt(hMIC.css('borderRightWidth'))||0}}
$(hG).stop();$(hG).animate({width:gWidth,height:gHeight},"slow","linear",function()
{window.setTimeout(function(){$.dmxGallery.showCaption(hG)},10);});}},debug:function(sMessage)
{if(this.bDebug)
{if(typeof window.console!='undefined')
{if(arguments.length>1)
{window.console.log(arguments);}
else
{window.console.log(sMessage);}}
else
{alert(sMessage);}}},dir:function(sMessage)
{if(this.bDebug)
{if(typeof window.console!='undefined')
{if(arguments.length>1)
{window.console.dir(arguments);}
else
{window.console.dir(sMessage);}}
else
{alert(sMessage);}}}}
jQuery.dmxGallery.counter=0;jQuery.fn.dmxGallery=jQuery.dmxGallery.build;
