// Firebug Console Debugging
if (! ('console' in window) || !('firebug' in console)) {  
    var names = ['log', 'debug', 'info', 'warn', 'error', 'assert', 'dir', 'dirxml', 'group', 'groupEnd', 'time', 'timeEnd', 'count', 'trace', 'profile', 'profileEnd'];  
    window.console = {};  
    for (var i = 0; i < names.length; ++i) window.console[names[i]] = function() {};  
}

function oeffnefenster (url) {
	fenster = window.open(url, "fenster1", 		"width=730,height=630,status=yes,scrollbars=yes,resizable=yes");
	fenster.focus();
}
function flvplay(flv_file,flv_thumb) {
	$('#slideshow').removeClass('show');
	$('#slideshow').addClass('hide');
	$('#player').removeClass('hide');
	$('#player').addClass('show');
	var s1 = new SWFObject('swf/mediaplayer/player.swf','ply','550','380','9','#');
	s1.addParam('allowfullscreen','true');
	s1.addParam('allowscriptaccess','always');
	s1.addParam('wmode','opaque');
	s1.addParam('flashvars','image=images/produktdarstellung/'+flv_thumb +'&file=http://new.p-ad.de/2009/images/produktdarstellung/'+ flv_file +'&skin=http://new.p-ad.de/2009/swf/mediaplayer/overlay.swf&frontcolor=E5F4A7&lightcolor=cc9900&stretching=fill&controlbar=none&autostart=true');
	
	s1.write('player');
}

function show_slideshow(){
		$('#player').addClass('hide');
		$('#player').removeClass('show');
		$('#slideshow').removeClass('hide');
		$('#slideshow').addClass('show');
}

function onBefore() { 
	/*
	// Navigation stylen
    //$('#element_nav li a').removeClass('active'); 
    //$('#element_nav li a[rel="'+this.name+'"]').addClass('active'); 
	// Texte setzen
	console.log ('aktueller ankertext: '+$('#element_nav li a[rel="'+this.name+'"]').text());
	$('#element_head').text($('#element_nav li a[rel="'+this.name+'"]').text());
	$('#element_text').addClass($('#element_nav li a[rel="'+this.name+'"]')); 
	*/
} 

/*
	Auf der Kundendetailseite werden Projekte mit passenden Bildern angezeigt.
	Falls es zu den Bildern weitere Textinformationen gibt, so werden diese über
	das Bild gelegt
*/
function showImageDetails() { 
	console.log ('aktuelles Slide: '+this.name);
	id = this.name;
	//$('#'+id).hide(3000).slideDown();
}


function onPagerClick() {
	$('#slideshow').cycle('pause');

		// Navigation stylen
    $('#element_nav li a').removeClass('active'); 
    $('#element_nav li a[rel="'+this.name+'"]').addClass('active'); 
	$('#element_head').text($('#element_nav li a[rel="'+this.name+'"]').text());
	$('#element_text').addClass($('#element_nav li a[rel="'+this.name+'"]')); 
}





function carousel_itemVisibleInCallback(carousel, item, i, state, evt) {
	var idx = carousel.index(i, carousel_itemList.length);
	// Nur Elements einfügen, wenn mehr Elemente vorhanden sind, als sichtbar.
	if ( carousel_itemList.length <= carousel.options.visible) {
		carousel.options.visible = carousel_itemList.length;
		carousel.locked = true;
		carousel.add(i, carousel_getItemHTML(carousel_itemList[idx - 1]));
	}
	else {
		carousel.add(i, carousel_getItemHTML(carousel_itemList[idx - 1]));
	}
};
function carousel_itemVisibleOutCallback(carousel, item, i, state, evt) {
    carousel.remove(i);
};
function carousel_getItemHTML(item) {
	if (menu == 'portfolio')
		return '<a href="index.php?menu='+menu+'&page='+page+'&projects='+item.id+'" rel="'+item.id+'">'+item.name+'</a>';
	if (menu == 'kunden')
		return '<a href="index.php?menu='+menu+'&page='+page+'&client='+item.id+'" rel="'+item.id+'">'+item.name+'</a>';
};
function dotheajax(id) {
	console.info('Ajax Call Kunde '+id);
	$.ajax({	type: 'GET',
				dataType: 'json',
				url:'ajax.php?kunde=true&client='+id,
	       		success: function(data){
	    			console.log(data.client);
					$('.clientindex').find('#element_head').html(data.client);
					$('.clientindex').find('#element_text').html(data.text);
					$('.clientindex').find('#slideshow img').attr('src',data.image);
				}
	});
}

	/* Andree möchte wissen wie spät es ist 
	$(function($) {
	 var options = {
        timeNotation: '24h',
      }
      $('.jclock').jclock(options);
    });*/




