jQuery.noConflict();

jQuery(document).ready(
	function() {
		tt_news_categories();
		wec_map_config();
		lightbox_overlay("thickbox");
		libAGENTURNET();
		if(checkBrowserName('MSIE 6.0')) {
			ingredients_ie6();
		}
		commerce_billing();
        /* jQuery('#teaser').hover(
            function() {
                jQuery(this).fadeTo("fast", 0.7);
            },
            function() {
                jQuery(this).fadeTo("fast", 1);
            }
        ); */
		//alert(navigator.userAgent.toLowerCase());
	}
);

function checkBrowserName(name){  
	var agent = navigator.userAgent.toLowerCase();  
	if (agent.indexOf(name.toLowerCase())>-1) {  
		return true;  
	}  
	return false;  
}

function ingredients_ie6() {
	jQuery('.tx_sicommerceingredients_pi1_list_ingredients_item').hover(
		function() {
			jQuery('.tx-sicommerceingredients-pi1 select').hide();
		},
		function () {
			jQuery('.tx-sicommerceingredients-pi1 select').show();
		});
}

function lightbox_overlay(a_class) {
	jQuery('a.'+a_class).append('<img src="fileadmin/template_sonnenmoor/img/lightbox_zoom.png" alt="zoom" class="lightbox_zoom" />');
	
 	jQuery('a.'+a_class).hover(
		function() {
			jQuery(this).find('.lightbox_zoom').toggle();
		},
		function() {
			jQuery(this).find('.lightbox_zoom').toggle();
		}
	);
 
	jQuery('a.'+a_class).each( function() {
		var height = jQuery(this).find('img').height();
		jQuery(this).find('.lightbox_zoom').css({'top' : height/2 - 23 + 'px'});
	});
}

function libAGENTURNET() {
	jQuery('#agentur_net').hover(
		function() {
			jQuery(this).find('ul li ul').show('slow');
		},
		function() {
			jQuery(this).find('ul li ul').hide('slow');
		}
	);
	
	jQuery('#agentur_net').click(
		function() {
			//alert(jQuery(this).find('a').attr('href'));
			//window.parent.location = jQuery(this).find('a').attr('href');
			window.open(jQuery(this).find('a').attr('href'));
		}
	);
}

function tt_news_categories() {
		jQuery('.news-catmenu').hover(
			function() {
				jQuery('.news_cat').toggle();
			},
			function() {
				jQuery('.news_cat').toggle();
			}
		);
		
		jQuery('.storagelist').hover(
			function() {
				jQuery('.tt_news_stpt').toggle();
			},
			function() {
				jQuery('.tt_news_stpt').toggle();
			}
		);
		
		var act_cat = jQuery('span.act_cat').text();
		var act_typ = jQuery('ul.tt_news_stpt li.act a').text();
		
		if(act_cat != '') {
			jQuery('.news-catmenu').append('<p class="news_cat" style="display: none;"><a title="" href="' + jQuery('.news-catmenu>a').attr('href') + '">' + jQuery('span.cat_header').text() + '</a></p>');
			jQuery('span.cat_header').text(act_cat);
		}
		
		if(act_typ != '') {
			jQuery('span.typ_header').text(act_typ);
		}
} 

/*
		HOAL 2009-12-04: Fügt eine Routenplanung zur wec_map hinzu
		Plug-In Konfiguration:
		Folgende Optionen müssen aktiviert sein:
		- Show Info Bubble On Load
		- Show Directions
		- Show Written Directions
		
		Die Adresse wird ebenfalls vom Plug-In geladen
		
		function check_wec_map() 			- Überprüft, ob die Karte geladen wurde
		function wec_map_config() 		- Ruft die entsprechenden Funktionen auf, wenn die Karte geladen wurde
		function wec_map_getAddress() - Holt sich die Adresse vom Plug-In und öffnet automatisch die Maske für den Routenplaner
		function wec_map_getForm() 		- Fügt die Form für den Routenplaner als HTML Code ein

*/
function check_wec_map() {
	window.setTimeout(function() { wec_map_config(); }, 2000);
}

function wec_map_config() {
	if(jQuery('.tx-wecmap-map .marker').html()) {
		wec_map_getAddress();
		wec_map_getForm();
	} else {
		check_wec_map();
	}
}

function wec_map_getAddress() {
	var data = jQuery('.marker').html();
	jQuery('.tx-wecmap-pi1').prepend('<div class="wec_map_extAddress">' + data + '</div>');
	jQuery('.tx-wecmap-pi1').append('<br class="clear" />');
	
	var mapid = jQuery('.tx-wecmap-map').attr('id');
	return WecMap.openDirectionsToHere(mapid, 0, 0);
}

function wec_map_getForm() {
//	jQuery('.wec_map_extAddress').append('<div class="wec_map_extAddress_form"><label for="map_plz">PLZ</label><input type="text" value="" name="map_plz" id="map_plz" class="search_box" /><br /><label for="map_land">Land</label><input type="text" value="" name="map_land" id="map_land" class="search_box" />' + jQuery('.fromdirform').html() + '</div>');
	jQuery('.wec_map_extAddress').append('<div class="wec_map_extAddress_form">' + jQuery('.fromdirform').html() + '</div>');
	jQuery("input[name='submit']").addClass('submit');
	jQuery("input[name='saddr']").addClass('search_box');
	
	var submit_action = jQuery('.wec_map_extAddress_form form').attr('onsubmit');
	
	//Hängt Österreich als Land hinzu
	jQuery('.wec_map_extAddress_form form').attr('onsubmit', jQuery('.wec_map_extAddress_form form').attr('onsubmit').replace('.value','.value+\', Österreich\''));
	/*jQuery('.wec_map_extAddress_form form').attr('onsubmit', '');
	jQuery('.wec_map_extAddress_form form').submit(function() {
		return submit_action.replace('return ', '');
	});*/
}

function commerce_billing() {
	if (jQuery('#billing-country').length) {
		jQuery('#billing-country').children('option[value="DEU"]').hide(0);
		jQuery('#billing-country').children('option[value="CHE"]').hide(0);
		jQuery('#billing-country').children('option[value="ITA"]').hide(0);
		jQuery('#billing-country').children('option[value="SVN"]').hide(0);
		jQuery('#billing-country').children('option[value="HUN"]').hide(0);
	}
	if (jQuery('#delivery-country').length) {
		jQuery('#delivery-country').children('option[value="DEU"]').hide(0);
		jQuery('#delivery-country').children('option[value="CHE"]').hide(0);
		jQuery('#delivery-country').children('option[value="ITA"]').hide(0);
		jQuery('#delivery-country').children('option[value="SVN"]').hide(0);
		jQuery('#delivery-country').children('option[value="HUN"]').hide(0);
	}
}
