// JavaScript Document

$(document).ready( function() {
	
	lang = $('input:hidden').val();
	
	if(document.getElementById("map_canvas")){ 
	  	if (GBrowserIsCompatible()) {
			var map = new GMap2(document.getElementById("map_canvas"));
			map.setCenter(new GLatLng(47.400734, 8.4511079), 15);
			map.setUIToDefault(); 
			var point = new GLatLng(47.40073434992528, 8.45110791508789);
			map.addOverlay(new GMarker(point)); 
	  	}
	}

	function change(e) {
		var y = $(this); var D = this.defaultValue; var V = $.trim(y.val()); var t = e.type;
		switch (t) {
			case 'focus': if(D==V&&D=='http://'){y.select();}else if(D==V){y.val('')}else{y.val(V); y.select();}; break;
			case 'blur': if(V==''){y.val(D);}; break;
		}
	} 
	
	$('input:text').bind('focus blur', change);
	
	$('.toggler_1').click(function(){
		var v = this.value;
		if(v == 'no'){
			$('.toggle_1').show();
		}else{
			$('.toggle_1').hide();
		}
	 });
	 
	$('.toggler_2').click(function(){
		var v = this.value;
		if(v == 'no'){
			$('.toggle_2').show();
		}else{
			$('.toggle_2').hide();
		}
	});
	
	$('.toggler_3').live('click', function(){
		var v = this.value;
		if(v == '4'){
			$('.toggle_3').show();
				$("input[name=location_old]").addClass('required')
				$("input[name=zip_old]").addClass('required')
				$("input[name=street_old]").addClass('required')
		}else{
			$('.toggle_3').hide();

				$("input[name=location_old]").removeClass('required')
				$("input[name=zip_old]").removeClass('required')
				$("input[name=street_old]").removeClass('required')
		}
	});
	 
	$('#offerform').validate();
	
	$('#contactform').validate();
	
	$('.add_product').bind('click', function(e){
		
		var t = this;
		e.preventDefault();
		
		var id = t.id.split('_')[1];
		var amount = Number($('#amount_' + id).val());
		
		var s = 'add='+id+'&amount='+amount;
		
		$.post('sites/'+lang+'/shop/cart.php', s, function(res) { $('#cart').html(res); });
		
		return false;
		
	});
	
	$('.remove_product').live('click', function(e){
		
		var t = this;
		e.preventDefault();
		
		var id = t.id.split('_')[1];
		var s = 'remove='+id;
		
		$.post('sites/'+lang+'/shop/cart.php', s, function(res) { $('#cart').html(res); });
		
		return false;
		
	});
	
	$('#remove_all').live('click', function(){
		
		var s = 'empty=yes';
		
		$.post('sites/'+lang+'/shop/cart.php', s, function(res) { $('#cart').html(res); });
		
	});
	
	$('.nav_main:not(:first):not(:last)').mouseover(function() {
		$(this).css('background', 'url(images/nav_main_active.png) 0 -60px no-repeat');
	}).mouseout(function() {
		$(this).css('background', 'none');
	});
	
	$('.nav_main:first').mouseover(function() {
		$(this).css('background', 'url(images/nav_main_active.png) 0 0 no-repeat');
	}).mouseout(function() {
		$(this).css('background', 'none');
	});
	
	$('.nav_main:last').mouseover(function() {
		$(this).css('background', 'url(images/nav_main_active.png) 0 -120px no-repeat');
	}).mouseout(function() {
		$(this).css('background', 'none');
	});
	
	$('.nav_main')
		.mouseover(function() {
			var ul = $(this).children()[1];
			$(ul).show().css('background', 'url(images/nav_sub_active.png) no-repeat');
		})
		.mouseout(function() {
			var ul = $(this).children()[1];
			$(ul).hide().css('background', 'none');
		});
	
	if($.browser.msie&&$.browser.version.split('.')[0]<=7){
		if($('#images_right').width()==0){ $('#content').width(620).css('paddingRight', '80px'); }
		var cwh = $('#content_wrapper').height();
		var ch = $('#content').height();
		var cp = parseInt($('#content').css('paddingTop')) + parseInt($('#content').css('paddingBottom'));
		var th = $('#pusher').height() + ch + cp;
		if(cwh<th){ $('#content_wrapper').height(th); }
	}
	
});


