/**
 * jQuery in den Kompatibiltätsmodus versetzen.
 * Wichtig, da sonst Konflikte mit anderen JS-Libs
 * wie z.B. Prototype für die EXT:powermail.
 *
 * Die Variable muß vor jede jQery-Anweisung gesetzt werden.
 * Anstatt $(... ist $jQ(... zu notieren.
 * Quelle: http://www.typo3forum.net/forum/powermail/30411-jquery-powermail-rgslideshow-vertragen.html
 */
var $jQ = jQuery.noConflict();

/**
 * Pulldown-Menu:
 */
function mainmenu(){
	$jQ(" #navigationMain ul ").css({display: "none"}); // Opera Fix
	$jQ(" #navigationMain li").hover(function(){
	$jQ(this).find('ul:first').css({visibility: "visible",display: "none"}).show(0);
	},function(){
		$jQ(this).find('ul:first').css({visibility: "hidden"});
	});
}
$jQ(document).ready(function(){
	mainmenu();
});

/**
 * SUPERSIZE BG-Image:
 * @param {Object} $jQ
 */
(function($jQ){
		//Resize image on ready or resize
		$jQ.fn.supersize = function() {
				//Invoke the resizenow() function on document ready
				$jQ(document).ready(function() {
						$jQ('#supersize').resizenow();
				});
				//Invoke the resizenow() function on browser resize
				$jQ(window).bind("resize", function() {
						$jQ('#supersize').resizenow();
				});
		};
		//Adjust image size
		$jQ.fn.resizenow = function() {
				//Define starting width and height values for the original image


		var startwidth =  1280;
		var startheight = 1024;
		/**
		 * var startwidth  = $("#supersize img").width();
		 * var startheight = $("#supersize img").height();
		 * alert(startwidth);
		 */


		//Define image ratio
		var ratio = startheight/startwidth;
		//Gather browser dimensions
		var browserwidth = $jQ(window).width();
		var browserheight = $jQ(window).height();
		//Resize image to proper ratio
		if ((browserheight/browserwidth) > ratio) {
				$jQ(this).height(browserheight);
				$jQ(this).width(browserheight / ratio);
				$jQ(this).children().height(browserheight);
				$jQ(this).children().width(browserheight / ratio);
		} else {
				$jQ(this).width(browserwidth);
				$jQ(this).height(browserwidth * ratio);
				$jQ(this).children().width(browserwidth);
				$jQ(this).children().height(browserwidth * ratio);
		}
		//Make sure the image stays center in the window
		$jQ(this).children().css('left', (browserwidth - $jQ(this).width())/2);
		$jQ(this).children().css('top', (browserheight - $jQ(this).height())/2);
		};
})(jQuery);

$jQ(document).ready(function() {
	//Invoking the supersized function on the div with id - supersize. It is the div that contains the large background image
	var startwidth  = $jQ("#supersize img").width();
	var startheight = $jQ("#supersize img").height();
	$jQ("div#supersize").supersize();

});

/******************************************************************************/
/**
 * EXT:powermail - Dinner-Guteschein(e)
 * Verschiebt den Submit-Button der letzten Seite (optisch)
 * hinter den Zurück-Button.
 */
$jQ(document).ready(function() {
	//$(".target").empty();
	//$(".tx_powermail_pi1_submitmultiple_back").empty();
	// Candle Light Dinner:
	$jQ(".powermail_submit_uid24").remove().appendTo(".tx-powermail-pi1_form_pages_browser");
	// Freier Gutschein:
	$jQ(".powermail_submit_uid60").remove().appendTo(".tx-powermail-pi1_form_pages_browser");
	// Online Reservierung:
	$jQ(".powermail_submit_uid85").remove().appendTo(".tx-powermail-pi1_form_pages_browser");

	// Gutschein Aktion 1:
	$jQ(".powermail_submit_uid109").remove().appendTo(".tx-powermail-pi1_form_pages_browser");
	// Gutschein Aktion 2:
	$jQ(".powermail_submit_uid139").remove().appendTo(".tx-powermail-pi1_form_pages_browser");
	// Gutschein Aktion 3:
	$jQ(".powermail_submit_uid163").remove().appendTo(".tx-powermail-pi1_form_pages_browser");
	// Gutschein Aktion 4:
	$jQ(".powermail_submit_uid187").remove().appendTo(".tx-powermail-pi1_form_pages_browser");
});


