Cufon.replace("h1,h2,h3:not(.eventsLink),.eventsLink span,h4",{hover:true});
(function($){

    $(function(){
        
        
        var mwh = $(".mainWrap").height();
        var diff = $(window).height() - 258;
        
        if(mwh < diff){
            $(".mainWrap .main").height(diff-80);
        }
        
        
        $(".mFix").each(function(){
            var href = $(this).attr("href");
            newhref = href.substr(15);
            newhref = newhref.replace(/\[--AT--\]/,"@");
            $(this).attr("href","mailto:"+newhref);
            
        });
        
        
        $(".mainEventsContainer .eventsList > li").each(function(i,el){
            if(i > 2){ $(el).remove(); }
        
        });
        
        
    });
    
    
    $.runSlideshow = function (imageList) {
        return $.runSlideshow.impl.init(imageList);
    };
    
	$.runSlideshow.impl = {

        init: function(imageList){
            this.imageA = imageList.split(" ");
            this.listLength = this.imageA.length;
            this.currentIndex=0;
            this.slideshowContainer = $(".slideshowContainer");
            this.slideshowImage = this.slideshowContainer.find("img");
            this.imageA.sort(function (){ return (Math.round(Math.random())-0.5); });

            
            for(var img in this.imageA){
                $("<img>").attr("src", this.imageA[img]);
            }
            setTimeout(function(){
                $.runSlideshow.impl.next();
            },2500);
            
        },
        next: function(){
            this.currentIndex++;
            if(this.currentIndex > this.listLength){
                this.currentIndex = 0;
            }
            var ssc = this.slideshowContainer;
            var ssimg = this.slideshowImage;
            var i = this.currentIndex;
            var list = this.imageA;
            this.slideshowContainer.fadeOut(1000, function(){
                ssimg.attr("src", list[i]);
                ssc.fadeIn(1000, function(){
                    setTimeout(function(){
                        $.runSlideshow.impl.next();
                    },2500);
                });
                
            });
        
        }
        
    };
    
    $.flSlideshow = function(setID){
        var flickrID = "40739549@N07";
        
            $.ajax({
                url: "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20flickr.photosets.photos(50)%20%20where%20photoset_id%3D'" + setID + "'%20%20&format=json&diagnostics=true&callback=?",
                dataType: "jsonp",
                success: function(data){

                    var container = $("#slideshowContainer");
                    var imgList = [];
                    var cur = 0;
                    var total = data.query.count;
                    $.each(data.query.results.photo,function(i,p){
                        var src= "http://farm" + p.farm + ".static.flickr.com/" + p.server + "/" + p.id + "_" + p.secret + "_m.jpg";
                        var href = "http://www.flickr.com/photos/ifaction/" + p.id;
                        var item = $(document.createElement("a")).attr("href",href).attr("title",p.title + " - on Flickr").append($(document.createElement("img")).attr("src",src).attr("alt",p.title));
                        imgList.push(item);
                        //$('<li><a href="' + href + '"><img src="' + src + '" alt="' + p.title + '" target="_blank" /></a></li>').appendTo(container);
                    });
                    imgList.sort(function (){ return (Math.round(Math.random())-0.5); });
                    imgList[0].appendTo(container);
                    
                    var switchPhoto = function(){
                        imgList[cur].fadeOut(500,function(){
                            $(this).remove();
                            cur++;
                            if(cur >= total){
                                cur = 0;
                            }
                            imgList[cur].hide().appendTo(container);
                            var marginLeft = Math.floor((292 - imgList[cur].width()-8)/2);
                            imgList[cur].css("margin","0 0 0 " + marginLeft + "px").fadeIn(500,
                                function(){
                                    setTimeout(function(){ switchPhoto(); },4000);
                                }
                            );
                        });
                        
                    };
                    
                    setTimeout(function(){ switchPhoto(); },2500);
                    
                    
                    
                }
            });
        };

})(jQuery);

