// Functions
jQuery.noConflict();

function setTop() {
	if (jQuery(window).height() > 650) {		
		jQuery('.start #colwrap').css('top', jQuery(window).height() - 300);
		jQuery('.start #list').css('top', 160 + (jQuery(window).height() - 650));
		jQuery('.start #teaserbox').css('top', 160 + (jQuery(window).height()-650));
		
		if(jQuery('.start #teaserbox').length > 0) {
			var offset_teaser = jQuery('.start #teaserbox').offset();
			if(offset_teaser.top > 350) {jQuery('.start #teaserbox').css('top', 350);}
		}
		if(jQuery('.start #list').length > 0) {
			var offset_list = jQuery('.start #list').offset();
			if(offset_list.top > 350) {jQuery('.start #list').css('top', 350);}
		}
				
	}
	else {
		jQuery('.start #colwrap').css('top', 350);
		jQuery('.start #list').css('top', 160);
		jQuery('.start #teaserbox').css('top', 160);
	}
}

function clog(value) {
	try{console.log(value);}
	catch (err) {}
}

jQuery(document).ready(function($){

//Cufón als Schriftersatz mit Canvas und VML
	Cufon.replace('.leftbox li a',{hover: true});
	Cufon.replace('.middlebox .s_result a',{hover: true});
	Cufon.replace('.tabs li a',{hover: true});
	Cufon.replace('.navi a',{hover: true});
	Cufon.replace('button.submit,a.submit',{hover: true});
	Cufon.replace('h1,h2,h3,h4',{hover: true});
	
	Cufon.replace('.start a.teaser .teaser_head');
	Cufon.replace('.start a.teaser .teaser_cont strong');
	Cufon.replace('fieldset legend');
	
	
//Leeren der Suchfelder beim Focus
	$('#search_query').bind('focus', function() {
		oldValue = $(this).val();
		$(this).val('');
	});
	$('#search_query').bind('blur', function() {
		newValue = $(this).val();
		if (newValue == '') {
			$(this).val(oldValue);
		}
	});
	
	
//Startseitenausrichtung oder Slideshow Navigation	
	if($('body').hasClass('start') == true){
		setTop();
	}
	else {
		$('.imagewrap').scrollable();
		try { 
			if($('.imagewrap').scrollable().getSize() == 1) {
				$('.prev').addClass('disabled');
				$('.next').addClass('disabled');
			}
		}
		catch(error) {}
	}
	
	
//Ausblenden der Slideshow Navigation
	if($('.prev').hasClass('disabled') && $('.next').hasClass('disabled') == true){
		$('.slidenavi').hide();
	}
	
	
//Nichtfolgen der Slideshow Navigationslinks
	$('.slidenavi a').click(function(event){
		event.preventDefault();
		this.blur();
	});


//Startseitenanpassung bei Viewportveränderungen
	$(window).resize(function() {
		if($('body').hasClass('start') == true) {
			setTop();
		}
 	});

//Checkt Lieferanschrift checkbox ob gecheckt dann Lieferadresse = Rechnungsadresse
	if(jQuery('#shippingCheck').attr('checked')){
		jQuery('#shippingForm').hide();
	}
	jQuery('#shippingCheck').click(function(event){
		if(jQuery('#shippingCheck').attr('checked')){
			jQuery('#shippingForm').slideUp('slow', function(){
				jQuery('#firstnameForShipping').val(jQuery('#firstnameForBill').val());
				jQuery('#surnameForShipping').val(jQuery('#surnameForBill').val());
				jQuery('#streetForShipping').val(jQuery('#streetForBill').val());
				jQuery('#plzForShipping').val(jQuery('#plzForBill').val());
				jQuery('#cityForShipping').val(jQuery('#cityForBill').val());
				jQuery('#districtForShipping').val(jQuery('#districtForBill').val());
			});
		}else{
			jQuery('#shippingForm').slideDown('slow', function(){});
		}
	});	
	jQuery('#firstnameForBill').change(function(event){
		if(jQuery('#shippingCheck').attr('checked')){
			jQuery('#firstnameForShipping').val(jQuery(this).val());
		}	
	});
	jQuery('#surnameForBill').change(function(event){
		if(jQuery('#shippingCheck').attr('checked')){
			jQuery('#surnameForShipping').val(jQuery(this).val());
		}	
	});
	jQuery('#streetForBill').change(function(event){
		if(jQuery('#shippingCheck').attr('checked')){
			jQuery('#streetForShipping').val(jQuery(this).val());
		}	
	});
	jQuery('#plzForBill').change(function(event){
		if(jQuery('#shippingCheck').attr('checked')){
			jQuery('#plzForShipping').val(jQuery(this).val());
		}	
	});
	jQuery('#cityForBill').change(function(event){
		if(jQuery('#shippingCheck').attr('checked')){
			jQuery('#cityForShipping').val(jQuery(this).val());
		}	
	});
	jQuery('#districtForBill').change(function(event){
		if(jQuery('#shippingCheck').attr('checked')){
			jQuery('#districtForShipping').val(jQuery(this).val());
		}	
	});
	
});
