var Gallery={gIdStr:'gallery',gJQIDSTR:'#gallery',ligthbox:false,loadByTag:false,easing:'easeInOutBack',galleryId:0,tagId:0,currentPageIndex:0,totalFiles:0,_mainImageId:'galleryMainImg',_singleItemWidth:90,_visibleWidth:416,_scrollPx:416,_animationDuration:1200,_itemsetLength:4,_itemsetWidth:0,_galleryWidth:0,maxLeft:0,webServiceMethod:'GetGalleryImages',pageSize:8,init:function(){if(isIE6OrLess()){Gallery.lightbox=false;}
if(this.lightbox){Gallery.webServiceMethod=Gallery.loadByTag?'GetAllTagImages':'GetAllGalleryImages';}
else{Gallery.webServiceMethod=Gallery.loadByTag?'GetTagImages':'GetGalleryImages';}
if(document.getElementById(Gallery.gIdStr)){this.constructList();this.getGalleryImages();activated=this.lightbox?$('.galleryMainImgWrap, .galleryHorizNav, #galleryImageCaption').hide():this.setFirstImageActive();}},constructList:function(){$(Gallery.gJQIDSTR+" #galleryImages").html("<ul></ul>");},appendImage:function(objDetails){var img=objDetails;var h='';var lb='';var f='';var sep=img.Caption!=''?': ':'';var title='title="'+img.Caption+sep+img.AltText+'"';onclickStr="";if(this.lightbox==true){lb='lightbox-';}
else{dims=",Dimensions:{width:"+img.ImageWidth+",height:"+img.ImageHeight+"}";f="Gallery.setMainImage({ImagePath:'"+img.ImagePath+"',Id:'"+img.Id+"',Caption:'"+img.Caption+"',AltText:'"+img.AltText+"',ImageReferenceId:'"+img.ReferenceId+"'"+dims+"},this);return false;"
onclickStr=' onclick="'+f+'"';}
h='<li id="galleryImage_'+img.Id+'"><a href="'+img.ImagePath+'" rel="'+lb+'gallery_'+this.galleryId+'" '+title+onclickStr+'><img src="'+img.ThumbPath+'" alt="'+img.AltText+'" /></a></li>';$('#gallery #galleryImages ul').append(h);this.galleryReConstructor();},setFirstImageActive:function(){if(Gallery.images){$(Gallery.gJQIDSTR+" li:first").find('a').trigger('click');}},buildGallery:function(images){firstRequest=false;images=images.d;if(images){if(Gallery.totalFiles==0){firstRequest=true;}
Gallery.images=images;Gallery.totalFiles=images.TotalFiles;currentSet=images.ImageItems;if(currentSet&&currentSet.length>0){csl=currentSet.length;for(var i=0;i<csl;i++){if(currentSet[i]){Gallery.appendImage(currentSet[i]);}}}}
if(firstRequest){if(Gallery.lightbox){Gallery.startLightbox();}
else{Gallery.setFirstImageActive();}}},getGalleryImages:function(){$("#galleryMainImg").ajaxSend(function(evt,request,settings){});$("#galleryMainImg").ajaxComplete(function(request,settings){});var postData='{';if(Gallery.loadByTag){postData=postData+'"tagId":"'+this.tagId;}
else{postData=postData+'"galleryId":"'+this.galleryId;}
if(Gallery.ligthbox){postData=postData+'"}';}
else{postData=postData+'","pageSize":"'+this.pageSize+'","pageIndex":"'+(++this.currentPageIndex)+'"}';}
$.ajax({type:"POST",url:"/Messaging/PhotoGallery.asmx/"+Gallery.webServiceMethod,contentType:"application/json; charset=utf-8",dataType:"json",data:postData,success:this.buildGallery});},galleryReConstructor:function(){this.setWidth();this._galleryWidth=this._calcWidth();this._itemsetWidth=this._singleItemWidth*this._itemsetLength;this.maxLeft=(this._galleryWidth-this._scrollPx);},startLightbox:function(){$.Lightbox.construct({start:false,options:{start:false},show_linkback:false,files:{js:{lightbox:'/scripts/jquery.lightbox.js',colorBlend:'/scripts/jQuery.colorBlend.pack.js'},css:{lightbox:'/styles/jquery.lightbox.css'},images:{prev:'/images/prev.gif',next:'/images/next.gif',blank:'/images/blank.gif',loading:'/images/loading.gif'}},opacity:0.8,speed:100,auto_relify:false,scroll:'disabled'});$('#galleryImages a').lightbox({start:false});},setMainImage:function(imgObj,el){var mId='#'+this._mainImageId;$("#stfImageId").attr('value',imgObj.Id);$(mId+' img').stop().animate({opacity:0},100);if(imgObj.Dimensions){var pW=parseInt($(mId).parent().width())+parseInt($(mId).parent().css('paddingLeft'))+parseInt($(mId).parent().css('paddingRight'))
var pH=$(mId).parent().height()+parseInt($(mId).parent().css('paddingTop'))+parseInt($(mId).parent().css('paddingBottom'));var bW=parseInt($(mId).css('borderLeftWidth'))+parseInt($(mId).css('borderRightWidth'));var bH=parseInt($(mId).css('borderTopWidth'))+parseInt($(mId).css('borderBottomWidth'));var iW=imgObj.Dimensions.width;var iH=imgObj.Dimensions.height;if(isIE6OrLess()){}
totalW=iW+bW;totalH=iH+bH;marginT=(pH-totalH)/2;marginL=(pW-totalW)/2;if(isIE6OrLess()){marginL=marginL/2;}
$(mId).animate({width:iW+'px',height:iH+'px',marginTop:marginT+'px',marginLeft:marginL+'px'},'normal',this.easing);}
this.setActive(el);imgSrc=imgObj.ImagePath;imgEl=el.getElementsByTagName('img')[0];imgAlt=imgEl.alt;imgId=imgObj.Id;$("#galleryImageCaption").empty();if(imgObj.Caption!=''){$("#galleryImageCaption").append("<p>"+imgObj.Caption+"</p>");}
mi=document.getElementById(this._mainImageId).getElementsByTagName('img')[0];mi.alt=imgAlt;$(mi).attr('height',iH);$(mi).attr('width',iW);if(isIE6OrLess()){setTimeout("mi.src=\""+imgSrc+"\"",0);}
else{mi.src=imgSrc;}
var capt=imgObj.Caption;if(imgObj.Caption==''){if(imgObj.AltText==''){capt='';}
else{capt=imgObj.AltText;}}
$("#"+this._mainImageId+" .caption p").html(capt);$(mId+' img').animate({opacity:1},200);$("#stfImageId").val(imgId);$("#stfGalleryId").val(this.galleryId);if(document.getElementById('CommentReferenceId')){$("#CommentReferenceId").attr('value',imgObj.ImageReferenceId);if(typeof(__doPostBack)=='function'){__doPostBack(commentUpdatePanelId,'');}}},setMainImageSource:function setMainImageSource(strSrc){im=document.getElementById(this._mainImageId).getElementsByTagName('img')[0];im.src=strSrc;},setActive:function(el){items=el.parentNode.parentNode.getElementsByTagName('li');for(var i=0;i<items.length;i++){imgEl=items[i];$(imgEl).removeClass('active');}
el.parentNode.className='active';},slideLeft:function(){leftVal=this._getLeft()+this._scrollPx;if((leftVal*-1)<0){leftVal=0;$('#galleryImages ul').stop().animate({left:leftVal+'px'},this._animationDuration/2,this.easing);}
if(((leftVal*1)-1)+(this._visibleWidth*(Math.floor(this._getImageCount()/this._itemsetLength)))<this._calcWidth()){$('#galleryImages ul').stop().animate({left:leftVal+'px'},this._animationDuration,this.easing);}},slideRight:function(){if(Gallery.totalFiles<=Gallery._itemsetLength){return;}
rightVal=this._getLeft()-this._scrollPx;if((rightVal*-1)>this.maxLeft){rightVal=-this.maxLeft;$('#galleryImages ul').stop().animate({left:rightVal+'px'},this._animationDuration/2,this.easing);}
if(rightVal*-1<this._calcWidth()){$('#galleryImages ul').stop().animate({left:rightVal+'px'},this._animationDuration,this.easing);}
if((rightVal-this._visibleWidth)<-this.maxLeft){var totalMinOffset=Gallery.totalFiles-Gallery._itemsetLength;modTotalLen=(Gallery.totalFiles%Gallery._itemsetLength);if(modTotalLen<Gallery._itemsetLength&&modTotalLen>0){totalMinOffset=Gallery.totalFiles-(Gallery.totalFiles%Gallery._itemsetLength);}
if($('#galleryImages ul').children().length<=(totalMinOffset)){this.getGalleryImages();}}},next:function(){negation=$('#galleryImages').offset().left;nextIm=$(this.gJQIDSTR+" ul li.active").next();c=$(nextIm).find('a').trigger('click');if($(nextIm).offset()&&(($(nextIm).offset().left-negation)>$('#galleryImages').width())){this.slideRight();}
return;if($(this.gJQIDSTR+" ul li.active").offset()&&(($(this.gJQIDSTR+" ul li.active").offset().left-negation)>$('#galleryImages').width())||(($(this.gJQIDSTR+" ul li.active").offset().left-negation)<0)){operator="";if(($(this.gJQIDSTR+" ul li.active").offset().left-negation)<0){operator="-";}
rightVal=this._getLeft()-this._scrollPx;if((rightVal*-1)>this.maxLeft){rightVal=-this.maxLeft;}
$('#galleryImages ul').stop().animate({left:operator+rightVal+'px'},this._animationDuration/2,this.easing);}},back:function(){negation=$('#galleryImages').offset().left
prevIm=$(this.gJQIDSTR+" ul li.active").prev();c=$(prevIm).find('a').trigger('click');if($(prevIm).offset()&&(($(prevIm).offset().left-negation)<0)){this.slideLeft();}
return;if($(this.gJQIDSTR+" ul li.active").offset()&&(($(this.gJQIDSTR+" ul li.active").offset().left-negation)>$('#galleryImages').width())||(($(this.gJQIDSTR+" ul li.active").offset().left-negation)<0)){$('#galleryImages ul').stop().animate({left:($(this.gJQIDSTR+" ul li.active").offset().left/2)+'px'},this._animationDuration,this.easing);}
leftVal=this._getLeft()+this._scrollPx;if((leftVal*-1)<0){leftVal=0;$('#galleryImages ul').stop().animate({left:leftVal+'px'},this._animationDuration/2,this.easing);}},toggleSendToFriend:function(){$('.gallerySendToFriendInner').slideToggle(500);$('.gallerySendToFriendInner').parent().css('overflow','hidden');},sendToFriend:function(){stfYourName=$("#stfYourName").css('backgroundColor','#fff').attr('value');stfYourEmail=$("#stfYourEmail").css('backgroundColor','#fff').attr('value');stfFriendName=$("#stfFriendName").css('backgroundColor','#fff').attr('value');stfFriendEmail=$("#stfFriendEmail").css('backgroundColor','#fff').attr('value');stfComment=$("#stfComment").attr('value');stfImageId=$("#stfImageId").attr('value');stfImageUrl=this.sendToAFriendBaseUrl;var stfErrors={};if(!Validator.regex(Validator.mask.names,stfYourName)||!Validator.hasValue('stfYourName')){stfErrors.stfYourName='Please enter your name';}
if(!Validator.hasValue('stfYourEmail')){stfErrors.stfYourEmail="Please enter your email address.";}
else if(!Validator.regex(Validator.mask.email,stfYourEmail)){stfErrors.stfYourEmail="Please enter a valid email address for your email address.";}
if(!Validator.regex(Validator.mask.names,stfFriendName)||!Validator.hasValue('stfFriendName')){stfErrors.stfFriendName="Please enter your friends' name.";}
if(!Validator.hasValue('stfFriendEmail')){stfErrors.stfFriendEmail="Please enter your friends' email address.";}
else if(!Validator.regex(Validator.mask.email,stfFriendEmail)){stfErrors.stfFriendEmail="Please enter a valid email address for your friends' email address.";}
if(this.sendToAFriendBaseUrl!=''&&typeof(parseInt(stfImageId))=='number'){stfImageUrl=stfImageUrl.replace('#IMAGEID#',stfImageId);}
else{if(typeof(parseInt(stfImageId))!='number'){stfErrors.stfImageId="Sorry, but I couldn't detect the image you want to send. Please try selecting the image you want to send and try again.";}}
Gallery.stfErrorDiv='stfErrors';Gallery.iterator=0;Gallery.stfErrorSet=Array();jQuery.each(stfErrors,function(i,n){Gallery.stfErrorSet[Gallery.iterator]=i;Gallery.iterator++;});if(Gallery.stfErrorSet.length>0){$("#"+Gallery.stfErrorDiv).empty();$("#"+Gallery.stfErrorDiv).append("<ul></ul>");jQuery.each(stfErrors,function(i,n){$("#"+i).animate({backgroundColor:"#fff"},100);$("#"+i).effect("pulsate",{times:2},200);$("#"+i).animate({backgroundColor:"#eebbbb"},500);$("#"+Gallery.stfErrorDiv+" ul").append("<li>"+n+"</li>");});return;}
stfYourName=stfYourName;stfYourEmail=stfYourEmail;stfFriendName=stfFriendName;stfFriendEmail=stfFriendEmail;stfComment=stfComment;$.ajax({type:"POST",url:"/Messaging/PhotoGallery.asmx/SendToAFriend",contentType:"application/json; charset=utf-8",dataType:"json",data:'{"imageUrl":"'+stfImageUrl+'",'
+'"senderName":"'+stfYourName+'",'
+'"senderEmail":"'+stfYourEmail+'",'
+'"friendsName":"'+stfFriendName+'",'
+'"friendsEmail":"'+stfFriendEmail+'",'
+'"personalMessage":"'+stfComment+'"}',success:this.sendToFriendSuccess,error:this.sendToFriendError});},sendToFriendSuccess:function(responseData,textStatus){if(responseData.d){$("#stfYourName").val('');$("#stfYourEmail").val('');$("#stfFriendName").val('');$("#stfFriendEmail").val('');$("#stfFriendEmail").val('');$("#stfComment").val('');Gallery.toggleSendToFriend();}},sendToFriendError:function(XMLHttpRequest,textStatus,errorThrown){errorMsg=errorThrown?errorThrown:textStatus;$("#"+Gallery.stfErrorDiv).empty();$("#"+Gallery.stfErrorDiv).append("<ul></ul>");$("#"+Gallery.stfErrorDiv+" ul").append("<li><p>Sorry, an error occured while trying to send this photo. Please try again later, or if this error perists, contact us and quote the following error message:</p><blockquote>"+errorMsg+"</blockquote></li>");alert(errorMsg);this;},_getLeft:function(){return parseInt($('#galleryImages ul').css('left'));},_calcWidth:function(){w=0;for(var i=0;i<$('#galleryImages ul').children('li').length;i++){s=$('#galleryImages ul').children('li')[i];var mL=parseInt($(s).css('marginLeft'));var mR=parseInt($(s).css('marginRight'));var pL=parseInt($(s).css('paddingLeft'));var pR=parseInt($(s).css('paddingRight'));var ie6Offset=0;if(isIE6OrLess()){}
w+=$(s).width()+mL+mR+pL+pR+ie6Offset;};return w;},setWidth:function(){$('#galleryImages ul').css('width',this._calcWidth()+"px");},_getImageCount:function(){return $('#galleryImages ul').children().length;}}
$(document).ready(init);function init(){Gallery.init();}
function isIE6OrLess(){version=0
if(navigator.appVersion.indexOf("MSIE")!=-1){temp=navigator.appVersion.split("MSIE");version=parseFloat(temp[1]);}
if(version<=6.0&&version!=0){return true;}
return false;}
var Validator={validated:false,mask:{email:/^([\w.])+\@(([\w])+\.)[a-zA-Z0-9]{2,}/,domain:/^(http:\/\/)([\w]+\.){1,}[A-Z]{2,4}\b/gi,numeric:/^[0-9]+$/gi,alphanumeric:/^[0-9a-f\-\s]+$/gi,names:/^[a-z\.\-\s\']{1,}$/gi},hasValue:function(el){v=Validator.getValue(el);if(v==undefined){return false;}
if(v==''){return false;}
if(v==null){return false;}
return true;},regex:function(rgMask,valueToTest){retVal=rgMask.test(valueToTest);rgMask.exec(valueToTest);return retVal;},getValue:function(elId){return $('#'+elId).attr('value');},setValue:function(strVal,elId){$('#'+elId).attr('value',strVal);},remove:function(rx,str){return str.replace(rx,'');},stripNonAlpha:function(str){return Validator.remove(/[^A-Za-z]+/g,str);},stripNonAlphaNumeric:function(str){return Validator.remove(/[^A-Za-z0-9]+/g,str);},stripNonNumeric:function(str){return Validator.remove(/[^0-9\-\.]/g,str);},stripNonNumericExplicit:function(str){return Validator.remove(/[^0-9]/g,str);}};