$(document).ready(function(){
	
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Rollovers for images
	
	$('.roll').hover(function(){
		$(this).attr("src", $(this).attr("src").replace(/_off/, '_on'));
	},function(){
		$(this).attr("src", $(this).attr("src").replace(/_on/, '_off'));
	});
	
	
	more_state = "right";
	$("#more").click(function () {
		
		if(more_state == "right"){
			$("#more").attr("src", $("#more").attr("src").replace(/_right/, '_down'));
			$("#tags").animate({
				height: 95
			}, 200, function() {
				more_state = "down";
			});
		} else {
			$("#more").attr("src", $("#more").attr("src").replace(/_down/, '_right'));
			$("#tags").animate({
				height: 28
			}, 200, function() {
				more_state = "right";
			});
		}

	});
	
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Search Field Actions
	
	if($("#search").val() != 'Look for a tag...'){
		$("#search").removeClass('blurred');
		$("#search").addClass('focused');
	}
	
	$("#search").focus(function(){
		if($(this).val() == 'Look for a tag...'){
			$(this).val('');
			$(this).removeClass('blurred');
			$(this).addClass('focused');
		}
	});
	
	$("#search").blur(function(){
		if($(this).val() == ''){
			$(this).val('Look for a tag...');
			$(this).removeClass('focused');
			$(this).addClass('blurred');
		}
	});
	
	$("#search").keydown(function(event){
		if(event.keyCode == 13){
			
			needle = $(this).val();
			//document.location.href='http://domain.com/search/'+needle+'/';
			
			$.ajax({
				type: "GET",
				url: "http://contactbenhaynes.com/business/projects.php",
				data: "q="+needle,
				success: function(msg){
					$("#panels").html(msg);
				}
			});
			
		}
	});
	
	$(".tag").click(function () {
			
		tag = $(this).html();
		
		$.ajax({
			type: "GET",
			url: "http://contactbenhaynes.com/business/projects.php",
			data: "q="+tag,
			success: function(msg){
				$("#panels").html(msg);
			}
		});
		
		return false;
			
	});
	
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// For slideshow
	/*
	$('.slideshow').cycle({ 
		timeout: 0, 
		speed:   300,
		prev:    '.slideshow_prev',
        next:    $this,
        after:   function() {
            //$('#caption').html(this.alt);
        }
	}); 
	*/
	$('.slideshow').each(function() {
		var p = this.parentNode;
		$(this).cycle({
			speed: 300,
			timeout: 0,
			next: $('a.next', p),
			prev: $('a.prev', p)
		});
	});
	
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// AJAX Log in
	
	function log_in(){
		username = $('#site_username').val();
		password = $('#site_password').val();
		
		$.ajax({
			type: "POST",
			url: "http://domain.com/inc/login.php",
			data: "username="+username+"&password="+password,
			success: function(msg){
				if(msg == 'success'){
					//window.location="index.php";
					//alert('You have successfully logged in!');
					window.location.reload(true);
				} else {
					alert('Incorrect: Please check your username or password.');
				}
			}
		});
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
});

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
