var accordion;
var countOfIntroSlides = 0;
var sliderWidth = /msie|MSIE 6/.test(navigator.userAgent) ? 577 : 580;

function slideEnd()
{
	var setCookie = true;
	/*if(sliderAccordion.showAccordion === null)
	{
		Delete_Cookie('activeAccordion', '/', '');
		countOfIntroSlides = 10;
		setCookie = false;
	}
	
	if(isHome === true && countOfIntroSlides < 2 && !Get_Cookie('activeAccordion'))
	{
		countOfIntroSlides++;
		sliderAccordion.activate($$('#sliderContainer .sliderToggle')[countOfIntroSlides]);
		setCookie = false;
	}
	else if(isHome === true && countOfIntroSlides === 2 && !Get_Cookie('activeAccordion'))
	{
		countOfIntroSlides++;
		//sliderAccordion.deactivate();
		setCookie = false;
	}*/
	
	if(setCookie) {
		if (testPersistentCookie()) {
		    writePersistentCookie ('activeAccordion', accordion.current.previous(0).id, 'hours', '12');
		  }
		  else
		    alert ("Sorry - session cookies are currently disabled."); 
	}
}


window.onload = function() {
	new Ajax.Request('/scripts/applications/contentSubNew.asp?lang=' + lang,
	{
		method:'post',
		encoding:'ISO-8859-1',
		contentType:'text/html; charset=ISO-8859-1',
		onSuccess: function(transport){
			var response = transport.responseText || "no response text";
			$('contentSub').innerHTML = response;
			fb.anchors.length = 0
			fb.tagAnchors(document);
			accordion = new Accordion({id: 'sliderContainer', type: 'horizontal', toggleClass: 'sliderToggle', activeClass: 'sliderActive', contentClass: 'sliderContent', onAnimationEnd: function() {slideEnd();}});


			/*if(!getCookieValue('activeAccordion') && isHome === true)
			{
				countOfIntroSlides = 0;
				//sliderAccordion.activate($$('#sliderContainer .sliderToggle')[0]);
			}
			else
			{
				//sliderAccordion.activate($(Get_Cookie('activeAccordion')));
			}*/
		},
		onFailure: function(){ alert('Something went wrong...') }
	});
};

function getSliderLoadingAnimation()
{
	return '<div class="sliderInnerContent"><div class="sliderLoading"><img src="/images/loadingAnimation.gif"/></div></div>';
}
function searchReset()
{
	embedHomeMovie();
	$('sliderContentSearch').innerHTML = getSliderLoadingAnimation();
	if (getCookieValue ('searchValues'))
	    deleteCookie ('searchValues');

	new Ajax.Request('/scripts/applications/partnerSearchCall.asp?lang=' + lang,
	{
		method:'post',
		encoding:'ISO-8859-1',
		contentType:'text/html; charset=ISO-8859-1',
		onSuccess: function(transport){
			var response = transport.responseText || "no response text";
			$('sliderContentSearch').innerHTML = response;
		},
		onFailure: function(){ alert('Something went wrong...') }
	});
}

function searchPartner(_type)
{
	embedHomeMovie();
	var cookieContent = _type + ';' + $F('searchCity') + ';' + $F('searchCountOfRooms') + ';' + $F('searchCapacity') + ';' + $F('searchType') + ';' + $F('searchCapacityPerRoom') + ';';
	writePersistentCookie ('searchValues', cookieContent, 'hours', '12');
	$('sliderContentSearch').innerHTML = getSliderLoadingAnimation();
	new Ajax.Request('/scripts/applications/partnerSearchCall.asp?lang=' + lang,
	{
		method:'post',
		encoding:'ISO-8859-1',
		contentType:'text/html; charset=ISO-8859-1',
		onSuccess: function(transport){
			var response = transport.responseText || "no response text";
			$('sliderContentSearch').innerHTML = response;
		},
		onFailure: function(){ alert('Something went wrong...') }
	});
}

var flaParamsHome = {
		menu: "false",
		wmode: "transparent",
		bgcolor: "#79a8bc"
	};

function embedHomeMovie()
{
	var counter = getMovieNumber();
	var movie = '';
	switch (counter) {
		case 1:
			movie = '10_08_03_hbf.swf';
			break;
		case 2:
			movie = '10_08_03_inder.swf';
			break;
		case 3:
			movie = '10_08_03_neckar.swf';
			break;			
		case 4:
			movie = '10_08_03_park.swf';
			break;
	}
	swfobject.embedSWF("/fla/" + lang + "/" + movie, "homeFlashReplacer", "1000", "450", "8", false, false, flaParamsHome, false);
}

function getMovieNumber() {
	var minCount = 1;
	var maxCount = 4;
	var number = Math.round(Math.random() * 100);

	if(number >= minCount && number <= maxCount)
	{
		return number;
	}
	else
	{
		return getMovieNumber();
	}
}