 $(document).ready(function(){
	
	
	var move=1;
	$("#forwardWeek").click(function(){
		var pos = $("#weekNav").css("left");
		pos = pos.replace(/px/, "");
		pos = parseInt(pos);
		if(move==1 && pos>-5390){
			pos = pos - 490;
			move=0;
			$("#weekNav").animate({ 
        		"left": pos+"px"
      			}, 1000, function(){ move=1; } );
		}
		return false;
	});
	$("#previousWeek").click(function(){
		var pos = $("#weekNav").css("left");
		pos = pos.replace(/px/, "");
		pos = parseInt(pos);
		if(move==1 && pos!=0){
			pos = pos + 490;
			move=0;
			$("#weekNav").animate({ 
        		"left": pos+"px"
      		}, 1000, function(){ move=1; } );
		}
		return false;
	});
	
	$('a.lightbox').lightBox();
	
	
	$(".toggle").click(function(){
		var attending = $(this).attr("rel");
		if(attending=="off") {
			$(this).attr("rel","on").css("background-position","0px 0px");
			var id = $(this).attr("id"); 
			
			$.post("framework/events/joinEvent.php", { eventID: id, attending: '1' },
				function(data){
				}
			);
			
		}
		if(attending=="on"){
			$(this).attr("rel","off").css("background-position","-44px 0px");
			var id = $(this).attr("id"); 
			
			$.post("framework/events/joinEvent.php", { eventID: id, attending: '0' },
				function(data){
				}
			);
		}
		
	});
	
	$(".addCalendar").click(function(){
		
			$(this).fadeOut();
			var id = $(this).attr("id"); 
			
			$.post("framework/events/joinEvent.php", { eventID: id, attending: '1' },
				function(data){
				}
			);
			return false;
		
		
	});
	
//search everything

var searchWords=$("#anythingSearch").val();
 $("#anythingSearch").focus(function(){
 	if($("#anythingSearch").val()==searchWords) $("#anythingSearch").val('');
 });
  $("#anythingSearch").blur(function(){
 	if($("#anythingSearch").val()=='') $("#anythingSearch").val(searchWords);
 });






//end search everything
	
//business search
 var bizSearchWords=$("#bizSearch").val();
 $("#bizSearch").focus(function(){
 	//alert($("#bizSearch").val() + bizSearchWords);
 	if($("#bizSearch").val()==bizSearchWords) $("#bizSearch").val('');
 });
  $("#bizSearch").blur(function(){
 	if($("#bizSearch").val()=='') $("#bizSearch").val(bizSearchWords);
 });
 
 $("#bizSearch").keyup(function(event){
	var searchval = $("#bizSearch").val();
		if($("#bizSearch").val().length>0) {
			$.get("framework/business/liveSearch.php", { q: searchval },
				function(data){
					$("#businessContentBizSearch .searchResults").html(data);
				}
			);
		}
	});
//end business search
 
 
 //cat search
 var bizCatWords=$("#catSearch").val();
 $("#catSearch").focus(function(){
 	
 	if($("#catSearch").val()==bizCatWords) $("#catSearch").val('');
 });
  $("#catSearch").blur(function(){
 	if($("#catSearch").val()=='') $("#catSearch").val(bizCatWords);
 });
 
 $("#catSearch").keyup(function(event){
	var searchval = $("#catSearch").val();
		if($("#catSearch").val().length>0) {
			$.get("framework/business/liveCatSearch.php", { q: searchval },
				function(data){
					$("#businessContentCatSearch .searchResults").html(data);
				}
			);
		}
	});
//end cat search
 
 
//sidebar login script

$("#sideLogin").submit(function(){
	var usernameval = $("#sideLoginUsername").val();
	var passwordval = $("#sideLoginPassword").val();
	
	$.post("authenticate.php", { username: usernameval, password: passwordval, action: "login" },function(data){
		
		
		
		if(data.pass==1){ // if username and password were valid
							//console.log("passed");
							
							//creating cookie... no expirey for now, so it will end on browser close
							var date = new Date();
							date.setTime(date.getTime()+(7*24*60*60*1000));
							var expires = "expires="+date.toGMTString();

							document.cookie = "token"+"="+data.token+"; " + expires +"; path=/";
							
							window.location="/";
							return(false);
						}
						else{
							
							$(".error").html(data.message).slideDown();
							return(false);
						}
						
						
	},"json");
	
	return false;
});



$("#showComment").click(function(){
	$("#postComment").slideToggle("slow");
	return false;
})

//end sidebar login 
 
 
 
//add event submit

  $(".eventType").change(function(){	
 
 	if($(this).val()=="3")
 		$(".groupDropDown").slideDown();
 	else
 		$(".groupDropDown").slideUp();
 	
 });
 
 $(".findACategory").click(function(){
 	$(this).addClass("current");
 	$(".searchResults").empty();
 	$(".findABusiness").removeClass("current");
 	$("#businessContentBizSearch").fadeOut("fast",function(){
 		$("#businessContentCatSearch").fadeIn();
 	});
 	
 	return(false);
 });
 
  $(".findABusiness").click(function(){
 	$(this).addClass("current");
 	$(".searchResults").empty();
 	$(".findACategory").removeClass("current");
 	$("#businessContentCatSearch").fadeOut("fast",function(){
 		$("#businessContentBizSearch").fadeIn();
 	});
 	
 	return(false);
 });
 
 
 });
 
