/**
 * --------------------------------------------------------------------
 * jQuery-Plugin "preloadCssImages"
 * by Scott Jehl, scott@filamentgroup.com
 * http://www.filamentgroup.com
 * reference article: http://www.filamentgroup.com/lab/automated_image_preloading/
 * demo page: http://www.filamentgroup.com/examples/preloadImages/
 * 
 * Copyright (c) 2008 Filament Group, Inc
 * Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
 *
 * Version: 1.0, 31.05.2007
 * Changelog:
 * 	02.20.2008 initial Version 1.0
 * --------------------------------------------------------------------
 */
$.preloadCssImages = function(settings){
	//overrideable defaults
	settings = jQuery.extend({
		 imgDir: 'img'
	}, settings);

	//dump all the css rules into one string
	var sheets = document.styleSheets;
	var cssPile = '';
	for(var i = 0; i<sheets.length; i++){
		if(!$.browser.msie){
			var thisSheetRules = document.styleSheets[i].cssRules;
			for(var j = 0; j<thisSheetRules.length; j++){
				cssPile+= thisSheetRules[j].cssText;
			}
		}
		else {
			cssPile+= document.styleSheets[i].cssText;
		}
	}
	//parse string for image urls and load them into the DOM
	var allImgs = [];//new array for all the image urls  
	var imgUrls = cssPile.match(/[^\/]+\.(gif|jpg|jpeg|png)/g);//reg ex to get a string of between a "/" and a ".filename"
	if(imgUrls != null && imgUrls.length>0 && imgUrls != ''){//loop array
		var arr = jQuery.makeArray(imgUrls);//create array from regex obj	 
		$(arr).each(function(k){
			allImgs[k] = new Image(); //new img obj
			allImgs[k].src = settings.imgDir +'/'+ this;	
		});
	}
	return allImgs;
}
   
   
   
   
/**
 * --------------------------------------------------------------------
 * FoundationFinder
 * by trigonella & vollprecht gestaltung
 * 
 * Copyright (c) 2010 Filament 
 *
 * Version: 1.2, 28.05.2010
 * Changelog:
 * 	28.05.2010 initial Version 1.1
 * --------------------------------------------------------------------
 */   
   
  
var strLocation = window.location.href;
var intPosition = strLocation.indexOf("/dev/");
var strRoot = (intPosition==-1) ? "http://www.foundationfinder.ch" : "http://www.foundationfinder.ch/dev";

//var strRoot="http://www.foundationfinder.ch/dev";   
   

$('document').ready(function() { 
    
    // Preload cssImages  
    $.preloadCssImages();
    
	// FAQ
	$("h3.question").css("cursor", "pointer");
	$("h3.question").next("p").css("display", "none");
	
	$("h3.question").click(function(){    
        $(this).next("p").slideToggle("100", function() {
			var e = $(this);
			clearTimeout(e.attr("timer"));
			timer = setTimeout(function(){e.slideUp("100")}, 60000);
			e.attr("timer", timer)
		}); 
    });

	// Tipps
	$("p.info_item").append("<span><!-- --></span>");
	
    $("p.info_item").mouseenter(function(){
        hWindow=Math.round($(window).height()); 
        yItem=Math.round($(this).offset().top); 
        xItem=Math.round($(this).offset().left);   
        hInfo=Math.round($(this).next("div.info").height());
        wInfo=Math.round($(this).next("div.info").outerWidth()); 
        yInfo=yItem-Math.round((hInfo/4)); 
        yInfoSpan = yInfo+Math.round((hInfo/4)); 
        xInfo=xItem-wInfo-14; 
        
        if ((yInfo+hInfo)>((hWindow-10)+$(window).scrollTop())) {
          yInfo=hWindow-hInfo-25+$(window).scrollTop();
          if (yItem>(yInfo+hInfo)) {
            yInfoSpan = yInfo+hInfo;   
          } else {
            yInfoSpan = yItem;   
          }
        }
        
        if (xInfo<0) {
            xInfo=xItem+130; 
            $(this).next("div.info").find("span").css("background-image", "url("+strRoot+"/img/ffPointer-right.gif)");
            $(this).next("div.info").offset({top:yInfo, left:xInfo}); 
            $(this).next("div.info").find("span").offset({top:yInfoSpan, left:xInfo-9}); 
        } else {  
            $(this).next("div.info").find("span").css("background-image","url("+strRoot+"/img/ffPointer-left.gif)");
            $(this).next("div.info").offset({top:yInfo, left:xInfo}); 
            $(this).next("div.info").find("span").offset({top:yInfoSpan, left:xInfo+wInfo-1});  
        }
        $(this).next("div.info").css('display', 'none');  
        $(this).next("div.info").fadeIn("500");
    });
    
    $("p.info_item").mouseleave(function(){  
        $(this).next("div.info").offset({top:"0", left:"-2000"}); 
    });      
    
	$("div.info").prepend("<span><!-- --></span>");
	
	// Ergebnis
	$("div.ergebnis div.bar. div.prozent").each(function() {    
	   w = "+="+$(this).attr("prozent")+"%"; 
	   $(this).delay("100").animate({width: w}, 2500);
	});
	
});

function showTab(tabId, elm) {
	$("div.tab").removeClass("select");
	$("div#"+tabId).addClass("select");
	$("div.container_head dd").removeClass("select");
	$(elm).parent().addClass("select"); 
}    

