
function newImage(arg) {
	var r = new Image();
	r.src = arg;
	return r;
}

function preloadImages() {
	var i, j;

	// images for the menu
	menu_images = new Array();
	for(i=1; i<=7; i++) {
		// subarray 0 index keeps background image
		menu_images.push(new Array(newImage("images/menu"+i+".jpg")));
		for(j=1; j<=7; j++) {
			// subarray index 1-7 keeps slices
			menu_images[i-1].push(newImage("images/menu"+i+"-menu"+j+"-over.jpg"));
		}
	}

	// images of the gallery
	gallery_images = new Array();
	for(i=1; i<=19; i++) {
		i = (i>9 ? i : '0'+i );
		gallery_images.push(newImage("gallery/t0"+i+".jpg"));
	}

	// images for catering
	catering_images = new Array();
	for(i=0; i<=16; i++) {
		i = (i>9 ? i : '0'+i );
		catering_images.push(newImage("catering/cat_"+i+".jpg"));
	}

	newImage("images/logo-rasas.png");
	newImage("images/rasas-first.jpg");
	newImage("images/jubileumfunf.png");
	newImage("images/rasas-funfjahre-web.jpg");
}

FotosAUTOPLAY = 1;

function startRasas() {

	if (document.images) {
		preloadImages();
	}

	// fix some browser issues
	if ($.browser.msie) {
		$(".MenuNav li").css('left', '-19px');
		// $("ul#innerContainer li.p1").css('margin-left', '24px');
		$("#slideLeft").css('top', '516px');
		$("#slideRight").css('top', '516px');
		$("#gnavCont").css('top', '617px');
		$("#Catering div.cgcont").css('left', '16px');
	}

	// start background sound
	startBGSound();

	// first make list of elements, to be used by event handler
	var ml, m = 1;
	var menulist = new Array();
	var contentlist = new Array();
	while( (ml = document.getElementById('MenuNav'+m)) ) {
		menulist.push(ml);
		contentlist.push(document.getElementById('Content'+m));
		m++;
	}

	m--;
	var e, i, j;
	for(i=0; i<m; i++) {

		// keep the list reference in <ul> node of each menu
		menulist[i].APPMenuList = menulist;
		menulist[i].APPContentList = contentlist;
		menulist[i].AppContentThis = contentlist[i];

		j=0;
		while (e = menulist[i].getElementsByTagName('LI')[j++]) {

			// to acces other nodes, only reference it through the list
			e.onclick = function () {
				var m = this.id.replace('Menu', '');
				var p = this.parentNode;
				p.className = p.className.replace('Show', 'Hide');
				p.APPMenuList[m-1].className = p.APPMenuList[m-1].className.replace('Hide', 'Show');
				p.AppContentThis.className = p.AppContentThis.className.replace('Show', 'Hide');
				p.APPContentList[m-1].className = p.APPContentList[m-1].className.replace('Hide','Show');

				if(this.id == "Menu2") {
					if(FotosAUTOPLAY == 1) {
						APtimer = setTimeout ("autoPlay()", showTime);
					}
				} else {
					if(FotosAUTOPLAY == 1) {
						clearTimeout(APtimer);
					}
				}
				if(this.id == "Menu5") {
					$(".tkcontainer").accordion({ active: document.getElementById('dow_now').value - 1 });
				}
			}

		}
	}

	gallery();
//	rasasPlay();
	speiseKarte();
	enlarge();
	initHMenu();
	Impressum();
	Webdesign();
	$("#prepage").hide();
}



function startBGSound() {
	if (navigator.appName == "Microsoft Internet Explorer") {
		$("body").prepend('<bgsound src="media/radiospot.mp3" loop="false">');
	}
	else {
		$("body").prepend('<embed type="application/x-mplayer2" src="media/radiospot.mp3" autostart="true" showstatusbar="0" showcontrols="0" showdisplay="0" volume="1" height="1" width="1" loop="false">');
	}
}


/*
function embedVideos() {
//put this into html header
//swfobject.registerObject("rasvid1", "9", "expressInstall.swf");

	var flashvars = {};
	var attributes = {};
	var params = {
		allowfullscreen: "true",
		allowscriptaccess: "always"
	};
	swfobject.embedSWF(
		"http://www.youtube-nocookie.com/v/xmJFg9fc2z8&hl=en_US&fs=1&rel=0&color1=0xe1600f&color2=0xfebd01&border=1",
		"RasasVideo1",
		"340", "285",
		"10.0.0",
		"swfobject/expressInstall.swf",
		flashvars, params, attributes
	);
}
*/

function rasasPlay() {
	rasastimer = 0;
	rasastimer = setTimeout ("playFirst()", 1000);
}

function playFirst() {
	$('#rasimage').fadeIn(1400, function() {
	});
//	$('#rasimage').fadeTo(2000, 0.2,  function() {
//		$('#rastext-de').fadeIn(2000, function() {
//		});
//	});
}

// ================ Impressum Page =================

ImpressumState = 0;

function Impressum() {
	new ImpressumPage();
}

ImpressumPage = function () {
	$("#Impressum p.hideme a").click( function () {
		$('#Impressum').fadeOut("slow");
		ImpressumState = 0;
	});

	$("#FooterContent p a.impinfo").click( function () {
		if( ImpressumState == 0 ) {
		  ImpressumState = 1;
		  $("#Impressum").fadeIn("slow");
		}
	});
}

// ================ Webdesign Page =================

WebdesignState = 0;

function Webdesign() {
	new WebdesignPage();
}

