// Gutschein und Rabattabwicklung - Eingabe Form Submit
$('#commit_bonus_img').live('click', function() {
	$('#bonus_form').ajaxSubmit({
		beforeSubmit: function(formData) {
			// show "please wait" message
		},
		url: sheego.commitBonusUrl,
		success: function(response) {
			// hide "please wait" message
		},
		target: $('#bonus_step')
	});
	return false;
});

// Gutschein und Rabattabwicklung - Eingabe Form Submit
$('#inputBonusCodeProcess').live('click', function() {
	$('#bonusCodeForm').ajaxSubmit({
		beforeSubmit: function() {
			// TODO jcmeyer: do we need some special visualization here?
		},
		dataType: 'json',
		url: sheego.inputBonusCodeProcess,
		success: function(json) {
			// TODO jcmeyer: do some error handling here
			if (json.updateResult == 'success') {
				// content update is done via ugly full page refresh currently :(
				window.location.reload();
			} else {
				// remove previous error message
				$('#bonusContainer').find('dd.errorBay').remove();
				// show current error message
				if (json.humanError != null) {
					$('#bonusContainer dl').prepend('<dd class="errorBay"><p class="softError">! ' + json.humanError + '</p></dd>');
				}
			}
		}
	});
	return false;
});

// Gutschein und Rabattabwicklung - Zurueck
$('#linkCancelBonusInput').live('click', function() {
	$('#bonusContainer').load(
		sheego.inputBonusCodeParentUpdate
	);
	return false;
});

// Gutschein und Rabattabwicklung - Zweite Eingabe Call
$('#linkUpstreamBonusInput').live('click', function() {
	$('#bonusContainer').load(sheego.inputBonusCodeParentUpdate, { UpstreamBonusInput: 'true' });
	return false;
});

// Gutschein- und Rabattabwicklung - Entfernen
// content update is done via ugly full page refresh currently :(
$(".linkDeleteBonus").live('click', function() {
	$.get(sheego.removeBonusUrl, { BonusNumber: $(this).attr('id').substr(6) }, function() {
		window.location.reload();
	} );
	// content update is done via ugly full page refresh currently :(
	return false;
});


// update MiniBasket auf Storefront
function updateMiniBasket(priceString, amountString){
	$('#jq_miniBasketPrice').html(priceString);
	$('#jq_miniBasketAmount').html(amountString);
}

function miniBasketGetPriceString(){
	return $('#jq_miniBasketPrice').html();
}

function miniBasketGetAmountString(){
	return $('#jq_miniBasketAmount').html();
}

function hoverMenuSimple(itemsSelector, hoverClass, delayTimeIn, delayTimeOut) {
			var $ = jQuery;
			
			if ($.trim(itemsSelector) !== '' && $.trim(hoverClass) !== '') {
				$(function() {
					var delayIn = 0;
					var delayOut = 0;
	
					if (delayTimeIn > 0) {
						delayIn = delayTimeIn;
					} // end: if
					
					if (delayTimeOut > 0) {
						delayOut = delayTimeOut;
					} // end: if
	
					var items = $(itemsSelector);
	
					// Timer1 is responsible to delay the 
					// showing up of the submenus.
					var timer1 = null;
					
					// Safe version of clearTimeout.
					var clearTimer = function(timer) {
						try {
							clearTimeout(timer)
						} catch (_) {
						} // end: try
					} // end: function clearTimer
	
					items.each(function(idx, item) {
						// Add event handlers for each main item.
						item = $(item);
	
						item.mouseover(function() {
							clearTimer(timer1);
							
							// --- 
							
							timer1 = setTimeout(function() {
								// --- edited by dmc |gm
								if($.browser.msie && parseFloat($.browser.version.substr(0,1)) < 7){
									$('select').css("visibility", "hidden");
								} 
								items.not(item).removeClass(hoverClass);
								item.addClass(hoverClass);
							}, delayIn);
						}); // end: mouseover
	
						item.mouseout(function() {
							clearTimer(timer1);
							
							// --- 
							
							timer1 = setTimeout(function() {
								items.removeClass(hoverClass);
								// --- edited by dmc |gm
								if($.browser.msie && parseFloat($.browser.version.substr(0,1)) < 7){
									$('select').css("visibility", "");
								}
							}, delayOut);
	
						}); // end: mouseout
					}); // end: items.each
				});
			} // end: if
} // end: function hoverMenuSimple

jQuery(function() {
	hoverMenuSimple('#navUL > li', 'sfhover', 250, 250);
});
