// redirect to mobile site
if(screen.width < 600) {
	if(confirm("Möchten Sie zur mobilen Reservierungsseite von STARCAR wechseln?")) {
		document.location.href = "./mobile";
	}
}

var slideshow;

function myFadeTo(id)
{
	// Teaser faden
	$('#bigTeaserSlideshow div.tile').each(function(i,e){
		if ($(this).attr("rel")=="on") {
			$(this).fadeTo("slow", 0).attr("rel", "off");
		}
	});
	$('#bigTeaserSlideshow #tile_' + id).fadeTo("slow", 1).attr("rel", "on");
	// Navi setzen
	$('#bigTeaserSlideshowNav a:not(#link_' + id + ')').removeClass("on").addClass("off");
	$('#bigTeaserSlideshowNav #link_' + id).removeClass("off").addClass("on");
	$('#bigTeaserSlideshowNav .teaserLink').removeClass("on").addClass("off");
	$('#bigTeaserSlideshowNav #teaserLink_' + id).removeClass("off").addClass("on");
}

function fadeTimer() {
	var strOn = "";
	var anzahl=0;
	$('#bigTeaserSlideshow div').each(function(i,e){
		anzahl++;
		if ($(this).attr("rel")=="on") strOn = $(this).attr("id");
	});
	var arrOn = strOn.split("_");
	var newOn = parseInt(arrOn[1])+1;
	if (newOn > anzahl) newOn = 1;
	myFadeTo(newOn);
}

var currentItem = 0;
var itemsInView = 0;
var maxItem = 0;
var autoscroll=null;

