/*

	JAVASCRIPT FOR GALLERIES PLUGIN

*/

jQuery(window).load(function($) {
						
						//Global Variables
						var imgthumb = $(".image-thumbs").find("img");
						var imgfull = $('.full-wrap').find('img');
						var thumbholder = $('.thumbs-holder');
						var galholder = $('.gallery-wrap');
						var imgslider = $('.image-thumbs-slider').children('span');
						var galslider = $('.gallery-list-slider').children('span');
						//On thumbnail click, replace the main image
						imgthumb.click(function(){
												//swap image
												var src = $(this).attr('src');
												var title = $(this).attr('title');
												var newsrc = src.replace('thumbs_'+title, title);
												newsrc = newsrc.replace('thumbs', '');
												//hide, then fade image in when done loading
												imgfull.hide().load(function () {
																			  $(this).fadeIn();
																			  })
												.attr('src', newsrc);
												});
						//thumbnail slide to the right
						imgslider.children('a.right').click(function(){
																	 //get the number of slides to know when to stop
																	 var numofslides = $('.thumbs-holder > div').size();
																	 //set the limit by finding multiplying the number of slides times the width
																	 var slidelimit = (numofslides-1)*(-170);
																	 var pos = thumbholder.position();
																	 //when the position hits the slide limit, it doesn't fire
																	 if (pos.left != slidelimit){
																		 var newtop = pos.left - 170;
																		 thumbholder.animate({left: newtop},500);
																		 }
																		 });
						//thumbnail slide to the left
						imgslider.children('a.left').click(function(){
																	var pos = thumbholder.position();
																	//if its on the first slide, don't slide
																	if (pos.left != 0){
																		var newtop = pos.left + 170;
																		thumbholder.animate({ left: newtop},500);
																		}
																		});	
						//gallery slider
						galslider.children('a.right').click(function(){
																	 // get the number of slides
																	 var numofslides = $('.gallery-wrap > div').size();
																	 var slidelimit = (numofslides-1)*(-155);
																	 var pos = galholder.position();
																	 /*alert(numofslides);*/
																	 if (pos.left != slidelimit){
																		 var newtop = pos.left - 155;
																		 galholder.animate({left: newtop},500);
																	}
																	});
						galslider.children('a.left').click(function(){
																	var pos = galholder.position();
																	if (pos.left != 0){
																		var newtop = pos.left + 155;
																		galholder.animate({ left: newtop},500);
																		}
																		});	
						});