﻿var IE7_PNG_SUFFIX = ":";

function check_delete(value) {
	Check = confirm(unescape("Wollen Sie "+value+" wirklich l%F6schen%3F"));
	if (Check == false) {
		return false;
	}
}

function hasCSS() {

	var _d = document.createElement('div');
	_d.id = 'css_test';
	$('body').append(_d);
	$('#css_test').css({width:'1px',height:'1px',display:'none'});
	var _v = ($('#css_test').width() != 1) ? false : true;
	$('#css_test').remove();
	return _v;
}

$(document).ready(function() {
	
	if($('.teaser_contentad').find('object').length == 0 && $('.teaser_contentad').find('img').length == 0)
		$('.teaser_contentad').hide();
	
	if(hasCSS()) {
		$('input[type=checkbox]').checkbox();
		
		$('html').css({overflowY: 'scroll'});
		$('.image .headliner h2.typeface-js').css({
			'font-size': '28px',
			'line-height': '10px',
			'padding': '3px 0 0'
		});
		Cufon.replace('.typeface-js');				
		Cufon.replace('.marketplace');
		
		$('select').selectbox({
			inputClass: 'selectbox',
			containerClass: 'selectbox-wrapper'
		});

		//AUFHUEBSCHUNG VON FORMULARFELDERN
		$('input[readonly=readonly]').livequery(function() {
			$(this).addClass('readonly');
		});
		$('input[disabled=disabled]').livequery(function() {
			$(this).addClass('disabled');
		});		
		$('textarea:not(.processed)').TextAreaResizer();
		initFileUploads();
		
		$('.blankTarget').attr('target', '_blank');
		
		// CSS-Workarounds
		if(jQuery.browser.mozilla) {
			$('.typeface-js').css({bottom: '1px', marginTop: '1px'});
		}
		if(jQuery.browser.opera)
			$('#navigation li > a').css('padding-bottom', '8px');

		$('.hometeaser').css({background: 'url("/page/img/design/am_dgreen.png")'});
		
		$('.table > div').filter(':odd').css("background-color", "#eee");
		$('#automotive_datatable tr').each(function(index, element) {
		
		});
		$('#automotive_datatable tr').filter(':visible').filter(':odd').css("background-color", "#eee");
		$('input.submit, .searchHelper *').css('text-shadow', '0 1px 0 #CF0'); //#CF0
		$('.selectbox.dgreen, .selectbox-wrapper *').css('text-shadow', 'none');
		$('input.bigsubmit, input.thinButton').css('text-shadow', '0 1px 0 #FFF'); 
		$('.filebutton, a.submit.chalf, .submitgreen').css('text-shadow', '0 1px 0 #CF0');
		$('.selectbox-wrapper').css('overflow-x', 'hidden');
		$('input[type=file], input[type=checkbox]').css({
			'-moz-opacity': 0,
			'filter': 'alpha(opacity: 0)',
			'opacity': 0
		});
		$('input.submit.chalf, a.submit.chalf.bl').css('text-shadow', '0 1px 0 #0CF');
		$('a.submit.chalf.bl').css('color', $('input.submit.chalf').css('color'));
		$('.subnavigation .subnavigation').css('-moz-box-shadow', '0 5px 10px rgba(0, 0, 0, 0.3)');
		$('.subnavigation .subnavigation').css('-webkit-box-shadow', '0 5px 10px rgba(0, 0, 0, 0.3)');
		$('.subnavigation .subnavigation').css('box-shadow', '0 5px 10px rgba(0, 0, 0, 0.3)');
		$('.dragItem img').css({
			'box-shadow': '0 0 5px rgba(0, 0, 0, 0.25)',
			'-moz-box-shadow': '0 0 5px rgba(0, 0, 0, 0.25)',
			'-webkit-box-shadow': '0 0 5px rgba(0, 0, 0, 0.25)',			
		});
		//$('.imagebox').filter(':has(img)').css('background', '#fff');
		$('.imagebox').css('background', '#fff');
		$('.page_benutzer .ischeck').not(':empty').remove();
		$('.page_benutzer .ischeck').parent('a').css('background', 'url(./img/design/am_free_image.gif)')
	}
	
	//FADE-TEASER INSERIEREN
	$('.teaser_inserieren').cycle({ 
		fx:     'fade',
		speed:   1000, 
		timeout: 20000
	});
	
	// LIGHTBOX!
	$('a.gallery').not('[href=]').lightBox({
		boxShadow: '0 0 4px #777',
		overlayBgColor: '#fff',
		imageBtnClose: 'schließen',
		imageBtnPrev: '',
		imageBtnNext: '',
		btnNext: 'weiter &#x25B6;',
		btnPrev: '&#x25C0; zurück',
		containerResizeSpeed: 10,
		txtImage: 'Bild',
		txtOf: 'von'
	});		
	
	// AUTOMATIC POSITIONING OF IMAGES IN WRAPPER-DIV
	$('.picwrap img').each(function(index,element) {
		$(element).css({
			marginTop: (-($(element).height()-$(element).parent('.picwrap').height())/2)+'px'
		});
	});
	$('.picwrap3 img').each(function(index,element) {
		$(element).css({
			marginTop: (-($(element).height()-128)/2)+'px'
		});
	});
	
	var footercount = 1;
	$('.footervehicles').not('#footervehicles_'+footercount).css('display', 'none');
	$('.fahrzeugfooterwrapper').css('display', 'block');
	$('.vehiclefootersite').click(function(event) {
		event.preventDefault();
		footercount = $(this).text();
		$('.footervehicles').css('display', 'none');
		$('#footervehicles_'+footercount).css('display', 'block');
	});
	
	$('#teaser_automotive').change(function() {
		$.post('/ajax.php', {
			'load': 'brands',
			'post': $(this).val()
		},
		function(data) {
			$('#teaser_automotive_brands option').remove();
			$('#teaser_automotive_brands').append($("<option></option> ").val('').text('Marke'));
			$($.parseJSON(data)).each(function(index, element) {
				$('#teaser_automotive_brands').append($("<option></option> ").val(element).text(element));
			});
			$('#teaser_automotive_brands_container').remove();
			$('#teaser_automotive_brands_input').remove();
			$('#teaser_automotive_brands').selectbox({
				inputClass: 'selectbox',
				containerClass: 'selectbox-wrapper'
			});
		});
	});
	$('#teaser_automotive_brands').change(function() {
		$.post('/ajax.php', {
			'load': 'models2',
			'post': $(this).val()
		},
		function(data) {
			$('#teaser_automotive_modells option').remove();
			$('#teaser_automotive_modells').append($("<option></option> ").val('').text('Modell'));
			$($.parseJSON(data)).each(function(index, element) {
				$('#teaser_automotive_modells').append($("<option></option> ").val(element).text(element));
			});
			$('#teaser_automotive_modells_container').remove();
			$('#teaser_automotive_modells_input').remove();
			$('#teaser_automotive_modells').selectbox({
				inputClass: 'selectbox',
				containerClass: 'selectbox-wrapper'
			});
		});
	});	
	/*
	$('#image_117').remove();
	$('#image_61').remove();
	$('#image_2027').remove();
	*/
	$('#service_2027').css('clear', 'both');
	$('#service_117').css('clear', 'both');
	$('#pc-000039').css('clear', 'both');
	
	//OBSERVER SOME STUFF
	$('#userData_title1').change(function() {
		if($(this).is(':checked'))
			$('#userData_title2').attr('checked', false);
		else
			$('#userData_title2').attr('checked', true);
	});
	$('#userData_title2').change(function() {
		if($(this).is(':checked'))
			$('#userData_title1').attr('checked', false);
		else
			$('#userData_title1').attr('checked', true);
	});
	
	$('.orderpayment').change(function() {
		if($(this).is(':checked')) {
			$('.orderpayment').attr('checked', false);
			$(this).attr('checked', true);
		}
		else {
			$('#vorkasse').attr('checked', true);
		}
	});
	
	// UMRUESTERMAP OBSERVING
	if($('#image_map').length == 1) {
		activeMapPoint = $('#image_map').attr('src').replace('./img/germany_map/am_map-de-active_', '').replace('.gif', '');
		$('area').click(function(event){
			event.preventDefault();
			$('#image_map').attr('src', './img/germany_map/am_map-de-active_'+$(this).attr('id').replace('map_', '')+'.gif');
			activeMapPoint = $(this).attr('id').replace('map_', '');
			$('#state').val($(this).attr('alt'));
			$('#state').change();
		});
		$('area').hover(function(event){
			$('#image_map').attr('src', './img/germany_map/am_map-de-hover_'+$(this).attr('id').replace('map_', '')+'.gif');
		}, function(){
			$('#image_map').attr('src', './img/germany_map/am_map-de-active_'+activeMapPoint+'.gif');
		});
	}
	
	$('a.extern, a.partner_von_carmondo').click(function(event) {
		event.preventDefault();
		window.open(this.href);
	});
	
	
	$('select#text_service').bind('change', function() {
		$('#text_naviId').val($(this).val());
	});
	
	$('select#text_naviId').bind('change', function() {
		var serviceval = $(this).val();
		$($('#text_naviId').get(0).options).each(function(index, element) {
			if($(element).val() == serviceval)
				$('#text_service').val($(element).text().replace(' ', '').replace(' ', ''));
		});
	});
	
	$('a.icn_tw').each(function(index, element) {
		splitted = $(element).attr('href').split('#');
		$.post('/ajax.php', {
			'load': 'bitly',
			'bitly': splitted[1]
		},
		function(data) {
			splitted = $(element).attr('href').split('#');
			$(element).attr('href', splitted[0]+$.parseJSON(data)+splitted[2]);
		});
	});
	
	if(anchor = $(window.location.hash).get(0)) {
		$.scrollTo('#'+anchor.id);
	}
});
