
var clickRn=0;
var clickLn = 0;
var clickedbtn =0;
var crT =0;
(function($) {


	 
 	var defaults = {
		autoPlay: false,
		speed: 5000,
		text: { play: "Play", stop: "Stop", previous: "Previous", next: "Next" },
		transition:[1],
		showCaption: true,
		IESafe: false,
		showTooltips: false,
		nthImage:0,
		animationFinished: null
	};
   
    $.fn.PikaChoose = function(o) {
		return this.each(function() {
			$(this).data('pikachoose', new $pc(this, o));
		});
	}

    $.PikaChoose = function(e, o) {
		
		this.options    = $.extend({}, defaults, o || {});
		this.list     	= null;
		this.image  	= null;
		this.anchor		= null;
		this.caption	= null;
		this.imgNav		= null;
		this.imgPlay 	= null;
		this.imgPrev	= null;
		this.imgNext 	= null;
		this.textNext	= null;
		this.textPrev	= null;
		this.previous  	= null;
		this.next 		= null;
		this.animDiv		= null;
		this.thumbs		= null;
		this.transition	= null;
		this.active		= null;
		this.tooltip	= null;
		this.animating	= false;
		this.stillOut 	= null;	
		
		if (e.nodeName == 'UL' || e.nodeName == 'OL') {
            this.list = $(e);
            this.build();
            this.bindEvents();
        }else{
        	return;
        }
	
			var widthstr = $("#SiHolder .wraptocenter").width();
			 var heightstr = $("#SiHolder .wraptocenter").height();
			
			
			var a = "<div class='wraptocenter'> <span></span><img id='anidivid' src=''/></div>";
		
			this.animDiv.append(a);	
			$(".animation .wraptocenter").css({"width":widthstr+"px","height":heightstr+"px"});


    };
    
    var $pc = $.PikaChoose;
        $pc.fn = $pc.prototype = {
        pikachoose: '4.1.4'
    };

    $pc.fn.extend = $pc.extend = $.extend;

    $pc.fn.extend({

        build: function() {
        	this.step 		= 0;
		
			this.wrap 		= $("<div class='pika-image'></div>").insertBefore(this.list);
			this.ww         = $("<div class='wraptocenter'><span id='vv'></span></div>").appendTo(this.wrap);
			this.image 		= $("<img>").insertAfter($("#vv"));
			
			this.anchor		= this.ww.wrap("<div id='SiHolder'>").parent();
			this.video      = $("<div class='videoinfo'></div>").insertAfter(this.anchor);
			this.stack      = $("<div class='stackinfo'></div>").insertAfter(this.video);
			this.imgNav 	= $("<div class='pika-imgnav'></div>").insertAfter(this.stack);
			this.imgPlay 	= $("<a></a>").appendTo($("#StartStopSlide"));
	
			if(this.options.autoPlay){ 
												this.imgPlay.addClass('pause');
									}
											     else{
												   this.imgPlay.addClass('play');
												    }


		
			this.imgPrev 	= $("<a class='previous'></a>").insertAfter(this.imgNav);
			this.imgNext 	= $("<a class='next'></a>").insertAfter(this.imgPrev);
			this.caption 	= $("<div class='caption'></div>").insertAfter(this.imgNav);
			if(!this.options.showCaption){ this.caption.hide(); }
			this.tooltip 	= $("<div class='pika-tooltip'></div>").insertAfter(this.list);
			this.tooltip.hide();
			this.animDiv		= $("<div class='animation'></div>").insertAfter(this.caption);
			this.textNav 	= $("<div class='pika-textnav'></div>").insertAfter(this.animDiv);
			this.textPrev 	= $("<a class='previous'>"+this.options.text.previous+"</a>").appendTo(this.textNav);
			this.textNext	= $("<a class='next'>"+this.options.text.next+"</a>").appendTo(this.textNav);
			this.textNext	= $("<a class='play'>"+this.options.text.play+"</a>").appendTo(this.textNav);
			         
			this.list.addClass('pika-thumbs');
        	this.list.children('li').wrapInner("<div class='clip' />");
			this.thumbs = this.list.find('img');
			this.active		= this.thumbs.eq(this.options.nthImage);

			this.finishAnimating({'source':this.active.attr('ref') || this.active.attr('src'),'caption':this.active.parents('li:first').find('span:first').html(), 'Iheight':this.active.attr('height'), 'Iwidth':this.active.attr('width')});

			var self = this;
			this.thumbs.each(function(){
				self.createThumb($(this),self);
			});
			if(typeof(this.options.buildFinished) == 'function'){
	     		this.options.buildFinished(this);
	     	}
		}, 
        createThumb: function(ele) {
        	var self = ele;
			var that = this;
        	self.hide();
            
        	$.data(ele[0],'clickThrough',self.parent('a').attr('href') || "#");
        	if(self.parent('a').length > 0){ self.unwrap(); }
        	$.data(ele[0],'caption',self.next('span').html() || "");
			self.next('span').remove();
        	$.data(ele[0],'source',imgurls[crT]);
						
			$.data(ele[0],'Iwidth',widthArr[crT]);
			$.data(ele[0],'Iheight',heightArr[crT]);
		    crT=crT+1;
			$.data(ele[0],'order',self.closest('ul').find('li').index(self.parents('li')));

    		var data = $.data(ele[0]);
			
    		$('<img />').bind('load',{data:data},function(){
    	
				
				var img = $(this);
				var w = img.width();
				var h = img.height();
				if(w===0){w = img.attr("width");}
				if(h===0){h = img.attr("height");}
		
				var rw = parseInt(self.parents('.clip').css('width').slice(0,-2))/w;
				var rh = parseInt(self.parents('.clip').css('height').slice(0,-2))/h;
		
				var ratio;
				if(rw<rh){
					
					ratio = rh;
					var left = ((w*ratio- parseInt(self.parents('.clip').css('width').slice(0,-2)))/2)*-1;
					left = Math.round(left);
					self.css({left:left});
				}else{
					ratio = rw;
					self.css({top:0});
				}
			
				var width = Math.round(w*ratio);
				var height = Math.round(h*ratio);
				self.css("position","relative");
				var imgcss={
					width: width+"px",
					height: height+"px"
				};
				self.css(imgcss);
				self.hover(
					function(e){
						clearTimeout(that.stillOut);
						$(this).stop(true,true).fadeTo(250,1);
						if(!that.options.showTooltips){ return; }
						that.tooltip.show().stop(true,true).html(data.caption).animate({top:$(this).parent().position().top, left:$(this).parent().position().left, opacity: 1.0},'fast');
					},
					function(e){
						if(!$(this).hasClass("active")){$(this).stop(true,true).fadeTo(250,0.4);
						that.stillOut = setTimeout(that.hideTooltip,700);
					}}
				);

				
				if(data.order == 0){
					self.fadeTo(250,1);
					self.addClass('active');
				}else{
					self.fadeTo(250,0.4);
				}
    		}).attr('src',self.attr('src'));
        },
        bindEvents: function() {
			
        	this.thumbs.bind('click',{self:this},this.imgClick);
        	this.imgNext.bind('click',{self:this},this.nextClick);
        	this.textNext.bind('click',{self:this},this.nextClick);
			$("#Irightarrow,#hiddenrightarrw, #nextSlide, .hiddenRight").bind('click',{self:this},this.nextClick);
            $("#Ileftarrow,#hiddenleftarrw, #prevSlide, .hiddenLeft").bind('click',{self:this},this.prevClick);
			$("#Irightarrow, #nextSlide, .hiddenRight").bind('mouseenter', function(){ $("#Irightarrow").addClass("arrowHover");}).bind('mouseleave', function(){ $("#Irightarrow").removeClass("arrowHover");});
            $("#Ileftarrow, #prevSlide, .hiddenLeft").bind('mouseenter', function(){$("#Ileftarrow").addClass("arrowHover");}).bind('mouseleave', function(){ $("#Ileftarrow").removeClass("arrowHover");});
        	this.imgPrev.bind('click',{self:this},this.prevClick);
        	this.textPrev.bind('click',{self:this},this.prevClick);
        	this.imgPlay.bind('click',{self:this},this.playClick);
			if(onfrontpage==0){
		   if(isslideshow=="no"){  
		        $("#StartStopSlide").css("display","none");
		    }
			}
     
			this.tooltip.bind('mouseenter',{self:this},function(e){
				clearTimeout(e.data.self.stillOut);
			});
			this.tooltip.bind('mouseleave',{self:this},function(e){
				e.data.self.stillOut = setTimeout(e.data.self.hideTooltip,700);
			});
			buttonssetup();
$("#imgPD div").each(function(){
	
	var thisurl = $(this).css("background-image");
	if(thisurl!="none"){
		getimagefrmbg(this,thisurl);
	}
	
});

$("#imgPD div a").each(function(){
	
	var thisurl = $(this).css("background-image");
	if(thisurl!="none"){
		getimagefrmbgps(this,thisurl);
}});
$("#Iinfoline").css({"text-align":btmnavalign});

        },
		
		hideTooltip: function (e){
			$(".pika-tooltip").animate({opacity:0.01});
		},
       
	     imgClick: function(e,x) {
	     	var self = e.data.self;
			var data = $.data(this);
			
	     	if(self.animating){return;}
			self.caption.css({'display':'none'});
     		if(typeof(x) == 'undefined' || x.how != "auto"){
	     		//arrive here if natural click
	     		if(self.options.autoPlay){
	     			self.imgPlay.trigger('click');
	     		}
			}
	     	self.animating = true;
	     	self.active.fadeTo(300,0.4).removeClass('active');
	     	self.active = $(this);
	     	self.active.addClass('active').fadeTo(200,1);
	     	
	 		$('<img />').bind('load', {self:self,data:data}, function(){
			
				var n =0;
				 if(self.options.transition[0] == -1){	
					//random
					n = Math.floor(Math.random()*6)+1;
				}else{
					n = self.options.transition[self.step];
					self.step++;
					if(self.step >= self.options.transition.length){self.step=0;}
				}
				if(self.options.IESafe && $.browser.msie){ n = 0; }
				   self.doAnimation(n,data);
				
			}).attr('src',$.data(this).source);//end image preload
	     },//end bindEvents
	     doAnimation: function(n,data){
			
			if(imagepage==1){
			     FpImgMode= Pfmode;	
			}
	
	     		var self = this; 
				
				if(data.order){
			    Imgnum = data.order+1;
				clickedImage=0;
			}
			else{
			     Imgnum=clickedImage+1;	
			}
			
			 var winW=$('#fpimg').width();
	        var winH=$(window).height();
			
	if(FpImgMode=="normal" && ThtoOrig=="yes"){
		
             if(imagepage==0){
                   var headerheight = $(".websitetitle").height()+145; 
	               var imageFrH = winH-headerheight; 
			      var imageFrW = winW;
			 }
			  else if(imagepage==1){
				var headerheight = $(".websitetitle").height()+165; 
				 $("#IContainer").css({"margin-top":"20px"});
	             var imageFrH = winH-headerheight; 
				 var imageFrW = winW-100; 
			  }
			   if(data.Iwidth!=0&&data.Iheight!=0){
				   
			      ImgW =data.Iwidth;
			     ImgH = data.Iheight;
			   }
			   else{
				  if(imagepage==1){
					
					 ImgW =widthArr[Imgnum-1];
				 ImgH = heightArr[Imgnum-1];	
					
				  }
				  else{
					if(data.order){
				   		  ImgW =widthArr[Imgnum-1];
						  ImgH = heightArr[Imgnum-1];
					}
					else{
							 ImgW =widthArr[0];
							ImgH = heightArr[0];
					}
				  }
			
			
			   }
			var reSw,reSh,ML,MT;
           if(ImgW<=imageFrW&&ImgH<=imageFrH){
		      
	                      var marL = Math.round((imageFrW-ImgW)/2);
		                  var marT = Math.round((imageFrH-ImgH)/2);
		                  reSw= ImgW;
		                  reSh=ImgH;
			              ML=marL;
			              MT=marT;
		  
	                  }
	             else{
	
		              var dw= imageFrW/ImgW;
		              var dh = imageFrH/ImgH;
		              var dratio,dw,dh,ww,hh,marLL,marTT;
	                    	if(dw<dh){
			                	 dratio = dw;
								 ww = Math.round(ImgW*dratio);
					 			 hh = Math.round(ImgH*dratio);
					 			 marLL=Math.round((imageFrW-ww)/2);
					  			 marTT= Math.round((imageFrH-hh)/2);
							}else{
					      
								dratio = dh;
								ww = Math.round(ImgW*dratio);
					            hh = Math.round(ImgH*dratio);
					            marLL=Math.round((imageFrW-ww)/2);
					            marTT= Math.round((imageFrH-hh)/2);
							}
											   
					  reSw= ww;
		      		  reSh=hh;
			  		  ML=marLL;
			 		  MT=marTT;
			}

		}
		else if(FpImgMode=="fit" && ThtoOrig=="yes"){
		 
			var imageFrH = winH;
	        var imageFrW = winW;
			 if(data.Iwidth!=0&&data.Iheight!=0){
			     ImgW =data.Iwidth;
			     ImgH = data.Iheight;
			
			   }
			   else{
				  if(imagepage==1){
					ImgW =widthArr[Imgnum-1];
				   ImgH = heightArr[Imgnum-1];	
				  }
				  else{
					if(data.order){
				    ImgW =widthArr[Imgnum-1];
					 ImgH = heightArr[Imgnum-1];
					
					}
					else{
					 ImgW =widthArr[0];
				    ImgH = heightArr[0];
							
					}
				  }
			
			
			   }
			
	         
			          var dw= imageFrW/ImgW;
		              var dh = imageFrH/ImgH;
		              var dratio,dw,dh,ww,hh,marLL,marTT;
	                    	if(dw<dh){
							  
			                	 reSw=imageFrW;
								reSh="auto";
					 			
							}else{
								 reSw="auto";
								reSh=imageFrH;
					          
								
					           
							}

		}
		else {
			var imageFrH = winH;
	        var imageFrW = winW;
			  if(data.Iwidth!=0&&data.Iheight!=0){
			     ImgW =data.Iwidth;
			    ImgH = data.Iheight;
			   }
			   else{
				 	 if(imagepage==1){
					
							ImgW =widthArr[Imgnum-1];
							ImgH = heightArr[Imgnum-1];	
				  		}
				  	else{
						if(data.order){
				    		ImgW =widthArr[Imgnum-1];
							ImgH = heightArr[Imgnum-1];
					
							}
						else{
							ImgW =widthArr[0];
							 ImgH = heightArr[0];
							
						}
				  	}
			
			
			   }
				
			          var dw= imageFrW/ImgW;
		              var dh = imageFrH/ImgH;
		              var dratio,dw,dh,ww,hh,marLL,marTT;
	                    if(ThtoOrig=="yes"){	
					
						    if(dw<dh){
			                		 reSw="auto";
									 reSh=imageFrH;

					 		    }else{
					           		 reSw=imageFrW;
										reSh="auto";
							
									}
			

			             }
						 else{
						
									  reSw="";
									 reSh=""; 
				
						 }
			
			
		}
				
				
				
				
				
            // var ob = "<img src="+data.source+" width="+reSw+" height="+reSh+"/>";
			// self.animDiv.html(ob);
			$("#anidivid").attr("src",data.source);
			
			// self.animDiv.css("display","block");
			
			
			if(FpImgMode=="normal" && ThtoOrig=="yes"){
					$("#anidivid").css({"width":reSw+"px","height":reSh+"px"});
				
				}
				else{
					       if(ThtoOrig=="yes"){
								
							 $("#anidivid").css({'width':reSw, 'height':reSh, 'padding-top':'0px'});
						
							}
							else{
					
							}
				}
	
	     		switch(n){
					case 0:
						//no transition
						self.image.hide();
							self.animDiv.show();
                           self.finishAnimating(data);
					
						break;
					case 1:
					
					      // self.image.fadeOut('slow');
							if(onzoomview==0){
								self.image.show();
			                 self.animDiv.hide();
						  self.image.fadeOut(transspeed);
							self.animDiv.fadeIn(transspeed,function(){
								
								  self.finishAnimating(data);
								});
							}
							else{
							  self.finishAnimating(data);	
							}
						break;
					case 2:
					
					if(onzoomview==0){
								self.image.show();
			                 self.animDiv.hide();
						  self.image.fadeOut(transspeed);
							self.animDiv.fadeIn(transspeed,function(){
								
								  self.finishAnimating(data);
								});
							}
							else{
								
							  self.finishAnimating(data);	
							}
	
						break;
					case 3:
				
					self.animDiv.hide();
						if(onzoomview==0){
							if(FpImgMode=="fill"){
								self.image.css({"margin-left":"0px","opacity":1,"z-index":"2001", "position":"relative"});
								self.image.show();
								self.animDiv.show();
						     self.image.animate({"margin-left":"-2500px","opacity":0},transspeed,"linear",function(){
							 self.image.hide();
							  self.finishAnimating(data);
						       });
							}
							else{
								if(clickedbtn==1){
									  self.image.css({"margin-left":"0px"});
							  			$("#anidivid").css({"margin-left":"2000px"});
											self.image.show();
										self.animDiv.show();
										self.image.animate({"margin-left":"-2000px"},transspeed,"linear",function(){
										self.image.hide();
										});
								
						    		 $("#anidivid").animate({"margin-left":"0px"},transspeed,"linear",function(){
							 			 self.finishAnimating(data);
							 			});
							    }
								 else if(clickedbtn==2){
									 self.image.css({"margin-left":"0px"});
							  			$("#anidivid").css({"margin-left":"-2000px"});
											self.image.show();
										self.animDiv.show();
										self.image.animate({"margin-left":"2000px"},transspeed,"linear",function(){
										self.image.hide();
										});
								
						    		 $("#anidivid").animate({"margin-left":"0px"},transspeed,"linear",function(){
							 			 self.finishAnimating(data);
							 			}); 
								 }
								}
							}
							else{
								
							  self.finishAnimating(data);	
							}
						break;
					case 4:
							if(onzoomview==0){
								self.image.show();
								self.animDiv.css({"z-index":"2001"});
			                 self.animDiv.hide();
						  //self.image.fadeOut(800);
							self.animDiv.fadeIn(transspeed,function(){
								self.image.hide();
								  self.finishAnimating(data);
								});
							}
							else{
								
							  self.finishAnimating(data);	
							}
						break;							
					case 5:
							if(onzoomview==0){
								self.image.show();
								self.animDiv.css({"z-index":"2001","width":"0%","opacity":0});
			                 self.animDiv.show();
						  
							self.animDiv.animate({"width":"100%","opacity":1},transspeed,function(){
								self.image.hide();
								  self.finishAnimating(data);
								});
							}
							else{
								
							  self.finishAnimating(data);	
							}
						break;
					case 6:
							if(onzoomview==0){
								self.image.show();
								self.animDiv.css({"z-index":"2001","width":"0%"});
			                 self.animDiv.show();
						  
							self.animDiv.animate({"width":"100%"},transspeed,function(){
								self.image.hide();
								  self.finishAnimating(data);
								});
							}
							else{
								
							  self.finishAnimating(data);	
							}
						break;
					case 7:
							if(onzoomview==0){
								self.image.show();
								self.animDiv.css({"z-index":"2001","width":"0%","height":"0%"});
			                 self.animDiv.show();
						  
							self.animDiv.animate({"width":"100%","height":"100%"},transspeed,function(){
								self.image.hide();
								  self.finishAnimating(data);
								});
							}
							else{
								
							  self.finishAnimating(data);	
							}
						break;
					
				}

	     },//end doAnimation
	     finishAnimating: function(data){
			 	     	  
                 
			
				if(sheffect=="on"){
											$("#fpimg img").addClass("boxshadow");
								}
				if(FpImgMode=="normal"){			
									 getthumbstyles("#fpimg img", imageBo, imageCo);
				}
							
				
			if(data.order){
			    Imgnum = data.order+1;
				clickedImage=0;
			}
			else{
			     Imgnum=clickedImage+1;	
			}
			
			if(imagepage==1){
				
				var imgpgurl = sAppurl+arrUrl[Imgnum];
			$("#imageurl").attr("value",imgpgurl);
			}
			 var winW=$('#fpimg').width();
	        var winH=$(window).height();
			
	if(FpImgMode=="normal" && ThtoOrig=="yes"){
		
             if(imagepage==0){
                   var headerheight = $(".websitetitle").height()+145; 
	               var imageFrH = winH-headerheight; 
			      var imageFrW = winW;
			 }
			  else if(imagepage==1){
				var headerheight = $(".websitetitle").height()+165; 
				 $("#IContainer").css({"margin-top":"20px"});
	             var imageFrH = winH-headerheight; 
				 var imageFrW = winW-100; 
			  }
			   if(data.Iwidth!=0&&data.Iheight!=0){
				   
			      ImgW =data.Iwidth;
			     ImgH = data.Iheight;
			   }
			   else{
				  if(imagepage==1){
					
					 ImgW =widthArr[Imgnum-1];
				 ImgH = heightArr[Imgnum-1];	
					
				  }
				  else{
					if(data.order){
				   		  ImgW =widthArr[Imgnum-1];
						  ImgH = heightArr[Imgnum-1];
					}
					else{
							 ImgW =widthArr[0];
							ImgH = heightArr[0];
					}
				  }
			
			
			   }
			
		 
			var reSw,reSh,ML,MT;
			var tr = this.options.transition[this.step];
			
			
	
			
                 if(ImgW<=imageFrW&&ImgH<=imageFrH){
		      
	                      var marL = Math.round((imageFrW-ImgW)/2);
		                  var marT = Math.round((imageFrH-ImgH)/2);
		                  reSw= ImgW;
		                  reSh=ImgH;
			              ML=marL;
			              MT=marT;
		  
	                  }
	             else{
	
		              var dw= imageFrW/ImgW;
		              var dh = imageFrH/ImgH;
		              var dratio,dw,dh,ww,hh,marLL,marTT;
	                    	if(dw<dh){
			                	 dratio = dw;
								 ww = Math.round(ImgW*dratio);
					 			 hh = Math.round(ImgH*dratio);
					 			 marLL=Math.round((imageFrW-ww)/2);
					  			 marTT= Math.round((imageFrH-hh)/2);
							}else{
					      
								dratio = dh;
								ww = Math.round(ImgW*dratio);
					            hh = Math.round(ImgH*dratio);
					            marLL=Math.round((imageFrW-ww)/2);
					            marTT= Math.round((imageFrH-hh)/2);
							}
					
											   
					  reSw= ww;
		      		  reSh=hh;
			  		  ML=marLL;
			 		  MT=marTT;
					 
						
			}
		 
     		this.animating = false;
     		this.image.attr('src',data.source);
			this.image.attr('width',ImgW);
			this.image.attr('height',ImgH);
		}
		else if(FpImgMode=="fit" && ThtoOrig=="yes"){
		   
			var tr = this.options.transition[this.step];
			var imageFrH = winH;
	        var imageFrW = winW;
			 if(data.Iwidth!=0&&data.Iheight!=0){
			     ImgW =data.Iwidth;
			     ImgH = data.Iheight;
			
			   }
			   else{
				  if(imagepage==1){
					
					ImgW =widthArr[Imgnum-1];
				 ImgH = heightArr[Imgnum-1];	
				  }
				  else{
					if(data.order){
				    ImgW =widthArr[Imgnum-1];
					 ImgH = heightArr[Imgnum-1];
					
					}
					else{
					 ImgW =widthArr[0];
				    ImgH = heightArr[0];
							
					}
				  }
			
			
			   }
			
			var tr = this.options.transition[this.step];
			         
			          var dw= imageFrW/ImgW;
		              var dh = imageFrH/ImgH;
		              var dratio,dw,dh,ww,hh,marLL,marTT;
	                    	if(dw<dh){
							  
			                	 reSw=imageFrW;
								reSh="auto";
					 			
							}else{
								 reSw="auto";
								reSh=imageFrH;
					          
								
					           
							}
			this.animating = false;
     		this.image.attr('src',data.source);
			this.image.attr('width',winW);
			this.image.attr('height',winH);
		}
		else {
		   
			var imageFrH = winH;
	        var imageFrW = winW;
			  if(data.Iwidth!=0&&data.Iheight!=0){
			     ImgW =data.Iwidth;
			    ImgH = data.Iheight;
			
			   }
			   else{
				 	 if(imagepage==1){
					
							ImgW =widthArr[Imgnum-1];
							ImgH = heightArr[Imgnum-1];	
				  		}
				  	else{
						if(data.order){
				    		ImgW =widthArr[Imgnum-1];
							ImgH = heightArr[Imgnum-1];
					
							}
						else{
							ImgW =widthArr[0];
							 ImgH = heightArr[0];
							
						}
				  	}
			
			
			   }
			
			var tr = this.options.transition[this.step];
			
			          var dw= imageFrW/ImgW;
		              var dh = imageFrH/ImgH;
		              var dratio,dw,dh,ww,hh,marLL,marTT;
	                    if(ThtoOrig=="yes"){	
					
						    if(dw<dh){
			                		 reSw="auto";
									 reSh=imageFrH;

					 		    }else{
					           		 reSw=imageFrW;
										reSh="auto";
							
									}
			
			this.animating = false;
     		this.image.attr('src',data.source);
			this.image.attr('width',imageFrW);
			this.image.attr('height',imageFrH);
			             }
						 else{
						
									  reSw="";
									 reSh=""; 
							this.animating = false;
     		                this.image.attr('src',data.source);	
					
						 }
			
			
			
			
			
		}
			switch(tr){
				case 0:
				    	if(FpImgMode=="normal" && ThtoOrig=="yes"){
							
					           this.image.css({'width':reSw+"px", 'height':reSh+"px"});
							   this.image.show();
					            this.animDiv.hide();
						}
						else{
							if(ThtoOrig=="yes"){
								
							 this.image.css({'width':reSw, 'height':reSh, 'padding-top':'0px'});
							 this.image.show();
					         this.animDiv.hide();	
							}
							else{
								
								//this.image.removeAttr("width");
								//this.image.removeAttr("height");
								this.image.show();
								this.animDiv.hide();	
							}
						   
						}
						if(onzoomview==1){
			              zoomview();	
						  
			             }
						 if(onfrontpage!=1){ 
						 queueclicks(this);
						 }
				break;
				case 1:
				if(FpImgMode=="normal" && ThtoOrig=="yes"){
					this.image.css({'width':reSw+"px", 'height':reSh+"px"});
				}
				else{
					       if(ThtoOrig=="yes"){
								
							 this.image.css({'width':reSw, 'height':reSh, 'padding-top':'0px'});
						
							}
							else{
				
							}
				}
					if(onzoomview==1){
						
			              zoomview();	
						  
			             }
						if(onfrontpage!=1){ 
						 queueclicks(this);
						}
			     break;
			    case 2:
				if(FpImgMode=="normal" && ThtoOrig=="yes"){
					this.image.css({'width':reSw+"px", 'height':reSh+"px"});
					  
					         	
				}
				else{
					       if(ThtoOrig=="yes"){
								
							 this.image.css({'width':reSw, 'height':reSh, 'padding-top':'0px'});
						
							}
							else{
					
							}
				}
					
					if(onzoomview==1){
			              zoomview();	
						  
			             }
						 if(onfrontpage!=1){ 
						 queueclicks(this);
						 }
				 break;
				  case 3:
				if(FpImgMode=="normal"){
					this.image.css({'width':reSw+"px", 'height':reSh+"px"});
					  
					         	
				}
				else{
					       if(ThtoOrig=="yes"){
								
							 this.image.css({'width':reSw, 'height':reSh, 'padding-top':'0px'});
						
							}
							else{
					
							}
				}
					
					if(onzoomview==1){
			              zoomview();	
						  
			             }
						 if(onfrontpage!=1){ 
			    	queueclicks(this);
						 }
				 break;
				 case 4:
						if(FpImgMode=="normal" && ThtoOrig=="yes"){
					this.image.css({'width':reSw+"px", 'height':reSh+"px"});
					  
					         	
				}
				else{
					       if(ThtoOrig=="yes"){
								
							 this.image.css({'width':reSw, 'height':reSh, 'padding-top':'0px'});
						
							}
							else{
					
							}
				}
					
					if(onzoomview==1){
			              zoomview();	
						  
			             }
						 if(onfrontpage!=1){ 
						 queueclicks(this);
						 }
				break;
				
				case 5:
						if(FpImgMode=="normal" && ThtoOrig=="yes"){
					this.image.css({'width':reSw+"px", 'height':reSh+"px"});
					  
					         	
				}
				else{
					       if(ThtoOrig=="yes"){
								
							 this.image.css({'width':reSw, 'height':reSh, 'padding-top':'0px'});
						
							}
							else{
					
							}
				}
					
					if(onzoomview==1){
			              zoomview();	
						  
			             }
						 if(onfrontpage!=1){ 
						 queueclicks(this);
						 }
				
				case 6:
						if(FpImgMode=="normal" && ThtoOrig=="yes"){
					this.image.css({'width':reSw+"px", 'height':reSh+"px"});
					  
					         	
				}
				else{
					       if(ThtoOrig=="yes"){
								
							 this.image.css({'width':reSw, 'height':reSh, 'padding-top':'0px'});
						
							}
							else{
					
							}
				}
					
					if(onzoomview==1){
			              zoomview();	
						  
			             }
						 if(onfrontpage!=1){ 
						 queueclicks(this);
						 }
				break;
				
				case 7:
					if(FpImgMode=="normal" && ThtoOrig=="yes"){
					this.image.css({'width':reSw+"px", 'height':reSh+"px"});
					  
					         	
				}
				else{
					       if(ThtoOrig=="yes"){
								
							 this.image.css({'width':reSw, 'height':reSh, 'padding-top':'0px'});
						
							}
							else{
					
							}
				}
					
					if(onzoomview==1){
			              zoomview();	
						  
			             }
						 if(onfrontpage!=1){ 
						 queueclicks(this);
						 }
				break;
			}
		    
		
					/*video link*/
			if($("#video"+Imgnum).html()!=null){
			  $(".videoinfo").css({"display":"block"});
			 
			   $("#hidzview").css({"z-index":0});
			  $(".videoinfo").bind('click',function(){
				  $("#video"+Imgnum).click();
	   						if(playing==1){
								$(".pause").click();
									playing=0;	
								}
				  });
			}
			else{
				$(".videoinfo").css({"display":"none"});
				 				
			}
			
			if($("#stack"+Imgnum).html()!=null){
			  $(".stackinfo").css({"display":"block"});
			  $("#hidzview").css({"z-index":0});
			  
			  $(".stackinfo").bind('click',function(){
				  $("#stack"+Imgnum).click();
				  });
			}
			else{
				$(".stackinfo").css({"display":"none"});
				 
			}
			
			if($("#video"+Imgnum).html()==null && $("#stack"+Imgnum).html()==null) {
			$("#hidzview").css({"z-index":100000});
			}
			
     		this.anchor.attr('href',data.clickThrough);
		
			
     		if(this.options.showCaption){
     			this.caption.html(data.caption).css({'display':'none'});
     		}
     		if(this.options.autoPlay == true){
     			var self = this;
     			this.image.delay(this.options.speed).fadeIn(0,function(){ if(self.options.autoPlay){ self.nextClick(); } });
     		}
     		
     		if(typeof(this.options.animationFinished) == 'function'){
	     		this.options.animationFinished(this);
	     	}
			$("#iimgname").html($(".caption").html());
			if(btmnavhide=="yes"){
$(".btmNavBg").css("display","none");

}
			$(window).bind('resize',function(){
			 if(FpImgMode=="normal"){
			   if(ImageScaling=="yes"){
				if(onfrontpage==1){ 
				imageReSize('#co_container',ImgW,ImgH,'#slide_holder #SiHolder img');
				imageReSize('#co_container',ImgW,ImgH,'#anidivid');
				}
				else if(imagepage==1&&ThtoOrig=="yes"){
					
					
				imageReSize('#IContainer',ImgW,ImgH,'#slide_holder #SiHolder img');
				imageReSize('#IContainer',ImgW,ImgH,'#anidivid');
					
				}
			   }
			 }
			 else if(FpImgMode!="normal"){
				  if(ImageScaling=="yes"){
				if(onfrontpage==1){ 
				imageReSize('#co_container',ImgW,ImgH,'#slide_holder #SiHolder img');
				imageReSize('#co_container',ImgW,ImgH,'#anidivid');
				}
				else if(imagepage==1&&ThtoOrig=="yes"){
				imageReSize('#IContainer', ImgW,ImgH,'#slide_holder #SiHolder img');
				imageReSize('#IContainer',ImgW,ImgH,'#anidivid');
					
				}
			   }
			 }
			});
	    checkdisprice();
		if(alwaysopenmenu=="yes"){
  openmenualways();	
  if(FpImgMode=="fill"){
  $("#main_content").css({"position":"fixed","top":"0","left":"0"});
  }
  
}
		
		wraptoc();
            
			
			if(ThtoOrig=="no"){
						     $("#hidzview").css({"display":"none"});
						
							 if($("#fpimg img").height()>$(window).height()||$("#fpimg img").width()>$(window).width()){
							 // $("#SiHolder").addClass("handcursor");
							// $("#SiHolder").draggable();
							$(".animation").addClass("handcursor");
							$(".animation").draggable();
							 }
                       	
			}
			else{
				
					if(enlarge=="yes" && onzoomview==0){
						if(imagepage==1){
						if(Pfmode=="normal"){	
 				            $("#hidzview").css({"display":"block"});
						}
						}
				if(sheffect=="on"){
				 $("#fpimg img").addClass("boxshadow");
				}
				}
			}
			
			
			
		
	     },//end finishedAnimating
		 gapper: function(ele, aHeight){
			if(ele.attr('row') == 9 && ele.attr('col') == 0){
				//last row, check the gap and fix it!
				var gap = ani_divs.height()-(aHeight*9);
				return gap;
			}
			return aHeight;
		 },
		 nextClick : function(e){
			 
			 if(onzoomview==1){
				$("#hidzview").addClass("addload"); 
			 }
			 if(infoopen==1){
		    closeinfo();
	        infoopen=0;	
			}
			var how = "natural";
		 	try{
				var self = e.data.self;
				if(typeof(e.data.self.options.next) == 'function'){
					e.data.self.options.next(this);
				}
			}catch(err){
				var self = this;
				how = "auto";
			}
			var next = self.active.parents('li:first').next().find('img');
			if(next.length == 0){next = self.list.find('img').eq(0);};
		 	next.trigger('click',{how:how});
			nextloadimg();
			if(ThtoOrig=="no"){
			
					//$("#SiHolder").css({"left":"","top":""});
					$(".animation").css({"left":"","top":""});
		
				
			}
			
		 },
		 prevClick : function(e){
			 if(onzoomview==1){
				$("#hidzview").addClass("addload"); 
			 }
			if(typeof(e.data.self.options.previous) == 'function'){
	     		e.data.self.options.previous(this);
	     	}
			if(infoopen==1){
		    closeinfo();
	        infoopen=0;	
			}
			var self = e.data.self;
			var prev = self.active.parents('li:first').prev().find('img');
			if(prev.length == 0){prev = self.list.find('img:last');};
		 	prev.trigger('click');
		prevloadimg();
			if(ThtoOrig=="no"){
				
					//$("#SiHolder").css({"left":"","top":""});
					$(".animation").css({"left":"","top":""});
		
				
			}
			
		 },
		 playClick: function(e){
			 playing=1;
			
		 	var self = e.data.self;
		 	self.options.autoPlay = !self.options.autoPlay;
			self.imgPlay.toggleClass('play').toggleClass('pause');
			
		
			var pl = $("#StartStopSlide a").css("background-image").replace('url(', '').replace(')', '').replace("'", '').replace('"', '').replace('"', '');
			
	
		
		$("#StartStopSlide a img").attr("src",pl);
			
			
			 if(btmnavfolder!=""){
				 var pathstr = "CommonFiles/templates/auckland/"+btmnavfolder;
			 $("#StartStopSlide a.play img").attr({"src":pathstr+"/playP.png"});
			 
			  $("#StartStopSlide a.pause img").attr({"src":pathstr+"/stopS.png"});
			 }
			if(self.options.autoPlay){ self.nextClick(); }
			if(ThtoOrig=="no"){
				
					//$("#SiHolder").css({"left":"","top":""});
					$(".animation").css({"left":"","top":""});
				
			}
			
		 }
		 
		
		 
	}); //end extend

})(jQuery);

