//define a few global variables

//var myServices=new Array("blog","twitter","delicious","youtube","facebook","friendfeed","smugmug","digg");
var myServices=new Array();
var terms = '';

// friendfeed: name of user who's feed we want to retrieve
var usr = 'davidcatalano';
var nam = 'David Catalano';


// RUN ONCE THE DOM IS READY!!!!!
$(document).ready(function() {

	
	//Set the Scrolling area to the current size of the browser window
	setScroller();

	// Rebuild scroller when window is resized
	$(window).bind("resize", setScroller);

	// initialize friendFeed
	friendFeed();

    // initialize scrollable  
    $("div.about").scrollable({items:'.elements', size: 1});  
    $("div.scrollable").scrollable();  
	$("div.banner").scrollable({vertical:true, size: 1});

	initializeBannerControls(); //this needs to be refactored BIGTIME!
	initializeFilterControls(); //this needs to be refactored BIGTIME!

//Services Scroll Controls
	$("a.older").click(function () { 
		var api = $("div.scrollable:first").scrollable(); 
		api.nextPage();
	});
	$("a.newer").click(function () { 
		var api = $("div.scrollable:first").scrollable(); 
		api.prevPage();
	});
	$("a.oldest").click(function () { 
		var api = $("div.scrollable:first").scrollable(); 
		api.end();
	});
	$("a.newest").click(function () { 
		var api = $("div.scrollable:first").scrollable(); 
		api.begin();
	});

//About Scroll Controls
	$("a.about-next").click(function () { 
		var api = $("div.about:first").scrollable(); 
		api.nextPage();
	});
	$("a.about-prev").click(function () { 
		var api = $("div.about:first").scrollable(); 
		api.prevPage();
	});

//Search Box
	$("a.srch").click(function () {
		terms = $("#search-box").val();
		$("a.srch").hide();
		$("a.srch-close").show();
		friendFeed();
		return false;
	});

	$("#search-box").focus(function() {
        //$(this).attr("value","");
    });
	$("#search-box").blur(function() {
		//clear the term value and requery FriendFeed if the value is blank and we previously searched for something (term wasn't blank)
        if(($(this).val() == "") && (terms != "")) {
			$(this).attr("value","");
			terms = "";
			$("a.srch").show();
			$("a.srch-close").hide();
			friendFeed();
		}
		//WHATS GOING ON HERE - HOW DOES THIS IMPACT THE CLOSE SEARCH BUTTON?
		terms = $("#search-box").val();
    });
	
	//Search Box (user presses Return key
	$("#search-form").submit(function () {
		terms = $("#search-box").val();
		friendFeed();
		$("a.srch").hide();
		$("a.srch-close").show();
		return false;
	});

	//Clear Search Button
	$("a.srch-close").click(function () {
		terms = "";
		$("a.srch-close").hide();
		$("a.srch").show();
		$("#search-box").val("");
		friendFeed();
		return false;
	});


	//Subscribe Box
	$("#feed-checkbox").click(function () { 
		if ($('#feed-checkbox').is(':checked')) {
			 //alert("box was checked");
			 $("#feed-name").attr('value', 'Blog Posts and Micro Posts on DavidCatalano.com');
			 $("#feed-url").attr('value', 'http://feeds.feedburner.com/~e?ffid=2055779');
		}
		else {
			 $("#feed-name").attr('value', 'Blog Posts on DavidCatalano.com');
			 $("#feed-url").attr('value', 'http://feeds.feedburner.com/~e?ffid=2055713');
		}
	});

	//Clear email box upon entering
	$("#email-input").focus(function () {
		 if ($(this).val()=="your email address"){
			$(this).attr('value','');
		 }
	});
	$("#email-input").blur(function () {
		 if ($(this).val()=="") {
			$(this).val("your email address");
		 }
	});


});