
var cacontent_selected = null;
var cacontent_active = null;
var cacontent_nameToIdMap = {};
var cacontent_idToPositionMap = {};
var cacontent_idToPositionMap_size = 0;
var caslider_offset = 1;
var caslider_height = 116;

/** seite aktivieren & anzeigen **/
function cisa_selPage(n)
{
	if ( !is_numeric(n) )
	{
		n = cacontent_nameToIdMap[n];	
	}
	cacontent_selected = n;
	cisa_showPage(n);
}

/** aktive seite anzeigen **/
function cisa_showSelectedPage()
{
	cisa_showPage(cacontent_selected);
}

/** seite anzeigen **/
function cisa_showPage(n)
{
	if ( n*1 == cacontent_active*1 )
	{
		return;
	}

	$('#caright > div.right > div.data').each(function(){
		if ( $(this).parent().attr('id') != n+"_right" )
		{
			$(this).fadeOut(400);
		}
	});
	var right = $('#'+n+'_right > div.data');
	right.fadeIn(400);
	var roheight = right.height();
	var rmheight = right.css('min-height').replace('px','');

	var oversize = roheight - rmheight;
	var calmh =  $('#caleft').css('min-height').replace('px','')*1;	

	$('#caleft').clearQueue().stop().animate({height:(calmh+oversize)+"px"},5,'linear');

	//$('#caleft > div.left').css('background-color','lightgrey');
	//$('#'+n+'_left').css('background-color','white');

	var pos = cacontent_idToPositionMap[n];

	$('#slider').clearQueue().stop().animate({top:(caslider_height*pos+caslider_offset)+"px",opacity:0.5},250, 'linear').animate({top:(caslider_height*pos+caslider_offset)+"px",opacity:1},250, 'linear');
	cacontent_active = n;

	var img = $('#'+n+' .imgright');
	if(img.size() > 0) {
		//alert("get " + img.html());
		imageSwapVFSloader('caright',img.html(),n);
	}
}

/** inhaltsliste initialisieren **/
function caMoveContents()
{

	var cal = $('#caleft');
	var car = $('#caright');
	var firstid = null;

	var pageUrlBase = window.location+'';
	var pageUrlBaseA = pageUrlBase.split('/');
	pageUrlBase = '/'+pageUrlBaseA[3]+'/'+pageUrlBaseA[4]+'/';

	$('div.cacontent').each(function() {
		var cacontent_id = $(this).attr('id');
		if ( firstid == null )
			firstid = cacontent_id;
		var left = $(this).find('div.left:first');
		var right = $(this).find('div.right:first'); 
		
		var titlelink = left.find('#NC_TITLELEFT_'+cacontent_id+'');

		var pageName = (titlelink.html()+"").toLowerCase()

		var curl = pageUrlBase+pageName.replace(/[^a-zA-Z]/g,'');

		cacontent_nameToIdMap[pageName.replace(/[^a-zA-Z]/g,'')] = cacontent_id;
		cacontent_idToPositionMap[cacontent_id] = cacontent_idToPositionMap_size++;
		
		titlelink.attr('href', curl);
		//alert($('#NC_IMGLEFT_'+cacontent_id).html());
		left.find('#'+cacontent_id+'_left_image').attr('src','/jwa/vfs'+$(this).find('#NC_IMGLEFT_'+cacontent_id).html());
		right.find('#'+cacontent_id+'_right_image').attr('src','/jwa/vfs'+$(this).find('#NC_IMGRIGHT_'+cacontent_id).html());

		cal.append(left);
		car.append(right);
		left.click(function (){
			cisa_selPage(cacontent_id);
		});
		left.mouseover(function (){
			cisa_showPage(cacontent_id);
		});
		/*left.mouseout(function (){
			cisa_showSelectedPage();
		});*/

	});
	if ( firstid != null && cacontent_selected == null) 
	{
		cisa_selPage(firstid);
	}	

}

function cisa_addthis()
{
	addthis.button([document.getElementById('adt_c')]);
}



function is_numeric(input){
    
    var RE = /^-{0,1}\d*\.{0,1}\d+$/;
    return (RE.test(input));

  }

var idcnt = 0;


$(document).ready(function() { 
 
    $('.fc_withdesc').each(function() {
        var popup_object_id = $(this).attr('id');
	$(this).append("<span class=\"descmore\"><a href=\"#"+popup_object_id+"\" id=\"open_"+popup_object_id+"\">mehr</a></span>");
	$('#open_'+popup_object_id).click(function (e){

		window.location = $(this).attr('href');

		//Cancel the link behavior
		e.preventDefault();
		//Get the A tag
		var id = '#dialog'; //$(this).attr('href');
	     
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	     
		if ( ! document.getElementById('mask') )
		{
			//alert('create mask '+document.getElementById('mask'));
			$('body').append("<div id=\"mask\"></div>");
			$('body').append('<div id="dialog" class="window"><div id="dialog_content" class="dc_frame"></div><br /><a href="#" class="close">schliessen</a></a>');

			//if close button is clicked
			    $('.window .close').click(function (e) {
				//Cancel the link behavior
				e.preventDefault();
				$('#mask, .window').hide();
			    });    
			     
			    //if mask is clicked
			    $('#mask').click(function () {
				$(this).hide();
				$('.window').hide();
			    }); 

		}

		$('#dialog_content').html($('#'+popup_object_id).html());

		


		//Set height and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		 
		//transition effect    
		$('#mask').fadeIn(1000);   
		$('#mask').fadeTo("slow",0.8); 
	     
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
		       
		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
	     
		//transition effect
		$(id).fadeIn(2000);
	});
    });

    //select all the a tag with name equal to modal
    $('.fc_withdesc').click(function(e) {

	/*
        //Cancel the link behavior
        e.preventDefault();
        //Get the A tag
        var id = '#dialog'; //$(this).attr('href');
     
        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();
     
	if ( ! document.getElementById('mask') )
	{
		//alert('create mask '+document.getElementById('mask'));
		$('body').append("<div id=\"mask\"></div>");
		$('body').append('<div id="dialog" class="window"><div id="dialog_content" class="dc_frame"></div><br /><a href="#" class="close">schliessen</a></a>');

		//if close button is clicked
		    $('.window .close').click(function (e) {
			//Cancel the link behavior
			e.preventDefault();
			$('#mask, .window').hide();
		    });    
		     
		    //if mask is clicked
		    $('#mask').click(function () {
			$(this).hide();
			$('.window').hide();
		    }); 

	}

	$('#dialog_content').html($(this).html());


        //Set height and width to mask to fill up the whole screen
        $('#mask').css({'width':maskWidth,'height':maskHeight});
         
        //transition effect    
        $('#mask').fadeIn(1000);   
        $('#mask').fadeTo("slow",0.8); 
     
        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();
               
        //Set the popup window to center
        $(id).css('top',  winH/2-$(id).height()/2);
        $(id).css('left', winW/2-$(id).width()/2);
     
        //transition effect
        $(id).fadeIn(2000);
	*/
     
    });
     
           
     
});









