//Common jQuery Stuff

$(document).ready(function() {
	
	//Tooltips
	if(jQuery().tipsy) {
		$('.tooltip').tipsy({gravity: 's', fade: true});
		$('img.tooltip').tipsy({gravity: 's', fade: true, title: 'alt'});
	}
	
	//Clear Search on Focus
	$('input[type=search]').focus(function() {
		if ($(this).val() == "Search") {
			$(this).val("");
		}
	});

	//Embed Button
	$('#embed').hide();
	$('.btn-embed').click(function(){
		$('#embed').slideToggle("fast");
	});	
	
	//Share Button
	$('#share').hide();
	$('.btn-share').click(function(){
		$('#share').slideToggle("fast");
	});
	
	//Messages
	$('.msg').delay(3000).fadeOut(2000);
	$('.msg').hover(function(){
		$(this).stop(true, true).fadeIn("fast");
	},function(){
		$(this).stop(true, true).fadeOut(2000);
	});
	
	$('.msg').click(function(){
		$(this).stop(true, true).fadeOut(2000);
	});
	
	
	//Toggle Divs
	$('.toggle').next('div').hide();
	$('.toggle').click(function () {
		$(this).next('div').slideToggle("slow");
		$(this).addClass('active');
	});

	//Scroll To Top
	$("#scroll").hide().removeAttr("href");
		
	$(window).scroll(function () {
		if($(window).scrollTop()=="0") {
			$("#scroll").fadeOut("slow")
		} else {
			$("#scroll").fadeIn("slow")
		}
	});
	
	//Highlight Form Field
	$('.crud form input[type=text], .crud form textarea').focus(function() {
		$('.crud form').find('div').removeClass('active');
		$(this).parent('div').addClass('active');
	});	
	
	$("#scroll").click(function() {
		$('html, body').animate({scrollTop:0}, 'slow')
	});
	
	//Zebra Table Rows For Older Browsers 
	//??not working??
	//$('tr:nth-child(odd)').addclass('odd');
			
	//Animated Anchor Scroll
	$('a[href*=#]').click(function(event) {
		event.preventDefault();
		
		var anchor = this.href.split("#");
		var anchor = anchor[1];
		var anchor = $("#"+anchor).offset().top;
	
		$("html, body").animate({scrollTop: anchor}, 'slow');
	});
	
	//Confirm
	$('.confirm').click(function() { 
		var confirmed = confirm('Are you sure you want to do this?');
		
		if (!confirmed) {
			return false;
		}
	});
	
	//Sortable Tables
	$('.sort').click(function(event) { 
//		event.preventDefault();
		
//		var location= $(this).attr("href");
//		$(this).removeAttr('href');
 
//		$('.sortable').load(location) 
		
		
	});		
	
});

