//<--- callbacks definieren
	var bwCallback="false";

//Portfolio Element aufrufen aus Flash
    function openLink(linkname) {
		if (linkname=='thundra'){linkname='type'}
		else if (linkname=='island'){linkname='illustration'}
		else if (linkname=='snow'){linkname='screendesign'};
		var complete_url = 'http://scramlings.de/incredibul/blog/wp-content/themes/incredibul/portfolio/portfolio.php?linkname='+linkname;
		$('#portfolio-content').load(complete_url, function(){
		$("#portfolio-content").slideToggle("normal", function () {
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: $('#bottomofall').offset().top}, 1100 );
		});
	});
	};
		
    function openGallery(projekt_id, category) {
		killGal();
		$('#pf-replace').load('http://scramlings.de/incredibul/blog/wp-content/themes/incredibul/portfolio/gallery.php?projekt_id='+projekt_id+'&category='+category+'&backswitch=false');
		pollGal();
	};
	
	function controlLink(linkname) {
		  if (document.getElementById('pf-slideshow'))
		      $("div#pf-slideshow").jump(linkname);
			};
		
	function closeLink(linkname) {
		$("#pf-slideshow").css("visibility","hidden");
		$("#portfolio-content").slideToggle("normal");
		};

//Hintergrundaustausch für die Flash Datei
    function bg_base() {
          newImage = "url(http://scramlings.de/incredibul/blog/wp-content/themes/incredibul/backgrounds/bg_base.gif)";
          document.getElementById('bottombackground').style.backgroundImage = newImage;
		  };
 
    
    function bg_island() {
          newImage = "url(http://scramlings.de/incredibul/blog/wp-content/themes/incredibul/backgrounds/bg_island.gif)";
          document.getElementById('bottombackground').style.backgroundImage = newImage;
		};
        
    function bg_thundra() {
          newImage = "url(http://scramlings.de/incredibul/blog/wp-content/themes/incredibul/backgrounds/bg_plane.gif)";
          document.getElementById('bottombackground').style.backgroundImage = newImage;
		};
        
 
    function bg_snow() {
          newImage = "url(http://scramlings.de/incredibul/blog/wp-content/themes/incredibul/backgrounds/bg_snow.gif)";
          document.getElementById('bottombackground').style.backgroundImage = newImage;
		};

	
//Instant sIFR for dynamically loaded content	
	function do_sIFR(){
		sIFR.replace(incredibulfont, {
		  selector: 'h2',
		css: [
			 'a { color: #ff3333;}',
			 'a { text-decoration:none;}',
			 'a:link { color: #333333; background:#ffffff}',
			 'a:hover { color: #FF2288; }'  
		 ],
		transparent: 'true'
		});

		sIFR.replace(incredibulfont, {
		  selector: 'h3',
		css: [
		'.sIFR-root { color: #FF2288;}',
			'a { color: #333333;}',
			 'a { text-decoration:none;}',
			 'a:link { color: #333333; background:#ffffff}',
			 'a:hover { color: #FF2288; }' 
		 ],
		transparent: 'true'
		});

		sIFR.replace(incredibulfont, {
		  selector: 'h4',
		css: [
			'.sIFR-root { color: #333333;}'
		 ],
		transparent: 'true'
		});
	};


/*

	***	Anchor Slider by Cedric Dugas   ***
	*** Http://www.position-absolute.com ***
	
	You can use and modify this script for any project you want, but please leave this comment as credit.
	
	Never have an anchor jumping your content, slide it.
	
	Just add the class anchor at your <a> tag and it will slide, user with no javascript will 
	still go to destination with the normal html anchor

	Don't forget to put an id to your anchor !
*/
		
$(document).ready(function() {
	anchor.init()
});

anchor = {
	init : function()  {
		$("a.anchorLink").click(function () {	
			elementClick = $(this).attr("href")
			destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100 );
		  	return false
		})
	}
};

 
//JQUERY SLIDE
jQuery(function(){
   jQuery("div.svw").prepend("<img src='images/spinner.gif' class='ldrgif' alt='loading...'/ >"); 
   });
   
