///////////////////////////////////////////////////////////////////////////////////////////////


(function($) {
	
$(function() {
    $('#nav li').hover(function() {
    	thisli = $(this).attr("id");
        $("#"+thisli+" a img").attr('tmp', $("#"+thisli+" a img").attr('src')).attr('src', $("#"+thisli+" a img").attr('data-hover')).attr('data-hover', $("#"+thisli+" a img").attr('tmp')).removeAttr('tmp');
    }).each(function() {
    	thisli = $(this).attr("id");
        $('<img />').attr('src', $("#"+thisli+" a img").attr('data-hover'));
    });
});

		
		$(document).ready(function(){ 
			
			
///////////////////////////////////////////////////////////////////////////////////////////////		     
// 1. Check what type of page we are on
///////////////////////////////////////////////////////////////////////////////////////////////
	
	// #content  -> index, categories
	// #content2 -> portfolio
	// #content3 -> page
	// #content4 -> news
	// #content5 -> gallery
	// #content6 -> web
	// #content7 -> video
	
	// Is it a single page (single.php page.php)			
			if ($("#content2, #content3, #content4, #content5, #content6").length == 0) {
				$single = 0;
			} else {
				$single = 1;
			}
			
	// #content2 is single-full.php for portfolio, this indicates its a different single page
			if ($("#content3, #content4, #content5").length == 0) {
				$currentpage = false;
			} else {
				$currentpage = true;
			}
			
	// #content7 is the video page
			if ($("#content7").length == 0) {
				$videopage = false;
			} else {
				$videopage = true;
			}
			
			
///////////////////////////////////////////////////////////////////////////////////////////////		     
// 2. Initialize all the startup values and functions
///////////////////////////////////////////////////////////////////////////////////////////////			
		
// Background containers and preloader	 
			$bg = $("#bg");
			$bgimg = $("#bg .bgimg");
			$preloader = $("#preloader");
			
// Single page gets its startup values from a different div container
			if ($currentpage == false) {
				$itemid = $("#item_0").attr("id");
				$itemid = $itemid.replace("item_", "");
				
				$bgurl = $("#item_0").attr("bg");
				$bgw = $("#item_0").attr("bgw");
				$bgh = $("#item_0").attr("bgh");
			} else {
				$itemid = 0;
				$bgurl = $("#content3").attr("imgurl");
				$bgw = $("#content3").attr("imgwidth");
				$bgh = $("#content3").attr("imgheight");
			}
	
	// Set an old item ID value		
			$itemidOld = $itemid;	
	// For checking the tabitems if its the same thumbnail item		
			$sameid = 0;
	// First item?
			$first = true;
	// Background slideshow timer
			$interval = null;
			$intervaldisable = false;
	// Portfolio automatic hide navigation timer
			$portTimer = null;
			$portTimer2 = null;
			$portTimer3 = null;
			$porthide = false;
			$portdelay = false;
			
			
	// Animation is false
			$anim = false;
	// Mouse is not on thumbnail items or text
			$mousethumb = false;
	
// Settings and variables for thumbnail item scroller		
			var pic2, numImgs2, arrLeft2, i2, totalWidth2, n2, myInterval2, pos;
			$currentprog = 0;
			$imgwidth = 215;
			$scrollrate = $imgwidth * 2;				
				
			$("#thumbsright").css({opacity: 0, filter: ''});
			$("#thumbsleft").css({opacity: 0, filter: ''});
			
	// If the browser resizes, change background again		
			$(window).resize(function() {
				FullScreenBackground($("#bg_"+$itemid),$bg);	
				relocVid();
			});
			
	// Set interval function for background slideshow, only for index and categories 	
			function timerfun() {
				if ($currentpage == false && $intervaldisable == false && $videopage == false) {
					clearTimeout($interval);
					$interval = setTimeout ( function(){timer("time")}, 5000 );
				} else {
					clearTimeout($interval);
				}				
			}
			
	// Initialize background function at startup		
			nextItem($itemid,$itemidOld,$bgurl,$bgw,$bgh);	
			
// Startup opacity values
			$(".thumbitemsingle").css({opacity: 0.5, filter: ''});
			$(".areabut").css({opacity: 0.7, filter: ''});
	// Set opacity values for menu items when ready		
			$("#subphoto").css({opacity: 0, filter: ''});
	// Set opacity values for the thumbnail items
			$(".thumbitem").css({opacity: 0.6, marginTop: '45px', filter: ''});	
	
// Set thumbnail items at the right place horizontal
			function relocateImg() {
				$pic2 = $("#thumbs ul").children("li");
				$numImgs2 = $pic2.length;
				$arrLeft2 = new Array($numImgs2);
				
				for (i2=0;i2<$numImgs2;i2++){
					
					totalWidth2=0;
					for(n2=0;n2<i2;n2++){
						totalWidth2 += $($pic2[n2]).width();
					}
			
					$arrLeft2[i2] = totalWidth2;
					
				}
				
				var myWidth=$(window).width();
				if (myWidth < totalWidth2) {
					$("#thumbsright").animate({opacity: 0.7, filter: ''},"slow");
				}
			}		
			$(window).load(function(){
				relocateImg();
				relocVid();
			});	
			
		
// Relocate the video container
			function relocVid() {
				myWidth = $(window).width();
				if ($videopage == true) {
					if(myWidth < 1440) {
						var change = (myWidth - $("#contentarea").width())/2;
						$("#content7").css({left: change});
					} else {
						var change = (myWidth)/2;
						$("#content7").css({left: change});
					}
				}
			}
			
			relocVid();
			
			
// Timer for hiding navigation on portfolio
			
			if (($single == 1 && $currentpage == 0 && $videopage == 0) || ($("#content").length == 1)) {
			
				$portTimer = setTimeout(function(){ portfolioHide() }, 10000);
	
				function portfolioHide() {
					//$("#menu").animate({opacity: 0,marginTop: "-50px", filter: ''},"fast");
					//$("#thumbs ul").animate({marginTop: "120px"},"slow");
					$("#thumbs, #thumbsleft, #thumbsright, #contentarea, #multisingle,#content3, #content4, #content5").animate({opacity: 0},"fast", function() { $porthide = true; });
					clearTimeout($portTimer);
				}
				
				function portfolioShow() {
					//$("#menu").animate({opacity: 1,marginTop: "0px", filter: ''},"fast");
					//$("#thumbs ul").animate({marginTop: "0px"},"fast");
					$("#thumbs, #thumbsleft, #thumbsright, #contentarea, #multisingle,#content3, #content4, #content5").animate({opacity: 1},"fast", function(){ });					
					
				}
				
				$("#bg,#menu, #thumbs, #thumbsleft, #thumbsright, #contentarea, #multisingle,#content3, #content4, #content5").mousemove(function(){
					if ($porthide == true) {
						$porthide = false;
						portfolioShow();
					}
					
					clearTimeout($portTimer);
					clearTimeout($portTimer2);
					$portTimer2 = setTimeout(function(){ $portTimer = setTimeout(function(){ portfolioHide() }, 3000); }, 10000);
					
				});
			}
		
///////////////////////////////////////////////////////////////////////////////////////////////			
// 3. Hover effect of the logo image. Shows the whole image and hides navigation		
///////////////////////////////////////////////////////////////////////////////////////////////
			
			$logotimer = setTimeout(function() { 
			
				$("#logoimg").hover(function (){
					$("#menu").animate({opacity: 0,marginTop: "-50px", filter: ''},"fast");
					$("#thumbs ul").animate({marginTop: "120px"},"slow");
					$("#thumbsleft, #thumbsright, #contentarea, #multisingle,#content3, #content4, #content5").animate({opacity: 0},"fast");
				}, function () {
					$("#menu").animate({opacity: 1,marginTop: "0px", filter: ''},"fast");
					$("#thumbs ul").animate({marginTop: "0px"},"fast");
					$("#thumbsleft, #thumbsright, #contentarea, #multisingle,#content3, #content4, #content5").animate({opacity: 1},"fast");
				});
				clearTimeout($logotimer);
			}, 5000);
			
///////////////////////////////////////////////////////////////////////////////////////////////
// 4. .areabut are the sub items/buttons like date, category, comment & tags under a post
///////////////////////////////////////////////////////////////////////////////////////////////

			$(".areabut").hover(function (){
				$(this).animate({opacity: 1, filter: ''},"fast");
			}, function () {
				$(this).animate({opacity: 0.7, filter: ''},"fast");
			});
			
///////////////////////////////////////////////////////////////////////////////////////////////
// 5. Hover effect for the menu and submenu
///////////////////////////////////////////////////////////////////////////////////////////////			
			
			$("#nav li").hover(function () {
				
	// Get the ID of the current li
				var navli = $(this).attr("id");
	// If its the photo menu item, get the submenu
				if (navli == "photo") {
	// Show the submenu image and fade it in
					$("#"+navli+" #subphoto").show();
					$("#"+navli+" #subphoto").animate({opacity: 1, filter: ''},"fast", function () {
	// Enable rollover image for menu item
						$("#"+navli+" img:nth-child(2)").animate({opacity: 1, filter: ''},"fast");
					});
	// Animation for the other menu items
				} 

			}, function (){
// Hover out, so fade the original menu item image back
				var navli = $(this).attr("id");
				
	// Disable submenu for photo
				if (navli == "photo") {				
					$("#"+navli+" #subphoto").animate({opacity: 0, filter: ''},"fast", function () { $("#"+navli+" #subphoto").hide(); });
				}
			});


			
///////////////////////////////////////////////////////////////////////////////////////////////
// 6. Tabitem function and the thumbnail at the bottom of the page
///////////////////////////////////////////////////////////////////////////////////////////////

	
// Hover effect of the thumbnail items for mouse 	
			$(".thumbitem").hover(function() {
				$(this).animate({opacity: 1, marginTop: '0px'},"fast");
			}, function () {
	// If its the active thumbnail item, don't fade out
				if($(this).attr("id") != ("item_"+$itemid)) {
					$(this).animate({opacity: 0.6, marginTop: '45px'},"fast");
				}
			});
	
// Switch effect of the thumbnail items for timer and keyboard navigation		
			function tabitem(itemid, oldid) {
		
	// If its a single page, first check what the ID is of the current item, so we can open up the thumbnail item tab
				if ($single == 1 ) {	
					itemid = $("#custom_"+itemid+" div").attr("id"); 
					itemid = itemid.replace("item_", "");
					
					$("#item_"+itemid).animate({opacity: 1, marginTop: '0px', filter: ''},"fast");
					$("#item_"+oldid).animate({opacity: 0.6, marginTop: '45px', filter: ''},"fast");
	// For normal pages the ID of the current item is in the #item_$ div
				} else {
					$("#item_"+itemid).animate({opacity: 1, marginTop: '0px', filter: ''},"fast");
					$("#item_"+oldid).animate({opacity: 0.6, marginTop: '45px', filter: ''},"fast");
				}
			}
			
// When clicked on a thumbnail item, change background if possible	
			$(".thumbitem").click(function() {
	// Only change background when no animation is running and if we are on the index or categories page (#content)
				if( $anim == false && $single == 0) {
					$bgurl = $(this).attr("bg");	
					$bgw = $(this).attr("bgw");
					$bgh = $(this).attr("bgh");
					
					$itemidOld = $itemid;
					$itemid = $(this).attr("id");
					$itemid = $itemid.replace("item_", "");	
					$itemid = parseInt($itemid);
					if ($itemid == $itemidOld) {
						url = $("#item_" + $itemid + " .thumbcontent .link").attr("href");
						window.location = url;
					} else {
	// If all the data is set, run the function for the next background				
						nextItem($itemid,$itemidOld,$bgurl,$bgw,$bgh);
					}
				}
			});
	
// Keyboard navigation, works in #content, #content2
			if ($currentpage == false) {	
				jQuery(document).keydown(function(e){
				    if (e.keyCode == 37) { 					
						timer("prev");	
						timerfun();						
				    }
				    if (e.keyCode == 39) { 
				    	timer("next");	s
				    	timerfun();		    	
				    }
				});
			}
    	
// If the cursor is on the thumbnails items or the current text, disable slideshow		
			$("#thumbs ul, #contentarea").hover(function () {

				$mousethumb = true;
				clearTimeout($interval);
			}, function (){
	// Enable it again when hover out
				$mousethumb = false;
				timerfun();
			});
			
// Thumbnail item prev & next navigation 			
		
			$("#next").click(function(){
				flexiScroll2(false);
				$intervaldisable = true;
				timerfun();						
			});
			$("#prev").click(function(){
				flexiScroll2(true);
				$intervaldisable = true;
				timerfun();		
			});
			
///////////////////////////////////////////////////////////////////////////////////////////////
// 7. Image navigation at single page
///////////////////////////////////////////////////////////////////////////////////////////////			

	
	// Hover effect of the small items		
			$(".thumbitemsingle").hover(function() {
				$(this).animate({opacity: 1,filter:''},"fast");
			}, function () {
	// Dont fade out the current item	
				if($(this).attr("id") != ("item2_"+$itemid)) {
					$(this).animate({opacity: 0.5,filter:''},"fast");
				}
			});
	
	// When clicked on an item, change background
			$(".thumbitemsingle").click(function () {
				$bgurl = $(this).attr("bg");	
				$bgw = $(this).attr("bgw");
				$bgh = $(this).attr("bgh");
				$itemidOld = $itemid;
				$itemid = $(this).attr("id");
	// The small items use a different ID, item2_$
				$itemid = $itemid.replace("item2_", "");	
				$itemid = parseInt($itemid);			
	// Run the next background function			
				nextItem($itemid,$itemidOld,$bgurl,$bgw,$bgh);
				timerfun();
			});
			
///////////////////////////////////////////////////////////////////////////////////////////////
// 8. Timer and keyboard navigation function, gets all the data and sends it to next background function
///////////////////////////////////////////////////////////////////////////////////////////////

	
	// dir -> next, prev or time
			function timer(dir) {
				
	// First check if there is no animation running
				//if( $anim == false ) {
					
// Runs if the timer uses the function (older items)
					if ((dir == "time" || dir == "next" || dir == "prev") && $single == 0) {
						if ($mousethumb == false) {
	// Set the new item IDs				
							$itemidOld = $itemid;
							$itemid = parseInt($itemid);
							
	// Is the direction previous or next/time						
							if (dir == "prev") {
	// Prev, so decrease item ID
								$itemid = $itemid-1;
							} else {
	// Next or time, so increase
								$itemid = $itemid+1;								
							}
							
	// Check if the next item exists, otherwise reset the item ID
							if ($("#item_"+$itemid).length == 0) {										
								if (dir != "prev") {
									flexiScroll2(true,true);
									$itemid = 0;
								} else {
									$itemid = $itemidOld;
								}
							}
							
							if (!($itemid == $itemidOld)) {
	// Get the new values for the next item										
								$bgurl = $("#item_"+$itemid).attr("bg");						
								$bgw = $("#item_"+$itemid).attr("bgw");
								$bgh = $("#item_"+$itemid).attr("bgh");
							
	// Get screen width					
								var myWidth=$(window).width();
	// Whats the x value of the item (leftside), so the thumbnail item scroller knows if it has to move								
								var x = $("#item_"+$itemid).offset().left;
							
	// If the screensize - width of an item (measures from the left) is larger than the x value, it means its off the screen at the right side							
								if (((myWidth-215) - x) < 0 ) {
	// Move the thumbnail items
									flexiScroll2(false);
								} else if (x < 0) {
									flexiScroll2(true,false);
								}
							
	// Fade in the new thumbnail item, after that run the next background script								
								$("#item_"+$itemid).animate({opacity: 1, marginTop: '0px', filter: ''},"slow", function () { nextItem($itemid,$itemidOld,$bgurl,$bgw,$bgh); });
	// Fade out the old thumbnail item
								$("#item_"+$itemidOld).animate({opacity: 0.6, marginTop: '45px', filter: ''},"slow");
							}
						}
						
// Runs on a single page, with multiple images attached			
					} else if ((dir == "time" || dir == "next" || dir == "prev") && $single != 0) {
						
	// Check if its really a single page with multiple images
						if (!$("#multisingle").length == 0) {
	// Get the old item IDs						
							$itemidOld = $itemid;
							$itemid = parseInt($itemid);
	
	// Is the direction previous or next/time						
							if (dir == "prev") {
	// Prev, so decrease item ID
								$itemid = $itemid-1;
							} else {
	// Next or time, so increase
								$itemid = $itemid+1;								
							}

	// Does the next small item exist							
							if ($("#item2_"+$itemid).length == 0) {
								
	// If the direction is prev and the old small item ID is the first item, find out what the last item ID is and go back to there	
								if (dir == "prev") {						
									$itemid = $("#multisingle li:last-child").attr("id");
									$itemid = $itemid.replace("item2_","");
	// If the direction is next or time and the old small item ID is the last one, go back to the first one
								} else {
									$itemid = 0;
								}
							} 
							
	// Get the new values for the next item														
							$bgurl = $("#item2_"+$itemid).attr("bg");						
							$bgw = $("#item2_"+$itemid).attr("bgw");
							$bgh = $("#item2_"+$itemid).attr("bgh");
	
 
	// Fade in the new thumbnail item, after that run the next background script								
							$("#item2_"+$itemid).animate({opacity: 1, filter: ''},"slow", function () { nextItem($itemid,$itemidOld,$bgurl,$bgw,$bgh); });
	// Fade out the old thumbnail item
							$("#item2_"+$itemidOld).animate({opacity: 0.5, filter: ''},"slow");
						}
											
					} 
				//}
			}
			

			
			function nextItem(itemid,oldid,bgurl,bgw,bgh) {
				
// Frontpage & category page background			

	// Reset the timeout for the slideshow
				clearTimeout($interval);
	
				if ($single == 0) {
	// Only run when no animation is in progress
	
					if( $anim == false ) {
						$anim = true;
				
						$thumbid = "#item_"+itemid; 						
						$(".current").addClass("previtem");
						$(".current").removeClass("current");
						//alert($thumbid);
						
		// Set background for first item						
						if ($first == true) {
							
							$("#bg").append('<a href="" class="current" id="link_'+itemid+'"><img width="'+bgw+'" height="'+bgh+'" src="'+bgurl+'" id="bg_'+itemid+'" class="bgimg" alt=""/></a>');
						}
		// Check if same item is clicked again, if it's not the case, append new image								
						if (itemid == oldid) {
							$sameid = 0;
						} else {
							$sameid = 1;
							$("#bg").append('<a href="" class="current" id="link_'+itemid+'"><img width="'+bgw+'" height="'+bgh+'"  src="'+bgurl+'" id="bg_'+itemid+'" class="bgimg" alt=""/></a>');
							$preloader.fadeIn("fast"); 
							
						}
		// Preload image, after that fade in and set all the data		
						$("#bg_"+itemid).load(function() {
					    	var $this=$(this);
					    	
					    	FullScreenBackground($this,$bg);
					    	
					    	$preloader.fadeOut("fast");
					    
					    	if ($first == true) {
					    		$($this).fadeIn("slow", function () { $anim = false; timerfun() });
					    		$url = $($thumbid + " .thumbcontent .link").attr("href");
					    		$("#bg a").attr("href",$url);
					    		tabitem(itemid);
					    	} else {
					    		$($this).fadeIn("slow", function () { $(".previtem").remove(); $anim = false; timerfun(); });
					    		tabitem(itemid,oldid);
					    		
					    		$("#contentarea h2 a").text($($thumbid + " .thumbcontent h2").text());
					    		$("#contentarea #areatext").text($($thumbid + " .excerpt").text());
					    		$("#contentarea #cat").html($($thumbid + " .category").html());
					    		$("#contentarea #dates a").text($($thumbid + " .date").text());
					    		$("#contentarea #comments2").html($($thumbid + " .comment").html()); 
					    		
					    		if ($videopage == true) {
					    			$vidid = $($thumbid).attr("vidid");
					    			if ($($thumbid).attr("vidsrc") == 'Youtube') {
					    				$(".content7mid").html('<iframe width="579" height="328" src="http://www.youtube.com/embed/'+$vidid+'?rel=0&amp;hd=1" frameborder="0" allowfullscreen></iframe>');
					    			} else {
					    				$(".content7mid").html('<iframe src="http://player.vimeo.com/video/'+$vidid+'?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=0" width="579" height="328" frameborder="0"></iframe>');
					    			}
					    		}
					    		
					    		$url = $($thumbid + " .thumbcontent .link").attr("href");
					    		$("#contentarea h2 a").attr("href",$url);
					    		$("#contentarea #readmore a").attr("href",$url);
					    		$("#contentarea #dates a").attr("href",$url);
					    		$("#bg a").attr("href",$url);
					    		Cufon.refresh();
					    		
					    	}
					    	
					   		$first = false;
					   		
						});
					}
// Single page background
				} else {
					
					if( $anim == false ) {
						$anim = true;
						
						if ($first == true) {
							if (($("#content3").length == 0) && ($("#content4").length == 0) && ($("#content5").length == 0) && ($("#content6").length == 0)) {
								$currentsingle = "#contentarea";
							} else {
								if (!$("#content3").length == 0){
									$currentsingle = "#content3";
								} else if (!$("#content4").length == 0){
									$currentsingle = "#content4";
								} else if (!$("#content5").length == 0){
									$currentsingle = "#content5";
								} else if (!$("#content6").length == 0){
									$currentsingle = "#content6";
								}
							}
			
							$bgurl = $($currentsingle).attr("imgurl");	
							$bgw = $($currentsingle).attr("imgwidth");
							$bgh = $($currentsingle).attr("imgheight");
		
							$("#bg").append('<div class="current"><img width="'+$bgw+'" height="'+$bgh+'" src="'+$bgurl+'" id="bg_0" class="bgimg" alt=""/></div>');
							
							
							$(".bgimg").load(function() {
								$("#item2_0").animate({opacity: 1,filter:''},"fast");
								var $this=$(this);		
								FullScreenBackground($this,$bg);					
								$preloader.fadeOut("fast");
								
								$("#bg_0").fadeIn("slow", function (){$anim = false; timerfun(); });
								if ($currentpage == false ) {
									
									$postid = $($currentsingle).attr("class");									
									$postid = $postid.replace("id_", "");
																
									tabitem($postid);
								}
								$first = false;	
								
							});
	// When there are more images, make slideshow for single page
						} else {
					
							$(".current").addClass("previtem");
							$preloader.fadeIn("fast"); 
							$("#bg").append('<div class="current"><img width="'+bgw+'" height="'+$bgh+'" src="'+bgurl+'" id="bg_'+itemid+'" class="bgimg" alt=""/></div>');
							$("#item2_"+oldid).animate({opacity: 0.5, filter: ''},"fast");
							$("#item2_"+itemid).animate({opacity: 1.0, filter: ''},"fast");
							
							$("#bg_"+itemid).load(function() {							
								var $this=$(this);		
								FullScreenBackground($this,$bg);					
								$preloader.fadeOut("fast");
								$("#bg_"+itemid).fadeIn("slow", function () { $(".previtem").remove(); $anim = false; timerfun(); });
								
							});
						}
					}
				}
							
			};
			 

	
			 
			function FullScreenBackground(theItem,theContainer){
			    var winWidth=$(window).width();
			    var winHeight=$(window).height();
			    var imageWidth=$(theItem).width();
			    var imageHeight=$(theItem).height();			    
			    var picHeight = imageHeight / imageWidth;
			    var picWidth = imageWidth / imageHeight;
			    
			    if ((winHeight / winWidth) < picHeight) {
			        $(theItem).css("width",winWidth);
			        $(theItem).css("height",picHeight*winWidth);
			    } else {
			        $(theItem).css("height",winHeight);
			        $(theItem).css("width",picWidth*winHeight);
			    };
			    $(theContainer).css("width",winWidth);
			    $(theContainer).css("height",winHeight);
			    $(theItem).css("margin-left",(winWidth- $(theItem).width())/2);
			    $(theItem).css("margin-top",(winHeight- $(theItem).height())/2);
			    
			}
		});
	
	
		function flexiScroll2(add,reset){
			
			var myWidth=$(window).width();
			
			// Hoeveel pixels er nog over zijn aan de rechterkant buiten het scherm
			$pos = ($imgwidth*$numImgs2) - (myWidth+$currentprog);
		
				for (i2=0;i2<$numImgs2;i2++){
					
					// naar oudere items toe
					if (add == false) {
						
						if ($pos > 0) {
							
							if ($pos < $scrollrate) {
								
								$arrLeft2[i2] -= $pos;
								if (i2 == $numImgs2-1) {
									$currentprog += $pos;
								}
								
							} else {
								$arrLeft2[i2] -= $scrollrate;
								if (i2 == $numImgs2-1) {
									
									$currentprog += $scrollrate;
								}
								
							}
						}
					
					// naar nieuwere items toe	
					} else if (add == true) {	
						if (reset == true) {
							$arrLeft2[i2] += $currentprog;	
							if (i2 == $numImgs2-1) {
								$currentprog = 0;
							}							
						} else {
							if ($currentprog > $scrollrate) {
								
								$arrLeft2[i2] += $scrollrate;	
					
								if (i2 == $numImgs2-1) {
									$currentprog -= $scrollrate;
								}
							} else if (($currentprog > 0) ) {
								
								$arrLeft2[i2] += $currentprog;						
								if (i2 == $numImgs2-1) {
									$currentprog = 0;
								}
							}
						}
			
					}
						
				
					$($pic2[i2]).animate({ left: $arrLeft2[i2] },"slow", "swing");
				}
				
				$pos = ($imgwidth*$numImgs2) - (myWidth+$currentprog);
				
				if ($currentprog > 0) {
					$("#thumbsleft").animate({opacity: 0.7, filter: ''},"slow");
				} else {
					$("#thumbsleft").animate({opacity: 0, filter: ''},"slow");
				}
			
				if ($pos > 0 ) {
					$("#thumbsright").animate({opacity: 0.7, filter: ''},"slow");
				} else {
					$("#thumbsright").animate({opacity: 0, filter: ''},"slow");
				}
				
			}

	
	})(jQuery);
	



