var footerTopPos = 0;
var $j = jQuery.noConflict();

function init(){
	initNavigation();

	$j('.teaserBox').each(function(inIndex){
		$j(this).draggable();
		$j(this).css('cursor','move');
	});
	
	$j('#teaserFields > .csc-textpic').each(function(inIndex){
		$j(this).draggable();
		$j(this).css('cursor','move');
	});	
	/*window.onresize = function(){
		var theHeight = $(window).height() > $j(document).height()  ? $j(window).height() -30 : $j(document).height() -30;
		$j('#footer_special').css('top', (theHeight) + 'px');
		$j('#teaserFields').css('top', (theHeight-90) + 'px');
	};
	
	var theHeight = $(window).height() > $(document).height() ? $(window).height() -30: $(document).height() -30;
	$('#footer_special').css('top', (theHeight) + 'px');
	
	
	$('#teaserFields').css('top', (theHeight-90) + 'px');
	*/
	
	var theOffset = $j('#footer_special').offset();
	footerTopPos = theOffset.top;
	$j('#teaserFields').css('top', (footerTopPos-$j('#teaserFields').height()-10) + 'px');
	$j('#teaserFields').css('display', 'block');
	
	window.onresize = function(){
		
		var theOffset = $j('#footer_special').offset();
		footerTopPos = theOffset.top;
		 
		$j('#teaserFields').css('top', (footerTopPos-$j('#teaserFields').height()-10) + 'px');
	};
	
	initLightbox();
}

function initLightbox(){
	//lightbox Links
	$j("a.lightboxLink").each(function(i){
		$j(this).fancybox({ 
			'hideOnContentClick': true 
		})
	}); 

}

function initNavigation(){
	$j('#nav').css('left',$j('#wrap').offset().left + 10);
	$j('#nav').draggable();
	
	$j('#nav > ul.navigation > li').each(function(inIndex){
			if (inIndex == 0){
				if (!$j(this).hasClass('open') && !$j('#nav > ul.navigation > li.open').length){
					$j(this).children('ul').each(function(){
							$j(this).slideDown('slow');
						});
						$j(this).removeClass('close');
						$j(this).addClass('open');
				}
			}
			$j(this).children('a').each(function(inChildIndex){
				
				$j(this).click(function(){

					if ($j(this).parent().hasClass('open')){
						if (inIndex == 0 && $j('#nav > ul.navigation > li:last').hasClass('close')){
							$j('#nav > ul.navigation > li:last').children('ul').each(function(){
								$j(this).slideDown('slow');
							});
							$j('#nav > ul.navigation > li:last').removeClass('close');
							$j('#nav > ul.navigation > li:last').addClass('open');	
						}
						if (inIndex == 1 && $j('#nav > ul.navigation > li:first').hasClass('close')){
							$j('#nav > ul.navigation > li:first').children('ul').each(function(){
								$j(this).slideDown('slow');
							});
							$j('#nav > ul.navigation > li:first').removeClass('close');
							$j('#nav > ul.navigation > li:first').addClass('open');	
						}						
						
						$j(this).parent().children('ul').each(function(){
							$j(this).slideUp('slow');
						});
						$j(this).parent().removeClass('open');
						$j(this).parent().addClass('close');
					}else{
						if (inIndex == 0 && $j('#nav > ul.navigation > li:last').hasClass('open')){
							$j('#nav > ul.navigation > li:last').children('ul').each(function(){
								$j(this).slideUp('slow');
							});
							$j('#nav > ul.navigation > li:last').removeClass('open');
							$j('#nav > ul.navigation > li:last').addClass('close');	
						}
						if (inIndex == 1 && $j('#nav > ul.navigation > li:first').hasClass('open')){
							$j('#nav > ul.navigation > li:first').children('ul').each(function(){
								$j(this).slideUp('slow');
							});
							$j('#nav > ul.navigation > li:first').removeClass('open');
							$j('#nav > ul.navigation > li:first').addClass('close');	
						}	
						
						$j(this).parent().children('ul').each(function(){
							$j(this).slideDown('slow');
						});
						$j(this).parent().removeClass('close');
						$j(this).parent().addClass('open');
					}
				});
			});

		});
		
}



