// JavaScript Document

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

//function setWindow (){
window.onload = function() {
    window.resizeTo(screen.availWidth,screen.availHeight);
	window.moveTo(0,0);
}

$(document).ready(function(){
	var conveyor = $(".content-conveyor", $("#sliderContent")),
	item = $(".item", $("#sliderContent"));
	var slides = $(".item");
	var widthMax = imgWidth*numberOfSlides;
	var imgWidth = $('.item').attr('width');
	var availWidth = screen.availWidth;
	var numberOfSlides = slides.length;
	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", item.length * parseInt(item.css("width")));
	
	/*$('#slider')
		.prepend('<span class="control" id="leftControl">Clicking moves left</span>')
		.append('<span class="control" id="rightControl">Clicking moves right</span>');
		
	slides
		.wrapAll('<div id="slideInner"></div>')
		.css({
		'float' : 'left',
		'position' : 'relative'
	});

	$('#slideInner').css('width', widthMax);*/

	var sliderOpts = {
		max: (item.length * parseInt(item.css("width"))) - parseInt($(".viewer", $("#sliderContent")).css("width"))+50,
		slide: function(e, ui) {
			conveyor.css("left", "-" + ui.value + "px");
		},
		change: function(event, ui) {
			if(! event.orginalEvent) { // only programmatically
				conveyor.css("left", "-" + ui.value + "px");
			}
		},
		//animate:true
	};

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

	/*$("#slider").append("<span class=\"sliderShow\"><p>Zum Navigieren bitte Slider nach links oder rechts ziehen</p></span>");
	
	
	$(".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;
		}
    });*/
	
	$('.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 + 265); 
		},
		{
			duration  : 100, // Dauer, bis bei voller Geschwindigkeit (ms)
			speed     : 200, // Geschwindigkeit
			min       : 220
		}
		);
		$('#leftControl').repeatedclick(function() {
			var currentValue = $('#slider').slider('option', 'value');
			$('#slider').slider('value', currentValue - 265);
		},
		{
			duration  : 100,
			speed     : 200,
			min       : 220
		}
		);
		
		if(document.location.hash != '') {
			$('#slider').slider('value', $('div' + document.location.hash).attr('offsetLeft') + 25);
		}
	});

});