/* Author:

*/
var ele, live = 0, item, timing = 100 ; 
// logo hover effect looping function
function go() {
	$('.logo').animate({'top': '-5px'},  1000, 'swing');
	$('.logo').animate({'top': '5px'}, 1000, 'swing');
}
go()
setInterval(function() { go() }, 2500)

// on hover background animation looping function
function moveBackground() {
	if(live) {
		$(ele).css({'backgroundPosition': '+= 1px 0'});
		setTimeout( function() { moveBackground() }, timing)
	}
}
// jQuery doc rdy begins
$(document).ready( function() {
$('#parallax div').parallax({
yparallax: false,
yorigin: 0,
frameDuration: 50,
decay: 0.90
});
// social buttons hover effect and start looping animation
$('li a').hover( function() {
	ele = this ;
		$(ele).css({backgroundImage: 'url(img/rainbow-linear-bg.jpg)', backgroundRepeat: 'repeat-x'});
		//console.log( $(ele).find('span').length )
		if( $(ele).find('span').length ) {
		$(ele).find('span').show().animate({top: '50px'}, 500, 'easeInOutBounce');
		} else { 
		$(ele).append('<span style="position:absolute;left:30%; top: -100px;" >' + $(ele).attr('class') + ' </span>' ).find(' span').animate({top: '50px'}, 500, 'easeInOutBounce');
		}
	live = 1 ;
	 moveBackground()
	}, function() {
		$(ele).css({backgroundImage: '',backgroundColor: '#4E4E4E' , backgroundPosition: '', backgroundRepeat: ''});
		$(ele).find('span').animate({top: '100%'}, 500, 'easeInOutBounce').fadeOut(200, function() {  $(this).css({top: '-100px'});  } );
	live = 0 ;
});

$('.socials a').click( function() {
	item = $(this).attr('class');
	if(!$('#feature').height() ) {
		$('#feature').fadeIn().animate({height: $('section#' + item).innerHeight()}, 500, 'easeInOutBack');
		
		$('section#'+item).animate({left: '0px'}).addClass('vis');
		$('#main').animate({top: '20%'}, 1000, 'easeInOutBack');
	} else {
		$('.vis').animate({left: '-500px'}, 500, 'easeInOutBack', function() { 
																		$('.vis').css({left: '500px'}).removeClass('vis'); 
																		$('section#'+item).addClass('vis');
																		});
		$('#feature').animate({height: $('section#' + item).innerHeight()}, 500, 'easeInOutBack');
		
		$('section#'+item).animate({left: '0px'})
	}
	
});

// load runkeeper stuff
$.ajax({url:'http://fitness.queso.com/widget/widget.js?id=1450', dataType:'script', cache:true, success: function() { $('#hgwp link').remove();  $('#hgw-top').remove(); $('#hgw-bot').remove(); } });

// flikr api load
$.getJSON("http://api.flickr.com/services/rest/?method=flickr.people.getPublicPhotos&api_key=e0f04b447fc693818e6b09dbfc0b5cdc&per_page=9&user_id=68106238%40N07&format=json&nojsoncallback=1",
	function(data) {
	var photoHtml='';
	$.each(data.photos.photo , function(index, value) {
			photoHtml += '<a class="link" href="http://farm' + value.farm + '.static.flickr.com/' + value.server +'/'+ value.id + '_' + value.secret + '_z.jpg" ><img alt="' + value.title + ' " src="http://farm' + value.farm + '.static.flickr.com/' + value.server +'/'+ value.id + '_' + value.secret + '_s.jpg" /> </a>' ;
			$('#photo').html(photoHtml);
	});
});


//flikr overlay on click
 var overlay = '';
var overlayHtml = function(link, that) {
	
if($('.overlay').length) {
$('.viewing').removeClass('viewing');
$('.spinner').fadeIn(1000);
$('.top').fadeOut(500, function() {
	$('.image').attr('src', link );
	});
	} else {

									overlay = '<div class="overlay bottom" style="width:100%;height:100%;position:fixed;background-color:#000000;opacity:0.5;z-index:100;"></div>'
									overlay += '<img style="position:fixed;top:50%;left:50%;margin:-50px;z-index:150;" class="overlay spinner" src="img/spinner.gif" />'
									overlay += '<div style="padding:20px;position:fixed;top:50%;left:50%;z-index:200;display:none;min-width:640px;text-align:center;background-color:#000000;border-radius:10px;" class="overlay top">'
									overlay += '<a href="prev"class="prev" style="position:absolute;left:-40px;top:50%;margin-top:-50px;z-index:150;" ><img src="img/arrows_L.png" /></a>'
									overlay += '<a style="position:absolute;top:-15px;right:-15px;" class="close"  href="close"><img src="img/close-img.png" /></a><img class="image" src="'+ link +'" />'
									overlay += '<a href="next" class="next" style="position:absolute;right:-40px;top:50%;margin-top:-50px;z-index:150;" ><img src="img/arrows_R.png" /></a></div>';
	
									$('body').append(overlay); 
									}
									$(that).addClass('viewing');
									(function checkImage() {
									if($('.top').height() > 20) {
										$('.top').css({margin: '-' + ($('.top').height()/2) + 'px 0 0 -' + ($('.top').width()/2) + 'px'  }).fadeIn(500);
										$('.spinner').fadeOut(1000);
										$('.top').fadeIn(500)
									} else { setTimeout( function() { checkImage() }, 10)	 }
									})()
			if($('.viewing').prev().length === 0 ) {
			$('.prev').fadeOut(200);
			} else {
			$('.prev').fadeIn(200);
			}
			if($('.viewing').next().length === 0 ) {
			$('.next').fadeOut(200);
			} else {
			$('.next').fadeIn(200);
			}
									}
$('a.link').live('click', function() {
	var link = $(this).attr('href'), that = this;
	overlayHtml(link, that);
	return false
			})
			
	$('div.overlay a').live('click', function(e) {
		e.preventDefault();
		if ($(this).attr('href') == 'close') {
			$($('.overlay')).fadeOut(500, function() { $(this).remove(); });
			} else if ($(this).attr('href') == 'prev') {
			link = $('.viewing').prev().attr('href');
			that = $('.viewing').prev();
			overlayHtml(link, that);
			} else if ($(this).attr('href') == 'next') {
			link = $('.viewing').next().attr('href');
			that = $('.viewing').next();
			overlayHtml(link, that);
			}
		return false
	});
			
// load tweets etc
        $('body').append(
    '<sc' + 'ript type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></sc' + 'ript>' +
    '<sc' + 'ript type="text/javascript" src="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=tobomedia&callback=twitterCallback2&count=3&exclude_replies=1"></sc' + 'ript>'
        );
//end doc rdy
});



    /**********************************************************************************
	******************************  Load Facebook SDK on doc ready ********************
	**********************************************************************************/

		window.fbAsyncInit = function() {
	   FB.init({appId: '174614942579895', status: true, cookie: true, xfbml: true});
	};
	(function() {
	   var e = document.createElement('script');
	   e.type = 'text/javascript';
	   e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
	   e.async = true;
	   var fbRoot = document.getElementById('fb-root');
	   if (fbRoot != null)
	   {
	       fbRoot.appendChild(e);
	   }

	}());
