$(document).ready(function () {

	var activediv = null;
	var nextdiv = null;
	$("div.promoImg").change(function () {
		if (activediv!=null)
		{
			if (activediv!=this)
			{
				nextdiv = this;
				$(activediv).fadeOut("fast", function(){$(nextdiv).fadeIn("fast");activediv=nextdiv});
			}
		}
		else
		{
		
			if($.browser.msie){
			$(this).fadeTo(100, 0.7);
			}
			else{
			$(this).fadeTo(100, 1.0);
			}  

			
			/*$(this).fadeIn("fast");*/
			activediv = this;
		}
	})
	$("div.promoButton").mouseover(function (event) {
		var targetId = event.currentTarget.id.replace(/[^0-9]*/, '');
		$("div#promoImg"+targetId).change();
		
		$("div.promoTitle").css({display:"none"}).removeClass("select");
		
		$("div#promoTitle"+targetId).fadeIn("400").addClass("select");
	
		window.location.hash = $("div#promoTitle"+targetId).attr('title');
	});
	
	var anchor = window.location.hash.substring(1);
	var itemId = $("div[title='" + anchor + "']").attr('id');
	
	if ( $("div#promoTitle1").is('*') ) {
		
		if (itemId && (itemId.substring(0, 10) == "promoTitle")) {
			
			$("#promoImg" + itemId.replace(/[^0-9]*/, '')).change();
			$("div#" + itemId).addClass("promoTitle").addClass("select");
		}
		else {
		
			do {
				var showId = (Math.floor(Math.random()*4))+1; /*(random number between 0 and 3) + 1*/
				
				if ( !$("div#promoTitle" + showId).is('*') ) {
					showId = 1;
				}
			}
			while( $.cookie("lastPromoTitleId") == showId );
			
			$("#promoImg" + showId).change();
			$("div#promoTitle" + showId).addClass("promoTitle").addClass("select");
			
			$.cookie("lastPromoTitleId", showId, { expires: 2 });
		}
	}
	
	setATMForm('Fiok');
	
	$('input[name=selectATMFiok]').click(function() {
		var type = $(this).attr('value');
		
		setATMForm(type);
		
	});
	
	function setATMForm(type) {
		$('div.agencyFormBox').removeClass('visible');
		$('div#divKompakt' + type).addClass('visible');
		
	}
	
});