$(document).ready(function() { 
	
	// play video in layer
	/*
	if($.browser.ios)
	{
		$("#home_video_link").hide();
	}
	else
	{
		var flashvars = {previewPicture:"swf/application/data/img/preview.jpg", video: "data/video/starcar1_2_169.f4v", autoStart:"true", loop:"false"};
		var params = {allowFullScreen: "true", wmode: "opaque"};
	
		$("#home_video_link a").click(function(e){
			$("#TB_window").css("z-index", 20000);
			swfobject.embedSWF("swf/application/main.swf", "home_video", "870", "488", "9.0.0", "swf/expressInstall.swf", flashvars, params);
		});
	}
	*/
		
	// teaser scroller
	$("#home_carteaser_scroller_container > ul").tabs({
		spinner: "Lade&#8230",
		show: function(event, ui) {

			$('.ui-tabs-hide').html("");
			$('.ui-tabs-nav-item a').click(function(){
				clearInterval(autoscroll);
			});
			
			currentItem = 0;
			itemsInView = 4;
			maxItem = $('.home_carteaser_scroller_content > div').length - itemsInView;

			//$('.home_carteaser_scroller').stop().scrollTo('0px', 800, {axis: 'x'});

			autoscroll = setInterval(function() {
				currentItem++;
				if (currentItem > maxItem) currentItem = 1;
				$('.home_carteaser_scroller').scrollTo('div:eq('+currentItem+')', 800, {axis: 'x'});
			}, 9000);

			$('img.home_carteaser_scroll_left').click(function(){
				clearInterval(autoscroll);
				currentItem--;
				if (currentItem < 1) currentItem = maxItem;
				$('.home_carteaser_scroller').stop().scrollTo('div:eq('+currentItem+')', 800, {axis: 'x'});
			});

			$('img.home_carteaser_scroll_right').click(function(){
				clearInterval(autoscroll);
				currentItem++;
				if (currentItem > maxItem) currentItem = 1;
				$('.home_carteaser_scroller').stop().scrollTo('div:eq('+currentItem+')', 800, {axis: 'x'});
			});

		}
	});

	// default values für input felder
  $('input[name="email"]').toggleVal();
	$("#newsletter_form").submit(function() {
		$(this).find(".toggleval").each(function() {
			if($(this).val() == $(this).data("defText")) {
				$(this).val("");
			}
		});
	});

	// count browsers
	/*
	if($.browser.mozilla) $.ajax({ url: "browsercheck.php?browser=mozilla"});
	if($.browser.msie) $.ajax({ url: "browsercheck.php?browser=msie"});
	if($.browser.chrome) $.ajax({ url: "browsercheck.php?browser=chrome"});
	if($.browser.safari) $.ajax({ url: "browsercheck.php?browser=safari"});
	if($.browser.opera) $.ajax({ url: "browsercheck.php?browser=opera"});
	*/

	// special styles for safari/chrome
	if($.browser.chrome) $('li.mainNavigationItem_space').width('159px');
	if($.browser.safari) $('li.mainNavigationItem_space').width('159px');

	// Big Teaser Slideshow
	$('#bigTeaserSlideshow').css({'visibility':'visible'});
	$('#bigTeaserSlideshow .tile').dumbCrossFade({
		'maxZIndex':'50', 
		'slideType':'fade', 
		'doHoverPause':'false', 
		'slideChange': function (currentSlideIndex) { 
			$('#bigTeaserSlideshowNav div a').attr("class", "teaserLink off");
			$('#bigTeaserSlideshowNav div').attr("class", "teaserLink off");
			$('#teaserLinkDiv'+currentSlideIndex).attr("class", "teaserLink on");
			$('#teaserLinkHref'+currentSlideIndex).attr("class", "teaserLink on");
		} 
	});

	// Big Teaser Slideshow Navigation
	$('#bigTeaserSlideshowNav div a').click(function(e)
	{
		e.preventDefault;
		$('#bigTeaserSlideshowNav div a').attr("class", "teaserLink off");
		$('#bigTeaserSlideshowNav div').attr("class", "teaserLink off");

		$(this).parent().attr("class", "teaserLink on");
		$(this).attr("class", "teaserLink on");

		$('#bigTeaserSlideshow .tile').dumbCrossFade('stop');
		$('#bigTeaserSlideshow .tile').dumbCrossFade('jump', $(this).attr('href') );

		return false;
	});
	
	// cluetip positionieren
	$('#stationIdStart_container ul li').bind('mouseenter', function(){
		var container_offset = $('#stationIdStart_container').offset();
		var container_pos = $('#stationIdStart_container').position();
		var container_top = container_pos.top + 111;
		var container_left = container_offset.left + $('#stationIdStart_container').width() + 4;
		if(jQuery.browser.msie) {
			container_top = container_top - 7;
			container_left = container_left - 1;
		}
		$('#cluetip').css({
			"top" : container_top,
			"left" : container_left
		});
	});
	
	$('#stationIdStart').bind('change', function(){

		if ($('#dateStart_time_hour').val() == 7) {
			$('#dateStart_time_minute_input_00').css({"color": "#ffffff", "cursor":"default"});
		} 

		if ($('#stationIdStart').val()=="")
		{
			$('#home_rueckgabe').slideUp('fast');
			$('#home_reservierungsbox_content').hide();
			$('#home_reservierungsbox_content_hinweis').show();
			$('#home_rueckagbe_aendern_content').hide();
			$('#home_rueckagbe_aendern_content_leer').show();
		}
		else
		{
			$('#home_rueckgabe').slideDown('fast');
			$('#home_reservierungsbox_content_hinweis').hide();
			$('#home_reservierungsbox_content').show();
			$('#home_rueckagbe_aendern_content_leer').hide();
			$('#home_rueckagbe_aendern_content').show();
		}
	});
	
	$('#home_bonusprogramm_head').bind('click', function(){
		$('#home_bonusprogramm_content').slideToggle('fast');
		if ($(this).hasClass('disabled'))
		{
			$('#home_bonusprogramm_head').removeClass('disabled').addClass('enabled');
			$('#home_bonusprogramm_head_arrow').attr('src', 'img/arrow_big_yellow_down.gif');
		}
		else
		{
			$('#home_bonusprogramm_head').removeClass('enabled').addClass('disabled');
			$('#home_bonusprogramm_head_arrow').attr('src', 'img/arrow_big_gray_right.gif');
		}
	});
	
	$('.home_reservierungsbox_box.teaser').bind('click', function(){
		window.location.replace($(this).find('a').attr('href'));
	});

	
});

