
jQuery(document).ready(function($) {

  setupsite();
 
});

function setupsite() {
	
    //Flickr Feed
    var apiKey = 'dd44b4ed994dd0c901b8ee29fe67520f'; 
    var userID = '36403915@N07';
    var perPage = 61;
    var jsonURL = 'http://api.flickr.com/services/rest/?&method=flickr.people.getPublicPhotos&api_key='+apiKey+'&user_id='+userID+'&per_page='+perPage+'&format=json&jsoncallback=?';
    
    $.getJSON(jsonURL, function(data){ 
        $.each(data.photos.photo, function(i,item){
            
            //Local Variables
            var imgSrc = 'http://farm'+item.farm+'.static.flickr.com/'+item.server+'/'+item.id+'_'+item.secret+'_b.jpg'; 
            var imgShareURL= 'http://www.flickr.com/photos/'+item.owner+'/'+item.id+'/in/photostream';
			
            //Build the Flickr Post
            var flickrFeed = 
            '<div class="post">\
                <img src='+imgSrc+' data-title="'+item.title+'" style="width: 300px;" />\
                <div class="hover-highlight">\
                    <a href="#" class="expand"><span>Expand</span></a>\
                    <div class="post-options">\
                        <a href="http://www.facebook.com/sharer.php?s=100&amp;p[title]='+item.title+'&amp;p[url]='+imgShareURL+'&amp;p[images][0]='+imgSrc+'" target="_blank" title="Share on Facebook" class="facebook">Facebook</a>\
                        <a href="http://twitter.com/share?url='+imgShareURL+'&amp;text='+item.title+' on Northern Lights" target="_blank" title="Share on Twitter" class="twitter">Twitter</a>\
                    </div>\
                </div>\
            </div>';

            //Render the Flickr Post
            $('#mobile-feed').append(flickrFeed);
                                
        });
    });
    
    jQuery('a.postpopup').live("click", function() {
        
        var id = jQuery(this).attr('rel');

        jQuery('<div id="video-pop" class="popout"></div>').hide().appendTo('body').load('http://nrthrnlghts.com/ajax-video-popup/?id='+id).show();
        return false;
                                    
    });
    
    jQuery('a.expand').live("click", function() {
        
        var id = jQuery(this).attr('rel');
        var title = jQuery(this).parent().siblings().attr('data-title');
        var imgSrc = jQuery(this).parent().siblings().attr('src');
        var twitterShare = jQuery(this).siblings().children('.twitter').attr('href');
        var facebookShare = jQuery(this).siblings().children('.facebook').attr('href');

        var imagePopup =
           '<div id="image-pop" class="popout">\
              <div class="popout-frame">\
                <a class="close">&nbsp;</a>\
                 <div class="popout-media">\
                    <img src='+imgSrc+' style="max-width: 700px;" />\
                 </div>\
                 <div class="information">\
                    <span class="hr"></span>\
                    <span class="title">'+title+'</span>\
                    <div class="post-options">\
                        <a href="'+facebookShare+'" target="_blank" title="Share on Facebook" class="facebook">Facebook</a>\
                        <a href="'+twitterShare+'" target="_blank" title="Share on Twitter" class="twitter">Twitter</a>\
					</div>\
                 </div>\
              </div>\
			  <div class="popout-skrim"></div>\
           </div>';
                
        jQuery(imagePopup).hide().appendTo('body');
        
        jQuery('#image-pop').show();
        
        var popWidth = jQuery('#image-pop .popout-frame').width();
        var adjustedWidth = popWidth/-2;
        
        jQuery('#image-pop .popout-frame').css({"margin-left" : adjustedWidth });

        jQuery('body').css({'overflow': 'hidden' });
        return false;
                                    
    });
    
    jQuery('a.close').live('click', function() {
    jQuery('.popout').hide().remove();
    jQuery('body').css({'overflow': 'visible' });
    return false;
    });
    jQuery('div.popout-skrim').live('click', function() {
    jQuery('.popout').hide().remove();
    jQuery('body').css({'overflow': 'visible' });
    return false;
    });
	
}

function disablePopup() {

}





