/* --- RUN ON LOAD --- */

$(document).ready(function() {
	/*EXTERNAL LINKS*/
	$("a[rel='external']").attr('target','_blank');
	
	/*INSIDE SLIDESHOWS*/
	var path = document.location.pathname.split('/');
	if(path[1] == 'vbarandcafe' || path[1] == 'vbarstmarks') {
		$('#content-home').cycle({
			fx: 'fade',
			sync: true,
			delay: 500,
			timeout: 5000
		});
	}
	
	/*STYLE FORMS*/
	$("input[type='text']").focus(function() { $(this).val(""); });
	$("textarea").focus(function() { $(this).val(""); });
	$("input#go, input#click").hover(
		function() {$(this).addClass('submit-hover');},
		function() {$(this).removeClass('submit-hover');}
	);
	
	/*SLIDENAV ANIMATION*/
	$("#slidenav-container").hover(
		function() { $(this).animate({bottom: "-95px"},1000); },
		function() { $(this).animate({bottom: "-275px"},1000); }
	);
	
	/*MENU NAVIGATION*/
	$("ul.menucatlist li").hover(
		function() { $(this).addClass('hover'); },
		function() { $(this).removeClass('hover'); }
	);
	$("ul.menucatlist li").click(function() {
		$("ul.menucatlist li").removeClass('highlight');
		$(".menu-page").css('display','none');
		var menuid = $(this).attr('id');
		var menu = menuid.split('menu-');
		$(this).addClass('highlight');
		$("#page-"+menu[1]).css('display','block');
	});

	/*KARMA BOARD FUNCTIONS*/
	$('.kb-links img').hover(
		function() { $(this).css('cursor','pointer'); },
		function() { $(this).css('cursor','default'); }
	);
	$('.kb-links img').click(function() {
		$('.kboard').toggle(0,function(){
			$('#kb-status').empty();
		});
	});
	$('form input[type="text"]').focus(function(){
		$(this).val('');
	});
	$('form input#go').hover(
		function(){ $(this).attr('class','hoveron') .css('cursor','pointer'); },
		function(){ $(this).attr('class','hoveroff') .css('cursor','default'); }
	);
	$('form#karma-buy').submit(function(){
		var from = $("input#from").val();
		var to = $("input#to").val();
		var amt = $("select#amount").val();
		if((from == "") || (from == "Your First and Last Name") || (from == "First and last name is required!")) {
			$("input#from").focus();
			$("input#from").val("First and last name is required!");
			return false;
		} else if((to == "") || (to == "Recipient's First and Last Name") || (to == "First and last name is required!")) {
			$("input#to").focus();
			$("input#to").val("First and last name is required!");
			return false;
		} else if((amt == "") || (amt == "")) {
			$("select#amount").focus();
			return false;
		} else {
			$(this).attr('target','_blank');
			var dataString = $(this).serialize();
			$("#kb-status").load('http://vbar.net/include/addKarma.php?'+dataString);
			return true;
  		}
  	});
	
});
