/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
(function ($) {
    $(function() {
            //run the currently selected effect
            function runEffect(){
                    //get effect type from 
                    var selectedEffect = 'highlight';

                    //most effect types need no options passed by default
                    var options = {};
                    //check if it's scale, transfer, or size - they need options explicitly set
                    if(selectedEffect == 'scale'){  options = {percent: 0}; }
                    else if(selectedEffect == 'size'){ options = { to: {width: 200,height: 60} }; }

                    //run the effect
                    $("#uberblick").toggle(selectedEffect,options,500);
                    $("#uberblick-schatten").toggle("blind",options,500);
                    if(document.all || $.browser.opera) { 
                            $("#uberblick-video").toggle("blind",options,500);
                    } else {
                    $("#uberblick-video").toggle(selectedEffect,options,500);
                    }
            };

            //set effect from select menu value
            $("#kampagne-button").click(function() {
                    //runEffect();
                    return false;
            });
    });


    $(function() {
            //run the currently selected effect
            function runEffect(){
                    //get effect type from 
                    var selectedEffect = 'blind';

                    //most effect types need no options passed by default
                    var options = {direction:'horizontal'};
                    //check if it's scale, transfer, or size - they need options explicitly set
                    if(selectedEffect == 'scale'){  options = {percent: 0}; }
                    else if(selectedEffect == 'size'){ options = { to: {width: 200,height: 60} }; }

                    //run the effect
                    $("#like-bar.home").toggle(selectedEffect,options,2000);
            };
            $(".home-teilen-button").click(function() {
                    if($('#likelbar-home').attr("style")){
                        $('#likelbar-home').attr("style","");
                    } else {
                        $('#likelbar-home').attr("style","border:1px solid #000; height: 28px;");
                    }
                    runEffect();
                    return false;
            });
    });



    $(function() {
            //run the currently selected effect
            function runEffect(){
                    //get effect type from 
                    var selectedEffect = 'drop';

                    //most effect types need no options passed by default
                    var options = {};
                    //check if it's scale, transfer, or size - they need options explicitly set
                    if(selectedEffect == 'scale'){  options = {percent: 0}; }
                    else if(selectedEffect == 'size'){ options = { to: {width: 200,height: 60} }; }

                    //run the effect
                    $("#effect").toggle(selectedEffect,options,500);
            };

            //set effect from select menu value
            $("#kostenlos-button").click(function() {
                    runEffect();
                    return false;
            });
    });

    $(function() {
            //run the currently selected effect
            function runEffect(){
                    //get effect type from 
                    var selectedEffect = 'blind';

                    //most effect types need no options passed by default
                    var options = {};
                    //check if it's scale, transfer, or size - they need options explicitly set
                    if(selectedEffect == 'scale'){  options = {percent: 0}; }
                    else if(selectedEffect == 'size'){ options = { to: {width: 200,height: 60} }; }

                    //run the effect
                    $("#spendenformular-box").toggle(selectedEffect,options,2000);
                    $("#seitenschieber").toggle(selectedEffect,options,2000);
            };

            $('a').click(function() {
                loadDonationFrame($(this).attr('href'));
            });

            loadDonationFrame(document.location.hash);
            
            function loadDonationFrame(link) {
                if(link.match(/.*(#spende).*/) && $("html").hasClass("mobile")){
                    self.location.href='/spende/frame_mobile';
                }else if(link.match(/.*(#spende).*/)) {
                    if($("#spendenformular-box").css('display') == 'none') {

                        $('#donation-form-frame').hide();
                        $('#spenden_iframe_loader').show();

                        $('#donation-form-frame').attr('src', $('#spende_iframe_src').attr('href')+link+','+Math.floor(Math.random()*10000));
                        $('#donation-form-frame').load(function() {
                            $('#spenden_iframe_loader').hide();
                            $(this).show();
                            //$.fn.gaqTrackPageview("/spende/start");
                        });
                    } else {
                        $('#donation-form-frame').attr('src', '');
                    }

                    runEffect();
                }
            }

            
            
    });

    $(function() {
            //run the currently selected effect
            function runEffect(){
                    //get effect type from 
                    var selectedEffect = 'blind';

                    //most effect types need no options passed by default
                    var options = {};
                    //check if it's scale, transfer, or size - they need options explicitly set
                    if(selectedEffect == 'scale'){  options = {percent: 0}; }
                    else if(selectedEffect == 'size'){ options = { to: {width: 200,height: 60} }; }

                    //run the effect
                    document.getElementById('info-box').style.display = "None";
                    $("#switch-box").toggle(selectedEffect,options,500);
            };
            function runEffect2(){
                    //get effect type from 
                    var selectedEffect = 'blind';

                    //most effect types need no options passed by default
                    var options = {};
                    //check if it's scale, transfer, or size - they need options explicitly set
                    if(selectedEffect == 'scale'){  options = {percent: 0}; }
                    else if(selectedEffect == 'size'){ options = { to: {width: 200,height: 60} }; }

                    //run the effect
                    document.getElementById('switch-box').style.display = "None";
                    $("#info-box").toggle(selectedEffect,options,500);
            };

            //set effect from select menu value
            $("#switch-button").click(function() {
                    runEffect();
                    return false;
            });
            $("#info-button").click(function() {
                    runEffect2();
                    return false;
            });
    });
    $(function() {
	//run the currently selected effect
	function runEffect(){
		//get effect type from 
		var selectedEffect = 'blind';
		
		//most effect types need no options passed by default
		var options = {};
		//check if it's scale, transfer, or size - they need options explicitly set
		if(selectedEffect == 'scale'){  options = {percent: 0}; }
		else if(selectedEffect == 'size'){ options = { to: {width: 200,height: 60} }; }
		
		//run the effect
		$("#news-footer-content-box").toggle(selectedEffect,options,500);
	};
	
	//set effect from select menu value
	$("#news-footer-button").click(function() {
		runEffect();
		return false;
	});
    });
    $(function(){
        $('#slides').slides({
            preload: true,
            preloadImage: 'images/ajax-loader.gif',
            play: 5000,
            pause: 2500,
            hoverPause: true
        });
        /*
        $(document).ready(function() {
            var length = $("#smoothmenu1 ul li#projekte ul li").size();
            var percol = length/3;
                percol = parseInt(percol);
            var percolrest = length%3;
            if(percolrest > 0) percol++;
            $('#smoothmenu1 ul li#projekte ul li:nth-child(2)').before('<div>test');
            $('#smoothmenu1 ul li#projekte ul li:nth-child('+percol+')').after('test</div>');
        });
        */
        
        $('#smoothmenu1 ul li#spenden ul li:nth-child(3n+2)').addClass('first');
        $('#smoothmenu1 ul li#spenden ul li:nth-child(3n+4)').addClass('last');
        $('#smoothmenu1 ul li#hilfmit ul li:nth-child(3n+2)').addClass('first');
        $('#smoothmenu1 ul li#hilfmit ul li:nth-child(3n+4)').addClass('last');
        $('#switch-box ul li:nth-child(3n+1)').addClass('first');
        $('#switch-box ul li:nth-child(3n+3)').addClass('last');
    });

    function geoip_country_code() {
        country = navigator.language.split('-');
        if(country.length == 2)
            return country[1];
        else if(country.length == 1)
            return country[0];
        else
            return "DE";
    }

    $(document).ready(function() {
        $('.banner_wrapper textarea').click(function() {
            this.focus();
            this.select();
        });
        if($("body").hasClass("ipad") == true){
            //alert("test");
            var el = document.getElementById('news-footer');
            var lowerleft = [window.pageXOffset,(window.pageYOffset+window.innerHeight)];
            var lowerright = [(lowerleft[0] + window.innerWidth),lowerleft[1]];
            var zoomFactor = window.innerWidth/document.documentElement.clientWidth;
            el.style.width = lowerright[0] - lowerleft[0] + 'px';
            el.style.height = parseInt(window.innerHeight/10) + 'px';
            el.style.left = lowerleft[0] + 'px';
            el.style.top = lowerleft[1]-el.offsetHeight + 'px';
            el.style.fontSize = parseInt(zoomFactor*60) + 'px';
            window.onscroll = function () {
                var lowerleft = [window.pageXOffset,(window.pageYOffset+window.innerHeight)];
                var lowerright = [(lowerleft[0] + window.innerWidth),lowerleft[1]];
                var zoomFactor = window.innerWidth/document.documentElement.clientWidth;
                el.style.width = lowerright[0] - lowerleft[0] + 'px';
                el.style.height = parseInt(window.innerHeight/10) + 'px';
                el.style.left = lowerleft[0] + 'px';
                el.style.top = lowerleft[1]-el.offsetHeight + 'px';
                el.style.fontSize = parseInt(zoomFactor*60) + 'px';
            }
        }
    })
    function getSiteheight() {
        var myWidth = 0, myHeight = 0;
        if( typeof( window.innerWidth ) == 'number' ) {
            //Non-IE
            myWidth = window.innerWidth;
            myHeight = window.innerHeight;
        } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
            //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth;
            myHeight = document.documentElement.clientHeight;
        } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
            //IE 4 compatible
            myWidth = document.body.clientWidth;
            myHeight = document.body.clientHeight;
        }
        return [myHeight];
    }
    $(function(){
        if(getSiteheight() > 1057){
            var footer_margin_top = getSiteheight() - 1032;
            $('#footerbackground').attr('style', 'margin-top: '+ footer_margin_top +'px;');
        }
    });
    function bodyScroll(){
        if($("body").hasClass('no-scrollbar') == false && getSiteheight() < 533){
            $("body").addClass("no-scrollbar");
        }else{
            $("body").removeClass("no-scrollbar");
        }
    }
    $(function() {
        var window = getSiteheight();
        var donationformheight = window-54;
        if(window < 523){
            $("#donation-form-frame").attr("style","max-height:"+donationformheight+"px;overflow:auto;width:100%;");
            $("#auftrag-schliesen-button").attr("style","position:fixed;right:5px;top:5px;margin-top:0;");
            $("#spendenformular_wrapper").attr("style","width: 100%");
        }
        $("#auftrag-button").click(function() {
            bodyScroll();
            return false;
        });
        $(".jetzt-helfen-button").click(function() {
            bodyScroll();
            return false;
        });
        $("#auftrag-schliesen-button").click(function() {
            bodyScroll();
            return false;
        });
        
    });
})(jQuery);
function setProgress(total,ziel){
    jQuery(".total .wert").text(total);
    jQuery("#pziel .wert").text(ziel);
    var prozent = parseInt((total/ziel)*100);
    jQuery("#pfortschritt").attr("style","width:"+prozent+"%");
}
;
(function($) {
    $.fn.tipsy = function(options) {

        options = $.extend({}, $.fn.tipsy.defaults, options);
        
        return this.each(function() {
            
            var opts = $.fn.tipsy.elementOptions(this, options);
            
            $(this).hover(function() {

                $.data(this, 'cancel.tipsy', true);

                var tip = $.data(this, 'active.tipsy');
                if (!tip) {
                    tip = $('<div class="tipsy"><div class="tipsy-inner"/></div>');
                    tip.css({position: 'absolute', zIndex: 100000});
                    $.data(this, 'active.tipsy', tip);
                }

                if ($(this).attr('title') || typeof($(this).attr('original-title')) != 'string') {
                    $(this).attr('original-title', $(this).attr('title') || '').removeAttr('title');
                }

                var title;
                if (typeof opts.title == 'string') {
                    title = $(this).attr(opts.title == 'title' ? 'original-title' : opts.title);
                } else if (typeof opts.title == 'function') {
                    title = opts.title.call(this);
                }

                tip.find('.tipsy-inner')[opts.html ? 'html' : 'text'](title || opts.fallback);

                var pos = $.extend({}, $(this).offset(), {width: this.offsetWidth, height: this.offsetHeight});
                tip.get(0).className = 'tipsy'; // reset classname in case of dynamic gravity
                tip.remove().css({top: 0, left: 0, visibility: 'hidden', display: 'block'}).appendTo(document.body);
                var actualWidth = tip[0].offsetWidth, actualHeight = tip[0].offsetHeight;
                var gravity = (typeof opts.gravity == 'function') ? opts.gravity.call(this) : opts.gravity;

                switch (gravity.charAt(0)) {
                    case 'n':
                        tip.css({top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}).addClass('tipsy-north');
                        break;
                    case 's':
                        tip.css({top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}).addClass('tipsy-south');
                        break;
                    case 'e':
                        tip.css({top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth}).addClass('tipsy-east');
                        break;
                    case 'w':
                        tip.css({top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width}).addClass('tipsy-west');
                        break;
                }

                if (opts.fade) {
                    tip.css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: 0.8});
                } else {
                    tip.css({visibility: 'visible'});
                }

            }, function() {
                $.data(this, 'cancel.tipsy', false);
                var self = this;
                setTimeout(function() {
                    if ($.data(this, 'cancel.tipsy')) return;
                    var tip = $.data(self, 'active.tipsy');
                    if (opts.fade) {
                        tip.stop().fadeOut(function() { $(this).remove(); });
                    } else {
                        tip.remove();
                    }
                }, 100);

            });
            
        });
        
    };
    
    // Overwrite this method to provide options on a per-element basis.
    // For example, you could store the gravity in a 'tipsy-gravity' attribute:
    // return $.extend({}, options, {gravity: $(ele).attr('tipsy-gravity') || 'n' });
    // (remember - do not modify 'options' in place!)
    $.fn.tipsy.elementOptions = function(ele, options) {
        return $.metadata ? $.extend({}, options, $(ele).metadata()) : options;
    };
    
    $.fn.tipsy.defaults = {
        fade: false,
        fallback: '',
        gravity: 'n',
        html: false,
        title: 'title'
    };
    
    $.fn.tipsy.autoNS = function() {
        return $(this).offset().top > ($(document).scrollTop() + $(window).height() / 2) ? 's' : 'n';
    };
    
    $.fn.tipsy.autoWE = function() {
        return $(this).offset().left > ($(document).scrollLeft() + $(window).width() / 2) ? 'e' : 'w';
    };
    
})(jQuery);
;