// Formulare AKTION 1 bis 4 Preisberechnung
$jQ(document).ready(function() {
	// fnEventOrder_setup(sIdCoutPersons, sIdPriceSingle, sIdPriceTotal)
	fnEventOrder_setup('select#uid113', 'input#uid111', 'input#uid91'); 	// Aktion 1
	fnEventOrder_setup('select#uid120', 'input#uid119', 'input#uid121'); 	// Aktion 2
	fnEventOrder_setup('select#uid144', 'input#uid143', 'input#uid145'); 	// Aktion 3
	fnEventOrder_setup('select#uid168', 'input#uid167', 'input#uid169'); 	// Aktion 4
});

function fnEventOrder_setup(sIdCoutPersons, sIdPriceSingle, sIdPriceTotal){
	// Euro-Text an Feld anfügen.
	$jQ('<span>&nbsp;&nbsp;Euro</span>').insertAfter(sIdPriceSingle);
	$jQ('<span>&nbsp;&nbsp;Euro</span>').insertAfter(sIdPriceTotal);

	// Trigger:
	$jQ(sIdCoutPersons).change(function() {
		// Berechnung:
		sPriceTotal = fnEventOrder_CalcTotal(sIdCoutPersons, sIdPriceSingle);
		// Ausgabe:
		$jQ(sIdPriceTotal).val(sPriceTotal);
		});
}
function fnEventOrder_CalcTotal(sIdCoutPersons, sIdPriceSingle){
	sCoutPersons = $jQ(sIdCoutPersons).val();
	sPriceSingle = $jQ(sIdPriceSingle).val();
	sPriceSingle = sPriceSingle.replace(/\,/g, "\.");

	iCoutPersons = parseInt(sCoutPersons);
	lPriceSingle = parseFloat(sPriceSingle);

	if( iCoutPersons > 0 && lPriceSingle > 0 ){
		lPriceTotal =  lPriceSingle * iCoutPersons;
	}else{
		lPriceTotal =  lPriceSingle;
	}
	sPriceTotal = lPriceTotal.toFixed(2);
	sPriceTotal = sPriceTotal.replace(/\./g, "\,");
	return sPriceTotal;
}
/******************************************************************************/


// Send a Card
function fnSendACard(oForm){
	urlSendForm = document.getElementById("tx_srsendcard_pi1_address").value;
	txtCheck1 = document.getElementById("tx_srsendcard_pi1_sex").value;
	txtCheck2 = document.getElementById("tx_srsendcard_pi1_email2").value;

	if( txtCheck1 > "" && txtCheck2 > "" ){
		return true;
	}else{
		oForm.action = urlSendForm;
		oForm.submit();
		return false;
	}
}

/******************************************************************************/
/**
 * Toogle Content:
 */
var fContentState = 'show'; // Default!

$jQ(document).ready(function() {
	// Content ausblenden:
	$jQ('a#CtrlVisibillityContentHide, a#CtrlVisibillityContentHideFooter').click(function() {
		//toggleContent('hide');
		$jQ('#boxPageInner').css('display', 'none');
		$jQ('#boxCtrlVisibillityContent').slideDown();
		fContentState = 'hide';
		});
	// Content einblenden:
	$jQ('a#CtrlVisibillityContentShow').click(function() {
		//toggleContent('show');
		$jQ('#boxCtrlVisibillityContent').slideUp('fast',function(){ // Run this after the fade-out is done..
			$jQ('#boxPageInner').css('display', 'block');
		}); // close fadeOut() callback
		fContentState = 'show';
		});
});

$jQ(document).keyup(function(e) {
	// alert(e.keyCode);
	// F2  = 113
	// ESC =  27
	if( e.keyCode == 113 && fContentState == 'show' ) {
		//toggleContent('hide');
		$jQ('#boxPageInner').css('display', 'none');
		$jQ('#boxCtrlVisibillityContent').slideDown();
		fContentState = 'hide';
	}else if( (e.keyCode == 113 || e.keyCode == 27) && fContentState == 'hide' ) {
		//toggleContent('show');
		$jQ('#boxCtrlVisibillityContent').slideUp('fast',function(){ // Run this after the fade-out is done..
			$jQ('#boxPageInner').css('display', 'block');
		}); // close fadeOut() callback
		fContentState = 'show';
	}
});
/******************************************************************************/

