/* _________________________________________________________________________
_______________													____________
_______________		Projekt: 	Evangelische Schulstiftung		____________
_______________		Datum:		2011.07.01						____________
_______________		Jquery										____________
____________________________________________________________________________  */
			
function createIECorners(){$('div#wrapper').corner('top');$('div#sidebar').append($('<div class="sb-rounded-bottom"> </div>')).append('<span class="rounded"> </span>');$('div#nav ul li.sub5 a:first').append('<span class="rounded"> </span>');$('div#sidebar .teaser .vevent:last-child').addClass('lchild');}
function createPipes(){$('div#nav ul li a').not($('div#nav li ul li a')).append('<span class="l"> </span><span class="r"> </span>');$('div#nav ul li').hover(function(){$(this).addClass('expand');},function(){$(this).removeClass('expand');});}
function createRotationList(){var show ="";for(var i=2;i<=7;i++){show+='<li><img class="rotate" src="/img/rot/0'+i+'.jpg" alt="" title="" /></li>';}return show;}
function overlayOnHover(ref) {
	var top, left, id, img, imgsrc, school, address, plz, local, tmp;
	top  = 25+Math.ceil($(ref).offset().top);
	left = 25+Math.ceil($(ref).offset().left);
	id = $(ref).attr('href').substring(1, 4);
	if ($('div#contact dl dt#'+id+' + dd img').length > 0 ) {
		imgsrc = $('div#contact dl dt#'+id+' + dd img').attr('src');
		img = '<img src="'+imgsrc+'" />';
		tmp=true;
	} else {img = '';}
	school = $('div#contact dl dt#'+id+' + dd address:first span.fn').text();
	address = $('div#contact dl dt#'+id+' + dd address:first span.street-address').text();
	plz = $('div#contact dl dt#'+id+' + dd address:first span.postal-code').text();
	local = $('div#contact dl dt#'+id+' + dd address:first span.locality').text();	
	$('body').append('	<div class="overlay" style="position:absolute;top:'+top+'px; left:'+left+'px;">'+
							'<div class="overlay-wrapper">'+
								'<div class="inner-overlay">'+
									img+
									'<address class="'+id+'">'+
										'<strong>'+school+'<span></span></strong>'+
										'<p>'+address+' <br />'+plz+' '+local+'</p>'+
									'</address>'+
								'</div>'+
							'</div>'+
						'</div>');
	if(tmp) { $('div.overlay address span').css('top','138px'); }
}
// JQUERY starts here ...
$(document).ready(function(){
	var rheight;
	$('div.chapter:has(img.left)').children('ul').addClass('left');
	$('div#contact dl dd').css('display','none');
	$('div#contact dl dt').addClass('hover').wrapInner($('<a onclick="return false;"></a>'));

	if (!($.browser.msie && $.browser.version == '6.0')){ createPipes(); rheight=220;
	} else {
		// JS only for IE6 comes here ...
		//$('div#map img').attr('src','/img/bas/saxonymap.gif');
		if ($('div#content').height()<320) {$('div#content').addClass('ie6');}
	}
	if ($.browser.msie){
		createIECorners();
		rheight=219;
	}
// rotation ul#slideshow 
	$('ul#slideshow').append(createRotationList());
	$('ul#slideshow').innerfade({
		speed: 3000,
		timeout: 7000,
		type: 'random',
		containerheight: rheight
	});
// mouseover div#map
$('div#map ul li a').hover(
	function(){
		overlayOnHover(this);
		$('div.overlay').fadeIn();
	},
	function () {
		$('div.overlay').remove();
	}
);
// onclick div#map a
$('div#map a').click(
	function(){
		clickID = $(this).attr('href').substring(1, 4);
		if($('div#contact dl dt#'+clickID).hasClass('hover')){
			$('div#contact dl dt#'+clickID).addClass('active').removeClass('hover');
			$('div#contact dl dt#'+clickID+' + dd').slideDown();
			$('div#contact dl dt#'+clickID+' a').addClass('on');
		}
		else if ($('div#contact dl dt#'+clickID).hasClass('active')) {
			$('div#contact dl dt#'+clickID).addClass('hover').removeClass('active');
			$('div#contact dl dt#'+clickID+' + dd').slideUp();
			$('div#contact dl dt#'+clickID+' a').removeClass('on');
		}
	}
);
// onclick div#contact dl dt
$('div#contact dl dt').click(
	function () {
		if( $(this).hasClass('hover')) {
			$(this).addClass('active').removeClass('hover');
			$('div#contact dt.active + dd').slideDown();
			$(this).find('a').addClass('on');
		}
		else if ($(this).hasClass('active')) {
				$(this).addClass('hover').removeClass('active');
				$('div#contact dt.hover + dd').slideUp();
				$(this).find('a').removeClass('on');
		}
	}
);
//jquery ends here
});

