/** TWEETER JSON API**/
/* 	Author: Ryan Sandagon
	Date: 20 June 2009
	How to Use: Simply replace userName and numTweets
*/

var userName = 'rsandagon';
var numTweets = 1;
var pl = $("<img src='images/loader.gif' alt='loading'/>");
	
function displayTweet(twitters){
		$(pl).remove();
		
		for(i=0;i<numTweets;i++){
			var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
			  return '<a href="'+url+'" style="color:#fff">'+url+'</a>';
			}).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
			  return  reply.charAt(0)+'<a href="http://www.twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
			});
			
			var image = twitters[i].user.profile_image_url.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
			  return '<img src="'+url+'" alt=""/>';
			});
			
			$('#tweet').html('<p class="footerP">'+status+'</p>');
		}
};


$(document).ready(function(){

/**1. Pretty Photo **/
$("a[rel^='prettyPhoto']").prettyPhoto();  

/**2. cycle rotation **/

$('#cycle_gallery').cycle({ 
    fx:     'scrollLeft', 
    speed:  'slow', 
    timeout: 6000, 
	pager: '#nav-menu',
	pagerEvent: 'mouseover',
	pause: 1
});
	
	
//testimonials
$('#quoteWrapper').cycle({ 
    fx:     'fade', 
    speed:  'slow', 
    timeout: 6000, 
	pause: 1
});
	
//SCROLL TO
$.scrollTo( 0 );

$('#homeFooter,#homeMenu').click(function(){
		$.scrollTo( '#header', 800 );
		return false;
});

$('#aboutMeFooter,#aboutMeMenu').click(function(){
		$.scrollTo( '#aboutMeH2', 800 );
		return false;
});

$('#portfolioFooter,#portfolioMenu').click(function(){
		$.scrollTo( '#portfolioH2', 800 );
		return false;
});

$('#servicesFooter,#servicesMenu').click(function(){
		$.scrollTo( '#clouds', 800 );
		return false;
});
	
	
/**3. This part for the 'Contact Us' Box**/	
	$('#badge,#contactUsFooter,#contactUsMenu').click(function() { 	 	 	 
        $.blockUI({ 
            message: $('#ContactUsBox'), 
            css: { top: '20%',width:'400px',height:'450px' } 
        });
		return false;
    }); 
	
	$('#closeBoxBtn').click(function(){
		$.unblockUI();
		return false;
	});

/**4. Fix PNG**/
	$("#header-wrapper").pngFix();
	$(".cycle_gallery").pngFix();
	$(".bannerItem").pngFix();
	
/**5. Tweeter**/
	$('#tweet').html(pl);	
	$.getScript("http://twitter.com/statuses/user_timeline/"+userName+".json?callback=displayTweet&count="+numTweets);
	
});