function wraptoc(){
	
if(imagepage==1&&ThtoOrig=="no"){
		  if(alwaysopenmenu=="no"){
			 $(".wraptocenter").css({"width":$(window).width()+"px","height":$(window).height()+"px"});
			}
			else{
				var dist = 230+away;
			$(".wraptocenter").css({"width":$(window).width()-dist+"px","height":$(window).height()+"px"});	
			 
			}
		}
		else if(ThtoOrig=="yes" && FpImgMode=="normal"){
			if(onzoomview==0){
			$(".wraptocenter").css({"width":$("#fpimg").width()+"px","height":$("#fpimg").height()-20+"px"});
			}
			else{
				if(alwaysopenmenu=="no"){
			 $(".wraptocenter").css({"width":$(window).width()+"px","height":$(window).height()+"px"});
			}
			else{
				var dist = 230+away;
			$(".wraptocenter").css({"width":$(window).width()-dist+"px","height":$(window).height()+"px"});	
			 
			}
			}
		}
		else if(imagepage!=1){
			$(".wraptocenter").css({"width":$("#fpimg").width()+"px","height":$("#fpimg").height()-20+"px"});
			
		}
		else{
			
			if(alwaysopenmenu=="no"){
			 $(".wraptocenter").css({"width":$(window).width()+"px","height":$(window).height()+"px"});
			}
			else{
				var dist = 230+away;
			$(".wraptocenter").css({"width":$(window).width()-dist+"px","height":$(window).height()+"px"});	
			 
			}
		}	
	
}

function queueclicksR(){
	clickRn = clickRn+1;
	clickedbtn = 1;	
		
	
}

function queueclicksL(){
	clickLn= clickLn+1;	
	clickedbtn=2;

}

function queueclicks(datat){
	
		 if(clickedbtn==1){		 
						 if(clickRn>1){
					       				 clickRn= clickRn-1; 
					       				 datat.nextClick();
				 		 }
				 	 else if(clickRn==1){
								clickRn=0;  
				 				 }
							}
						else if(clickedbtn==2){
				 					 if(clickLn>1){
										clickLn = clickLn-1;  
										datat.imgPrev.click();
										 }
                		 else if(clickLn==1){
						clickLn=0;  
				  		}
				}
	
}
