function buka(isi){	
	$("#left").slideUp("slow");
	setTimeout(function(){	 
			$("#left").empty();
			$("#left").load(isi).slideDown('slow');
	 }, 500);
}

function comment(){
		//disable the submit button to avoid spamming
		//and change the button text to Sending...
	  $('#send').attr({'disabled' : 'true', 'value' : 'Sending...' });
	
	  var id = "";
	  var url = $('#url').val();
	  var email = $('#email').val();
	  var name = $('#name').val();
	  var comment = $('#comment').val();
	  var errorstr = "Please fix the error below:\n\n";
	  if(name.length == 0){
		var error = true;
		
		errorstr=errorstr+"Please type your name";
	  }
	  if(email.length == 0 || email.indexOf('@') == '-1'){
		var error = true;
		errorstr=errorstr+"\nPlease type your valid email address";
	  }
						
			
			if(error!=true){
			$.ajax({
		 type: "POST",
		 url: "comment.add.php",
		 data: "comment="+comment+"&name="+name+"&email="+email+"&url="+url,
		 success: function(resp){
		   //if the mail is sent remove the submit paragraph
		   //$('#send').remove();
		   //$('#toggler').remove();
		   //$('#table').remove();
		   //$('#info').html("<img src='http://www.laymark.com/i/o/07.gif'/> Thanks.. Your comment has been submitted");		   
			 $('#comments').prepend(resp).show(500);				
			 $('#send').removeAttr('disabled').attr('value', 'Submit');
		 },
		 error: function(e){
		   //show the mail failed div
			$('#fail').fadeIn(500);
			//reenable the submit button by removing attribute disabled and change the text back to Send The Message
			$('#send').removeAttr('disabled').attr('value', 'Submit');
		 }
	   });				
   }	else {$('#send').removeAttr('disabled').attr('value', 'Submit');alert(errorstr);}
}


$(function(){			
              $("#extruder").buildMbExtruder({
                position:"left",
                width:300,
                extruderOpacity:.3,
                autoCloseTime:1500,
                onExtOpen:function(){},
                onExtContentLoad:function(){},
                onExtClose:function(){}
              }); 
              $("a[rel=porto]").fancybox({
                'transitionIn'		: 'elastic',
                'transitionOut'		: 'elastic',
                'titlePosition' 	: 'over',
                'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
                  return '<span id="fancybox-title-over">Portfolio ' + (currentIndex + 1) + ' / ' + currentArray.length + ' listed. <b>' + (title.length ? ' &nbsp; ' + title : '') + '</b></span>';
                }
              });  
              $("#photo").fancybox({
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'titlePosition' 	: 'inside'
			});    
              updateIt();                 
          });
          

function updateIt() {
	$.ajax({
		type : 'GET',
		url : 'https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=andiim3&count=2',
		dataType : 'jsonp',
		error : function() {},
		success : function(hasil) {
			var theTweets = '',
				 elem = $('#update').empty();
			$.each(hasil, function(index, tweet) {
				if ( index === 4 ) {
					return false;
				}
				else {
					//if(tweet.to_user){kepada='-> '+tweet.to_user;}else{kepada='';}
					theTweets += '<table border=0 style="color:#000000;font-size:9pt;"><tr valign=top><td><img src="'+tweet.user.profile_image_url+'" width=48/></td><td><b>'+tweet.user.screen_name + '</b> ('+tweet.user.name+') <br/> '+ tweet.text + ' <br/><i>'+tweet.created_at+'</i></td></tr></table><hr/>';
				}
			});
			$('#update').append(theTweets);
			
			$.ajax({
				type : 'GET',
				url : 'http://search.twitter.com/search.json?q=andiim3',
				dataType : 'jsonp',
				error : function() {},
				success : function(results) {
					var tTweets = '';						 
					$.each(results.results, function(ind, twt) {
						if ( ind === 2 ) {
							return false;
						}
						else {
							if(twt.to_user){kepada='-> '+twt.to_user;}else{kepada='-> andiim3';}
							tTweets += '<table border=0 style="color:#000000;font-size:9pt;"><tr valign=top><td><img src="'+twt.profile_image_url+'" width=48/></td><td><b>'+twt.from_user + '</b> '+kepada+'<br/> '+ twt.text + ' <br/> <i>'+ twt.created_at + '</i> </td></tr></table><hr/>';
						}
					});
					$('#update').append(tTweets);					
				}
			});
			
			setTimeout(function(){	 
				updateIt();
	 		}, 60000);
		}
	});
}
