// JavaScript Document

$(function(){
	
	$('.nivoSlider').nivoSlider({
        effect: 'fade', // Specify sets like: 'fold,fade,sliceDown'
        slices: 15, // For slice animations
        boxCols: 8, // For box animations
        boxRows: 4, // For box animations
        animSpeed: 500, // Slide transition speed
        pauseTime: 7000, // How long each slide will show
        startSlide: 0, // Set starting Slide (0 index)
        directionNav: false, // Next and Prev navigation
        directionNavHide: false, // Only show on hover
		captionOpacity: 0, // Universal caption opacity
        controlNav: false, // 1,2,3... navigation
        controlNavThumbs: false, // Use thumbnails for Control Nav
        controlNavThumbsFromRel: false, // Use image rel for thumbs
        keyboardNav: true, // Use left and right arrows
        pauseOnHover: true // Stop animation while hovering
        
    });
	
	//sliderHomeStart
	
	if($('#sliderBox .slide ul').length != 0) sliderHome($('#sliderBox'));
	else {//$('#sliderBox').remove();
	}
	
	//GoogleMap einbinden
	if($('#googleMap').length > 0) {
		gMap();	
	}
	
	//Partner, Referenzen
	
	$('.referenz img, .referenz h2').click(function(){
		$(this).parent().find('.hiddentext').slideToggle(200);
			
	})
	$('.partner img, .partner h2').click(function(){
		$(this).parent().find('.hiddentext').slideToggle(200);
			
	})
	
	$('.spoilermore').click(function(){
		
		$(this).fadeOut(200, function(){
			$(this).next().slideDown(300);
			$(this).remove();
		})
		return false;
	})
	
	//Refernenzen
	
	$('#refselect').change(function(){
		
	var a = $(this).val();
	if (a=="") {
		$('.referenz').fadeIn(300);
	}
	else {
		$('.referenz:not(.'+a+')').fadeOut(200);
		$('.'+a).fadeIn(300);	
	}
	return false;		
	})
	

})

function gMap(){
	
var myOptions = {
      zoom: 14,
      center: new google.maps.LatLng(51.05222, 13.7250),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById("googleMap"),
                                  myOptions);

    var image = '/gmapIcon.png';
	var contentString = '<b>CSS GmbH Dresden</b><br>Behringstra&szlig;e 45,01159 Dresden</font>';
	
	var infowindow = new google.maps.InfoWindow({
        content: contentString
    });
	
    var myLatLng = new google.maps.LatLng(51.05129, 13.7127);
    var marker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        icon: image
    });
	
	google.maps.event.addListener(marker, 'click', function() {
      infowindow.open(map,marker);
    });

  }


function sliderHome(x){
	
	
		$('.slide ul').roundabout({
			minOpacity: 0.2,
         	tilt: -5
		 });
		 
		 $('#sliderContent .slide').css('display','none');
		 $('#sliderContent .slide:first').css('display','block');
		 $('#sliderBox .menu li:first a').addClass('current');
		 $('#sliderContent').css('visibility','visible');
	
		x.find('.menu li a').click(function(){
			x.find('.menu li a').removeClass('current');
			var ref = $(this).parent().attr('class');
			var ref1 = ref.replace(/cat-item cat-item-/g, "");
			$(this).addClass('current');
			$('#sliderContent .slide').fadeOut(300);
			$('#sliderContent #p_'+ref1).stop().fadeIn(300);	
			return false;
			
		})
		//JS BUG Roundabout
		lightBoxINIT();
	
}

function lightBoxINIT(){
		$('.lightbox').click(function(){
			if($(this).parent().hasClass('onair') || $(this).parent().hasClass('roundabout-in-focus')){
				var id= $(this).attr('id');
				openLightBox(id);
				return false;	
			}
			else{
				$('.slide ul li').removeClass('onair')
				$(this).parent().addClass('onair');
			}
		});
	};
	
	
function openLightBox(id){
		$('body').append('<div id="overlay"></div><div id="info"></div>')
		
		//HIER AJAX
		var title = $('#post_'+ id + ' p.title').html();
		//var content = $('#post_' + id + ' .content').html();
		var content ="";
		
		
		
		
		gotoNews(id);
		
		$('#overlay').fadeTo(500, 0.8);
		$('#info').fadeIn(600);
		
		$('#overlay').click(function(){
			$('#overlay, #info').fadeOut(200,function(){
				$('#overlay, #info').remove();
			});
		})
		return false;
}


function gotoNews(x){
		$('#info').html('<img class="ajaxload" src="'+blog_path+'/images/ajax-loader.gif" />')
		$.get(blog_path+'/ajax.php?param='+x, function (data){ 
                content =  data;         
				$('#info').html('<a href="#" class="closeThis">x</a>' + content);
				
				
				 $('#info .closeThis').unbind('click').click(function(){
					$('#overlay, #info').fadeOut(200,function(){
				$('#overlay, #info').remove();
				});	 
				})
				
				
				$('a.prev, a.next').unbind('click').click(function(){
				var x = $(this).attr('rel');
				gotoNews(x);
				return false;	
			})
		})
		return false;
};
	
	


	

