// HOMEPAGE SLIDER

// set this variable for delay (1000 = 1 second)
var delayLength = 8000;

$(function(){

	$("#spotlight").append('<span class="pause png_bg">Stop</span>');
	
	var $slide1 = $("#item1");

	var panelWidth = $slide1.css("width");
	var panelPaddingLeft = $slide1.css("paddingLeft");
	var panelPaddingRight = $slide1.css("paddingRight");

	panelWidth = parseFloat(panelWidth, 10) + 100;
	panelPaddingLeft = parseFloat(panelPaddingLeft, 10);
	panelPaddingRight = parseFloat(panelPaddingRight, 10);

	panelWidth = panelWidth + panelPaddingLeft + panelPaddingRight;

	var numPanels = $(".spotlight-item").length;
	var tooFar = -(panelWidth * numPanels);
	
	function doMove(panelWidth, tooFar) {
		var leftValue = $("#mover").css("left");
	
		// Fix for IE
		if (leftValue == "auto") { leftValue = 0; };
	
		var movement = parseFloat(leftValue, 10) - panelWidth;
	
		if (movement == tooFar) {
			$(".spotlight-item img").animate({
				"top": -300
			}, function() {
				$("#mover").animate({
					"left": 0
				}, function() {
					$(".spotlight-item img").animate({
						"top": 0
					});
				});
			});
		}
		else {
			$(".spotlight-item img").animate({
				"top": -300
			}, function() {
				$("#mover").animate({
					"left": movement
				}, function() {
					$(".spotlight-item img").animate({
						"top": 0
					});
				});
			});
		}
	}
	
	sliderIntervalID = setInterval(function(){
		doMove(panelWidth, tooFar);
	}, delayLength);
	
	$(".pause").click(function(){
	if ($(this).text() == "Stop") {
		clearInterval(sliderIntervalID);
	 	$(this).text("Start");
	}
	else {
		sliderIntervalID = setInterval(function(){
			doMove(panelWidth, tooFar);
		}, delayLength);
	 	$(this).text("Stop");
	 }
	});

});

// END OF HOMEPAGE SLIDER


// LIGHTBOX - FANCYBOX

$(function(){

	$("a.fancybox").fancybox({
				'transitionIn'		: 'fade',
				'transitionOut'		: 'fade',
				'titlePosition' 	: 'over',
				//'overlayColor'		: '#FFF',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Bild ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
		
});

// END OF FANCYBOX




// CONTACT FORM VALIDATION


$(function() {
    // These first three lines of code compensate for Javascript being turned on and off. 
    // It simply changes the submit input field from a type of "submit" to a type of "button".

    var paraTag = $('input#submit').parent('p');
    $(paraTag).children('input').remove();
    $(paraTag).append('<input type="button" name="submit" id="submit" value="Send" />');

    $('#contactForm input#submit').click(function() {
        $('#contactForm').append('<img src="images/loader.gif" class="loaderIcon" alt="Loading..." />');

        var name = $('input#name').val();
        var email = $('input#email').val();
        var message = $('textarea#message').val();

        $.ajax({
            type: 'post',
            url: 'sendEmail.php',
            data: 'name=' + name + '&email=' + email + '&message=' + message,

            success: function(results) {
                $('#contactForm img.loaderIcon').fadeOut(1000);
                $('ul#response').html(results);
            }
        }); // end ajax
    });
});


// GARTENMAGAZIN

function popSpecial(sitename){
	if(screen.height < 1024){
		ow = 860;
		oh = 680;
		url = "gartenmagazin/gartenmagazin_lowres.html";
	}else{
		ow = 860;
		oh = 860;
		url = "gartenmagazin/gartenmagazin_hires.html";
	}
	leftposition = (screen.width) ? (screen.width-ow)/2 : 0;
	topposition = (screen.height) ? (screen.height-oh)/2 : 0;
	gm = window.open(url,sitename,"width=" + ow  + ",height=" + oh + ",left=" + leftposition + ",top=" + topposition + ",scrollbars=no,resizable=no,status=no");
	gm.focus();
}
