$(document).ready(function() {
	
	if( $('div#alerts').html() != '' ) {
		$('div#alerts').fadeIn();
		setTimeout(function() { $('div#alerts').fadeOut("fast") }, 2000);
	}
	

	$('div.above_info div.close').click(function() {
		
		$('div.above_info').fadeOut();
		
		// Grab the ID of the dialog you just hid.
		var thisId = $(this).parent().attr('id');
		
		// Make a GET request, to create a $_SESSION variable on the server with that ID and a value of 1.
		$.get("../includes/ajax_sessions.php?id=" + thisId, null, function(c) {
			
		});
		
		// This should hide the dialog for the entire time you're logged in and on the server.
		
	});
	
	
	
	/* Hide comment instructions on image pages */
	$('p.commentInstructions').hide();


	// Tinymce Plugin
			$('textarea.tinymce').tinymce({
				
				// Location of TinyMCE script
				script_url : '../includes/js/tiny_mce/tiny_mce.js',
	
				// General options
				theme : "advanced",
				plugins : "pagebreak,style,layer,table,save,advhr,advimage,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist",
	
				// Theme options
				theme_advanced_buttons1 : "mybutton,bold,italic,underline,undo,redo,link,unlink",
				theme_advanced_buttons2 : "",
				theme_advanced_buttons3 : "",
				theme_advanced_toolbar_location : "top",
				theme_advanced_toolbar_align : "center",
				theme_advanced_statusbar_location : false,
				theme_advanced_resizing : false,
	
				// Example content CSS (should be your site CSS)
				content_css : "../includes/css/tinymce.css"
	
		});
	

	/* SEARCH BAR FOCUS ACTION */
	
	$('input#navbar_search').focus(function() {
	
		if( $(this).val() == "Search Images" ) {
			$('input#navbar_search').val('');
		}
		else if( $(this).val() == "Search Questions" ) {
			$('input#navbar_search').val('');
		}
		else if( $(this).val() == "Search" ) {
			$('input#navbar_search').val('');
		}
		
	
	});
	
	$('input#navbar_search').blur(function() {
	
		if( $(this).val() == "" ) {
			$('input#navbar_search').val('Search');
		}
		
	});
	


	
	
	
	
	
	$('#user_modal input').keypress(function() {
		
		var searchVal = $(this).val();
		
		$('ul#user_modal_list').load('../includes/ajax_user_search.php?s='+searchVal);
		
	});
	
	$('a.delete_image_link').click(function() {
		return confirm('Are you sure?');
	});
	
	
	$('input#image_comment').focus(function() {
	
		$('p.commentInstructions').slideDown("fast");
	
	});
	
	$('input#image_comment').blur(function() {
	
		$('p.commentInstructions').slideUp("fast");
	
	});
	
	$('a.image_nesting_link').hover(function() {
		
		
		
		
		
		$(this).prepend('<div class="clickThroughInfo"><p></p></div>');
		
		var imgWidth = $('a.image_nesting_link img').width();
		var imgHeight = $('a.image_nesting_link img').height();
		
		$('.clickThroughInfo').css({
			'width' : 720
			//'height' : imgHeight+'px',
			//'background' : 'rgba(0, 0, 0, 0.6)'
		});
		
				
		$('.clickThroughInfo').hide().fadeIn();
		
		if( $(this).attr('href').indexOf("youtube.com") != -1 ) {
		
			$('.clickThroughInfo p').append('View Video On Youtube');
		
		} 
		
		else if( $(this).attr('href').indexOf("vimeo.com") != -1 ) {
		
			$('.clickThroughInfo p').append('View Video On Vimeo.com');
			
		} else if( $(this).attr('href').indexOf("flickr.com") != -1 ) {
		
			$('.clickThroughInfo p').append('View Image On Flickr.com');
			
		} else if( $(this).attr('href').indexOf("viddler.com") != -1 ) {
		
			$('.clickThroughInfo p').append('View Video On Viddler.com');
			
		} else {
		
			$('.clickThroughInfo p').append('<strong>Go to </strong>: ' + $(this).attr("href"));
		
		}
		
		
		
		
		
		
	}, function() {
	
		$('.clickThroughInfo').fadeOut("fast", function() { $('.clickThroughInfo').remove(); });
		
		
	});
	
	
	$('a.delete_image_link').click(function(){
		
		return confirm('Are you sure you want to delete this image?');
	});
	
	// Modal Login Form
	
	$('#log_in').click(function() {
		$('#inline_login').fadeIn("fast");
		$('div#overlay').fadeIn("fast");
		$('input#email').focus();
		return false;
	});
	
	$('div#overlay').click(function() {
		$('div#overlay').fadeOut("fast");
		$('#inline_login').fadeOut("fast");
		$('input#email').blur();
		
	});
	
	$('a.contactButtonProfileDisabled').click(function() {
	
		alert('This user doesn\'t wish to be contacted through Crit.it');
		return false;
	
	});
	
	// IMAGE PAGE FORWARD/BACK BUTTON ANIMATIONS.
	
	$('a.imageBackButton').hover(function() {
	
		$('a.imageBackButton').animate({
			'left' : '0'
		}, 20);
	
	}, function() {
	
	$('a.imageBackButton').animate({
		'left' : '-80'
	}, 20);
	
	});
	
	$('a.imageForwardButton').hover(function() {
	
		$('a.imageForwardButton').animate({
			'right' : '0'
		}, 20);
	
	}, function() {
	
	$('a.imageForwardButton').animate({
		'right' : '-80'
	}, 20);
	
	});
	
	
	
	
	
});

