/**
 * @author g.paul / d.rerych
 */

$(document).ready(function(){		
  $("#teaser").hide();
	$("#content").css("width","800px");
	
	if ($.browser.msie && ($.browser.version < 7)) {
		$('#vb_suche').addClass('ie6');
	}

	$('#imagemap_oesterreich').find('area').each(function(){
		
		thisID = $(this).attr('id');
		thisTitle = $(this).attr('title');
		thisHref = $(this).attr('href');
		thisALT = $(this).attr('alt');
		thisALT = thisALT.substring(thisALT.lastIndexOf(" ")+1,thisALT.length);
				
		// build tooltip text
			var titleValue = '';
			titleValue += thisALT + ' - ' + $(thisHref +' li').length + ' Volksbanken';
			
			$(this).attr('title', titleValue)
		
		
		// change the bg-position of the sprite map
		
			if (!($.browser.msie && ($.browser.version < 7))) {
				$(this).hover(function(){
					$(this).parents('.content').addClass($(this).attr('id'));
				}, function(){
					$(this).parents('.content').removeClass($(this).attr('id'));
				})
			}

		// show popup with branch list
			$(this).bind('click', function(event){
				event.preventDefault();
												
				thisHref = $(this).attr('href');
				vbLength = $(thisHref +' li').length;
						
				$(thisHref).siblings().hide();
					
				subtitle = '<p class="subtitle">Insgesamt <strong>' + vbLength + '</strong> Volksbanken:: Bitte wählen Sie:</p>';
				
				$(thisHref).find('.subtitle').remove();
				
				$(thisHref + ' .header').append(subtitle);							
				$(thisHref).fadeIn('slow');
				
				// IE cannot render box-shadow
				if ($.browser.msie && ($.browser.version <= 8)) {
					$(thisHref).css('border', '1px solid #ccc');
				}				
			})	
		
	})

	$('#imagemap_europa').find('area').each(function(){
		
		thisID = $(this).attr('id');

		// build tooltip text
			var titleValue = '';
			titleValue += thisID;
			
			$(this).attr('title', titleValue)
						
		// change the bg-position of the sprite map
			$(this).hover(function(){
				$(this).parents('#vb_in_europa').addClass($(this).attr('id'));
			}, function(){
				$(this).parents('#vb_in_europa').removeClass($(this).attr('id'));
			})
			
	})

	$('#tabs a').bind('click', function(event){
		event.preventDefault();
		
		$(this).siblings().removeClass('active');
		$(this).addClass('active');
		
		visibleMap = $(this).attr('rel');
		
		if ($.browser.msie) {
			$('#' + visibleMap).siblings().hide();
			$('#' + visibleMap).show();
		}
		else {
			$('#' + visibleMap).siblings().fadeOut('slow', function(){
				$('#' + visibleMap).fadeIn('fast');
			})
		}
		
	})
	
	$('#vb_filialen .close').bind('click', function(event){
		event.preventDefault();
		
		parentEl = $(this).parents('.filiale');
		
		$(parentEl).hide();
		$(parentEl).find('.subtitle').remove();
		
	})
	
	
	// init tooltip plugin
		$('#imagemap_oesterreich area').tooltip({
			track: true,
			delay: 0,
			showURL: false,
			showBody: " - ",
			fade: 250,
			top: -55,
			left: -110
		});
		$('#imagemap_europa area').tooltip({
			track: true,
			delay: 0,
			showURL: false,
			showBody: " - ",
			fade: 250,
			top: -30,
			left: 5
		});		
	
})


function FensterOeffnen(Adresse, wt){

    var plz = wt.PLZ.value;
    var ort = wt.ORT.value;
    var strasse = wt.STRASSE.value;
    var hnr = wt.HNR.value;
    
    MeinFenster = window.open(Adresse + "&ORT=" + ort + "&PLZ=" + plz + "&STRASSE=" + strasse + "&HNR=" + hnr, "Lagekarte", "width=870,height=720,left=100,top=200,scrollbars=yes,resizable=yes");
    return (false);
    reset_felder(wt);
}
