var ifo = {
   Api: 'eb4be2bc9b39e0625af47006c9a790cc',
   UserId: '48322076@N08'
};

TopUp.host = "http://libjs.s3.amazonaws.com/";
TopUp.images_path = "JS/topup/images/";
TopUp.addPresets({".top_up": {resizable: 0,layout: "flatlook", modal: 1, overlayClose: 1}});

// Clean WhiteSpace function for the contribution page
/*
cleanWhitespace = function() {
    textNodes = this.contents().filter(
        function() { return (this.nodeType == 3 && !/\S/.test(this.nodeValue)); })
        .remove();
}
*/
$j(document).ready(function() {

	// Contribution page functions
	
	/*
	$j("#contribute_one_time label.radio_button:lt(4)").wrapAll("<div class='ammount_1'/>");
	$j("#contribute_one_time label.radio_button:gt(3)").wrapAll("<div class='ammount_2'/>");
	
	$j("#contribute_recurring label.radio_button:lt(4)").wrapAll("<div class='ammount_1'/>");
	$j("#contribute_recurring label.radio_button:gt(3)").wrapAll("<div class='ammount_2'/>");
	
	
	$j("<span/>",{
		html: '$',
		'class' : 'dollar'
	}).appendTo($j("#contribute_one_time"));
	
	$j("<span/>",{
		html: '$',
		'class' : 'dollar'
	}).appendTo($j("#contribute_recurring"))
	
	
	if ($j.browser.msie && $j.browser.version == 7) {
	  $j("div.ammount_2").css("margin-top","-15px");
	  $j("#contribute_other_amount, #contribute_other_amount_recurring").css({"left":"150px", "top":"80px"});
	  $j(".dollar").css({"left":"140px", "top":"85px"});
	} 
	*/
	
	// END
	
	// Show or hide the "other" donation designation
	$j("#model_donation_target").change(function(){
		if ($j('option[value=specific_school]:selected').val() == "specific_school" ) {
			$j("#other-donation-target").slideDown("fast"); 
			}
			else 
				 {
				$j("#other-donation-target").css("display","none");
			}
	});
	
	$j("#employer-match-check").change(function(){
		if ($j(this).attr("checked", "checked")) {
			$j("#employer-match-fields").slideDown("fast"); 
			}
			else 
				 {
				$j("#employer-match-fields").css("display","none");
			}
	});
	
	$j("#in-kind-check").change(function(){
		if ($j(this).attr("checked", "checked")) {
			$j("#in-kind-description").slideDown("fast"); 
			}
			else 
				 {
				$j("#in-kind-check").css("display","none");
			}
	}); // END

});