WebdesignPage = function () {
	$("#Webdesign p.hideme a").click( function () {
		$('#Webdesign').fadeOut("slow");
		WebdesignState = 0;
	});

	$("#FooterContent p a.desinfo").click( function () {
		if( WebdesignState == 0 ) {
		  WebdesignState = 1;
		  $("#Webdesign").fadeIn("slow");
		}
	});
}

// ================== First Page ===================

function initHMenu() {

	var pages = new Array (
		{ id: "willkommen", wh: 740, hh: 300 },
		{ id: "philosophie", wh: 740, hh: 250 },
		{ id: "about_de", wh: 740, hh: 500 },
		{ id: "empfehlungen", wh: 740, hh: 530 },
		{ id: "gutscheine", wh: 740, hh: 210 },
		{ id: "about_en", wh: 740, hh: 590 }
	);

	for (pg in pages) {
		new HMenuPage(pages[pg].id, pages[pg].wh, pages[pg].hh);
	}

	new SilvesterPage(980, 820);
	new JubileePage(760, 640);
}

HMenuPage = function ( page, pgwidth, pgheight ) {

	$("div.submenu ul li.hm_"+page).click( function () {
		
		$.window.closeAll();

		var newin = $("#Page").window({
			title: "RASAS - The Spirit of India",
			content: $('#'+page).html(),
			headerClass: "hm_winheader",
			footerClass: "hm_winfooter",
			frameClass: "hm_winframe",
			showFooter: false,
			x: 50,
			y: 130,
			z: 5000,
			width: pgwidth,
			maxWidth: pgwidth,
			height: pgheight,
			maxHeight: pgheight,
			checkBoundary: false,
			draggable: true,
			closable: false,
			minimizable: false,
			maximizable: false
		});

		var wid_close = "#" + newin.getWindowId() + " div.about p.hideme a";

		$(wid_close).click( function () {
			newin.close();
		});

 		return false;
	});
}

SilvesterPage = function ( pgwidth, pgheight ) {

	$("div ul.jubilee li.sil10").click( function () {
		
		$.window.closeAll();

		var newin = $("#Page").window({
			title: "Weihnachten und Silvester 2011/2012",
			content: $('#sil10').html(),
			headerClass: "hm_winheader",
			footerClass: "hm_winfooter",
			frameClass: "hm_winframe",
			showFooter: false,
			x: 20,
			y: 0,
			z: 5000,
			width: pgwidth,
			maxWidth: pgwidth,
			height: pgheight,
			maxHeight: pgheight,
			checkBoundary: false,
			draggable: true,
			closable: false,
			minimizable: false,
			maximizable: false
		});

		$("#silvmenu").tabs();

		var wid_close = "#" + newin.getWindowId() + " div.about p.hideme a";

		$(wid_close).click( function () {
			newin.close();
		});

 		return false;
	});

}

JubileePage = function ( pgwidth, pgheight ) {
	$("#jubimage img").click( function () {
		
		$.window.closeAll();

		var newin = $("#Page").window({
			title: "5 Jahre RASAS - The Spirit of India",
			content: $('#jub1').html(),
			headerClass: "hm_winheader",
			footerClass: "hm_winfooter",
			frameClass: "hm_winframe",
			showFooter: false,
			x: 50,
			y: 130,
			z: 5000,
			width: pgwidth,
			maxWidth: pgwidth,
			height: pgheight,
			maxHeight: pgheight,
			checkBoundary: false,
			draggable: true,
			closable: false,
			minimizable: false,
			maximizable: false
		});

		var wid_close = "#" + newin.getWindowId() + " div.about p.hideme a";

		$(wid_close).click( function () {
			newin.close();
		});

 		return false;
	});
}

// ================== Speisekarte ==================

function speiseKarte() {
	var pages = new Array ("soups", "hotstart", "salad", "vegdish", "chickdish", "lambdish", "fishdish", "duckdish", "ricedish", "tandoris", "rasaspec", "spec2p", "sideo", "sweet", "drinks", "tabwine", "redwine", "whitewine");
	for (pg in pages) {
		new SpeiseKartePage(pages[pg]);
	}
}

SpeiseKarteState = 0;

SpeiseKartePage = function ( page ) {
	$("#speisekarte div."+page+" p.hideme a").click( function () {
		$("#speisekarte div."+page).fadeOut("slow");
		SpeiseKarteState = 0;
	});

	$("#speiselist li."+page).click( function () {
		if( SpeiseKarteState == 0) {
			SpeiseKarteState = 1;
			$("#speisekarte div."+page).fadeIn("slow");
		}
	});
}

// ================== Catering ==================

enlarge = function() {

	var imageArray = $('.enlarge');
	var total = $('.enlarge').length;

	for (q=0; q<total; q++) {
		$(imageArray[q]).css({ cursor:'pointer' });
	}

	$('.enlarge').click(function() {

		source = $(this).attr("src");
		title = $(this).attr("title");

		$('#CateringIMG').html('<p><span class="close"><b>Schliessen / Close</b> </span></p> <img src="' + source + '"/>' );

		$('#CateringBG').css({ display: 'block' });
		$('#CateringIMG').css({ display: 'block' });

		imgWidth = $('#CateringIMG img').innerWidth();
		imgHeight = $('#CateringIMG img').innerHeight();

		$('#CateringIMG img').css({
			display: 'none',
			height: imgHeight,
			width: 0
		});

		$('#CateringIMG').css({ visibility: 'visible' });
		$('#CateringIMG img').animate({ "width": imgWidth }, 500, function() {
			$('#CateringIMG p').show();
		});

		$('.close').click(function(){
			$('#CateringIMG p').hide();
			$('#CateringIMG').fadeOut('fast');
			$('#CateringBG').hide();
		});
	});

	return false;
}


