jQuery.noConflict();

jQuery(document).ready(function(){

	// Navigation
	jQuery('#stage ul a.top').click(function(event){
		jQuery('#stage ul ul').css({ 'display':'none' });
		jQuery(this).parent('li').find('ul').css({ 'display':'block' });
		jQuery(this).parent('li').parent('ul').find('li.active').find('a.top').parent('li').removeClass('active');
		
		jQuery(this).parent('li').addClass('active');
		jQuery(this).blur();
	});
	
	jQuery("form#kontakt").submit( function () {
			var uid = new Array ("2", "4", "5", "6", "7", "8", "12", "13", "14", "15");
			var val = new Array ();
			var i, j, bool = true;
			
			for (i = 0; i <= uid.length; i++) {
				val[i] = jQuery("#uid" + uid[i]).val();
			}
			
			for (j = 0; j <= uid.length; j++) {
				if (val[j] == "Bitte auswählen" || val[j] == "") jQuery("#uid" + uid[j]).addClass("val-failed");
				else jQuery("#uid" + uid[j]).removeClass("val-failed");
			}
			
			for (j = 0; j <= uid.length; j++) {
				if (jQuery("#uid" + uid[j]).hasClass("val-failed")) bool = false;
			}
			
			if (bool == false) return false;
		});
	

	jQuery(".myGallery").bind("contextmenu", function(e){
        return false;
    });
	
	jQuery(".myGallery").click( function () { 
			jQuery("#rglbCenter").bind("contextmenu", function(e){
						return false;
				});
		});
	
	jQuery(".csc-textpic").click( function () { 
			jQuery("#lbCenter").bind("contextmenu", function(e){
						return false;
				});
		});
	
	jQuery(".csc-textpic img").bind("contextmenu", function(e){
        return false;
    });
		
		
	// Standorte
	
	var preload = new Array;
	var preloadPath;
	jQuery('div#map img.bullet, div#map img.bubble').each(function(){
		preload[jQuery(this).attr('id')] = jQuery('<img />').attr('src', jQuery(this).attr('src'));
		preload[jQuery(this).attr('id')+'-over'] = jQuery('<img />').attr('src', jQuery(this).attr('src').replace(/([^.]*)\.(.*)/, '$1-over.$2'));
		//console.log(jQuery(this).attr('src').replace(/([^.]*)\.(.*)/, '$1-over.$2'));
		preloadPath = jQuery(this).attr('src').replace(/([^.]*)\/(.*)\.(.*)/, '$1');
	});
	preload['bigbubble-tl'] = jQuery('<img />').attr('src', preloadPath+'/map-bubble-big-tl.png');
	preload['bigbubble-tr'] = jQuery('<img />').attr('src', preloadPath+'/map-bubble-big-tr.png');
	preload['bigbubble-bl'] = jQuery('<img />').attr('src', preloadPath+'/map-bubble-big-bl.png');
	preload['bigbubble-br'] = jQuery('<img />').attr('src', preloadPath+'/map-bubble-big-br.png');
	
	var activeCity = "";
	
	jQuery('#map-list').hide();
	
	jQuery('div#map img.bullet, div#map img.bubble, div#map img.bubble-close').css('cursor','pointer');
	
	jQuery('div#map img.bullet, div#map img.bubble').mouseenter(function(e){
		
		var hoverCity = jQuery(this).attr('id').replace(/^(bullet|bubble)-([a-z]*)$/, '$2');
		
		//console.log('mouseenter: '+hoverCity);
		activateHover(hoverCity);
		
	});
	
	jQuery('div#map img.bullet, div#map img.bubble').mouseleave(function(e){
	
		var hoverCity = jQuery(this).attr('id').replace(/^(bubble|bullet)-([a-z]*)$/, '$2');
		
		//console.log('mouseleave: '+hoverCity);
		
		if(activeCity != hoverCity){
			deactivateHover(hoverCity);
		}
		
		hoverCity = "";
		
	});
	
	function activateHover(city){
	
		var overSrc1 = jQuery('div#map #bullet-'+city).attr('src').replace('-over', '').replace(/([^.]*)\.(.*)/, '$1-over.$2');
		jQuery('div#map #bullet-'+city).attr('src',overSrc1);
		
		var overSrc2 = jQuery('div#map #bubble-'+city).attr('src').replace('-over', '').replace(/([^.]*)\.(.*)/, '$1-over.$2');
		jQuery('div#map #bubble-'+city).attr('src',overSrc2);
		
		//console.log('activateHover: '+city+', '+overSrc1+', '+overSrc2);
		
	}
	function deactivateHover(city){
	
		var normalSrc1 = jQuery('div#map #bullet-'+city).attr('src').replace('-over', '');
		jQuery('div#map #bullet-'+city).attr('src',normalSrc1);
		
		var normalSrc2 = jQuery('div#map #bubble-'+city).attr('src').replace('-over', '');
		jQuery('div#map #bubble-'+city).attr('src',normalSrc2);
		
		//console.log('deactivateHover: '+city+', '+normalSrc1+', '+normalSrc2);
		
	}
	
	function deactivateHoverGlobal(){
	
		var normalSrc;
		
		jQuery('div#map .bullet, div#map .bubble').each(function(){
			normalSrc = jQuery(this).attr('src').replace('-over', '');
			jQuery(this).attr('src',normalSrc);
			//console.log('deactivateHoverGlobal: '+normalSrc);
		});
		
	}
	
	jQuery('div#map img.bullet, div#map img.bubble').click(function(e){
		
		var clickedCity = jQuery(this).attr('id').replace(/^(bullet|bubble)-([a-z]*)$/, '$2');
		
		//console.log('click: '+clickedCity);
		
		if(activeCity != clickedCity){
			
			activeCity = clickedCity;
			
			//console.log('click: '+activeCity);

			deactivateHoverGlobal();
			activateHover(activeCity);
			
			jQuery('div#map .bubble').fadeIn(200);
			jQuery('div#map #bubble-'+activeCity).fadeOut(200);
			jQuery('div#map .bigbubble').fadeOut(200);
			jQuery('div#map #bigbubble-'+activeCity).fadeIn(200);
			
		} else {
			//console.log('click: gleiche Stadt > schließen');
			jQuery('div#map #bigbubble-'+clickedCity+' img.bubble-close').click();
		}
	
	});
	
	jQuery('div#map img.bubble-close').click(function(e){

		activeCity = "";
		deactivateHoverGlobal();
		jQuery('div#map .bubble').fadeIn(200);
		jQuery('div#map .bigbubble').fadeOut(200);
		
	});
	
	jQuery(".clickenlarge-1 a").each( function (i) {
			jQuery(this).append('<div class="lupe"></div');
		});
	
});