// Load jQuery functions, if DOM is ready
$(document).ready( function(){
	
	/* Fancybox für Anfahrtskarte */
	
	$("a#maps").fancybox({
				'frameWidth': 640, 
				'frameHeight': 480
	});

	 $("a.group").fancybox();	
	
	/* Fancy für News */
	/*
	$("a.news").fancybox({
	
				'frameWidth': 550,
				'overlayShow': true,
				'overlayOpacity': 0.6,
				'imageScale': true
	});
	*/
	
	/* Fancy für Anzeige */
	/*
	$("a.news_anzeige").fancybox({
				'frameWidth': 200,
				'frameHeight': 640,	
				'overlayShow': true,
				'overlayOpacity': 0.6,
				'imageScale': true	
	});
	*/
	
	$("ul.thumb li").hover(function() {
	$(this).css({'z-index' : '10'}); /*Add a higher z-index value so this image stays on top*/ 
	$(this).find('img').addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
		.animate({
			marginTop: '-80px', /* The next 4 lines will vertically align this image */ 
			marginLeft: '-95px',
			top: '50%',
			left: '50%',
			width: '154px', /* Set new width */
			height: '60px', /* Set new height */
			padding: '20px'
		}, 200); /* this value of "200" is the speed of how fast/slow this hover animates */

	} , function() {
	$(this).css({'z-index' : '0'}); /* Set z-index back to 0 */
	$(this).find('img').removeClass("hover").stop()  /* Remove the "hover" class , then stop animation queue buildup*/
		.animate({
			marginTop: '0', /* Set alignment back to default */
			marginLeft: '0',
			top: '0',
			left: '0',
			width: '90px', /* Set width back to default */
			height: '35px', /* Set height back to default */
			padding: '5px'
		}, 400);
});

	


	/* Karussell für die Portfolio Liste */
	if(typeof carousel_itemList != "undefined")
		jQuery('#portfolio_data').jcarousel({
			size: carousel_itemList.length,
			vertical: true,
			visible: 3,
			animation: 200,
			easing: null,
			wrap: 'circular',
			itemVisibleInCallback: {onBeforeAnimation: carousel_itemVisibleInCallback},
			itemVisibleOutCallback: {onAfterAnimation: carousel_itemVisibleOutCallback}
		});
	
	/* Karussell für die Kunden Liste */
	if(typeof carousel_itemList != "undefined")
		jQuery('.kunden').jcarousel({
			size: carousel_itemList.length,
			vertical: true,
			visible: 9,
			scroll: 9,
			animation: 200,
			easing: null,
			wrap: 'circular',
			itemVisibleInCallback: {onBeforeAnimation: carousel_itemVisibleInCallback},
			itemVisibleOutCallback: {onAfterAnimation: carousel_itemVisibleOutCallback}
		});



	/*
		Beim hovern der Subnavi auf der Kundenseite die Kundeninfos via AJAX laden
		live, damit das auch für generierte Elemente gilt
	*/
	$('.clientindex').find('#element_nav a').live('mouseover', function(){
		dotheajax($(this).attr('rel'));
	});

	
	$("#1, #2, #3").lavaLamp({
                		fx: "backout", 
                		speed: 700,
                		click: function(event, menuItem) {
                    		return false;
                		}
            		});
	
	/*
		Wenn ein Ajax Call durch jQuery gestartet wird, wird eine Meldung ausgegeben
	*/
	$('.clientindex').find('#slideshow').ajaxStart(function(){
   		console.log('Ajax Request gestartet');
		//$(this).text("Laden").show();
 	});

	/*
		Wenn ein Ajax Call beendet wurde, wird das AJAX Meldungsfenster ausgeblendet
	*/
	$('.clientindex').find('#slideshow').ajaxStop(function(){
		console.log('Ajax Request beendet');
		//$(this).fadeOut('slow');
	});

	
	

	$('.clientdetails').find('#slideshow img:first').fadeIn(2000);
	$('.clientdetails').find('#slideshow').cycle({
		//	fx:     'shuffle',
			fx: 	'fade',
	    	easing: 'backout',
	    	delay:  -40000,
			timeout:0, 
		//	before: onBefore, 
			after:  showImageDetails,
			pause: 	true, 
			pager:  '#element_nav',
			pagerClick: onPagerClick, 
			pagerAnchorBuilder: function(idx, slide) { 
			        // return selector string for existing anchor 
					return '#element_nav li:eq(' + idx + ') a'; 
				}
				
		});
	

	$('.clientdetails').find('.kunden_thumbs li a[class!=foo activeSlide]').css('opacity','0.7');
	$('.clientdetails').find('.kunden_thumbs li a[class!=foo activeSlide]').hover(	
		function(){
			$(this).animate({
				opacity: 1.0
			}, 200 );
		},
		function() {
			$(this).animate({
				opacity: 0.7
			}, 200 );
		}
	);
	
	$('.clientdetails').find('.kunden_thumbs li a').hover(	
		function(){
		    console.log($(this).attr('class'));
			if ($(this).attr('class') == 'foo activeSlide') {
				id = $(this).attr('rel');
            	$('#'+id).slideDown();
			}
		},
		function(){
            if ($(this).attr('class') == 'foo activeSlide') {
				id = $(this).attr('rel');
            	$('#'+id).slideUp();
			}
		}
	);
	
	/*
		Startseite Sneak News
	*/
	
	$('#sneak_news').cycle({ 
		timeout: 6000,
	    delay: 1000,
	    speed: 1000,
		before: function(currSlideElement, nextSlideElement, options, forwardFlag) { 
							sCurrNewsID = $(nextSlideElement).attr('class');
							aCurrNewsIDClasses = sCurrNewsID.split(' ');
							for (i = 0; i < aCurrNewsIDClasses.length; i++) {
								$('#cleft .news p').removeClass('focus');
								$('#cleft .news p.'+aCurrNewsIDClasses[i]).addClass('focus');
							}
				}
	});
	
	
/* Weihnachtsbotschaft */
	
	$('#sneak_xmas').cycle({ 
		timeout: 3000,
	    delay: 500,
	    speed: 1000,
	    pause: true,
		before: function(currSlideElement, nextSlideElement, options, forwardFlag) { 
							sCurrNewsID = $(nextSlideElement).attr('class');
							aCurrNewsIDClasses = sCurrNewsID.split(' ');
							
				}
	});
	
	
	    


});

	
