/*
 * 	Easy Slider 1.5 - jQuery plugin
 *	written by Alen Grakalic	
 *	http://cssglobe.com/post/4004/easy-slider-15-the-easiest-jquery-plugin-for-sliding
 *
 *	Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
 *	Dual licensed under the MIT (MIT-LICENSE.txt)
 *	and GPL (GPL-LICENSE.txt) licenses.
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */
 
/* Modified 2009 by Kristy Mayes */
 
function Loader() {
var bodyEl = document.getElementsByTagName("body");

//alert("bodyEl" + bodyEl.length);
     var pageName = bodyEl[0].id;

//alert(pageName);

     if(pageName != "home") {
		
		var imgList  = $("#images > li > img");
		var imgTotal = imgList.length;
		var num      = 0;
		
		if(pageName=="rooms") {
			num = 2;
		} else if(pageName=="reservations") {
			num = 3;
		} else if(pageName=="story") {
			num = 7;
		} else if(pageName=="whats_near") {
			num = 4;
		} else if(pageName=="contact") {
			num = 6;
		} else if(pageName=="profile") {
			num = 5;
		} else if(pageName=="directions") {
			num = 8;
		}
		
		for(var i=0; i< imgTotal; i++) {
			var src_normal  = imgList[i].getAttribute('src');
			var imgNum      = i + num;
			var src_new     = src_normal.substring(0, src_normal.lastIndexOf('_'));
			src_new        += "_" + imgNum + ".jpg";
			imgList[i].setAttribute('src', src_new); 
		}
		
	} 	    
}
(function($) {


  if(navigator.appName != "Microsoft Internet Explorer") {

//alert("not ie");

$.fn.easySlider = function(options){

		// default configuration properties
		var defaults = {			
			prevId: 		'prevBtn',
			prevText: 		'Previous',
			nextId: 		'nextBtn',	
			nextText: 		'Next',
			controlsShow:	true,
			controlsBefore:	'',
			controlsAfter:	'',	
			controlsFade:	false,
			firstId: 		'firstBtn',
			firstText: 		'First',
			firstShow:		false,
			lastId: 		'lastBtn',	
			lastText: 		'Last',
			lastShow:		false,				
			vertical:		false,
			speed: 			400,
			auto:			false,
			pause:			2000,
			continuous:		false
		}; 
		
		var options = $.extend(defaults, options);  
		

	
		this.each(function() 
		{  
			var obj 		= $(this); 	//imageBox			
			var numSlides 	= $("li", obj).length;
			var slideWidth 	= $("li", obj).width(); 
			var slideHeight = $("li", obj).height(); 
			var totalSlides = numSlides+1;
			var total 		= 0;
			var totalWidth  = $("#imageBox").width();
			var num         = 0;
			var position    = 0;

			obj.height(slideHeight); 
			obj.css("overflow","hidden");
			$("ul", obj).css('width',numSlides*slideWidth);	
			
			var slides = $("#images > li");
			var ogTotal = slides.length;
			
			// z-index
			for(var i=0; i< ogTotal; i++) {
				var index = 100 - i;
				index.toString();
				var id = "#img" + (i+1).toString();
				$(id).css('z-index',index);
				//$(id).css('visibility','visible');
			}
			
			//alert('good');
			
			//create controls
			/*
			if(options.controlsShow) {
				var html = options.controlsBefore;
				html += ' <span id="'+ options.prevId +'"><a href=\"javascript:void(0);\">'+ options.prevText +'</a></span>';
				html += ' <span id="'+ options.nextId +'"><a href=\"javascript:void(0);\">'+ options.nextText +'</a></span>';
				if(options.lastShow) html += ' <span id="'+ options.lastId +'"><a href=\"javascript:void(0);\">'+ options.lastText +'</a></span>';
				html += options.controlsAfter;
				$("#shadow").after(html);	
			};
			*/
			
			//intialise prevBtn as hidden
			$("a", "#prevBtn").hide();
			
	
			//next button fx
			$("a","#"+options.nextId).click(function(){	
				animate("next", true, num);	
			});
			
			//prev button fx
			$("a","#"+options.prevId).click(function(){		
				animate("prev", true, num);		
			});	
			
			
				
			//animate function
			function animate(dir, clicked, imgNum){
				
				var opacity   = 0;
				var speed     = options.speed;	
				var slideshow = 5;
					
				switch(dir){
					case "next":
						num++;
						var img = "#img" + num;
						var newImg = "#img" + (num + 5);
						$(newImg).css('visibility','visible');
						$(img).fadeTo(speed, opacity);
					
						break; 
						
					case "prev":
						opacity = 100;
						var img = "#img" + num;
						$(img).css('visibility','visible');
						$(img).fadeTo(speed, opacity);
						num--;
						break;
						
					default:
						break; 
				};
				
				
				
				
				
				//move images
				position = (num * 95 * -1);
				
				$("ul",obj).animate(
					{ marginLeft: position }, 
					speed
				);
				
				
				var images 		 = $("#images > li");
				var currentTotal = images.length;
				
				if(num >= (currentTotal-4)){addSlide(currentTotal);} 
				
				if(num==0){$("a","#prevBtn").hide();} else {$("a","#prevBtn").show();};
				
				//add another slide
				function addSlide(currentTotal) {
				
					var newLi     = document.createElement('li');
					var newImgNum = currentTotal + 1;
					var newId     = "img" + newImgNum;
					var idLength  = newId.length; 
					
					newLi.setAttribute('id', newId);
					idLength--;
					var imgNum  = newId.charAt(idLength);
					if(imgNum=='0') {imgNum = "10"}
					
					newLi.innerHTML  = "<img src='../../../images/booklovers/image_" + imgNum + ".jpg' alt='' />";
					
					document.getElementById("images").appendChild(newLi);
					newId = "#" + newId;
					$(newId).addClass("image");
					$(newId).css('z-index', (100-currentTotal).toString());	
					$(newId).css('visibility','visible');
					
					//add click fx to new slide
					$(newId, obj).click(function() {
						var img = newId.substr(4);
						num = parseInt(img);
						animate("num",true, num);				
					});	
				
				}
				
				
			};
							
			
		});
	  
	};
  } else {
    // alert("ie user");
     window.onload = Loader;
     	
  }

})(jQuery);




