$(document).ready(function () {
	
	/*
	$('#q').liveUpdate('#cars').focus();
	$('form input[type=text]').focus(function() {
		var value = $(this).val();
		$(this).val('');
		$(this).blur(function() {
			if ($(this).val()=='') {
				$(this).val(value);
			}
		})
	});
	*/
	
	$('#name_request').focus(function() {
		var val = $(this).val();
		if(val == 'Ihr Name (Pflichtfeld)'){
			$(this).val('');
		} else {}
	});	$('#name_request').blur(function() {
		var val = $(this).val();
		if(val == ''){
			$(this).val('Ihr Name (Pflichtfeld)');
		} else {}
	});
	
	$('#email_request').focus(function() {
		var val = $(this).val();
		if(val == 'Ihre E-Mail-Adresse (Pflichtfeld)'){
			$(this).val('');
		} else {}
	});	$('#email_request').blur(function() {
		var val = $(this).val();
		if(val == ''){
			$(this).val('Ihre E-Mail-Adresse (Pflichtfeld)');
		} else {}
	});
	
	$('#tel_request').focus(function() {
		var val = $(this).val();
		if(val == 'Ihre Telefonnummer'){
			$(this).val('');
		} else {}
	});	$('#tel_request').blur(function() {
		var val = $(this).val();
		if(val == ''){
			$(this).val('Ihre Telefonnummer');
		} else {}
	});
	
	
	
	$('#name_tellafriend').focus(function() {
		var val = $(this).val();
		if(val == 'Ihr Name (Pflichtfeld)'){
			$(this).val('');
		} else {}
	});	$('#name_tellafriend').blur(function() {
		var val = $(this).val();
		if(val == ''){
			$(this).val('Ihr Name (Pflichtfeld)');
		} else {}
	});
	
	$('#email_tellafriend').focus(function() {
		var val = $(this).val();
		if(val == 'Ihre E-Mail-Adresse (Pflichtfeld)'){
			$(this).val('');
		} else {}
	});	$('#email_tellafriend').blur(function() {
		var val = $(this).val();
		if(val == ''){
			$(this).val('Ihre E-Mail-Adresse (Pflichtfeld)');
		} else {}
	});
	
	$('#topic_tellafriend').focus(function() {
		var val = $(this).val();
		if(val == 'Betreff (Pflichtfeld)'){
			$(this).val('');
		} else {}
	});	$('#topic_tellafriend').blur(function() {
		var val = $(this).val();
		if(val == ''){
			$(this).val('Betreff (Pflichtfeld)');
		} else {}
	});
	
	$('#receipient_tellafriend').focus(function() {
		var val = $(this).val();
		if(val == 'Empfänger E-Mail-Adresse (Pflichtfeld)'){
			$(this).val('');
		} else {}
	});	$('#receipient_tellafriend').blur(function() {
		var val = $(this).val();
		if(val == ''){
			$(this).val('Empfänger E-Mail-Adresse (Pflichtfeld)');
		} else {}
	});
	
	$('.forms p label').hide();
	$('.send_friend').next().hide();
	$('#mail_frame').hide();
	
	$('strong.send_retailer').addClass('active');
	
	$('strong.send_retailer').click(function() {
		$('#mail_frame').hide();
		$('strong').removeClass('active');
		$(this).addClass('active');
		
		$('#send_retailer').show();
		$('#send_friend').hide();
	});
	
	$('#call').click(function() {
		$('#call_form').show();
	});
	
	$('strong.send_friend').click(function() {
		$('#mail_frame').hide();
		$('strong').removeClass('active');
		$(this).addClass('active');
		
		$('#send_retailer').hide();
		$('#send_friend').show();
	});
	
	$('#search_input').keyup(function(){
		$.post('http://fzgsite.automarkt-24.biz/text.txt', { kunden_id: $('#kdid').val(), location_id: $('#lid').val() },  function(data) {
			$('#sresults').html('sss ' + data);
		});

	});
	
	$('.send_retailer').submit(function() {
		$('#mail_frame').show();
	});
	$('.send_friend').submit(function() {
		$('#mail_frame').show();
	});
	
	$(".slideshow").click(function() { 
		return doLightbox($(this), ''); 
		return false; 
	});

	$('.preview_image').mouseover(function() {
		$('#mainImage').hide();
		$('#mainImageFrame').attr('style', 'background:url(http://fzgsite.automarkt-24.biz/images/kunden/ajax-loader-big.gif) center center no-repeat;');
		var fullImage = $(this).attr('rel');
		$('#mainImage').attr('src', fullImage);
		$('#mainImage').show();
	});

	$('.preview_image').click(function() {
		var fullImage = $(this).attr('rel');
		var Ausdruck = /(.*).jpg?(.*)/;
		Ausdruck.exec(fullImage);
		fullImage = RegExp.$1 + '.jpg';

		var popup_window = window.open('image_popup.html?image=' + fullImage, 'pic_full_view', 'scrollbars=yes,width=680,height=596');
		popup_window.focus();
	});
	
});

function getGETParameter(name){
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null ) {
		return "";
	} else {
		return results[1];
	}
}



var slideInterval = null;

function doLightbox(element, maxHeight) {
	$('#infolightbox').remove();
	
	//alert('Document: ' +  + ' Window: ' + $(document).width());
	
	$('body').append('<div id="infolightboxbg" onclick="removeLightbox()"></div>');
	
	$('#infolightboxbg').css('width', $(document).width() + 'px');
	$('#infolightboxbg').css('height', $(document).height() + 'px');
	$('#infolightboxbg').fadeIn();
	
	$('body').append('<div id="infolightbox" style="width: 640px;height: 466px;" class="'+element.attr('class')+'">&nbsp;</div');
		
	$('#infolightbox').css('top', ($(window).scrollTop()+20) + 'px');
	$('#infolightbox').css('left', (($(document).width()-640)/2) + 'px');
	
	$('#infolightbox').html('<img id="slide-image-full" rel="0" style="display: none;" src="" /><p><a href="javascript:slideback();">zurück</a> <a href="javascript:slidestartstop();">stop / start</a> <a href="javascript:slideforward();">vor</a></p>');
	
	var rel = 0;
	$('#pics img').each(function(i) {
		 rel = $(this).attr('rel');
	});
	
	slideInterval = setInterval("loopSlider("+rel+")", 1250);
	$('#slide-image-full').show();
	
	return false;
}

function slidestartstop() {
	if($('#slide-image-full').hasClass('stopped')) {
		var rel = 0;
		$('#pics img').each(function(i) {
			 rel = $(this).attr('rel');
		});
		
		slideInterval = setInterval("loopSlider("+rel+")", 4000);
	} else {
		$('#slide-image-full').addClass('stopped');
		clearInterval(slideInterval);
	}	
}

function loopSlider(maxrel) {
	var currentrel = $('#slide-image-full').attr('rel')
	$('#pics img').each(function(i) {
		var rel = $(this).attr('rel');
		
		if(currentrel == maxrel) {
			currentrel = 0;
		}
		
		if(rel-1 == currentrel) {
			newsrc = $(this).attr('src');	
			$('#slide-image-full').attr('src', newsrc.replace(/thumbs\//, ""));
			$('#slide-image-full').attr('rel', rel);
		}
	});
}

function removeLightbox() {
	$('#infolightbox').remove();
	$('#infolightboxbg').remove();
}

function getSize() {
    var myWidth = 0, myHeight = 0;
 
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return [ myWidth, myHeight ];
}