var LAengine = {
    structure : {
        footermenu : {
            removeLastULStyling : function(){
                $j("ul.footerMenu ul:last").css({
                    "border-right":"none",
                    "padding":"0",
                    "margin":"0"
                })
            }
        },
        mainMenu : {
            removeLastAStyling : function(){
                $j("#menuMain>li:last a").css({
                    "border-right":"none"
                })
            }
        }
    },
    behavior : {
        pageToolsFontSize : function(){
            $j("#font_select").click(function(){
                LAengine.animation.animateContentFontSize(12)
            });
            $j("#font_select_med").click(function(){
                LAengine.animation.animateContentFontSize(15)
            });
            $j("#font_select_large").click(function(){
                LAengine.animation.animateContentFontSize(20)
            });
        },
        externalLinks : function(){
            $j('a:external').not('.te_close_link, .te_previous_link, .te_next_link').addClass('external');
            $j('a.external').click(function() {
                var link = $j(this).attr('href');
                window.open(link);
                return false;
            });
        },
        menuRollOver : function(){
            LAengine.structure.mainMenu.removeLastAStyling();
            $j("#menuMain li a:not(.selected)").hover(function(){
                LAengine.animation.animateArrow.down(this)
            },
            function(){
                LAengine.animation.animateArrow.up(this)
            });
        },
        tabClick : {
            init : function(opts){
                $j(opts.tabs + " .content").hover(function(){
                    LAengine.animation.animateArrow.right(this)
                },
                function(){
                    LAengine.animation.animateArrow.left(this)
                })
                .click(function(){
                    if (! $j(this).has(".eventInfo").length) {
                       document.location.href=$j(this).find("a:first").attr("href")
                    }
                });
                $j("#contentHere .content:first-child").css({
                    "background-color":"#F6F5F5"
                });
                $j(opts.tabs + ":first-child").show();
                $j(opts.navigation).click(function(){
                    opts.tabNumber = $j(this).getIndex();
                    LAengine.behavior.tabClick.loadContent(opts);
                    return false;
                })
            },
            markSelected : function(opts){
                var $old = $j(opts.navigation + ":not(:eq("+opts.tabNumber+")) a.selected");
                var $new = $j(opts.navigation + ":eq("+opts.tabNumber+") a:not(.selected)");
                var $newArrow = $new.find("span");
                $newArrow.fadeOut(200);
                $old.removeClass("selected",200);
                $new.addClass("selected", 200, function(){
                    $newArrow.fadeIn(1000)
                })
            },
            loadContent : function(opts){
                $j(opts.tabs + ":not(:eq("+opts.tabNumber+"))").hide();
                $j(opts.tabs + ":eq("+opts.tabNumber+")").fadeIn(300, function(){
                    LAengine.behavior.tabClick.markSelected(opts);
                });
            },
            showTab : function(t){}
        },
        footerMenu : function(){
            LAengine.animation.animateFooterMenuLinks()
        },
        showError : function(msg){
        $j("<div class='docError'/>").html(msg).appendTo('body').slideDown(300);
        window.setTimeout(function() {
            jQuery("div.docError").fadeOut("slow",function() {
                jQuery("div.docError").remove();
            });
        } ,2500);
        }
    },
    animation : {
        animateContentFontSize : function(s){
            $j("#contentHere").stop().animate({
                fontSize: s+"px"
            }, 300 )
        },
        animateArrow : {
            up : function(e){
                $j(e).stop().animate({
                    backgroundPosition:"(50% 0px)"
                },200);
            },
            down : function(e){
                //console.log(1);
                $j(e).stop().animate({
                    backgroundPosition:"(50% 10px)"
                },300)
                
            },
            left : function(e) {
                $j(e).stop().animate({
                    backgroundPosition:"(600px 50%)"
                },300)
            },
            right : function(e) {
                $j(e).stop().animate({
                    backgroundPosition:"(610px 50%)"
                },300)
            }
        },
        animateFooterMenuLinks : function() {
            $j(".footerMenu li a").hover(function(){
                $j(this).stop().animate({
                    "left":5,
                    "color":"#F1F1F2"
                },100)
            }, function(){
                $j(this).stop().animate({
                    "left":0,
                    "color":"#9B9489"
                },200)
            })
        },
        donateLink : function(){
          $j("a.donate").hover(function(){$j(this).stop().animate({"background-color":"#918E41"}, 500)}, function(){$j(this).stop().animate({"background-color":"#F5654D"}, 500)})
        },
        schoolLink : function(){
          $j("div.schoolInfo a").hover(function(){$j(this).stop().animate({"background-color":"#F5654D"}, 500)}, function(){$j(this).stop().animate({"background-color":"#918E41"}, 500)})
        },
        slideShow : function(){
            $j("#slides").cycle({
		fx: 'fade',
		timeout: 5000, 
		pause: 1,
		prev:   '#prev', 
		next:   '#next'
    	    });
        },
        featuredSchools : function(){
            $j("#school div.schools").cycle({
		fx: 'fade',
		timeout: 5000, 
		pause: 1,
		prev:   '#prev-s', 
		next:   '#next-s'
    	    });
        },
        flickrFeed : function(num){
    		$j("#flickr").append("<ul id='flickrFeed' class='flickrFeed'/>");
   		$j.getJSON('http://api.flickr.com/services/rest/?format=json&jsoncallback=?&api_key=' + ifo.Api + '&method=flickr.people.getPublicPhotos&user_id=' + ifo.UserId, function (Data) {
        	if (Data.stat == "ok") {
            		for (var i = 0; i < Data.photos.photo.length; i++) {
                		var photo = Data.photos.photo[i];
                		var Thum = 'http://farm' + photo['farm'] + '.static.flickr.com/' + photo['server'] + '/' + photo['id'] + '_' + photo['secret'] + '_' + 's.jpg';
                		$j("#flickr ul").append('<li style="height:75px" id="photo'+ i +'"><a href="' + Thum.replace('_s.jpg', '.jpg') + '" title="' + photo['title'] + '"><img src="' + Thum + '" alt="' + photo['title'] + '" /></a></li>');
                		//if (i > num) {$j('#photo'+i).hide().addClass('hiddenPhoto')};
            		};
            	$j("ul#flickrFeed").randomize();
            	$j("ul#flickrFeed li:eq("+ num +")").nextAll().hide().addClass('hiddenPhoto');
            	$j("ul#flickrFeed li:eq(8)").css({"margin-right":0});
            	$j('ul#flickrFeed, ul.socialLinks').children().hover(function () {
                	$j(this).siblings().not('.hiddenPhoto').stop().fadeTo(500, 0.4);
            	},
            	function () {
                	$j(this).siblings().not('.hiddenPhoto').stop().fadeTo(500, 1);
            	});

       		}
    	})
       }
    }
}

$j(function(){
    plugins.blogComments();
    LAengine.behavior.pageToolsFontSize();
    LAengine.behavior.externalLinks();
    LAengine.structure.footermenu.removeLastULStyling();
    LAengine.behavior.menuRollOver();
    if ( $j("#homepage").html().length > 100 ) {
        $j("#contentHere").addClass("contentHereHome");
    	LAengine.behavior.tabClick.init({
        	navigation:"ul.tabs li",
        	tabs:"#contentHere>div"
    	});
    }
    LAengine.behavior.footerMenu();
    LAengine.animation.donateLink();
    LAengine.animation.schoolLink();
    LAengine.animation.slideShow();
    LAengine.animation.featuredSchools();
    if ($j("#flickr").length) 
    LAengine.animation.flickrFeed(8);
    $j("div.slide").click(function(){document.location.href = $j(this).find("a").attr("href")});
    $j("ul.sf-menu").supersubs({minWidth:11,maxWidth:20,extraWidth:1}).superfish().find('ul').bgIframe({opacity:false});
    $j.fn.formLables()

 
});
