$(document).ready(function() {

var twtruser ="krosstheory";
var fbphotos = "357792070914059";
var fbheaders = "137183452969";
var fbprofile = "209594052400529";

/*$.getJSON(tumblr + "/api/read/json?&callback=?", function(data) {
 $('.contactbox div').html(data.tumblelog.description);
});*/

//TWITTER--------------------------------------------------------------------------------------

/*$.getJSON("http://twitter.com/statuses/user_timeline/krosstheory.json?callback=?", function(data) {
 var tweet = (data[0].text).replace(/(https?[^ ]*)/g, '<a href="$1">$1</a>');
 var tweetid = (data[0].id_str);
 $('.twitter').html('<h3>Twitter</h3>' + tweet + ' <a class="retweet" href="javascript:void(0);"  onclick="openWindow(\'https://twitter.com/intent/retweet?tweet_id=' + tweetid + '\', \'follow\',530,340);"></a> <span class="tweetcount">' + data[0].retweet_count + '</span>');
});*/

//PHOTO GALLERY--------------------------------------------------------------------------------------

$.getJSON('https://graph.facebook.com/' + fbphotos + '/photos&callback=?',function(json){
    $.each(json.data,function(){
	$('<li></li>')	
    .append('<span class="thumb" style="background: url(' + this.images[1].source + ')center no-repeat;"><a href="' + this.images[0].source + '" rel="gallery"></a></span>')
  .appendTo('#photos');
  });

 $('.photogallery').jcarousel({
 	wrap: 'both',
 	scroll: 2
 });


 $("#photos .thumb a").fancybox({
	'speedIn'		:	100, 
	'speedOut'		:	100,
	'overlay'		: 	false
 });

});

//VIDEO GALLERY--------------------------------------------------------------------------------------

$.getJSON("http://vimeo.com/api/v2/album/1805770/videos.json?callback=?", function(data) {
$.each(data, function() {
var vid_id = (this.url).match(/\d/g);
vid_id = vid_id.join('');
$('<li class="video"></li>')
.append('<iframe src="http://player.vimeo.com/video/'+vid_id+'?title=0&amp;byline=0&amp;portrait=0" width="400" height="300" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe><p class="vidinfo"><a class="vidtitle" href="'+this.url+'">'+this.title+'</a><span class="viddescription">' + this.description + '</span><span class="share"><a href="javascript:void(0);"  onclick="openWindow(\'http://twitter.com/share?url=' + this.url + '\', \'follow\',530,340);">tweet</a>&nbsp;&bull;&nbsp;<a href="javascript:void(0);"  onclick="openWindow(\'http://www.facebook.com/sharer.php?u=' + this.url + '\', \'follow\',530,340);">share on facebook</a></span></p>')
.appendTo('ul.vids');
});

$('ul.vids').jcarousel({
 	wrap: 'both',
 	scroll: 1
 });
});

//MORE INFO--------------------------------------------------------------------------------------

$.getJSON('https://graph.facebook.com/' + fbprofile + '&callback=?',function(json){
 $('<span></span>')
.append('<img src="' + json.picture + '" /><p>' + json.description + '</p><br><p><b>Label: </b>' + json.record_label + '</p><p><b>Genre: </b>' + json.genre + '</p><p><b>Hometown: </b>' + json.hometown + '</p><p><span class="number">' + json.likes + '</span> people like ' + json.name + '</p>')
.appendTo('#moreinfo');
});

$('#moreinfo').hide();

$('#topbar h1').toggle(function() {
 $('#moreinfo').fadeIn(100,'linear')
 $('#topbar h1').css({'background-position':'161px 17px', 'background-color':'transparent'});
}, function() {
 $('#moreinfo').fadeOut(100,'linear')
 $('#topbar h1').css({'background-position':'161px -25px', 'background-color':'transparent'});
});

//CONTACT--------------------------------------------------------------------------------------

$.getJSON('https://graph.facebook.com/' + fbprofile + '&callback=?',function(json){
var press = (json.press_contact).replace(/(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})/g, '<a href="mailto:$1">$1</a>');
var manager = (json.general_manager).replace(/(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})/g, '<a href="mailto:$1">$1</a>');
var agent = (json.booking_agent).replace(/(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})/g, '<a href="mailto:$1">$1</a>');
$('<span></span>')
.append('<p><b>Management: </b>' + manager + '</p><p><b>Press: </b>' + press + '</p><p><b>Booking: </b>' + agent + '</p>')
.appendTo('#contact div');
});

$('#contact div').hide();

$('#contact h2').toggle(function() {
 $('#contact div').fadeIn(100,'linear')
 $('#contact h2').css({'background-position':'58px 19px', 'background-color':'#333'});
}, function() {
 $('#contact div').fadeOut(100,'linear')
 $('#contact h2').css({'background-position':'58px -24px', 'background-color':'transparent'});
});

//BLOG and NEWS--------------------------------------------------------------------------------------

$.getJSON('https://graph.facebook.com/209594052400529/notes?access_token=AAACEdEose0cBAPK9ZCgeFmZBLl4ldzAEBuJQNjyjerk3Tv2qTBc3npUKzl2sQQ47MeSOz3gXYwPbEF2qDQ8LKEjNZCZCHZCYZD&limit=1&callback=?', function(json) {
 $.each(json.data, function() {
var subject = (this.subject);
 $('<li></li>')
 .append('<a href="http://www.facebook.com/note.php?note_id=' + this.id + '" target="_blank"><h3>' + subject + '</h3></a>' + this.message + '<span class="more">...<a href="http://www.facebook.com/note.php?note_id=' + this.id + '" target="_blank">read more</a></span></p><span class="share"><a class="tweet" href="javascript:void(0);"  onclick="openWindow(\'http://twitter.com/share?url=http://www.facebook.com/note.php?note_id=' + this.id + '&amp;via=' + twtruser + '&amp;text=' + this["regular-title"] + ' \', \'follow\',530,340);">tweet</a>&nbsp;<a class="fb" href="javascript:void(0);"  onclick="openWindow(\'http://facebook.com/sharer.php?u=http://www.facebook.com/note.php?note_id=' + this.id + '\', \'follow\',530,340);">fb</a></span>')
 .appendTo('.news ul');
});
});

//E4M--------------------------------------------------------------------------------------

$('input.clear').each(function() {
	$(this)
		.data('default', $(this).val())
		.addClass('inactive')
		.focus(function() {
			$(this).removeClass('inactive');
			if ($(this).val() == $(this).data('default') || '') {
				$(this).val('');
			}
		})
		.blur(function() {
			var default_val = $(this).data('default');
			if ($(this).val() == '') {
				$(this).addClass('inactive');
				$(this).val($(this).data('default'));
			}
		});
	});

$('#signup').submit(function() { 
        $(this).ajaxSubmit();
        $('#email').val('thanks!');
		return false; 
	});

});//end
