/*! sunstonehome General v1 <http://nvinteractive.co.nz>
	Copyright (c) NV Interactive
	
	References:
		jquery-1.2.6.js
		
	Release Notes:

		
*/

sunstonehome = function() {

    var TWITTERRSS = "http://twitter.com/statuses/user_timeline/57038652.rss";
    var BLOGRSS = "http://sunstoneadventures.blogspot.com/feeds/posts/default?alt=rss";
    var FLICKRRSS = "http://api.flickr.com/services/feeds/photos_public.gne?id=40370429@N07&lang=en-us&format=rss_200";
    //var CALENDARRSS =	"http://www.google.com/calendar/feeds/sam.langley%40nvinteractive.co.nz/public/full";
    var CALENDARRSS = "http://www.google.com/calendar/feeds/sunstoneadventures%40googlemail.com/public/full";

    var init = function() {



        $("#tweets .content").feedfetcher({
            feed_source: TWITTERRSS,
            feed_items: 4,
            contentWordCount: 200,
            container: "<dl></dl>",
            itemtemplate: "<dt><a href='$link$' target='blank'>$when$</a></dt><dd>$content$</dd>",
            parselinks: true,
			contentparsefunction: function(c) { var re = new RegExp(/#([^\s]*)/ig); return c.replace(re, "<a href='http://twitter.com/search?q=%23$1' target='_blank'>#$1</a>").replace("Sunst0ne: ", ""); }
        });

        $("#blog .content").feedfetcher({
            feed_source: BLOGRSS,
            feed_items: 4,
            container: "<ul id='blog-posts'></ul>",
            itemtemplate: "<li> <div class='title'><a href='$link$' target='blank'>$title$</a></div> <div class='summary'>$content$</div> <div class='data'><span class='date'>Posted $when$</span></div></li>"
        });

        $("#flickr .content").feedfetcher({
            feed_source: FLICKRRSS,
            feed_items: 12,
            container: "<ul class='flickr-thumbs'></ul>",
            itemtemplate: "<li><a href='$link$' target='_blank'><img src='$content$' width='75' height='75' alt='$title$' /></a></li>",
            contentparsefunction: function(c) { var re = new RegExp(/src="([^"]*)"/ig); re.exec(c); return RegExp.$1.replace("_m", "_s") }
        });

        $("#calendar .content").feedfetcher({
            feed_source: CALENDARRSS,
            feed_items: 3,
            contentWordCount: 25,
            container: '<dl class="calendar-list"></dl>',
            itemtemplate: '<dt><strong>$day$</strong>$month$</dt><dd><strong><a href="$link$" target="_blank">$title$</a></strong><br/>$content$</dd>'
        });



        $('#home-feature').cycle({
            timeout: 8000,
            pause: 1,
            prevNextClick: move,
            speed: 750,
            next: '#slide_next',
            prev: '#slide_previous',
            after: move,
        });
		
		$('.feature_nav').css("opacity", 0);

        $("#quick-links li").click(function() {
            window.location = $(this).find("a").attr("href"); return false;
        });

        $('#home-feature-wrapper').hover(show_nav, hide_nav);

    }

    return {
        /* Public API
        */
        init: init
    }

} ();

var before = function(fn){
    $('.content', this).css({right: -400});
}

var move = function(fn){
    $('.content', this).animate({right: 0}, 500);
}

var show_nav = function(){
    $('.feature_nav').stop(true, false)
        .animate({
            opacity: 1
        }, 750);
}

var hide_nav = function(){
    $('.feature_nav').stop(true, false)
        .animate({
            opacity: 0
        }, 750);
}

$(sunstonehome.init);

