var aktElem = '';
var aktKat = '';

function showProject(_id,_image){

	loadDescription(_id,''+_image+'')
	$('#content').load('incl/incl_diashow.php?id='+_id, function() {
																 
		var cntImg = $('.image_wrapper img');
		
		
		// >1 Pic
		if(cntImg.length >= 2){
			$('.image_wrapper').cycle({
				fx: 'fade' ,// choose your transition type, ex: fade, scrollUp, shuffle, zoom,etc...
				containerResize: 1,
				speed:  300 ,
				timeout: 0,
				before:  function(currSlideElement, nextSlideElement, options, forwardFlag){
						
							if(! forwardFlag  && options.currSlide-1 == -1){
								$('#slideshow').cycle('destroy');
								if(aktKat == 'kunde'){
									showClients(aktElem);
								}
								else{
									showKat(aktKat,aktElem);
								}
							}
						
							if(forwardFlag  && options.currSlide+1 == options.slideCount){
								$('#slideshow').cycle('destroy');
								if(aktKat == 'kunde'){
									showClients(aktElem);
								}
								else{
									showKat(aktKat,aktElem);
								}
							}
					},
				after:  function(currSlideElement, nextSlideElement, options, forwardFlag){ 
						//alert('after')
							setDescription(nextSlideElement.offsetWidth);
							loadDescription(_id,''+this.name+'')
							$('#dianav').html((options.currSlide+1) +"/"+ options.slideCount);				
						}
			});	
			
			$(".image_wrapper img").mousemove(function(e){
							var imgWidth =  parseInt(($(this).css('width')));	
							var offset = 0;
							var x = e.pageX -180 ;
							var y = e.pageY -20
							jQuery("#leftRight").css({top:  y +10 , left: x });
							
							if(x > imgWidth/2){
								jQuery("#leftRight").html('<img src="img/rechts.gif">')
								$('.image_wrapper img').css('cursor','none');
							}
							else{
								jQuery("#leftRight").html('<img src="img/links.gif">')
								$('.image_wrapper img').css('cursor','none');
							}

      		}); 
			
			$(".image_wrapper img").click(function(e){
							var imgWidth =  parseInt(($(this).css('width')));	
							var x = e.pageX -170 ;
							if(x > imgWidth/2){
								$('.image_wrapper').cycle('next');
							}
							else{
								$('.image_wrapper').cycle('prev');
							}

      		}); 
		}
		
		else{
			setDescription(cntImg[0].offsetWidth);
			$('#dianav').html("1/1");
			$('.image_wrapper img').click(function() {
  				//showKat(aktKat,aktElem);
				if(aktKat == 'kunde'){
					showClients(aktElem);
				}
				else{
					showKat(aktKat,aktElem);
				}
			});
		}
	    
	});
	
	
	
}


function loadDescription(_id,_image){
	$('.description').load('incl/incl_description.php?id='+_id+'&image='+_image, function() {
					$('.description').show();
	});
}


function showKat(_id,_elem){
	closeVid();
	
	if(! _id || _id == 'new'){
		$('#suche').hide();	
	}
	
	$('#kontakt').hide();
	aktKat = _id;
	if(aktElem){
		$(aktElem).removeClass('active');
	}
	$(_elem).addClass('active');
	aktElem = _elem;
	$('.description').hide();
	$('.image_wrapper').cycle('stop');
	$('#content').load('incl/incl_thumbs.php?id='+_id, function() {
		
	});
}


function showClientProjects(_id){
	
	$('.description').hide();
	$('.image_wrapper').cycle('stop');
	$('#content').load('incl/incl_clientthumbs.php?id='+_id, function() {
		
	});
}


function showClients(_elem,_cat_id){
	closeVid();
	$('#kontakt').hide();
	$('#suche').hide();
	aktKat = 'kunde';
	if(aktElem){
		$(aktElem).removeClass('active');
	}
	$(_elem).addClass('active');
	aktElem = _elem;
	
	$('.description').hide();
	$('.image_wrapper').cycle('stop');
	
	$('#content').load('incl/incl_clients.php?cat_id='+_cat_id, function() {

	});
}


function showContact(_elem){
	closeVid();
	$('#suche').hide();
        $('#downloads').hide();
	$('#kontakt').toggle();
}

function showDownloads(_elem){
	closeVid();
	$('#suche').hide();
        $('#kontakt').hide();
	$('#downloads').toggle();
}



function showNews(_elem){
	closeVid();
	$('#content').load('incl/incl_news.php', function() {

	});
}

function setDescription(_offset){
	//alert($('#dianav').css('width'));
	$('#dianav').animate({
			left: _offset - 35
		}, 0, function() {
			// Animation complete.
		}
	);
	
	var startpos = parseInt($('#content').css("left"));
	var imagewidth = _offset;
	var target = startpos + imagewidth +10 +"px";
	
	$('.description').animate({
			left: target
		}, 0, function() {
			// Animation complete.
		}
	);
}


var temphtml = '';
function openVid(_in){
	$("#content").hide();
	$("#contentvid").show();
	$('#contentvid').load('incl/incl_video.php?id='+_in, function() {
		//alert(_in);
	});
}

function closeVid(){
	$("#contentvid").html('');
	$("#contentvid").hide();
	$("#content").show();
}

