/*******/
var $j = jQuery.noConflict();

$j(document).ready(function () {
	$j('body').addClass('js-active');
	// set header height dynamicly
	$j('#contentwrapper').css('padding-top', $j('#header').height()+20);
	
	// languageSwitch
	$j('#languageSwitch li[class!=active]').hide();
	$j('#languageSwitch ul').hover(function () {
		$j('#languageSwitch li[class!=active]').show();
	}, function () {
		$j('#languageSwitch li[class!=active]').hide();
	});
	// teaser
    $j('#teaser').find('.teaserbox1').each(function () {
        $j(this).mousedown(function () {
            // mousedown
			$j('.teaser-frame', this).hide();
			$j('.teaser-active', this).show();
        });
        $j(this).mouseup(function () {
            // mouseup
			$j('.teaser-frame', this).show();
			$j('.teaser-active', this).hide();
			// first link within the box will be used
			if($j('a', this).attr('href')) {
				//if link points to an external page
				if($j('a', this).attr('href').match('http://*')) {
					document.location = $j('a', this).attr('href');
				} else {
					//if link points to an internal page
					document.location = $j('base').attr('href')+$j('a', this).attr('href');
				}
			}
        });
        $j(this).hover(function () {
            // on hover
			$j('.teaser-hover', this).hide();
        }, function () {
			// off hover
			$j('.teaser-hover', this).show();
		});
	});
	
	$j('.headlink>a').click(function(){  
		return false; 
	}); 
	$j('.mainnav-subcontent>a').click(function(){  
		return true; 
	}); 
	
	// Ajax-Type für link setzen
	$j("a.wm-ajax-link").attr("href", $j("a.wm-ajax-link").attr("href") + '?type=541');


	
	// Worldmap
	initWorldMap();
	$j("#worldMap a").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 930,
		'frameHeight': 470,
		'callbackOnShow': initWorldMap,
		'overlayOpacity': 0.6,
		'overlayColor': '#000'
	});
	
	// fancybox gallery
	$j("a.gallery").fancybox({
		'overlayOpacity': 0.6,
		'overlayColor': '#000'		
	});
	// gallery links jump to wtgallery_single div
	$j('.wtgallery_list_area a').each(function() {
		$j(this).attr('href', $j(this).attr('href')+'#wtgallery_single');
	});
	$j('.wtgallery_single_browser a').each(function() {
		$j(this).attr('href', $j(this).attr('href')+'#wtgallery_single');
	});
	
	// logoleiste
	$j('.logo_color').hide();
    $j('#footercontent .footerelement').find('.logo_block').each(function () {
        $j(this).hover(function () {
            // on hover
			$j('.logo_white', this).hide();
        	$j('.logo_color', this).show();
			var pos = $j(this).offset();  
			var width = $j(this).width();
			var popmargin = 10;
			$j(this).parent().find('.pop').css({"left": (width - popmargin) + "px"});
			$j(this).parent().css('z-index', '30');
			$j(this).parent().find('.pop').show();
        }, function () {
            // off hover
			$j('.logo_white', this).show();
        	$j('.logo_color', this).hide();
        	$j(this).parent().css('z-index', '20');
			$j(this).parent().find('.pop').hide();
			
		});
	});
	$j('.js-active .tx-damdownloads-pi1 h2').click(function() {
		$j(this).toggleClass('selected').next().toggle('fast');
		return false;
	}).next().hide();
	
	// rggooglemap
	// prüfen ob makeMap function benötigt wird
	if(typeof(window.makeMap) == "function") {
		makeMap();
	}
});

function initWorldMap() {
	var imgPath = 'fileadmin/template_coscom/img/worldmap/'
	var imgSrc = 'coscom_weltkarte.png';
	$j('.tx-magworldmap-pi1 .continentboxtop .cancelimg').click(function() {
		$j(this).parent().parent().hide();
	});
	$j('#kontinent1area').click(function(e) {
		e.preventDefault();
		$j('.tx-magworldmap-pi1 .continentbox').hide();
		var x = e.pageX+10;
		var y = e.pageY;	
		$j('#north_america').css({'display' : 'block', 'position' : 'fixed', 'top' : y, 'left' : x});
	});
	$j('#kontinent1area').hover(function() {
		$j('#worldmapimg').attr('src', imgPath+'coscom_weltkarte_nordamerika.png');
	}, function() {
		$j('#worldmapimg').attr('src', imgPath+imgSrc);
	});
	
	$j('#kontinent2area').click(function(e) {
		e.preventDefault();
		$j('.tx-magworldmap-pi1 .continentbox').hide();
		var x = e.pageX+10;
		var y = e.pageY;
		$j('#south_america').css({'display' : 'block', 'position' : 'fixed', 'top' : y, 'left' : x});
	});
	$j('#kontinent2area').hover(function() {
		$j('#worldmapimg').attr('src', imgPath+'coscom_weltkarte_suedamerika.png');
	}, function() {
		$j('#worldmapimg').attr('src', imgPath+imgSrc);
	});
	
	$j('#kontinent3area').click(function(e) {
		e.preventDefault();
		$j('.tx-magworldmap-pi1 .continentbox').hide();
		var x = e.pageX+10;
		var y = e.pageY;
		$j('#europe').css({'display' : 'block', 'position' : 'fixed', 'top' : y, 'left' : x});
	});
	$j('#kontinent3area').hover(function() {
		$j('#worldmapimg').attr('src', imgPath+'coscom_weltkarte_europa.png');
	}, function() {
		$j('#worldmapimg').attr('src', imgPath+imgSrc);
	});
	
	$j('#kontinent4area').click(function(e) {
		e.preventDefault();
		$j('.tx-magworldmap-pi1 .continentbox').hide();
		var x = e.pageX+10;
		var y = e.pageY;
		$j('#asia').css({'display' : 'block', 'position' : 'fixed', 'top' : y, 'left' : x});
	});
	$j('#kontinent4area').hover(function() {
		$j('#worldmapimg').attr('src', imgPath+'coscom_weltkarte_asien.png');
	}, function() {
		$j('#worldmapimg').attr('src', imgPath+imgSrc);
	});
	
	$j('#kontinent5area').click(function(e) {
		e.preventDefault();
		$j('.tx-magworldmap-pi1 .continentbox').hide();
		var x = e.pageX+10;
		var y = e.pageY;
		$j('#australia').css({'display' : 'block', 'position' : 'fixed', 'top' : y, 'left' : x});
	});
	$j('#kontinent5area').hover(function() {
		$j('#worldmapimg').attr('src', imgPath+'coscom_weltkarte_australien.png');
	}, function() {
		$j('#worldmapimg').attr('src', imgPath+imgSrc);
	});
	
	$j('#kontinent6area').click(function(e) {
		e.preventDefault();
		$j('.tx-magworldmap-pi1 .continentbox').hide();
		var x = e.pageX+10;
		var y = e.pageY;
		$j('#africa').css({'display' : 'block', 'position' : 'fixed', 'top' : y, 'left' : x});
	});
	$j('#kontinent6area').hover(function() {
		$j('#worldmapimg').attr('src', imgPath+'coscom_weltkarte_afrika.png');
	}, function() {
		$j('#worldmapimg').attr('src', imgPath+imgSrc);
	});
}
