// JavaScript Document

window.onresize = function() {
	window.onresize=null;
	document.location=document.location;
}


$(document).ready(function() {
		//vars
		var conveyor = $(".content-conveyor_500", $("#sliderContent")),
		item = $(".item_500", $("#sliderContent"));
	  var imgWidth = $('.item_500 img').attr('width');
	  var availWidth = screen.availWidth;
	  var loader = "<img src=\"../00_img/_control/load.gif\" class=\"load\" alt=\"Lädt…\" />";
	  var stepper = 0;
	  
	  $('#slider').css('width', $('#sliderContainer').width()
							  - $('#leftControl').width()
							  - $('#rightControl').width()
							  - parseInt($('#slider').css('margin-right'))
							  - parseInt($('#slider').css('margin-left')));
	  
	  
	conveyor.css("width", imgWidth);

				
        var sliderOpts = {
		  max: imgWidth - parseInt($(".viewer_500", $("#sliderContent")).css("width"))-20,
          slide: function(e, ui) { 
			$(".viewer_500").css("left", "-" + ui.value + "px");
          },
		  change: function(event, ui) {
			if(! event.orginalEvent) { // only programmatically
				$(".viewer_500").css("left", "-" + ui.value + "px");
			}
		  },
		};

		if (imgWidth < availWidth) {
			//$("#slider").css();
		} else {
        	$("#slider").slider(sliderOpts);
		}
	
	$('.image').hide();
	$('.image_frame').append(loader);
	$(window).load( function() {
		$('.load').hide();
		$('.image').fadeIn();
		$('#rightControl').repeatedclick(function() {
			var currentValue = $('#slider').slider('option', 'value');
			$('#slider').slider('value', currentValue + 100); 
		},
		{
			duration  : 100, // Dauer, bis bei voller Geschwindigkeit (ms)
			speed     : 400, // Geschwindigkeit
			min       : 220
		}
		);
		$('#leftControl').repeatedclick(function() {
			var currentValue = $('#slider').slider('option', 'value');
			$('#slider').slider('value', currentValue - 100);
		},
		{
			duration  : 100,
			speed     : 400,
			min       : 220
		}
		);
		
		if(document.location.hash != '') {
			$('#slider').slider('value', $('div' + document.location.hash).attr('offsetLeft') + 25);
		}
		
		if(imgWidth < availWidth){
			$('#leftControl').hide();	
			$('#rightControl').hide();	
		}
	});
	
	//$("#slider").append("<span class=\"sliderShow\"><p>Zum Navigieren bitte Slider nach links oder rechts ziehen</p></span>");
	/*$("#slider").mouseover(
		function() {
			if ($(".shower").css('display') == 'none') {
				$(".sliderShow").fadeIn();
			} else {
				$(".sliderShow").fadeOut();
			}
		}
	);*/

	$(".ui-slider-handle").mouseover(function() {
			//if ($(".shower").css('display') == 'none') {
				$("div.sliderShow").fadeIn();
			//}
		}).mouseleave(function() {
			$("div.sliderShow").fadeOut();
		});

	
	/*$(".ui-slider-handle").mouseout(function(){
		if (stepper == 0) {
		  //$(".sliderShow").fadeOut("fast");
		  $(".sliderShow").css("display","none");
		}
		if (stepper == 1) {
		  //$(".sliderShow").fadeOut("fast");
		  $(".sliderShow").css("display","none");
		}
    });
	
	$(".ui-slider-handle").hover(function(){
		if (stepper == 0) {
		  //$(".sliderShow").fadeIn();
		  $(".sliderShow").css("display","block");
		  stepper = 1;
		}
    });*/
});