var j = 0;
var quantofamo = 0;
jQuery.fn.slideView = function(settings) {
	settings = jQuery.extend({
    easeFunc: "easeInOutExpo",
    easeTime: 750,
    toolTip: false
  }, settings);


	var container = jQuery(this);
	container.find("img.ldrgif").remove(); // removes the preloader gif
	container.removeClass("svw").addClass("stripViewer");		
	var pictEls = container.find("li").size();
	var imageArray = [];
	container.find('img').each(function() { 
		imageArray.push( $(this).attr('src'));
	});

	var gotime = imageArray.length;
	$("#pf-slideshow").css("visibility","hidden");
	$.each(imageArray,function(e) {
		$(new Image()).load(function() {
			if (--gotime < 1) 	preloaded();
		}).attr('src',this);
	});
	do_sIFR();
	
	function preloaded(){
		$("#pf-slideshow").css("visibility","visible");
		var pictWidth = container.find("img").width();
		var pictHeight = container.find("img").height();
		var stripViewerWidth = pictWidth*pictEls;
		container.find("ul").css("width" , stripViewerWidth); //assegnamo la larghezza alla lista UL	
		container.css("width" , pictWidth);
		container.css("height" , pictHeight);
		

		
		container.each(function(i) {
			jQuery(this).after("<div class='stripTransmitter' id='stripTransmitter" + (j) + "'><ul><\/ul><\/div>");
			jQuery(this).find("li").each(function(n) {
						jQuery("div#stripTransmitter" + j + " ul").append("<li><a title='" + jQuery(this).find("img").attr("alt") + "' href='#'>"+(n+1)+"<\/a><\/li>");												
				});
				
			jQuery("div#stripTransmitter" + j + " a").each(function(z) {
				jQuery(this).bind("click", function(){
				jQuery(this).addClass("current").parent().parent().find("a").not(jQuery(this)).removeClass("current"); // wow!
				var cnt = -(pictWidth*z);
				container.find("ul").animate({ left: cnt}, settings.easeTime, settings.easeFunc);
				return false;
				   });
				});

			// next image via image click	14/01/2009
			jQuery("div#stripTransmitter" + j + " a").parent().parent().parent().prev().find("img").each(function(z) {
				jQuery(this).bind("click", function(){
					var ui 	= 	jQuery(this).parent().parent().parent().next().find("a");
					if(z+1 < pictEls){
						ui.eq(z+1).trigger("click");
					}
					else ui.eq(0).trigger("click");
					});
				});
				

				// jump it
				jQuery.fn.jump = function(linkname){
						
						var listitemtotal = $("li").size();
						var item = $("a.current").parent()[0];
						var position = $("li").index( item )-listitemtotal+pictEls; 
						var ui2	= jQuery(this).next().find("a");
						
						var menuui	= jQuery("ul.projektliste").find("a");
						var menutotal = $(menuui).size();
						
						var menuitem = $("a.currentMenu")[0];
						var menuPosition = $("ul.projektliste a").index(menuitem);
						
						//Wenns vorwärts geht:
						if (linkname=="forward"){
						
							if(position+1 < pictEls){
								ui2.eq(position+1).trigger("click");
							}
							else if (position+1 == pictEls) {
								
								if (menuPosition+1 < menutotal){
									menuui.eq(menuPosition+1).trigger("click");
									var menuID = menuui.eq(menuPosition+1).attr('href');} 
								else if (menuPosition+1 == menutotal){
									menuui.eq(0).trigger("click");
									var menuID = menuui.eq(0).attr('href');}
								
									//Das hier splittet mir die Links... und holt sich nur die Attribute raus.
									var werte = menuID.replace(/javascript:(.+)\((.+)\)/,'$2').split(',');
									var gallItem = new String(eval(werte[0]));
									var gallGroup = new String(eval(werte[1]));
									openGallery(gallItem, gallGroup);
									$("html:not(:animated),body:not(:animated)").animate({ scrollTop: $('#bottomofall').offset().top}, 1100 );
							};

						}
						
						//und für die andere Richtung:						
						else if (linkname=="backward"){
												
							if(position-1 > -1){
								ui2.eq(position-1).trigger("click");
							}
							else if (position-1 == -1) {
								
								if (menuPosition-1 > -1){
									menuui.eq(menuPosition-1).trigger("click");
									var menuID = menuui.eq(menuPosition-1).attr('href');
									
								} 
								else if (menuPosition-1 == -1){
									menuui.eq(menutotal-1).trigger("click");
									var menuID = menuui.eq(menutotal-1).attr('href');}
								
									var werte = menuID.replace(/javascript:(.+)\((.+)\)/,'$2').split(',');
									var gallItem = new String(eval(werte[0]));
									var gallGroup = new String(eval(werte[1]));
									killGal();
									$('#pf-replace').load('http://scramlings.de/incredibul/blog/wp-content/themes/incredibul/portfolio/gallery.php?projekt_id='+gallItem+'&category='+gallGroup+'&backswitch=true');
									pollGal();
									$("html:not(:animated),body:not(:animated)").animate({ scrollTop: $('#bottomofall').offset().top}, 1100 );
									//ui2.eq(pictEls-1).trigger("click");
							};
						}
						//...und für die info
							else if (linkname=="info"){
							$(".hover").fadeToggle();
							};
					};
				//jump end
			jQuery("div#stripTransmitter" + j).css("width" , pictWidth);
			
			if (bwCallback=="false"){
				jQuery("div#stripTransmitter" + j + " a:first").addClass("current");
			}
			//backwards
			
			else if (bwCallback=="true"){
				//alert(stripViewerWidth-pictWidth);
				jQuery("div#pf-slideshow").find("ul").css("left",(stripViewerWidth-pictWidth)*-1);
				jQuery("div#stripTransmitter" + j + " a:last").trigger("click");
				bwCallback="false";
			};
			
			
			if(settings.toolTip){
			container.next(".stripTransmitter ul").find("a").Tooltip({
				track: true,
				delay: 0,
				showURL: false,
				showBody: false
				});
			};

			
					
			
			});
		j++;
			};

};

