var currentPosition = 1;
var arrowpos = [138,338,468,608,773];
var mainpos  = [447,-396,-1920,-3840,-4800];

function isOld()
{ 
	return !($.browser.webkit ||
		($.browser.mozilla && parseFloat($.browser.version) >= 1.9) ||
		($.browser.opera && parseFloat($.browser.version) >= 10.5)
	);

}

function setHighlighted(state)
{
	for(x=1; x<4; x++) {
		document.getElementById('slide' + x).style.opacity = (x == state ? "1" : "0");
	}
}

function setPosition(state)
{
	currentPosition = state;
	for(x=0;x<4;x++) {
		document.getElementById('sliderPagination').getElementsByTagName('li')[x].removeAttribute("class");
	}

	if(state > 1) {
		document.getElementById('sliderPagination').getElementsByTagName('li')[state-2].className = "active";
	}
	else {
		document.getElementById('icon').className = "active";
	}

	document.getElementById('sliderPagination').className = "slide"+state;

	currentPosition = state;
	document.getElementById('mainwindow').className = "position"+state;
	document.getElementById('sliderUl').className = "show"+state;

	//ist keiner der allerneusten
	if (!isOld())
		return;

	$('#slider .show'+state).animate({
		'left':(-960*(state-1))+'px'
	}
	);

	$('#arrow').animate({
		'left':arrowpos[state-1]+'px'
	}
	);

	$('#mainwindow').animate({
		'left':mainpos[state-1]+'px'
	}
	);

}

$(document).ready( function()
{



$('#blz_input').keyup(function(e) 
{
  
  if (!isOld()) $('#blz_status').addClass("modern");

  
   if(this.value.match(/^\d{8}$/g))
   {
       $.ajax({
             url: "/wp-content/themes/OutBank/blzsuche.php?blz_input=" + this.value + "&ajax=1",
           success: function(data)
           {
              $('#blz_input').removeClass("ok bad");
              $('#blz_status').removeClass("ok bad");
               switch( parseInt(data) )
               {
                  
                  case 0:
                    $('#blz_status p').html('Dein Kreditinstitut unterstützt (noch) nicht die für OutBanking notwendigen Verfahren. Bitte beachte hierzu auch die Informationen in unserer <a href="/support/banken/#toContent">FAQ</a>.');
                    $('#blz_input').addClass("bad");
                    $('#blz_status').addClass("show bad");
                  break;
                  
                  case 1:
                    $('#blz_status p').html('Dein Kreditinstitut ist fit für OutBanking!');
                    $('#blz_input').addClass("ok");
                    $('#blz_status').addClass("show ok");
                  break;
                  
                  case 2:
                    $('#blz_status p').html('OutBank unterstützt derzeit nur die Salden- und Umsatzabfrage. Bitte beachte hierzu auch unsere Informationen in den <a href="/support/banken/#toContent">FAQ</a>.');
                    $('#blz_input').addClass("ok");
                    $('#blz_status').addClass("show");
                  break;

                  default:
                    $('#blz_status p').html('Bitte überprüfe Deine Eingabe / Ist die Bankleitzahl korrekt?');
                    $('#blz_input').addClass("bad");
                    $('#blz_status').addClass("show bad");
                  break;
               }
             }
             
       });
   } else {
    $('#blz_input').removeClass("ok bad");
    $('#blz_status').removeClass("show ok bad");
    
   }
});

$('#blz_form').submit(function(e){return false;});





		$('#mainwindow').click( function() {
		  $(this).toggleClass("show");
			if(isOld())
			{
			 if(!$(this).hasClass("show")) {
			   if(currentPosition == 1) {
			     $(this).animate({'left': '447px'});
			   } else if(currentPosition == 2) {
			     $(this).animate({'left': '-396px'});
			   }
			 } else {
			   $(this).animate({'left': '20px'});
			 
			   }
		  }
    });
			
	var pos = {
		s:0,
		e:0
	};

	$('#sliderUl').bind('touchstart', function(e)
	{
		pos.s = event.touches[0].pageX;
		pos.e = pos.s;
	}).bind('touchmove', function(e)
	{
		pos.e = event.touches[0].pageX;
	}).bind('touchend', function(e)
	{
		diff = pos.s - pos.e;
		adiff= Math.abs(diff)
		nextPage = currentPosition +(diff/adiff);

		if(!(nextPage < 1 || nextPage> 5 || adiff < 100)) {
			setPosition(nextPage);
		}
	});
});





