// JavaScript Document

$(document).ready(function() {

//	$('#tweets').tweetable({username: 'fakhreldine', time: true, limit: 5});
	
	// Get latest 6 tweets by jQueryHowto
    $.jTwitter('fakhreldine', 5, function(data){
        
        var num_posts = 0 ;
        var followers = 0 ;
		$('#tweets').empty();
        $.each(data, function(i, post){
            profile_pic = post.user.profile_image_url ;
            if ( post.user.statuses_count > num_posts ) num_posts = post.user.statuses_count ;
            followers = post.user.followers_count ;
            $('#tweets').append(
                '<div id="post' + (i+1) + '">'
                // +' <div class="txt">'
                // See output-demo.js file for details
				+	 '<span class="txt">'
                +    post.text.replace(/(https?:\/\/[^ ;|\\*'"!,()<>]+\/?)/g,'<a href="$1" target="_blank">$1</a>')
				+	 '</span>'
				+	 '<div class="date">'
				+    H( post.created_at )
				+	 '<span class="from"> via '
				+    post.source
				+	 '</span>'
				+	 '</div>'
                // +' </div>'
                +'</div>'
            );
        });

        $('#profile #avatar').html('<img src="' + profile_pic + '" />');
        $('#profile #account').html('<a href="http://twitter.com/fakhreldine" target="_blank">follow fakhreldine</a> on twitter<br><span class="followers">Followers: ' + followers + ', Posts: ' + num_posts + '</span>') ;
		
    	$('#tweets').cycle({
			fx: 'scrollUp', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			timeout: 8000
		});
		
	});
	
    $('#reviews').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		timeout: 9000
	});

    $("a.gallery_lib").fancybox({
        'transitionIn'    :    'elastic',
        'transitionOut'    :    'elastic',
        'speedIn'        :    600, 
        'speedOut'        :    200, 
        'overlayShow'    :    true
    });

    $(".more").click(function() {
       $("#more").toggle('slow');
    });

});

// from http://widgets.twimg.com/j/1/widget.js
var K = function () {
    var a = navigator.userAgent;
    return {
        ie: a.match(/MSIE\s([^;]*)/)
    }
}();
 
var H = function (a) {
    var b = new Date();
    var c = new Date(a);
    if (K.ie) {
        c = Date.parse(a.replace(/( \+)/, ' UTC$1'))
    }
    var d = b - c;
    var e = 1000,
        minute = e * 60,
        hour = minute * 60,
        day = hour * 24,
        week = day * 7;
    if (isNaN(d) || d < 0) {
        return ""
    }
    if (d < e * 7) {
        return "right now"
    }
    if (d < minute) {
        return Math.floor(d / e) + " seconds ago"
    }
    if (d < minute * 2) {
        return "about 1 minute ago"
    }
    if (d < hour) {
        return Math.floor(d / minute) + " minutes ago"
    }
    if (d < hour * 2) {
        return "about 1 hour ago"
    }
    if (d < day) {
        return Math.floor(d / hour) + " hours ago"
    }
    if (d > day && d < day * 2) {
        return "yesterday"
    }
    if (d < day * 365) {
        return Math.floor(d / day) + " days ago"
    } else {
        return "over a year ago"
    }
};

var win = null;

function openBooking(){

	if(win != null){
  	win.close();
  	}
	w = 800
	h = 400
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	MyPage="http://www.opentable.com/single.aspx?rid=4513&restref=4513";
	MyName="bookingpopup";
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',location=no,directories=no,status=no,menubar=no,scrollbars=yes,toolbar=no,resizable=no,alwaysraised=yes,dependent=yes';
//	Win = window.open(MyPage, MyName, settings);
//	Win.focus();
    LBDirect_Popup('UK-RES-FAKHRELDINE_116411:24743','en-GB,0,79BCFF,CC0099,df,000000,0,,FFFFFF,');
}