//SLIDESHOW FUNCTIONS

		function pollGal(){
		  if(document.getElementById('pf-slideshow'))
		     $("div#pf-slideshow").slideView();
		  else
		      setTimeout('pollGal()', 300);
		};

	
		function killGal(){
    		  if(document.getElementById('pf-slideshow'))
		      document.getElementById('pf-slideshow').id='';
		      };
		  
//hover function
function hider(){	
	
$(document).ready(function(){

    $('.hover').hide();


    $('.pf-content').bind('mouseenter', (function (){
        $('.hover').fadeIn('slow');
    }));

  
    $('.pf-content').bind('mouseleave', (function (){
        $('.hover').fadeOut('slow');
    }));
   $(".blogroll a").favoriteIcon({ iconClass : 'favoriteIcon' });
}); 

	};

//active Menuitem
function highlightCurrentMenu(){
	
	jQuery("ul.projektliste a").each(function(x) {
				jQuery(this).bind("click", function(){
					jQuery(this).addClass("currentMenu").parent().parent().find("a").not(jQuery(this)).removeClass("currentMenu"); // Die Zeile zaubert. Gibt aktivem Menueitem die Klasse currentMenu
				});
			});			
			};	


//function to toggle fade
jQuery.fn.fadeToggle = function(speed, easing, callback) {
   return this.animate({opacity: 'toggle'}, speed, easing, callback);
}; 			


/* FavoriteIcon v1.1 - 5 May 09 (http://blog.liviuholhos.com/javascript/add-a-favicon-near-external-links-with-jquery)
 * Author : Liviu Holhos (http://www.liviuholhos.com/) */
(function($){
	$.fn.favoriteIcon = function(options) {
		var defaults = {
			iconClass    : 'favoriteIcon',
			insertMethod : 'prependTo',
			iconSearched : 'favicon.ico'
		};
		var options = $.extend(defaults, options);
	
		$(this).filter(function(){
			return this.hostname && this.hostname !== location.hostname;
		}).each(function() {
			var link = jQuery(this);
			var faviconURL = link.attr('href').replace(/^(http:\/\/[^\/]+).*$/, '$1')+'/'+options.iconSearched;
			var faviconIMG = jQuery('<img class="'+options.iconClass+'" src="" alt="" />')[options.insertMethod](link);
			var extImg = new Image();
			extImg.src = faviconURL;
			if (extImg.complete)
				faviconIMG.attr('src', faviconURL);
			else
				extImg.onload = function() { faviconIMG.attr('src', faviconURL); };
		});
	}
})(jQuery);
