(function($){

	$.fn.hm_Slider = function(options){

		var defaults = {
			slideDuration: 500,
			slideEasing: "swing"
		};

		options = $.extend(defaults, options);

		this.each(function(){


			//Bind controls
			$("#tour-nav a.trigger").live("click", function(event){
				element = $(this);
				slideTour(element, event);
			});

			$(".tour-subnav .trigger").live("click", function(event){
				element = $(this);
				slideTour(element, event);
				$('html,body').animate({ scrollTop: 0 }, { duration: 'slow', easing: 'swing' });
			});

			//Functions
			function slideTour(element, event){
				event.preventDefault();
				$("#tour-nav a").removeClass("active");
				currentTab = element.attr("href").replace("#","");
				$("#tour-nav ."+currentTab).addClass("active");
				animateTour(currentTab);
				
				
			}
			
			function animateTour(currentTab){

				slideSize = 0;
				
				if(currentTab == "slide1") {
					slideSize = "0";
				}
				
				if(currentTab == "slide2") {
					slideSize = "-" + $(window).width() + "px";
				}
				
				if(currentTab == "slide3") {
					slideSize = "-" + $(window).width() * 2 + "px";
				}
				
				if(currentTab == "slide4") {
					slideSize = "-" + $(window).width() * 3 + "px";
				}
				
				if(currentTab == "slide5") {
					slideSize = "-" + $(window).width()  * 4 	 + "px";
				}

				$("#tour .inner").animate({
					marginLeft : slideSize
				}, defaults.slideDuration, defaults.slideEasing, function(){
					window.location.hash = "/" + currentTab;
					$(".section").css("height","1px");
					$("#"+currentTab).css("height","auto");
				});
				
			}
			
			
			

			(function(){

				//Load page to a specific section
				if(window.location.hash){
					currentTab = window.location.hash.replace(/#*\//g,"");
					animateTour(currentTab);
					$("#tour-nav a").removeClass("active");
					$("." + currentTab).addClass("active");
				}else{
					$(".section").css("height","1px");
					$("#slide1").css("height","auto");
				}
				

			})();

		});

	};
	
	
	

})(jQuery);

//Instantiate plugin
$(document).ready(function() {
	$(document).hm_Slider();
});


(function($){

	$.fn.iesCarousel = function(options){
		
		var defaults = {
				delay: 15000,
				slideDuration: 500,
				slideEasing: "swing"
			};

			options = $.extend(defaults, options);

			this.each(function(){
				
				//Bind controls
				$("#slide_right").click(function(event){
					event.preventDefault();
					slideNext();
				});
				
				$("#slide_left").click(function(event){
					event.preventDefault();
					slideBack();
				});
				
				
				function slideNext(){
					alert('right');
				}
				
				function slideBack(){
					alert('left');
				}
				
				
		});

	};
	
})(jQuery);

//Instantiate plugin
$(document).ready(function(){
	$(document).iesCarousel();
});



